d3d10core/tests: Test the creation of textures with invalid multisample settings.
[wine.git] / dlls / d3d10core / tests / device.c
blobf2ef89debebae49fadd73000b25162c74c220fba
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 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d11.h"
22 #include "wine/test.h"
23 #include <limits.h>
25 struct vec2
27 float x, y;
30 struct vec3
32 float x, y, z;
35 struct vec4
37 float x, y, z, w;
40 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
42 box->left = left;
43 box->top = top;
44 box->front = front;
45 box->right = right;
46 box->bottom = bottom;
47 box->back = back;
50 static ULONG get_refcount(IUnknown *iface)
52 IUnknown_AddRef(iface);
53 return IUnknown_Release(iface);
56 static BOOL compare_float(float f, float g, unsigned int ulps)
58 int x = *(int *)&f;
59 int y = *(int *)&g;
61 if (x < 0)
62 x = INT_MIN - x;
63 if (y < 0)
64 y = INT_MIN - y;
66 if (abs(x - y) > ulps)
67 return FALSE;
69 return TRUE;
72 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
74 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
75 return FALSE;
76 c1 >>= 8; c2 >>= 8;
77 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
78 return FALSE;
79 c1 >>= 8; c2 >>= 8;
80 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
81 return FALSE;
82 c1 >>= 8; c2 >>= 8;
83 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
84 return FALSE;
85 return TRUE;
88 struct texture_readback
90 ID3D10Texture2D *texture;
91 D3D10_MAPPED_TEXTURE2D mapped_texture;
94 static void get_texture_readback(ID3D10Texture2D *texture, struct texture_readback *rb)
96 D3D10_TEXTURE2D_DESC texture_desc;
97 ID3D10Device *device;
98 HRESULT hr;
100 memset(rb, 0, sizeof(*rb));
102 ID3D10Texture2D_GetDevice(texture, &device);
104 ID3D10Texture2D_GetDesc(texture, &texture_desc);
105 texture_desc.Usage = D3D10_USAGE_STAGING;
106 texture_desc.BindFlags = 0;
107 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
108 texture_desc.MiscFlags = 0;
109 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rb->texture)))
111 trace("Failed to create texture, hr %#x.\n", hr);
112 ID3D10Device_Release(device);
113 return;
116 ID3D10Device_CopyResource(device, (ID3D10Resource *)rb->texture, (ID3D10Resource *)texture);
117 if (FAILED(hr = ID3D10Texture2D_Map(rb->texture, 0, D3D10_MAP_READ, 0, &rb->mapped_texture)))
119 trace("Failed to map texture, hr %#x.\n", hr);
120 ID3D10Texture2D_Release(rb->texture);
121 rb->texture = NULL;
124 ID3D10Device_Release(device);
127 static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, unsigned int y)
129 return rb->texture
130 ? ((DWORD *)rb->mapped_texture.pData)[rb->mapped_texture.RowPitch * y / sizeof(DWORD) + x] : 0xdeadbeef;
133 static void release_texture_readback(struct texture_readback *rb)
135 if (!rb->texture)
136 return;
138 ID3D10Texture2D_Unmap(rb->texture, 0);
139 ID3D10Texture2D_Release(rb->texture);
142 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
144 struct texture_readback rb;
145 DWORD color;
147 get_texture_readback(texture, &rb);
148 color = get_readback_color(&rb, x, y);
149 release_texture_readback(&rb);
151 return color;
154 static ID3D10Device *create_device(void)
156 ID3D10Device *device;
158 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
159 return device;
160 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
161 return device;
162 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
163 return device;
165 return NULL;
168 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL windowed)
170 IDXGISwapChain *swapchain;
171 DXGI_SWAP_CHAIN_DESC desc;
172 IDXGIDevice *dxgi_device;
173 IDXGIAdapter *adapter;
174 IDXGIFactory *factory;
175 HRESULT hr;
177 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
178 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
179 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
180 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
181 IDXGIDevice_Release(dxgi_device);
182 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
183 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
184 IDXGIAdapter_Release(adapter);
186 desc.BufferDesc.Width = 640;
187 desc.BufferDesc.Height = 480;
188 desc.BufferDesc.RefreshRate.Numerator = 60;
189 desc.BufferDesc.RefreshRate.Denominator = 1;
190 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
191 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
192 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
193 desc.SampleDesc.Count = 1;
194 desc.SampleDesc.Quality = 0;
195 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
196 desc.BufferCount = 1;
197 desc.OutputWindow = window;
198 desc.Windowed = windowed;
199 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
200 desc.Flags = 0;
202 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
203 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
204 IDXGIFactory_Release(factory);
206 return swapchain;
209 static void test_feature_level(void)
211 D3D_FEATURE_LEVEL feature_level;
212 ID3D11Device *device11;
213 ID3D10Device *device10;
214 HRESULT hr;
216 if (!(device10 = create_device()))
218 skip("Failed to create device, skipping tests.\n");
219 return;
222 hr = ID3D10Device_QueryInterface(device10, &IID_ID3D11Device, (void **)&device11);
223 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
224 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
225 if (FAILED(hr))
227 win_skip("D3D11 is not available.\n");
228 ID3D10Device_Release(device10);
229 return;
232 /* Device was created by D3D10CreateDevice. */
233 feature_level = ID3D11Device_GetFeatureLevel(device11);
234 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
236 ID3D11Device_Release(device11);
237 ID3D10Device_Release(device10);
240 static void test_device_interfaces(void)
242 IDXGIAdapter *dxgi_adapter;
243 IDXGIDevice *dxgi_device;
244 ID3D10Device *device;
245 IUnknown *iface;
246 ULONG refcount;
247 HRESULT hr;
249 if (!(device = create_device()))
251 skip("Failed to create device.\n");
252 return;
255 hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
256 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
257 IUnknown_Release(iface);
259 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
260 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
261 IUnknown_Release(iface);
263 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
264 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
265 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
266 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
267 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
268 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
269 IUnknown_Release(iface);
270 IUnknown_Release(dxgi_adapter);
271 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
272 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
273 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
274 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
275 IUnknown_Release(dxgi_adapter);
276 IUnknown_Release(dxgi_device);
278 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
279 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
280 "Device should implement IDXGIDevice1.\n");
281 if (SUCCEEDED(hr)) IUnknown_Release(iface);
283 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
284 ok(SUCCEEDED(hr), "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
285 IUnknown_Release(iface);
287 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
288 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
289 "Device should implement ID3D10Device1 interface, hr %#x.\n", hr);
290 if (SUCCEEDED(hr)) IUnknown_Release(iface);
292 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&iface);
293 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
294 "Device should implement ID3D11Device interface, hr %#x.\n", hr);
295 if (SUCCEEDED(hr)) IUnknown_Release(iface);
297 refcount = ID3D10Device_Release(device);
298 ok(!refcount, "Device has %u references left.\n", refcount);
301 static void test_create_texture2d(void)
303 ULONG refcount, expected_refcount;
304 D3D10_SUBRESOURCE_DATA data = {0};
305 ID3D10Device *device, *tmp;
306 D3D10_TEXTURE2D_DESC desc;
307 ID3D10Texture2D *texture;
308 UINT quality_level_count;
309 IDXGISurface *surface;
310 HRESULT hr;
312 if (!(device = create_device()))
314 skip("Failed to create device, skipping tests.\n");
315 return;
318 desc.Width = 512;
319 desc.Height = 512;
320 desc.MipLevels = 1;
321 desc.ArraySize = 1;
322 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
323 desc.SampleDesc.Count = 1;
324 desc.SampleDesc.Quality = 0;
325 desc.Usage = D3D10_USAGE_DEFAULT;
326 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
327 desc.CPUAccessFlags = 0;
328 desc.MiscFlags = 0;
330 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
331 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
333 expected_refcount = get_refcount((IUnknown *)device) + 1;
334 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
335 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
336 refcount = get_refcount((IUnknown *)device);
337 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
338 tmp = NULL;
339 expected_refcount = refcount + 1;
340 ID3D10Texture2D_GetDevice(texture, &tmp);
341 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
342 refcount = get_refcount((IUnknown *)device);
343 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
344 ID3D10Device_Release(tmp);
346 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
347 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
348 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
349 ID3D10Texture2D_Release(texture);
351 desc.MipLevels = 0;
352 expected_refcount = get_refcount((IUnknown *)device) + 1;
353 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
354 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
355 refcount = get_refcount((IUnknown *)device);
356 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
357 tmp = NULL;
358 expected_refcount = refcount + 1;
359 ID3D10Texture2D_GetDevice(texture, &tmp);
360 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
361 refcount = get_refcount((IUnknown *)device);
362 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
363 ID3D10Device_Release(tmp);
365 ID3D10Texture2D_GetDesc(texture, &desc);
366 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
367 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
368 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
369 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
370 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
371 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
372 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
373 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
374 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
375 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
376 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
378 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
379 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
380 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
381 ID3D10Texture2D_Release(texture);
383 desc.MipLevels = 1;
384 desc.ArraySize = 2;
385 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
386 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
388 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
389 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
390 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
391 ID3D10Texture2D_Release(texture);
393 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
394 desc.ArraySize = 1;
395 desc.SampleDesc.Count = 2;
396 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
397 if (quality_level_count)
399 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
400 ID3D10Texture2D_Release(texture);
401 desc.SampleDesc.Quality = quality_level_count;
402 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
404 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
406 /* We assume 15 samples multisampling is never supported in practice. */
407 desc.SampleDesc.Count = 15;
408 desc.SampleDesc.Quality = 0;
409 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
410 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
412 refcount = ID3D10Device_Release(device);
413 ok(!refcount, "Device has %u references left.\n", refcount);
416 static void test_texture2d_interfaces(void)
418 ID3D11Texture2D *d3d11_texture;
419 D3D10_TEXTURE2D_DESC desc;
420 ID3D10Texture2D *texture;
421 IDXGISurface *surface;
422 ID3D10Device *device;
423 unsigned int i;
424 ULONG refcount;
425 HRESULT hr;
427 static const struct test
429 UINT bind_flags;
430 UINT misc_flags;
431 UINT expected_bind_flags;
432 UINT expected_misc_flags;
434 desc_conversion_tests[] =
437 D3D10_BIND_RENDER_TARGET, 0,
438 D3D11_BIND_RENDER_TARGET, 0
441 0, D3D10_RESOURCE_MISC_SHARED,
442 0, D3D11_RESOURCE_MISC_SHARED
446 if (!(device = create_device()))
448 skip("Failed to create device, skipping tests.\n");
449 return;
452 desc.Width = 512;
453 desc.Height = 512;
454 desc.MipLevels = 0;
455 desc.ArraySize = 1;
456 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
457 desc.SampleDesc.Count = 1;
458 desc.SampleDesc.Quality = 0;
459 desc.Usage = D3D11_USAGE_DEFAULT;
460 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
461 desc.CPUAccessFlags = 0;
462 desc.MiscFlags = 0;
464 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
465 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
467 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
468 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
470 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
471 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
472 "Texture should implement ID3D11Texture2D.\n");
473 if (SUCCEEDED(hr)) ID3D11Texture2D_Release(d3d11_texture);
474 ID3D10Texture2D_Release(texture);
476 if (FAILED(hr))
478 win_skip("D3D11 is not available, skipping tests.\n");
479 ID3D10Device_Release(device);
480 return;
483 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
485 const struct test *current = &desc_conversion_tests[i];
486 D3D11_TEXTURE2D_DESC d3d11_desc;
487 ID3D11Device *d3d11_device;
489 desc.Width = 512;
490 desc.Height = 512;
491 desc.MipLevels = 1;
492 desc.ArraySize = 1;
493 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
494 desc.SampleDesc.Count = 1;
495 desc.SampleDesc.Quality = 0;
496 desc.Usage = D3D10_USAGE_DEFAULT;
497 desc.BindFlags = current->bind_flags;
498 desc.CPUAccessFlags = 0;
499 desc.MiscFlags = current->misc_flags;
501 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
502 /* Shared resources are not supported by REF and WARP devices. */
503 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
504 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
505 if (FAILED(hr))
507 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
508 continue;
511 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
512 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
513 IDXGISurface_Release(surface);
515 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
516 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
517 ID3D10Texture2D_Release(texture);
519 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
521 ok(d3d11_desc.Width == desc.Width,
522 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
523 ok(d3d11_desc.Height == desc.Height,
524 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
525 ok(d3d11_desc.MipLevels == desc.MipLevels,
526 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
527 ok(d3d11_desc.ArraySize == desc.ArraySize,
528 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
529 ok(d3d11_desc.Format == desc.Format,
530 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
531 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
532 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
533 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
534 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
535 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
536 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
537 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
538 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
539 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
540 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
541 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
542 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
544 d3d11_device = NULL;
545 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
546 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
547 ID3D11Device_Release(d3d11_device);
549 ID3D11Texture2D_Release(d3d11_texture);
552 refcount = ID3D10Device_Release(device);
553 ok(!refcount, "Device has %u references left.\n", refcount);
556 static void test_create_texture3d(void)
558 ULONG refcount, expected_refcount;
559 D3D10_SUBRESOURCE_DATA data = {0};
560 ID3D10Device *device, *tmp;
561 D3D10_TEXTURE3D_DESC desc;
562 ID3D10Texture3D *texture;
563 IDXGISurface *surface;
564 HRESULT hr;
566 if (!(device = create_device()))
568 skip("Failed to create device, skipping tests.\n");
569 return;
572 desc.Width = 64;
573 desc.Height = 64;
574 desc.Depth = 64;
575 desc.MipLevels = 1;
576 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
577 desc.Usage = D3D10_USAGE_DEFAULT;
578 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
579 desc.CPUAccessFlags = 0;
580 desc.MiscFlags = 0;
582 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
583 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
585 expected_refcount = get_refcount((IUnknown *)device) + 1;
586 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
587 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
588 refcount = get_refcount((IUnknown *)device);
589 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
590 tmp = NULL;
591 expected_refcount = refcount + 1;
592 ID3D10Texture3D_GetDevice(texture, &tmp);
593 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
594 refcount = get_refcount((IUnknown *)device);
595 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
596 ID3D10Device_Release(tmp);
598 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
599 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
600 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
601 ID3D10Texture3D_Release(texture);
603 desc.MipLevels = 0;
604 expected_refcount = get_refcount((IUnknown *)device) + 1;
605 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
606 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
607 refcount = get_refcount((IUnknown *)device);
608 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
609 tmp = NULL;
610 expected_refcount = refcount + 1;
611 ID3D10Texture3D_GetDevice(texture, &tmp);
612 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
613 refcount = get_refcount((IUnknown *)device);
614 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
615 ID3D10Device_Release(tmp);
617 ID3D10Texture3D_GetDesc(texture, &desc);
618 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
619 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
620 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
621 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
622 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
623 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
624 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
625 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
626 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
628 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
629 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
630 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
631 ID3D10Texture3D_Release(texture);
633 refcount = ID3D10Device_Release(device);
634 ok(!refcount, "Device has %u references left.\n", refcount);
637 static void test_buffer_interfaces(void)
639 ID3D11Buffer *d3d11_buffer;
640 D3D10_BUFFER_DESC desc;
641 ID3D10Buffer *buffer;
642 ID3D10Device *device;
643 unsigned int i;
644 ULONG refcount;
645 HRESULT hr;
647 static const struct test
649 UINT bind_flags;
650 UINT misc_flags;
651 UINT expected_bind_flags;
652 UINT expected_misc_flags;
654 desc_conversion_tests[] =
657 D3D10_BIND_VERTEX_BUFFER, 0,
658 D3D11_BIND_VERTEX_BUFFER, 0
661 D3D10_BIND_INDEX_BUFFER, 0,
662 D3D11_BIND_INDEX_BUFFER, 0
665 D3D10_BIND_CONSTANT_BUFFER, 0,
666 D3D11_BIND_CONSTANT_BUFFER, 0
669 D3D10_BIND_SHADER_RESOURCE, 0,
670 D3D11_BIND_SHADER_RESOURCE, 0
673 D3D10_BIND_STREAM_OUTPUT, 0,
674 D3D11_BIND_STREAM_OUTPUT, 0
677 D3D10_BIND_RENDER_TARGET, 0,
678 D3D11_BIND_RENDER_TARGET, 0
681 0, D3D10_RESOURCE_MISC_SHARED,
682 0, D3D11_RESOURCE_MISC_SHARED
686 if (!(device = create_device()))
688 skip("Failed to create device.\n");
689 return;
692 desc.ByteWidth = 1024;
693 desc.Usage = D3D10_USAGE_DEFAULT;
694 desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
695 desc.CPUAccessFlags = 0;
696 desc.MiscFlags = 0;
698 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
699 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
701 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
702 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
703 "Buffer should implement ID3D11Buffer.\n");
704 if (SUCCEEDED(hr)) ID3D11Buffer_Release(d3d11_buffer);
705 ID3D10Buffer_Release(buffer);
707 if (FAILED(hr))
709 win_skip("D3D11 is not available.\n");
710 ID3D10Device_Release(device);
711 return;
714 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
716 const struct test *current = &desc_conversion_tests[i];
717 D3D11_BUFFER_DESC d3d11_desc;
718 ID3D11Device *d3d11_device;
720 desc.ByteWidth = 1024;
721 desc.Usage = D3D10_USAGE_DEFAULT;
722 desc.BindFlags = current->bind_flags;
723 desc.CPUAccessFlags = 0;
724 desc.MiscFlags = current->misc_flags;
726 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
727 /* Shared resources are not supported by REF and WARP devices. */
728 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
729 if (FAILED(hr))
731 win_skip("Failed to create a buffer, skipping test %u.\n", i);
732 continue;
735 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
736 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
737 ID3D10Buffer_Release(buffer);
739 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
741 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
742 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
743 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
744 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
745 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
746 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
747 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
748 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
749 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
750 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
751 ok(d3d11_desc.StructureByteStride == 0,
752 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
754 d3d11_device = NULL;
755 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
756 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
757 ID3D11Device_Release(d3d11_device);
759 ID3D11Buffer_Release(d3d11_buffer);
762 refcount = ID3D10Device_Release(device);
763 ok(!refcount, "Device has %u references left.\n", refcount);
766 static void test_create_depthstencil_view(void)
768 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
769 D3D10_TEXTURE2D_DESC texture_desc;
770 ULONG refcount, expected_refcount;
771 ID3D10DepthStencilView *dsview;
772 ID3D10Device *device, *tmp;
773 ID3D10Texture2D *texture;
774 HRESULT hr;
776 if (!(device = create_device()))
778 skip("Failed to create device, skipping tests.\n");
779 return;
782 texture_desc.Width = 512;
783 texture_desc.Height = 512;
784 texture_desc.MipLevels = 1;
785 texture_desc.ArraySize = 1;
786 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
787 texture_desc.SampleDesc.Count = 1;
788 texture_desc.SampleDesc.Quality = 0;
789 texture_desc.Usage = D3D10_USAGE_DEFAULT;
790 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
791 texture_desc.CPUAccessFlags = 0;
792 texture_desc.MiscFlags = 0;
794 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
795 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
797 expected_refcount = get_refcount((IUnknown *)device) + 1;
798 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
799 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr);
800 refcount = get_refcount((IUnknown *)device);
801 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
802 tmp = NULL;
803 expected_refcount = refcount + 1;
804 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
805 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
806 refcount = get_refcount((IUnknown *)device);
807 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
808 ID3D10Device_Release(tmp);
810 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
811 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
812 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
813 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
814 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
816 ID3D10DepthStencilView_Release(dsview);
817 ID3D10Texture2D_Release(texture);
819 refcount = ID3D10Device_Release(device);
820 ok(!refcount, "Device has %u references left.\n", refcount);
823 static void test_depthstencil_view_interfaces(void)
825 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
826 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
827 ID3D11DepthStencilView *d3d11_dsview;
828 D3D10_TEXTURE2D_DESC texture_desc;
829 ID3D10DepthStencilView *dsview;
830 ID3D10Texture2D *texture;
831 ID3D10Device *device;
832 ULONG refcount;
833 HRESULT hr;
835 if (!(device = create_device()))
837 skip("Failed to create device.\n");
838 return;
841 texture_desc.Width = 512;
842 texture_desc.Height = 512;
843 texture_desc.MipLevels = 1;
844 texture_desc.ArraySize = 1;
845 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
846 texture_desc.SampleDesc.Count = 1;
847 texture_desc.SampleDesc.Quality = 0;
848 texture_desc.Usage = D3D10_USAGE_DEFAULT;
849 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
850 texture_desc.CPUAccessFlags = 0;
851 texture_desc.MiscFlags = 0;
853 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
854 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
856 dsv_desc.Format = texture_desc.Format;
857 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
858 U(dsv_desc).Texture2D.MipSlice = 0;
860 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
861 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
863 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
864 ID3D10DepthStencilView_Release(dsview);
865 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
866 "Depth stencil view should implement ID3D11DepthStencilView.\n");
868 if (SUCCEEDED(hr))
870 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
871 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
872 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
873 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
874 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
875 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
876 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
878 ID3D11DepthStencilView_Release(d3d11_dsview);
880 else
882 win_skip("D3D11 is not available.\n");
885 ID3D10Texture2D_Release(texture);
887 refcount = ID3D10Device_Release(device);
888 ok(!refcount, "Device has %u references left.\n", refcount);
891 static void test_create_rendertarget_view(void)
893 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
894 D3D10_SUBRESOURCE_DATA data = {0};
895 D3D10_TEXTURE2D_DESC texture_desc;
896 ULONG refcount, expected_refcount;
897 D3D10_BUFFER_DESC buffer_desc;
898 ID3D10RenderTargetView *rtview;
899 ID3D10Device *device, *tmp;
900 ID3D10Texture2D *texture;
901 ID3D10Buffer *buffer;
902 IUnknown *iface;
903 HRESULT hr;
905 if (!(device = create_device()))
907 skip("Failed to create device, skipping tests.\n");
908 return;
911 buffer_desc.ByteWidth = 1024;
912 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
913 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
914 buffer_desc.CPUAccessFlags = 0;
915 buffer_desc.MiscFlags = 0;
917 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
918 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
920 expected_refcount = get_refcount((IUnknown *)device) + 1;
921 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
922 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
923 refcount = get_refcount((IUnknown *)device);
924 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
925 tmp = NULL;
926 expected_refcount = refcount + 1;
927 ID3D10Buffer_GetDevice(buffer, &tmp);
928 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
929 refcount = get_refcount((IUnknown *)device);
930 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
931 ID3D10Device_Release(tmp);
933 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
934 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
935 U(rtv_desc).Buffer.ElementOffset = 0;
936 U(rtv_desc).Buffer.ElementWidth = 64;
938 expected_refcount = get_refcount((IUnknown *)device) + 1;
939 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
940 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
941 refcount = get_refcount((IUnknown *)device);
942 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
943 tmp = NULL;
944 expected_refcount = refcount + 1;
945 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
946 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
947 refcount = get_refcount((IUnknown *)device);
948 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
949 ID3D10Device_Release(tmp);
951 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
952 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
953 "Render target view should implement ID3D11RenderTargetView.\n");
954 if (SUCCEEDED(hr)) IUnknown_Release(iface);
956 ID3D10RenderTargetView_Release(rtview);
957 ID3D10Buffer_Release(buffer);
959 texture_desc.Width = 512;
960 texture_desc.Height = 512;
961 texture_desc.MipLevels = 1;
962 texture_desc.ArraySize = 1;
963 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
964 texture_desc.SampleDesc.Count = 1;
965 texture_desc.SampleDesc.Quality = 0;
966 texture_desc.Usage = D3D10_USAGE_DEFAULT;
967 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
968 texture_desc.CPUAccessFlags = 0;
969 texture_desc.MiscFlags = 0;
971 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
972 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
974 /* For texture resources it's allowed to specify NULL as desc */
975 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
976 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
978 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
979 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
980 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
981 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
982 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
984 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
985 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
986 "Render target view should implement ID3D11RenderTargetView.\n");
987 if (SUCCEEDED(hr)) IUnknown_Release(iface);
989 ID3D10RenderTargetView_Release(rtview);
990 ID3D10Texture2D_Release(texture);
992 refcount = ID3D10Device_Release(device);
993 ok(!refcount, "Device has %u references left.\n", refcount);
996 static void test_create_shader_resource_view(void)
998 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
999 D3D10_TEXTURE2D_DESC texture_desc;
1000 ULONG refcount, expected_refcount;
1001 ID3D10ShaderResourceView *srview;
1002 D3D10_BUFFER_DESC buffer_desc;
1003 ID3D10Device *device, *tmp;
1004 ID3D10Texture2D *texture;
1005 ID3D10Buffer *buffer;
1006 IUnknown *iface;
1007 HRESULT hr;
1009 if (!(device = create_device()))
1011 skip("Failed to create device, skipping tests.\n");
1012 return;
1015 buffer_desc.ByteWidth = 1024;
1016 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1017 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1018 buffer_desc.CPUAccessFlags = 0;
1019 buffer_desc.MiscFlags = 0;
1021 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1022 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
1024 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
1025 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1027 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1028 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
1029 U(srv_desc).Buffer.ElementOffset = 0;
1030 U(srv_desc).Buffer.ElementWidth = 64;
1032 expected_refcount = get_refcount((IUnknown *)device) + 1;
1033 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
1034 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
1035 refcount = get_refcount((IUnknown *)device);
1036 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1037 tmp = NULL;
1038 expected_refcount = refcount + 1;
1039 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
1040 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1041 refcount = get_refcount((IUnknown *)device);
1042 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1043 ID3D10Device_Release(tmp);
1045 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1046 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1047 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1048 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1049 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
1050 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1051 "Shader resource view should implement ID3D11ShaderResourceView.\n");
1052 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1054 ID3D10ShaderResourceView_Release(srview);
1055 ID3D10Buffer_Release(buffer);
1057 texture_desc.Width = 512;
1058 texture_desc.Height = 512;
1059 texture_desc.MipLevels = 0;
1060 texture_desc.ArraySize = 1;
1061 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1062 texture_desc.SampleDesc.Count = 1;
1063 texture_desc.SampleDesc.Quality = 0;
1064 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1065 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1066 texture_desc.CPUAccessFlags = 0;
1067 texture_desc.MiscFlags = 0;
1069 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1070 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1072 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srview);
1073 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
1075 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
1076 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1077 ok(srv_desc.ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D,
1078 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1079 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1080 U(srv_desc).Texture2D.MostDetailedMip);
1081 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1083 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1084 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1085 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1086 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1087 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
1088 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1089 "Shader resource view should implement ID3D11ShaderResourceView.\n");
1090 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1092 ID3D10ShaderResourceView_Release(srview);
1093 ID3D10Texture2D_Release(texture);
1095 refcount = ID3D10Device_Release(device);
1096 ok(!refcount, "Device has %u references left.\n", refcount);
1099 static void test_create_shader(void)
1101 #if 0
1102 float4 light;
1103 float4x4 mat;
1105 struct input
1107 float4 position : POSITION;
1108 float3 normal : NORMAL;
1111 struct output
1113 float4 position : POSITION;
1114 float4 diffuse : COLOR;
1117 output main(const input v)
1119 output o;
1121 o.position = mul(v.position, mat);
1122 o.diffuse = dot((float3)light, v.normal);
1124 return o;
1126 #endif
1127 static const DWORD vs_4_0[] =
1129 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1130 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1131 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1132 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1133 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1134 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1135 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1136 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1137 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1138 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1139 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1140 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1141 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1142 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1143 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1144 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1147 static const DWORD vs_2_0[] =
1149 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1150 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1151 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1152 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1153 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1154 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1155 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1156 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
1157 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
1158 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
1159 0x90e40001, 0x0000ffff,
1162 static const DWORD vs_3_0[] =
1164 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
1165 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1166 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1167 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1168 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1169 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1170 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1171 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
1172 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
1173 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
1174 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
1175 0x0000ffff,
1178 #if 0
1179 float4 main(const float4 color : COLOR) : SV_TARGET
1181 float4 o;
1183 o = color;
1185 return o;
1187 #endif
1188 static const DWORD ps_4_0[] =
1190 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
1191 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
1192 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
1193 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
1194 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
1195 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1196 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
1197 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1198 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
1199 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
1200 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
1201 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
1202 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1203 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1204 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1205 0x00000000, 0x00000000,
1208 #if 0
1209 struct gs_out
1211 float4 pos : SV_POSITION;
1214 [maxvertexcount(4)]
1215 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1217 float offset = 0.1 * vin[0].w;
1218 gs_out v;
1220 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1221 vout.Append(v);
1222 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1223 vout.Append(v);
1224 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1225 vout.Append(v);
1226 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1227 vout.Append(v);
1229 #endif
1230 static const DWORD gs_4_0[] =
1232 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1233 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1234 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1235 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1236 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1237 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1238 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1239 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1240 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1241 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1242 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1243 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1244 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1245 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1246 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1247 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1248 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1249 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1252 ULONG refcount, expected_refcount;
1253 ID3D10Device *device, *tmp;
1254 ID3D10GeometryShader *gs;
1255 ID3D10VertexShader *vs;
1256 ID3D10PixelShader *ps;
1257 IUnknown *iface;
1258 HRESULT hr;
1260 if (!(device = create_device()))
1262 skip("Failed to create device, skipping tests.\n");
1263 return;
1266 /* vertex shader */
1267 expected_refcount = get_refcount((IUnknown *)device) + 1;
1268 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
1269 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
1271 refcount = get_refcount((IUnknown *)device);
1272 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1273 tmp = NULL;
1274 expected_refcount = refcount + 1;
1275 ID3D10VertexShader_GetDevice(vs, &tmp);
1276 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1277 refcount = get_refcount((IUnknown *)device);
1278 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1279 ID3D10Device_Release(tmp);
1281 hr = ID3D10VertexShader_QueryInterface(vs, &IID_ID3D11VertexShader, (void **)&iface);
1282 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1283 "Vertex shader should implement ID3D11VertexShader.\n");
1284 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1286 refcount = ID3D10VertexShader_Release(vs);
1287 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
1289 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
1290 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
1292 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
1293 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
1295 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
1296 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
1298 /* pixel shader */
1299 expected_refcount = get_refcount((IUnknown *)device) + 1;
1300 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
1301 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
1303 refcount = get_refcount((IUnknown *)device);
1304 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1305 tmp = NULL;
1306 expected_refcount = refcount + 1;
1307 ID3D10PixelShader_GetDevice(ps, &tmp);
1308 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1309 refcount = get_refcount((IUnknown *)device);
1310 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1311 ID3D10Device_Release(tmp);
1313 hr = ID3D10PixelShader_QueryInterface(ps, &IID_ID3D11PixelShader, (void **)&iface);
1314 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1315 "Pixel shader should implement ID3D11PixelShader.\n");
1316 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1318 refcount = ID3D10PixelShader_Release(ps);
1319 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
1321 /* geometry shader */
1322 expected_refcount = get_refcount((IUnknown *)device) + 1;
1323 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
1324 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
1326 refcount = get_refcount((IUnknown *)device);
1327 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1328 tmp = NULL;
1329 expected_refcount = refcount + 1;
1330 ID3D10GeometryShader_GetDevice(gs, &tmp);
1331 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1332 refcount = get_refcount((IUnknown *)device);
1333 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1334 ID3D10Device_Release(tmp);
1336 hr = ID3D10GeometryShader_QueryInterface(gs, &IID_ID3D11GeometryShader, (void **)&iface);
1337 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1338 "Geometry shader should implement ID3D11GeometryShader.\n");
1339 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1341 refcount = ID3D10GeometryShader_Release(gs);
1342 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
1344 refcount = ID3D10Device_Release(device);
1345 ok(!refcount, "Device has %u references left.\n", refcount);
1348 static void test_create_sampler_state(void)
1350 static const struct test
1352 D3D10_FILTER filter;
1353 D3D11_FILTER expected_filter;
1355 desc_conversion_tests[] =
1357 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
1358 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
1359 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
1360 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
1361 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
1362 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
1363 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
1364 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
1365 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
1366 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
1367 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
1369 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
1370 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
1372 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
1373 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
1375 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
1376 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
1378 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
1379 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
1380 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
1383 ID3D10SamplerState *sampler_state1, *sampler_state2;
1384 ID3D11SamplerState *d3d11_sampler_state;
1385 ULONG refcount, expected_refcount;
1386 ID3D10Device *device, *tmp;
1387 ID3D11Device *d3d11_device;
1388 D3D10_SAMPLER_DESC desc;
1389 unsigned int i;
1390 HRESULT hr;
1392 if (!(device = create_device()))
1394 skip("Failed to create device, skipping tests.\n");
1395 return;
1398 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
1399 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1401 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
1402 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
1403 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
1404 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
1405 desc.MipLODBias = 0.0f;
1406 desc.MaxAnisotropy = 16;
1407 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
1408 desc.BorderColor[0] = 0.0f;
1409 desc.BorderColor[1] = 1.0f;
1410 desc.BorderColor[2] = 0.0f;
1411 desc.BorderColor[3] = 1.0f;
1412 desc.MinLOD = 0.0f;
1413 desc.MaxLOD = 16.0f;
1415 expected_refcount = get_refcount((IUnknown *)device) + 1;
1416 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
1417 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1418 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
1419 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1420 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
1421 refcount = get_refcount((IUnknown *)device);
1422 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1423 tmp = NULL;
1424 expected_refcount = refcount + 1;
1425 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
1426 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1427 refcount = get_refcount((IUnknown *)device);
1428 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1429 ID3D10Device_Release(tmp);
1431 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
1432 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
1433 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
1434 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
1435 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
1436 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
1437 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
1438 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
1439 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
1440 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
1441 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
1442 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
1443 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
1444 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
1446 refcount = ID3D10SamplerState_Release(sampler_state2);
1447 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1448 refcount = ID3D10SamplerState_Release(sampler_state1);
1449 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1451 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
1452 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1453 "Device should implement ID3D11Device.\n");
1454 if (FAILED(hr))
1456 win_skip("D3D11 is not available.\n");
1457 goto done;
1460 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1462 const struct test *current = &desc_conversion_tests[i];
1463 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
1465 desc.Filter = current->filter;
1466 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
1467 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
1468 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
1469 desc.MipLODBias = 0.0f;
1470 desc.MaxAnisotropy = 16;
1471 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
1472 desc.BorderColor[0] = 0.0f;
1473 desc.BorderColor[1] = 1.0f;
1474 desc.BorderColor[2] = 0.0f;
1475 desc.BorderColor[3] = 1.0f;
1476 desc.MinLOD = 0.0f;
1477 desc.MaxLOD = 16.0f;
1479 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
1480 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
1482 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
1483 (void **)&d3d11_sampler_state);
1484 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
1486 memcpy(&expected_desc, &desc, sizeof(expected_desc));
1487 expected_desc.Filter = current->expected_filter;
1488 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
1489 expected_desc.MaxAnisotropy = 0;
1490 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
1491 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
1493 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
1494 ok(d3d11_desc.Filter == expected_desc.Filter,
1495 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
1496 ok(d3d11_desc.AddressU == expected_desc.AddressU,
1497 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
1498 ok(d3d11_desc.AddressV == expected_desc.AddressV,
1499 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
1500 ok(d3d11_desc.AddressW == expected_desc.AddressW,
1501 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
1502 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
1503 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
1504 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
1505 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
1506 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
1507 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
1508 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
1509 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
1510 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
1511 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
1512 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
1513 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
1514 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
1515 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
1516 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
1517 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
1518 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
1520 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
1521 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1523 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
1524 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
1525 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
1526 (void **)&sampler_state2);
1527 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
1528 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
1530 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
1531 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1532 refcount = ID3D10SamplerState_Release(sampler_state2);
1533 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1534 refcount = ID3D10SamplerState_Release(sampler_state1);
1535 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1538 ID3D11Device_Release(d3d11_device);
1540 done:
1541 refcount = ID3D10Device_Release(device);
1542 ok(!refcount, "Device has %u references left.\n", refcount);
1545 static void test_create_blend_state(void)
1547 ID3D10BlendState *blend_state1, *blend_state2;
1548 ID3D11BlendState *d3d11_blend_state;
1549 ULONG refcount, expected_refcount;
1550 D3D11_BLEND_DESC d3d11_blend_desc;
1551 D3D10_BLEND_DESC blend_desc;
1552 ID3D11Device *d3d11_device;
1553 ID3D10Device *device, *tmp;
1554 IUnknown *iface;
1555 unsigned int i;
1556 HRESULT hr;
1558 if (!(device = create_device()))
1560 skip("Failed to create device.\n");
1561 return;
1564 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
1565 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1567 blend_desc.AlphaToCoverageEnable = FALSE;
1568 blend_desc.SrcBlend = D3D10_BLEND_ONE;
1569 blend_desc.DestBlend = D3D10_BLEND_ZERO;
1570 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
1571 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
1572 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
1573 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
1574 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1576 blend_desc.BlendEnable[i] = FALSE;
1577 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
1580 expected_refcount = get_refcount((IUnknown *)device) + 1;
1581 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
1582 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1583 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
1584 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1585 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
1586 refcount = get_refcount((IUnknown *)device);
1587 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1588 tmp = NULL;
1589 expected_refcount = refcount + 1;
1590 ID3D10BlendState_GetDevice(blend_state1, &tmp);
1591 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1592 refcount = get_refcount((IUnknown *)device);
1593 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1594 ID3D10Device_Release(tmp);
1596 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
1597 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1598 "Blend state should implement ID3D10BlendState1.\n");
1599 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1601 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
1602 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1603 "Device should implement ID3D11Device.\n");
1604 if (FAILED(hr))
1606 win_skip("D3D11 is not available.\n");
1607 goto done;
1610 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
1611 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
1613 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
1614 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
1615 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
1616 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
1617 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
1618 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1620 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
1621 "Got unexpected blend enable %#x for render target %u.\n",
1622 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
1623 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
1624 "Got unexpected src blend %u for render target %u.\n",
1625 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
1626 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
1627 "Got unexpected dest blend %u for render target %u.\n",
1628 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
1629 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
1630 "Got unexpected blend op %u for render target %u.\n",
1631 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
1632 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
1633 "Got unexpected src blend alpha %u for render target %u.\n",
1634 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
1635 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
1636 "Got unexpected dest blend alpha %u for render target %u.\n",
1637 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
1638 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
1639 "Got unexpected blend op alpha %u for render target %u.\n",
1640 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
1641 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
1642 "Got unexpected render target write mask %#x for render target %u.\n",
1643 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
1646 refcount = ID3D11BlendState_Release(d3d11_blend_state);
1647 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
1648 refcount = ID3D10BlendState_Release(blend_state2);
1649 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1651 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
1652 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1654 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
1655 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
1656 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
1658 refcount = ID3D11BlendState_Release(d3d11_blend_state);
1659 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
1660 refcount = ID3D10BlendState_Release(blend_state2);
1661 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1662 refcount = ID3D10BlendState_Release(blend_state1);
1663 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1665 blend_desc.BlendEnable[0] = TRUE;
1666 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
1667 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
1668 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
1670 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
1671 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1673 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
1674 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
1676 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
1677 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
1678 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
1679 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
1680 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
1681 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1683 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
1684 "Got unexpected blend enable %#x for render target %u.\n",
1685 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
1686 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
1687 "Got unexpected src blend %u for render target %u.\n",
1688 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
1689 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
1690 "Got unexpected dest blend %u for render target %u.\n",
1691 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
1692 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
1693 "Got unexpected blend op %u for render target %u.\n",
1694 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
1695 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
1696 "Got unexpected src blend alpha %u for render target %u.\n",
1697 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
1698 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
1699 "Got unexpected dest blend alpha %u for render target %u.\n",
1700 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
1701 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
1702 "Got unexpected blend op alpha %u for render target %u.\n",
1703 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
1704 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
1705 "Got unexpected render target write mask %#x for render target %u.\n",
1706 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
1709 refcount = ID3D11BlendState_Release(d3d11_blend_state);
1710 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1712 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
1713 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1715 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
1716 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
1717 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
1719 refcount = ID3D11BlendState_Release(d3d11_blend_state);
1720 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
1722 ID3D11Device_Release(d3d11_device);
1724 done:
1725 refcount = ID3D10BlendState_Release(blend_state2);
1726 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1727 refcount = ID3D10BlendState_Release(blend_state1);
1728 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1730 refcount = ID3D10Device_Release(device);
1731 ok(!refcount, "Device has %u references left.\n", refcount);
1734 static void test_create_depthstencil_state(void)
1736 ID3D10DepthStencilState *ds_state1, *ds_state2;
1737 ULONG refcount, expected_refcount;
1738 D3D10_DEPTH_STENCIL_DESC ds_desc;
1739 ID3D10Device *device, *tmp;
1740 HRESULT hr;
1742 if (!(device = create_device()))
1744 skip("Failed to create device, skipping tests.\n");
1745 return;
1748 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
1749 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1751 ds_desc.DepthEnable = TRUE;
1752 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
1753 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
1754 ds_desc.StencilEnable = FALSE;
1755 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
1756 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
1757 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1758 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1759 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1760 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1761 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1762 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1763 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1764 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1766 expected_refcount = get_refcount((IUnknown *)device) + 1;
1767 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
1768 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
1769 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
1770 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
1771 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
1772 refcount = get_refcount((IUnknown *)device);
1773 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1774 tmp = NULL;
1775 expected_refcount = refcount + 1;
1776 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
1777 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1778 refcount = get_refcount((IUnknown *)device);
1779 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1780 ID3D10Device_Release(tmp);
1782 refcount = ID3D10DepthStencilState_Release(ds_state2);
1783 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1784 refcount = ID3D10DepthStencilState_Release(ds_state1);
1785 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1787 refcount = ID3D10Device_Release(device);
1788 ok(!refcount, "Device has %u references left.\n", refcount);
1791 static void test_create_rasterizer_state(void)
1793 ID3D10RasterizerState *rast_state1, *rast_state2;
1794 ULONG refcount, expected_refcount;
1795 D3D10_RASTERIZER_DESC rast_desc;
1796 ID3D10Device *device, *tmp;
1797 HRESULT hr;
1799 if (!(device = create_device()))
1801 skip("Failed to create device, skipping tests.\n");
1802 return;
1805 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
1806 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1808 rast_desc.FillMode = D3D10_FILL_SOLID;
1809 rast_desc.CullMode = D3D10_CULL_BACK;
1810 rast_desc.FrontCounterClockwise = FALSE;
1811 rast_desc.DepthBias = 0;
1812 rast_desc.DepthBiasClamp = 0.0f;
1813 rast_desc.SlopeScaledDepthBias = 0.0f;
1814 rast_desc.DepthClipEnable = TRUE;
1815 rast_desc.ScissorEnable = FALSE;
1816 rast_desc.MultisampleEnable = FALSE;
1817 rast_desc.AntialiasedLineEnable = FALSE;
1819 expected_refcount = get_refcount((IUnknown *)device) + 1;
1820 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
1821 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1822 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
1823 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1824 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
1825 refcount = get_refcount((IUnknown *)device);
1826 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1827 tmp = NULL;
1828 expected_refcount = refcount + 1;
1829 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
1830 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1831 refcount = get_refcount((IUnknown *)device);
1832 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1833 ID3D10Device_Release(tmp);
1835 refcount = ID3D10RasterizerState_Release(rast_state2);
1836 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1837 refcount = ID3D10RasterizerState_Release(rast_state1);
1838 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1840 refcount = ID3D10Device_Release(device);
1841 ok(!refcount, "Device has %u references left.\n", refcount);
1844 static void test_create_predicate(void)
1846 static const D3D10_QUERY other_queries[] =
1848 D3D10_QUERY_EVENT,
1849 D3D10_QUERY_OCCLUSION,
1850 D3D10_QUERY_TIMESTAMP,
1851 D3D10_QUERY_TIMESTAMP_DISJOINT,
1852 D3D10_QUERY_PIPELINE_STATISTICS,
1853 D3D10_QUERY_SO_STATISTICS,
1856 ULONG refcount, expected_refcount;
1857 D3D10_QUERY_DESC query_desc;
1858 ID3D10Predicate *predicate;
1859 ID3D10Device *device, *tmp;
1860 IUnknown *iface;
1861 unsigned int i;
1862 HRESULT hr;
1864 if (!(device = create_device()))
1866 skip("Failed to create device.\n");
1867 return;
1870 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
1871 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1873 query_desc.MiscFlags = 0;
1875 for (i = 0; i < sizeof(other_queries) / sizeof(*other_queries); ++i)
1877 query_desc.Query = other_queries[i];
1878 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1879 ok(hr == E_INVALIDARG, "Got unexpected hr %#x for query type %u.\n", hr, other_queries[i]);
1882 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
1883 expected_refcount = get_refcount((IUnknown *)device) + 1;
1884 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1885 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1886 refcount = get_refcount((IUnknown *)device);
1887 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1888 tmp = NULL;
1889 expected_refcount = refcount + 1;
1890 ID3D10Predicate_GetDevice(predicate, &tmp);
1891 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1892 refcount = get_refcount((IUnknown *)device);
1893 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1894 ID3D10Device_Release(tmp);
1895 hr = ID3D10Predicate_QueryInterface(predicate, &IID_ID3D11Predicate, (void **)&iface);
1896 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1897 "Predicate should implement ID3D11Predicate.\n");
1898 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1899 ID3D10Predicate_Release(predicate);
1901 query_desc.Query = D3D10_QUERY_SO_OVERFLOW_PREDICATE;
1902 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1903 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1904 if (SUCCEEDED(hr))
1905 ID3D10Predicate_Release(predicate);
1907 refcount = ID3D10Device_Release(device);
1908 ok(!refcount, "Device has %u references left.\n", refcount);
1911 static void test_device_removed_reason(void)
1913 ID3D10Device *device;
1914 ULONG refcount;
1915 HRESULT hr;
1917 if (!(device = create_device()))
1919 skip("Failed to create device, skipping tests.\n");
1920 return;
1923 hr = ID3D10Device_GetDeviceRemovedReason(device);
1924 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1925 hr = ID3D10Device_GetDeviceRemovedReason(device);
1926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1928 refcount = ID3D10Device_Release(device);
1929 ok(!refcount, "Device has %u references left.\n", refcount);
1932 static void test_scissor(void)
1934 D3D10_SUBRESOURCE_DATA buffer_data;
1935 ID3D10InputLayout *input_layout;
1936 D3D10_RASTERIZER_DESC rs_desc;
1937 D3D10_BUFFER_DESC buffer_desc;
1938 ID3D10RenderTargetView *rtv;
1939 ID3D10Texture2D *backbuffer;
1940 unsigned int stride, offset;
1941 ID3D10RasterizerState *rs;
1942 IDXGISwapChain *swapchain;
1943 D3D10_RECT scissor_rect;
1944 ID3D10VertexShader *vs;
1945 ID3D10PixelShader *ps;
1946 ID3D10Device *device;
1947 D3D10_VIEWPORT vp;
1948 ID3D10Buffer *vb;
1949 ULONG refcount;
1950 DWORD color;
1951 HWND window;
1952 HRESULT hr;
1954 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
1955 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1957 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1959 static const DWORD vs_code[] =
1961 /* float4 main(float4 position : POSITION) : SV_POSITION
1963 * return position;
1964 * } */
1965 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
1966 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
1967 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1968 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1969 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1970 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1971 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1972 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1973 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1974 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
1975 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1976 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1977 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1978 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1980 static const DWORD ps_code[] =
1982 /* float4 main(float4 position : SV_POSITION) : SV_Target
1984 * return float4(0.0, 1.0, 0.0, 1.0);
1985 * } */
1986 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
1987 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
1988 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1989 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1990 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1991 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1992 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1993 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
1994 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
1995 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
1996 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
1997 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1998 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1999 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2001 static const struct
2003 float x, y;
2005 quad[] =
2007 {-1.0f, -1.0f},
2008 {-1.0f, 1.0f},
2009 { 1.0f, -1.0f},
2010 { 1.0f, 1.0f},
2013 if (!(device = create_device()))
2015 skip("Failed to create device, skipping tests.\n");
2016 return;
2018 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2019 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2020 swapchain = create_swapchain(device, window, TRUE);
2021 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2022 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2024 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2025 vs_code, sizeof(vs_code), &input_layout);
2026 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2028 buffer_desc.ByteWidth = sizeof(quad);
2029 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2030 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2031 buffer_desc.CPUAccessFlags = 0;
2032 buffer_desc.MiscFlags = 0;
2034 buffer_data.pSysMem = quad;
2035 buffer_data.SysMemPitch = 0;
2036 buffer_data.SysMemSlicePitch = 0;
2038 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
2039 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2040 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2041 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2042 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2043 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2045 rs_desc.FillMode = D3D10_FILL_SOLID;
2046 rs_desc.CullMode = D3D10_CULL_BACK;
2047 rs_desc.FrontCounterClockwise = FALSE;
2048 rs_desc.DepthBias = 0;
2049 rs_desc.DepthBiasClamp = 0.0f;
2050 rs_desc.SlopeScaledDepthBias = 0.0f;
2051 rs_desc.DepthClipEnable = TRUE;
2052 rs_desc.ScissorEnable = TRUE;
2053 rs_desc.MultisampleEnable = FALSE;
2054 rs_desc.AntialiasedLineEnable = FALSE;
2055 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
2056 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2058 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtv);
2059 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2061 ID3D10Device_IASetInputLayout(device, input_layout);
2062 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2063 stride = sizeof(*quad);
2064 offset = 0;
2065 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2066 ID3D10Device_VSSetShader(device, vs);
2067 ID3D10Device_PSSetShader(device, ps);
2069 vp.TopLeftX = 0;
2070 vp.TopLeftY = 0;
2071 vp.Width = 640;
2072 vp.Height = 480;
2073 vp.MinDepth = 0.0f;
2074 vp.MaxDepth = 1.0f;
2075 ID3D10Device_RSSetViewports(device, 1, &vp);
2077 scissor_rect.left = 160;
2078 scissor_rect.top = 120;
2079 scissor_rect.right = 480;
2080 scissor_rect.bottom = 360;
2081 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
2083 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2085 ID3D10Device_ClearRenderTargetView(device, rtv, red);
2086 color = get_texture_color(backbuffer, 320, 240);
2087 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2089 ID3D10Device_Draw(device, 4, 0);
2090 color = get_texture_color(backbuffer, 320, 60);
2091 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2092 color = get_texture_color(backbuffer, 80, 240);
2093 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2094 color = get_texture_color(backbuffer, 320, 240);
2095 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2096 color = get_texture_color(backbuffer, 560, 240);
2097 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2098 color = get_texture_color(backbuffer, 320, 420);
2099 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2101 ID3D10Device_ClearRenderTargetView(device, rtv, red);
2102 ID3D10Device_RSSetState(device, rs);
2103 ID3D10Device_Draw(device, 4, 0);
2104 color = get_texture_color(backbuffer, 320, 60);
2105 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2106 color = get_texture_color(backbuffer, 80, 240);
2107 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2108 color = get_texture_color(backbuffer, 320, 240);
2109 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2110 color = get_texture_color(backbuffer, 560, 240);
2111 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2112 color = get_texture_color(backbuffer, 320, 420);
2113 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2115 ID3D10RenderTargetView_Release(rtv);
2116 ID3D10RasterizerState_Release(rs);
2117 ID3D10PixelShader_Release(ps);
2118 ID3D10VertexShader_Release(vs);
2119 ID3D10Buffer_Release(vb);
2120 ID3D10InputLayout_Release(input_layout);
2121 ID3D10Texture2D_Release(backbuffer);
2122 IDXGISwapChain_Release(swapchain);
2123 refcount = ID3D10Device_Release(device);
2124 ok(!refcount, "Device has %u references left.\n", refcount);
2125 DestroyWindow(window);
2128 static void test_clear_state(void)
2130 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2132 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2134 #if 0
2135 float4 main(float4 pos : POSITION) : POSITION
2137 return pos;
2139 #endif
2140 static const DWORD simple_vs[] =
2142 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
2143 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2144 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2145 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2146 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
2147 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2148 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2151 #if 0
2152 struct gs_out
2154 float4 pos : SV_POSITION;
2157 [maxvertexcount(4)]
2158 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
2160 float offset = 0.1 * vin[0].w;
2161 gs_out v;
2163 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
2164 vout.Append(v);
2165 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
2166 vout.Append(v);
2167 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
2168 vout.Append(v);
2169 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
2170 vout.Append(v);
2172 #endif
2173 static const DWORD simple_gs[] =
2175 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
2176 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2177 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2178 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2179 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
2180 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
2181 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
2182 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2183 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
2184 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2185 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
2186 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
2187 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
2188 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
2189 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
2190 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2191 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
2192 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2195 #if 0
2196 float4 main(float4 color : COLOR) : SV_TARGET
2198 return color;
2200 #endif
2201 static const DWORD simple_ps[] =
2203 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
2204 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
2205 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
2206 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2207 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
2208 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
2209 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2212 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
2213 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
2214 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
2215 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
2216 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
2217 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
2218 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
2219 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
2220 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
2221 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
2222 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
2223 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
2224 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
2225 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
2226 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
2227 ID3D10InputLayout *tmp_input_layout, *input_layout;
2228 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
2229 ID3D10BlendState *tmp_blend_state, *blend_state;
2230 ID3D10RasterizerState *tmp_rs_state, *rs_state;
2231 ID3D10Predicate *tmp_predicate, *predicate;
2232 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
2233 ID3D10DepthStencilView *tmp_dsv, *dsv;
2234 D3D10_PRIMITIVE_TOPOLOGY topology;
2235 D3D10_TEXTURE2D_DESC texture_desc;
2236 ID3D10GeometryShader *tmp_gs, *gs;
2237 D3D10_DEPTH_STENCIL_DESC ds_desc;
2238 ID3D10VertexShader *tmp_vs, *vs;
2239 D3D10_SAMPLER_DESC sampler_desc;
2240 D3D10_QUERY_DESC predicate_desc;
2241 ID3D10PixelShader *tmp_ps, *ps;
2242 D3D10_RASTERIZER_DESC rs_desc;
2243 D3D10_BUFFER_DESC buffer_desc;
2244 D3D10_BLEND_DESC blend_desc;
2245 ID3D10Texture2D *ds_texture;
2246 float tmp_blend_factor[4];
2247 float blend_factor[4];
2248 ID3D10Device *device;
2249 BOOL predicate_value;
2250 DXGI_FORMAT format;
2251 UINT sample_mask;
2252 UINT stencil_ref;
2253 ULONG refcount;
2254 UINT count, i;
2255 HRESULT hr;
2257 if (!(device = create_device()))
2259 skip("Failed to create device, skipping tests.\n");
2260 return;
2263 /* Verify the initial state after device creation. */
2265 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2266 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2268 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2270 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2271 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2273 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2275 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2276 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2278 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2280 ID3D10Device_VSGetShader(device, &tmp_vs);
2281 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
2283 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2284 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2286 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2288 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2289 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2291 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2293 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2294 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2296 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2298 ID3D10Device_GSGetShader(device, &tmp_gs);
2299 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
2301 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2302 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2304 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2306 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2307 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2309 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2311 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2312 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2314 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2316 ID3D10Device_PSGetShader(device, &tmp_ps);
2317 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
2319 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
2320 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2322 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
2323 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
2324 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
2326 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
2327 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
2328 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
2329 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
2330 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
2331 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
2332 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
2333 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
2335 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
2336 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
2337 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
2338 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
2339 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2340 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
2341 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
2342 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
2343 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
2344 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
2345 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
2346 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2348 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
2350 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
2352 ID3D10Device_RSGetScissorRects(device, &count, NULL);
2353 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
2354 memset(tmp_rect, 0x55, sizeof(tmp_rect));
2355 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2356 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
2357 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2359 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
2360 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2361 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2363 ID3D10Device_RSGetViewports(device, &count, NULL);
2364 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
2365 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
2366 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2367 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
2368 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2370 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2371 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2372 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2373 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2374 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2376 ID3D10Device_RSGetState(device, &tmp_rs_state);
2377 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
2379 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2380 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2382 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
2383 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2386 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2387 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
2388 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2390 /* Create resources. */
2392 buffer_desc.ByteWidth = 1024;
2393 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2394 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2395 buffer_desc.CPUAccessFlags = 0;
2396 buffer_desc.MiscFlags = 0;
2398 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2400 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb[i]);
2401 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
2404 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE;
2406 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2408 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer[i]);
2409 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
2411 stride[i] = (i + 1) * 4;
2412 offset[i] = (i + 1) * 16;
2415 buffer_desc.BindFlags = D3D10_BIND_STREAM_OUTPUT;
2417 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2419 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &so_buffer[i]);
2420 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
2423 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2424 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
2425 U(srv_desc).Buffer.ElementOffset = 0;
2426 U(srv_desc).Buffer.ElementWidth = 64;
2428 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2430 hr = ID3D10Device_CreateShaderResourceView(device,
2431 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
2432 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
2435 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
2436 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
2437 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
2438 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
2439 sampler_desc.MipLODBias = 0.0f;
2440 sampler_desc.MaxAnisotropy = 16;
2441 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2442 sampler_desc.BorderColor[0] = 0.0f;
2443 sampler_desc.BorderColor[1] = 0.0f;
2444 sampler_desc.BorderColor[2] = 0.0f;
2445 sampler_desc.BorderColor[3] = 0.0f;
2446 sampler_desc.MinLOD = 0.0f;
2447 sampler_desc.MaxLOD = 16.0f;
2449 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2451 sampler_desc.MinLOD = (float)i;
2453 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
2454 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2457 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
2458 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2460 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
2461 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
2463 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
2464 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2466 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2467 simple_vs, sizeof(simple_vs), &input_layout);
2468 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2470 blend_desc.AlphaToCoverageEnable = FALSE;
2471 blend_desc.BlendEnable[0] = FALSE;
2472 blend_desc.BlendEnable[1] = FALSE;
2473 blend_desc.BlendEnable[2] = FALSE;
2474 blend_desc.BlendEnable[3] = FALSE;
2475 blend_desc.BlendEnable[4] = FALSE;
2476 blend_desc.BlendEnable[5] = FALSE;
2477 blend_desc.BlendEnable[6] = FALSE;
2478 blend_desc.BlendEnable[7] = FALSE;
2479 blend_desc.SrcBlend = D3D10_BLEND_ONE;
2480 blend_desc.DestBlend = D3D10_BLEND_ZERO;
2481 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
2482 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
2483 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
2484 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
2485 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
2486 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
2487 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
2488 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
2489 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
2490 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
2491 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
2492 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
2494 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
2495 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2497 ds_desc.DepthEnable = TRUE;
2498 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
2499 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
2500 ds_desc.StencilEnable = FALSE;
2501 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
2502 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
2503 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
2504 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
2505 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
2506 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
2507 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
2508 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
2509 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
2510 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
2512 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
2513 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2515 texture_desc.Width = 512;
2516 texture_desc.Height = 512;
2517 texture_desc.MipLevels = 1;
2518 texture_desc.ArraySize = 1;
2519 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2520 texture_desc.SampleDesc.Count = 1;
2521 texture_desc.SampleDesc.Quality = 0;
2522 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2523 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2524 texture_desc.CPUAccessFlags = 0;
2525 texture_desc.MiscFlags = 0;
2527 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2529 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
2530 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2533 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2534 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2536 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
2537 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2539 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2541 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
2542 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2545 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
2546 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
2548 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2550 tmp_rect[i].left = i;
2551 tmp_rect[i].top = i * 2;
2552 tmp_rect[i].right = i + 1;
2553 tmp_rect[i].bottom = (i + 1) * 2;
2555 tmp_viewport[i].TopLeftX = i * 3;
2556 tmp_viewport[i].TopLeftY = i * 4;
2557 tmp_viewport[i].Width = 3;
2558 tmp_viewport[i].Height = 4;
2559 tmp_viewport[i].MinDepth = i * 0.01f;
2560 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
2563 rs_desc.FillMode = D3D10_FILL_SOLID;
2564 rs_desc.CullMode = D3D10_CULL_BACK;
2565 rs_desc.FrontCounterClockwise = FALSE;
2566 rs_desc.DepthBias = 0;
2567 rs_desc.DepthBiasClamp = 0.0f;
2568 rs_desc.SlopeScaledDepthBias = 0.0f;
2569 rs_desc.DepthClipEnable = TRUE;
2570 rs_desc.ScissorEnable = FALSE;
2571 rs_desc.MultisampleEnable = FALSE;
2572 rs_desc.AntialiasedLineEnable = FALSE;
2574 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
2575 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2577 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
2578 predicate_desc.MiscFlags = 0;
2580 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
2581 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2583 /* Verify the behavior of set state methods. */
2585 blend_factor[0] = 0.1f;
2586 blend_factor[1] = 0.2f;
2587 blend_factor[2] = 0.3f;
2588 blend_factor[3] = 0.4f;
2589 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2590 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
2591 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
2592 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
2593 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2594 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
2595 ID3D10BlendState_Release(tmp_blend_state);
2597 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
2598 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
2599 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
2600 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
2601 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2602 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
2603 ID3D10BlendState_Release(tmp_blend_state);
2605 /* Setup state. */
2607 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
2608 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
2609 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
2610 ID3D10Device_VSSetShader(device, vs);
2612 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
2613 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
2614 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
2615 ID3D10Device_GSSetShader(device, gs);
2617 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
2618 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
2619 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
2620 ID3D10Device_PSSetShader(device, ps);
2622 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
2623 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
2624 ID3D10Device_IASetInputLayout(device, input_layout);
2625 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2627 blend_factor[0] = 0.1f;
2628 blend_factor[1] = 0.2f;
2629 blend_factor[2] = 0.3f;
2630 blend_factor[3] = 0.4f;
2631 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
2632 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
2633 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
2635 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
2636 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
2637 ID3D10Device_RSSetState(device, rs_state);
2639 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
2641 ID3D10Device_SetPredication(device, predicate, TRUE);
2643 /* Verify the set state. */
2645 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2646 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2648 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
2649 tmp_buffer[i], i, cb[i]);
2650 ID3D10Buffer_Release(tmp_buffer[i]);
2652 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2653 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2655 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
2656 tmp_srv[i], i, srv[i]);
2657 ID3D10ShaderResourceView_Release(tmp_srv[i]);
2659 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2660 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2662 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
2663 tmp_sampler[i], i, sampler[i]);
2664 ID3D10SamplerState_Release(tmp_sampler[i]);
2666 ID3D10Device_VSGetShader(device, &tmp_vs);
2667 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
2668 ID3D10VertexShader_Release(tmp_vs);
2670 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2671 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2673 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
2674 tmp_buffer[i], i, cb[i]);
2675 ID3D10Buffer_Release(tmp_buffer[i]);
2677 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2678 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2680 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
2681 tmp_srv[i], i, srv[i]);
2682 ID3D10ShaderResourceView_Release(tmp_srv[i]);
2684 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2685 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2687 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
2688 tmp_sampler[i], i, sampler[i]);
2689 ID3D10SamplerState_Release(tmp_sampler[i]);
2691 ID3D10Device_GSGetShader(device, &tmp_gs);
2692 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
2693 ID3D10GeometryShader_Release(tmp_gs);
2695 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2696 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2698 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
2699 tmp_buffer[i], i, cb[i]);
2700 ID3D10Buffer_Release(tmp_buffer[i]);
2702 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2703 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2705 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
2706 tmp_srv[i], i, srv[i]);
2707 ID3D10ShaderResourceView_Release(tmp_srv[i]);
2709 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2710 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2712 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
2713 tmp_sampler[i], i, sampler[i]);
2714 ID3D10SamplerState_Release(tmp_sampler[i]);
2716 ID3D10Device_PSGetShader(device, &tmp_ps);
2717 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
2718 ID3D10PixelShader_Release(tmp_ps);
2720 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
2721 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2723 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
2724 tmp_buffer[i], i, buffer[i]);
2725 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
2726 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
2727 ID3D10Buffer_Release(tmp_buffer[i]);
2729 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
2730 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
2731 ID3D10Buffer_Release(tmp_buffer[0]);
2732 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
2733 todo_wine ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
2734 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
2735 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
2736 tmp_input_layout, input_layout);
2737 ID3D10InputLayout_Release(tmp_input_layout);
2738 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
2739 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
2741 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
2742 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
2743 ID3D10BlendState_Release(tmp_blend_state);
2744 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
2745 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
2746 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2747 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
2748 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
2749 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
2750 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
2751 ID3D10DepthStencilState_Release(tmp_ds_state);
2752 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
2753 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
2754 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2756 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
2757 tmp_rtv[i], i, rtv[i]);
2758 ID3D10RenderTargetView_Release(tmp_rtv[i]);
2760 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
2761 ID3D10DepthStencilView_Release(tmp_dsv);
2763 ID3D10Device_RSGetScissorRects(device, &count, NULL);
2764 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
2765 "Got unexpected scissor rect count %u.\n", count);
2766 memset(tmp_rect, 0x55, sizeof(tmp_rect));
2767 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
2768 for (i = 0; i < count; ++i)
2770 ok(tmp_rect[i].left == i
2771 && tmp_rect[i].top == i * 2
2772 && tmp_rect[i].right == i + 1
2773 && tmp_rect[i].bottom == (i + 1) * 2,
2774 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2775 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2777 ID3D10Device_RSGetViewports(device, &count, NULL);
2778 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
2779 "Got unexpected viewport count %u.\n", count);
2780 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
2781 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
2782 for (i = 0; i < count; ++i)
2784 ok(tmp_viewport[i].TopLeftX == i * 3
2785 && tmp_viewport[i].TopLeftY == i * 4
2786 && tmp_viewport[i].Width == 3
2787 && tmp_viewport[i].Height == 4
2788 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
2789 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
2790 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2791 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2792 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2794 ID3D10Device_RSGetState(device, &tmp_rs_state);
2795 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
2796 ID3D10RasterizerState_Release(tmp_rs_state);
2798 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2799 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2801 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
2802 tmp_buffer[i], i, so_buffer[i]);
2803 ID3D10Buffer_Release(tmp_buffer[i]);
2804 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2807 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2808 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
2809 ID3D10Predicate_Release(tmp_predicate);
2810 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2812 /* Verify ClearState(). */
2814 ID3D10Device_ClearState(device);
2816 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2817 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2819 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2821 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2822 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2824 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2826 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2827 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2829 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2831 ID3D10Device_VSGetShader(device, &tmp_vs);
2832 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
2834 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2835 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2837 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2839 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2840 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2842 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2844 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2845 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2847 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2849 ID3D10Device_GSGetShader(device, &tmp_gs);
2850 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
2852 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
2853 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2855 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
2857 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
2858 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2860 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
2862 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
2863 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2865 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
2867 ID3D10Device_PSGetShader(device, &tmp_ps);
2868 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
2870 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
2871 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2873 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
2874 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
2875 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
2877 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
2878 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
2879 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
2880 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
2881 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
2882 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
2883 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
2884 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
2886 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
2887 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
2888 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
2889 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
2890 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2891 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
2892 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
2893 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
2894 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
2895 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
2896 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
2897 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2899 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
2901 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
2903 ID3D10Device_RSGetScissorRects(device, &count, NULL);
2904 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
2905 memset(tmp_rect, 0x55, sizeof(tmp_rect));
2906 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2907 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
2908 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2910 if (!i)
2911 todo_wine ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
2912 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2913 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2914 else
2915 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
2916 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2917 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2919 ID3D10Device_RSGetViewports(device, &count, NULL);
2920 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
2921 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
2922 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2923 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
2924 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2926 if (!i)
2927 todo_wine ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2928 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2929 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2930 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2931 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2932 else
2933 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2934 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2935 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2936 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2937 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2939 ID3D10Device_RSGetState(device, &tmp_rs_state);
2940 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
2942 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2943 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2945 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
2946 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2949 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2950 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
2951 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2953 /* Cleanup. */
2955 ID3D10Predicate_Release(predicate);
2956 ID3D10RasterizerState_Release(rs_state);
2957 ID3D10DepthStencilView_Release(dsv);
2958 ID3D10Texture2D_Release(ds_texture);
2960 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2962 ID3D10RenderTargetView_Release(rtv[i]);
2963 ID3D10Texture2D_Release(rt_texture[i]);
2966 ID3D10DepthStencilState_Release(ds_state);
2967 ID3D10BlendState_Release(blend_state);
2968 ID3D10InputLayout_Release(input_layout);
2969 ID3D10VertexShader_Release(vs);
2970 ID3D10GeometryShader_Release(gs);
2971 ID3D10PixelShader_Release(ps);
2973 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2975 ID3D10SamplerState_Release(sampler[i]);
2978 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2980 ID3D10ShaderResourceView_Release(srv[i]);
2983 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2985 ID3D10Buffer_Release(so_buffer[i]);
2988 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2990 ID3D10Buffer_Release(buffer[i]);
2993 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2995 ID3D10Buffer_Release(cb[i]);
2998 refcount = ID3D10Device_Release(device);
2999 ok(!refcount, "Device has %u references left.\n", refcount);
3002 static void test_blend(void)
3004 ID3D10RenderTargetView *backbuffer_rtv, *offscreen_rtv;
3005 ID3D10BlendState *src_blend, *dst_blend;
3006 ID3D10Texture2D *backbuffer, *offscreen;
3007 D3D10_SUBRESOURCE_DATA buffer_data;
3008 D3D10_TEXTURE2D_DESC texture_desc;
3009 ID3D10InputLayout *input_layout;
3010 D3D10_BUFFER_DESC buffer_desc;
3011 D3D10_BLEND_DESC blend_desc;
3012 unsigned int stride, offset;
3013 IDXGISwapChain *swapchain;
3014 ID3D10VertexShader *vs;
3015 ID3D10PixelShader *ps;
3016 ID3D10Device *device;
3017 D3D10_VIEWPORT vp;
3018 ID3D10Buffer *vb;
3019 ULONG refcount;
3020 DWORD color;
3021 HWND window;
3022 HRESULT hr;
3024 static const DWORD vs_code[] =
3026 #if 0
3027 struct vs_out
3029 float4 position : SV_POSITION;
3030 float4 color : COLOR;
3033 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
3035 struct vs_out o;
3037 o.position = position;
3038 o.color = color;
3040 return o;
3042 #endif
3043 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
3044 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3045 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3046 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
3047 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3048 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
3049 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
3050 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
3051 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
3052 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
3054 static const DWORD ps_code[] =
3056 #if 0
3057 struct vs_out
3059 float4 position : SV_POSITION;
3060 float4 color : COLOR;
3063 float4 main(struct vs_out i) : SV_TARGET
3065 return i.color;
3067 #endif
3068 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
3069 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
3070 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
3071 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
3072 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3073 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3074 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3075 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3077 static const struct
3079 struct vec3 position;
3080 DWORD diffuse;
3082 quads[] =
3084 /* quad1 */
3085 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
3086 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
3087 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
3088 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
3089 /* quad2 */
3090 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3091 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3092 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3093 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3095 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
3097 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
3098 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
3100 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
3101 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3103 if (!(device = create_device()))
3105 skip("Failed to create device, skipping tests.\n");
3106 return;
3108 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3109 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3110 swapchain = create_swapchain(device, window, TRUE);
3111 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
3112 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3114 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3115 vs_code, sizeof(vs_code), &input_layout);
3116 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3118 buffer_desc.ByteWidth = sizeof(quads);
3119 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3120 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
3121 buffer_desc.CPUAccessFlags = 0;
3122 buffer_desc.MiscFlags = 0;
3124 buffer_data.pSysMem = quads;
3125 buffer_data.SysMemPitch = 0;
3126 buffer_data.SysMemSlicePitch = 0;
3128 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
3129 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3130 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
3131 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3132 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3133 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3135 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
3136 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3138 memset(&blend_desc, 0, sizeof(blend_desc));
3139 blend_desc.BlendEnable[0] = TRUE;
3140 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
3141 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
3142 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
3143 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
3144 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
3145 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
3146 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
3148 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
3149 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3151 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
3152 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
3153 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
3154 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
3156 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
3157 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3159 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
3160 ID3D10Device_IASetInputLayout(device, input_layout);
3161 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3162 stride = sizeof(*quads);
3163 offset = 0;
3164 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
3165 ID3D10Device_VSSetShader(device, vs);
3166 ID3D10Device_PSSetShader(device, ps);
3168 vp.TopLeftX = 0;
3169 vp.TopLeftY = 0;
3170 vp.Width = 640;
3171 vp.Height = 480;
3172 vp.MinDepth = 0.0f;
3173 vp.MaxDepth = 1.0f;
3174 ID3D10Device_RSSetViewports(device, 1, &vp);
3176 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3178 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
3179 ID3D10Device_Draw(device, 4, 0);
3180 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
3181 ID3D10Device_Draw(device, 4, 4);
3183 color = get_texture_color(backbuffer, 320, 360);
3184 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
3185 color = get_texture_color(backbuffer, 320, 120);
3186 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
3188 texture_desc.Width = 128;
3189 texture_desc.Height = 128;
3190 texture_desc.MipLevels = 1;
3191 texture_desc.ArraySize = 1;
3192 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
3193 texture_desc.SampleDesc.Count = 1;
3194 texture_desc.SampleDesc.Quality = 0;
3195 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3196 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
3197 texture_desc.CPUAccessFlags = 0;
3198 texture_desc.MiscFlags = 0;
3200 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
3201 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
3203 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
3204 goto done;
3207 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
3208 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3210 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
3212 vp.TopLeftX = 0;
3213 vp.TopLeftY = 0;
3214 vp.Width = 128;
3215 vp.Height = 128;
3216 vp.MinDepth = 0.0f;
3217 vp.MaxDepth = 1.0f;
3218 ID3D10Device_RSSetViewports(device, 1, &vp);
3220 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
3222 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
3223 ID3D10Device_Draw(device, 4, 0);
3224 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
3225 ID3D10Device_Draw(device, 4, 4);
3227 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
3228 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
3229 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
3230 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
3232 ID3D10RenderTargetView_Release(offscreen_rtv);
3233 ID3D10Texture2D_Release(offscreen);
3234 done:
3235 ID3D10BlendState_Release(dst_blend);
3236 ID3D10BlendState_Release(src_blend);
3237 ID3D10PixelShader_Release(ps);
3238 ID3D10VertexShader_Release(vs);
3239 ID3D10Buffer_Release(vb);
3240 ID3D10InputLayout_Release(input_layout);
3241 ID3D10RenderTargetView_Release(backbuffer_rtv);
3242 ID3D10Texture2D_Release(backbuffer);
3243 IDXGISwapChain_Release(swapchain);
3244 refcount = ID3D10Device_Release(device);
3245 ok(!refcount, "Device has %u references left.\n", refcount);
3246 DestroyWindow(window);
3249 static void test_texture(void)
3251 struct shader
3253 const DWORD *code;
3254 size_t size;
3256 struct texture
3258 UINT width;
3259 UINT height;
3260 UINT miplevel_count;
3261 DXGI_FORMAT format;
3262 D3D10_SUBRESOURCE_DATA data[3];
3265 D3D10_SUBRESOURCE_DATA resource_data;
3266 const struct texture *current_texture;
3267 D3D10_TEXTURE2D_DESC texture_desc;
3268 D3D10_SAMPLER_DESC sampler_desc;
3269 ID3D10InputLayout *input_layout;
3270 const struct shader *current_ps;
3271 ID3D10ShaderResourceView *srv;
3272 D3D10_BUFFER_DESC buffer_desc;
3273 ID3D10Texture2D *backbuffer;
3274 ID3D10RenderTargetView *rtv;
3275 ID3D10SamplerState *sampler;
3276 unsigned int stride, offset;
3277 struct texture_readback rb;
3278 IDXGISwapChain *swapchain;
3279 ID3D10Texture2D *texture;
3280 ID3D10VertexShader *vs;
3281 ID3D10PixelShader *ps;
3282 ID3D10Buffer *vb, *cb;
3283 ID3D10Device *device;
3284 unsigned int i, x, y;
3285 struct vec4 miplevel;
3286 D3D10_VIEWPORT vp;
3287 ULONG refcount;
3288 HWND window;
3289 DWORD color;
3290 HRESULT hr;
3292 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
3294 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
3296 static const DWORD vs_code[] =
3298 #if 0
3299 float4 main(float4 position : POSITION) : SV_POSITION
3301 return position;
3303 #endif
3304 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3305 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3306 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3307 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3308 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3309 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3310 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3312 static const DWORD ps_ld_code[] =
3314 #if 0
3315 Texture2D t;
3317 float miplevel;
3319 float4 main(float4 position : SV_POSITION) : SV_TARGET
3321 float3 p;
3322 t.GetDimensions(miplevel, p.x, p.y, p.z);
3323 p.z = miplevel;
3324 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
3325 return t.Load(int3(p));
3327 #endif
3328 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
3329 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3330 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3331 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3332 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
3333 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
3334 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3335 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
3336 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
3337 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
3338 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
3339 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
3340 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
3341 0x00107e46, 0x00000000, 0x0100003e,
3343 static const DWORD ps_ld_sint8_code[] =
3345 #if 0
3346 Texture2D<int4> t;
3348 float4 main(float4 position : SV_POSITION) : SV_TARGET
3350 float3 p, s;
3351 int4 c;
3353 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3354 t.GetDimensions(0, s.x, s.y, s.z);
3355 p *= s;
3357 c = t.Load(int3(p));
3358 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
3360 #endif
3361 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
3362 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3363 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3364 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3365 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
3366 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
3367 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3368 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3369 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3370 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3371 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3372 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3373 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3374 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
3375 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
3376 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3377 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
3378 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
3380 static const DWORD ps_ld_uint8_code[] =
3382 #if 0
3383 Texture2D<uint4> t;
3385 float4 main(float4 position : SV_POSITION) : SV_TARGET
3387 float3 p, s;
3389 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3390 t.GetDimensions(0, s.x, s.y, s.z);
3391 p *= s;
3393 return t.Load(int3(p)) / (float4)255;
3395 #endif
3396 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
3397 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3398 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3399 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3400 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
3401 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
3402 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3403 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3404 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3405 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3406 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3407 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3408 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3409 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
3410 0x3b808081, 0x0100003e,
3412 static const DWORD ps_sample_code[] =
3414 #if 0
3415 Texture2D t;
3416 SamplerState s;
3418 float4 main(float4 position : SV_POSITION) : SV_Target
3420 float2 p;
3422 p.x = position.x / 640.0f;
3423 p.y = position.y / 480.0f;
3424 return t.Sample(s, p);
3426 #endif
3427 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3428 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3429 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3430 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3431 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3432 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3433 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3434 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3435 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3436 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3438 static const DWORD ps_sample_b_code[] =
3440 #if 0
3441 Texture2D t;
3442 SamplerState s;
3444 float bias;
3446 float4 main(float4 position : SV_POSITION) : SV_Target
3448 float2 p;
3450 p.x = position.x / 640.0f;
3451 p.y = position.y / 480.0f;
3452 return t.SampleBias(s, p, bias);
3454 #endif
3455 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
3456 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3457 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3458 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3459 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3460 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3461 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3462 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3463 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
3464 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3465 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3467 static const DWORD ps_sample_l_code[] =
3469 #if 0
3470 Texture2D t;
3471 SamplerState s;
3473 float level;
3475 float4 main(float4 position : SV_POSITION) : SV_Target
3477 float2 p;
3479 p.x = position.x / 640.0f;
3480 p.y = position.y / 480.0f;
3481 return t.SampleLevel(s, p, level);
3483 #endif
3484 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
3485 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3486 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3487 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3488 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3489 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3490 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3491 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3492 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
3493 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3494 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3496 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
3497 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
3498 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
3499 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
3500 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
3501 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
3502 static const struct
3504 struct vec2 position;
3506 quad[] =
3508 {{-1.0f, -1.0f}},
3509 {{-1.0f, 1.0f}},
3510 {{ 1.0f, -1.0f}},
3511 {{ 1.0f, 1.0f}},
3513 static const DWORD rgba_level_0[] =
3515 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3516 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3517 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3518 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3520 static const DWORD rgba_level_1[] =
3522 0xffffffff, 0xff0000ff,
3523 0xff000000, 0xff00ff00,
3525 static const DWORD rgba_level_2[] =
3527 0xffff0000,
3529 static const BYTE bc1_data[4 * 8] =
3531 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3532 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3533 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3534 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3536 static const BYTE bc2_data[4 * 16] =
3538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3543 static const BYTE bc3_data[4 * 16] =
3545 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3546 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3547 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3548 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3550 static const struct texture rgba_texture =
3552 4, 4, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
3554 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
3555 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
3556 {rgba_level_2, sizeof(*rgba_level_2), 0},
3559 static const struct texture bc1_texture = {8, 8, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
3560 static const struct texture bc2_texture = {8, 8, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
3561 static const struct texture bc3_texture = {8, 8, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
3562 static const struct texture sint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_SINT,
3563 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3564 static const struct texture uint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UINT,
3565 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3566 static const DWORD level_1_colors[] =
3568 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3569 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3570 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3571 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3573 static const DWORD lerp_1_2_colors[] =
3575 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3576 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3577 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3578 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3580 static const DWORD level_2_colors[] =
3582 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3583 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3584 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3585 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3587 static const DWORD bc_colors[] =
3589 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3590 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3591 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3592 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3594 static const DWORD sint8_colors[] =
3596 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
3597 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
3598 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
3599 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
3601 static const DWORD zero_colors[4 * 4] = {0};
3602 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3604 static const struct test
3606 const struct shader *ps;
3607 const struct texture *texture;
3608 D3D10_FILTER filter;
3609 float lod_bias;
3610 float min_lod;
3611 float max_lod;
3612 float miplevel;
3613 const DWORD *expected_colors;
3615 tests[] =
3617 {&ps_ld, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3618 {&ps_ld, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
3619 {&ps_ld, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
3620 {&ps_ld, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
3621 {&ps_ld, &bc1_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3622 {&ps_ld, &bc1_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3623 {&ps_ld, &bc2_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3624 {&ps_ld, &bc2_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3625 {&ps_ld, &bc3_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3626 {&ps_ld, &bc3_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3627 {&ps_ld_sint8, &sint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
3628 {&ps_ld_uint8, &uint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3629 {&ps_sample, &bc1_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3630 {&ps_sample, &bc2_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3631 {&ps_sample, &bc3_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3632 {&ps_sample, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3633 {&ps_sample, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 0.0f, rgba_level_0},
3634 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3635 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3636 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3637 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3638 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.0f, level_1_colors},
3639 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.4f, level_1_colors},
3640 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.5f, level_2_colors},
3641 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 9.0f, level_2_colors},
3642 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
3643 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
3644 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
3645 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
3646 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, -1.0f, rgba_level_0},
3647 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 0.0f, rgba_level_0},
3648 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 0.4f, rgba_level_0},
3649 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 0.5f, level_1_colors},
3650 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 1.0f, level_1_colors},
3651 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 1.4f, level_1_colors},
3652 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 1.5f, level_2_colors},
3653 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 2.0f, level_2_colors},
3654 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 3.0f, level_2_colors},
3655 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 4.0f, level_2_colors},
3656 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 0.0f, 0.0f, D3D10_FLOAT32_MAX, 1.5f, lerp_1_2_colors},
3657 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D10_FLOAT32_MAX, -2.0f, rgba_level_0},
3658 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D10_FLOAT32_MAX, -1.0f, level_1_colors},
3659 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D10_FLOAT32_MAX, 0.0f, level_2_colors},
3660 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D10_FLOAT32_MAX, 1.0f, level_2_colors},
3661 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D10_FLOAT32_MAX, 1.5f, level_2_colors},
3662 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3663 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3664 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3665 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3666 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3667 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3668 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3669 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3670 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3671 {&ps_sample_l, &rgba_texture, D3D10_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3674 if (!(device = create_device()))
3676 skip("Failed to create device.\n");
3677 return;
3679 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3680 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3681 swapchain = create_swapchain(device, window, TRUE);
3682 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
3683 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3685 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3686 vs_code, sizeof(vs_code), &input_layout);
3687 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3689 buffer_desc.ByteWidth = sizeof(quad);
3690 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3691 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
3692 buffer_desc.CPUAccessFlags = 0;
3693 buffer_desc.MiscFlags = 0;
3695 resource_data.pSysMem = quad;
3696 resource_data.SysMemPitch = 0;
3697 resource_data.SysMemSlicePitch = 0;
3699 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3700 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3702 buffer_desc.ByteWidth = sizeof(miplevel);
3703 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
3705 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
3706 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3708 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
3709 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3711 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtv);
3712 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3714 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3715 ID3D10Device_IASetInputLayout(device, input_layout);
3716 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3717 stride = sizeof(*quad);
3718 offset = 0;
3719 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
3720 ID3D10Device_VSSetShader(device, vs);
3721 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
3723 vp.TopLeftX = 0;
3724 vp.TopLeftY = 0;
3725 vp.Width = 640;
3726 vp.Height = 480;
3727 vp.MinDepth = 0.0f;
3728 vp.MaxDepth = 1.0f;
3729 ID3D10Device_RSSetViewports(device, 1, &vp);
3731 texture_desc.Width = 4;
3732 texture_desc.Height = 4;
3733 texture_desc.MipLevels = 3;
3734 texture_desc.ArraySize = 1;
3735 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3736 texture_desc.SampleDesc.Count = 1;
3737 texture_desc.SampleDesc.Quality = 0;
3738 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3739 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3740 texture_desc.CPUAccessFlags = 0;
3741 texture_desc.MiscFlags = 0;
3743 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
3744 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
3745 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
3746 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
3747 sampler_desc.MipLODBias = 0.0f;
3748 sampler_desc.MaxAnisotropy = 0;
3749 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
3750 sampler_desc.BorderColor[0] = 0.0f;
3751 sampler_desc.BorderColor[1] = 0.0f;
3752 sampler_desc.BorderColor[2] = 0.0f;
3753 sampler_desc.BorderColor[3] = 0.0f;
3754 sampler_desc.MinLOD = 0.0f;
3755 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
3757 ps = NULL;
3758 srv = NULL;
3759 sampler = NULL;
3760 texture = NULL;
3761 current_ps = NULL;
3762 current_texture = NULL;
3763 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3765 const struct test *test = &tests[i];
3767 if (current_ps != test->ps)
3769 if (ps)
3770 ID3D10PixelShader_Release(ps);
3772 current_ps = test->ps;
3774 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
3775 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
3777 ID3D10Device_PSSetShader(device, ps);
3780 if (current_texture != test->texture)
3782 if (texture)
3783 ID3D10Texture2D_Release(texture);
3784 if (srv)
3785 ID3D10ShaderResourceView_Release(srv);
3787 current_texture = test->texture;
3789 texture_desc.Width = current_texture->width;
3790 texture_desc.Height = current_texture->height;
3791 texture_desc.MipLevels = current_texture->miplevel_count;
3792 texture_desc.Format = current_texture->format;
3794 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
3795 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3797 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
3798 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
3800 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
3803 if (!sampler || (sampler_desc.Filter != test->filter
3804 || sampler_desc.MipLODBias != test->lod_bias
3805 || sampler_desc.MinLOD != test->min_lod
3806 || sampler_desc.MaxLOD != test->max_lod))
3808 if (sampler)
3809 ID3D10SamplerState_Release(sampler);
3811 sampler_desc.Filter = test->filter;
3812 sampler_desc.MipLODBias = test->lod_bias;
3813 sampler_desc.MinLOD = test->min_lod;
3814 sampler_desc.MaxLOD = test->max_lod;
3816 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
3817 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3819 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
3822 miplevel.x = test->miplevel;
3823 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &miplevel, 0, 0);
3825 ID3D10Device_ClearRenderTargetView(device, rtv, red);
3826 ID3D10Device_Draw(device, 4, 0);
3828 get_texture_readback(backbuffer, &rb);
3829 for (x = 0; x < 4; ++x)
3831 for (y = 0; y < 4; ++y)
3833 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
3834 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
3835 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
3838 release_texture_readback(&rb);
3840 ID3D10ShaderResourceView_Release(srv);
3841 ID3D10SamplerState_Release(sampler);
3842 ID3D10Texture2D_Release(texture);
3843 ID3D10PixelShader_Release(ps);
3845 ID3D10Buffer_Release(cb);
3846 ID3D10VertexShader_Release(vs);
3847 ID3D10Buffer_Release(vb);
3848 ID3D10InputLayout_Release(input_layout);
3849 ID3D10RenderTargetView_Release(rtv);
3850 ID3D10Texture2D_Release(backbuffer);
3851 IDXGISwapChain_Release(swapchain);
3852 refcount = ID3D10Device_Release(device);
3853 ok(!refcount, "Device has %u references left.\n", refcount);
3854 DestroyWindow(window);
3857 static void test_private_data(void)
3859 D3D10_TEXTURE2D_DESC texture_desc;
3860 ULONG refcount, expected_refcount;
3861 ID3D11Texture2D *d3d11_texture;
3862 ID3D11Device *d3d11_device;
3863 ID3D10Device *test_object;
3864 ID3D10Texture2D *texture;
3865 IDXGIDevice *dxgi_device;
3866 IDXGISurface *surface;
3867 ID3D10Device *device;
3868 IUnknown *ptr;
3869 HRESULT hr;
3870 UINT size;
3872 static const GUID test_guid =
3873 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
3874 static const GUID test_guid2 =
3875 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
3876 static const DWORD data[] = {1, 2, 3, 4};
3878 if (!(device = create_device()))
3880 skip("Failed to create device, skipping tests.\n");
3881 return;
3884 test_object = create_device();
3886 texture_desc.Width = 512;
3887 texture_desc.Height = 512;
3888 texture_desc.MipLevels = 1;
3889 texture_desc.ArraySize = 1;
3890 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3891 texture_desc.SampleDesc.Count = 1;
3892 texture_desc.SampleDesc.Quality = 0;
3893 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3894 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3895 texture_desc.CPUAccessFlags = 0;
3896 texture_desc.MiscFlags = 0;
3898 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3899 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3900 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
3901 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
3903 /* SetPrivateData() with a pointer of NULL has the purpose of
3904 * FreePrivateData() in previous D3D versions. A successful clear returns
3905 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
3906 * considered a clear but as setting an interface pointer that happens to
3907 * be NULL. */
3908 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
3909 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3910 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
3911 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3912 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3914 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3915 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3917 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
3918 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3919 size = sizeof(ptr) * 2;
3920 ptr = (IUnknown *)0xdeadbeef;
3921 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
3922 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3923 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3924 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3926 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
3927 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
3928 size = sizeof(ptr) * 2;
3929 ptr = (IUnknown *)0xdeadbeef;
3930 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
3931 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3932 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3933 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3934 IDXGIDevice_Release(dxgi_device);
3936 refcount = get_refcount((IUnknown *)test_object);
3937 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
3938 (IUnknown *)test_object);
3939 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3940 expected_refcount = refcount + 1;
3941 refcount = get_refcount((IUnknown *)test_object);
3942 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3943 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
3944 (IUnknown *)test_object);
3945 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3946 refcount = get_refcount((IUnknown *)test_object);
3947 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3949 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
3950 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3951 --expected_refcount;
3952 refcount = get_refcount((IUnknown *)test_object);
3953 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3955 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
3956 (IUnknown *)test_object);
3957 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3958 size = sizeof(data);
3959 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
3960 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3961 refcount = get_refcount((IUnknown *)test_object);
3962 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3963 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
3964 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3965 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
3966 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3968 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
3969 (IUnknown *)test_object);
3970 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3971 ++expected_refcount;
3972 size = 2 * sizeof(ptr);
3973 ptr = NULL;
3974 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
3975 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3976 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
3977 ++expected_refcount;
3978 refcount = get_refcount((IUnknown *)test_object);
3979 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3980 IUnknown_Release(ptr);
3981 --expected_refcount;
3983 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3984 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3985 "Device should implement ID3D11Device.\n");
3986 if (SUCCEEDED(hr))
3988 ptr = NULL;
3989 size = sizeof(ptr);
3990 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
3991 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3992 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
3993 IUnknown_Release(ptr);
3994 ID3D11Device_Release(d3d11_device);
3995 refcount = get_refcount((IUnknown *)test_object);
3996 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3997 refcount, expected_refcount);
4000 ptr = (IUnknown *)0xdeadbeef;
4001 size = 1;
4002 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
4003 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4004 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4005 size = 2 * sizeof(ptr);
4006 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
4007 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4008 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4009 refcount = get_refcount((IUnknown *)test_object);
4010 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4012 size = 1;
4013 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
4014 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
4015 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4016 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4017 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
4018 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4019 size = 0xdeadbabe;
4020 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
4021 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
4022 ok(size == 0, "Got unexpected size %u.\n", size);
4023 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4024 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
4025 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4026 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4028 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
4029 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4030 ptr = NULL;
4031 size = sizeof(ptr);
4032 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
4033 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4034 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
4035 IUnknown_Release(ptr);
4037 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
4038 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4039 "Texture should implement ID3D11Texture2D.\n");
4040 if (SUCCEEDED(hr))
4042 ptr = NULL;
4043 size = sizeof(ptr);
4044 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
4045 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4046 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
4047 IUnknown_Release(ptr);
4048 ID3D11Texture2D_Release(d3d11_texture);
4051 IDXGISurface_Release(surface);
4052 ID3D10Texture2D_Release(texture);
4053 refcount = ID3D10Device_Release(device);
4054 ok(!refcount, "Device has %u references left.\n", refcount);
4055 refcount = ID3D10Device_Release(test_object);
4056 ok(!refcount, "Test object has %u references left.\n", refcount);
4059 static void test_il_append_aligned(void)
4061 ID3D10RenderTargetView *backbuffer_rtv;
4062 D3D10_SUBRESOURCE_DATA resource_data;
4063 ID3D10InputLayout *input_layout;
4064 D3D10_BUFFER_DESC buffer_desc;
4065 ID3D10Texture2D *backbuffer;
4066 unsigned int stride, offset;
4067 IDXGISwapChain *swapchain;
4068 ID3D10VertexShader *vs;
4069 ID3D10PixelShader *ps;
4070 ID3D10Device *device;
4071 ID3D10Buffer *vb[3];
4072 D3D10_VIEWPORT vp;
4073 ULONG refcount;
4074 DWORD color;
4075 HWND window;
4076 HRESULT hr;
4078 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4080 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
4081 D3D10_INPUT_PER_INSTANCE_DATA, 2},
4082 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
4083 D3D10_INPUT_PER_INSTANCE_DATA, 1},
4084 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
4085 D3D10_INPUT_PER_VERTEX_DATA, 0},
4086 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
4087 D3D10_INPUT_PER_INSTANCE_DATA, 1},
4088 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
4089 D3D10_INPUT_PER_INSTANCE_DATA, 2},
4091 static const DWORD vs_code[] =
4093 #if 0
4094 struct vs_in
4096 float4 position : POSITION;
4097 float2 color_xy : COLOR0;
4098 float2 color_zw : COLOR1;
4099 unsigned int instance_id : SV_INSTANCEID;
4102 struct vs_out
4104 float4 position : SV_POSITION;
4105 float2 color_xy : COLOR0;
4106 float2 color_zw : COLOR1;
4109 struct vs_out main(struct vs_in i)
4111 struct vs_out o;
4113 o.position = i.position;
4114 o.position.x += i.instance_id * 0.5;
4115 o.color_xy = i.color_xy;
4116 o.color_zw = i.color_zw;
4118 return o;
4120 #endif
4121 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
4122 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
4123 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
4124 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
4125 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
4126 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
4127 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4128 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
4129 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
4130 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
4131 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
4132 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
4133 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
4134 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
4135 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
4136 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
4137 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
4139 static const DWORD ps_code[] =
4141 #if 0
4142 struct vs_out
4144 float4 position : SV_POSITION;
4145 float2 color_xy : COLOR0;
4146 float2 color_zw : COLOR1;
4149 float4 main(struct vs_out i) : SV_TARGET
4151 return float4(i.color_xy.xy, i.color_zw.xy);
4153 #endif
4154 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
4155 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
4156 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
4157 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
4158 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
4159 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
4160 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
4161 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4162 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
4164 static const struct
4166 struct vec4 position;
4168 stream0[] =
4170 {{-1.0f, -1.0f, 0.0f, 1.0f}},
4171 {{-1.0f, 1.0f, 0.0f, 1.0f}},
4172 {{-0.5f, -1.0f, 0.0f, 1.0f}},
4173 {{-0.5f, 1.0f, 0.0f, 1.0f}},
4175 static const struct
4177 struct vec2 color2;
4178 struct vec2 color1;
4180 stream1[] =
4182 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4183 {{0.5f, 0.5f}, {1.0f, 1.0f}},
4185 static const struct
4187 struct vec2 color3;
4188 struct vec2 color0;
4190 stream2[] =
4192 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4193 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4194 {{0.5f, 0.5f}, {0.0f, 0.0f}},
4195 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4197 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4199 if (!(device = create_device()))
4201 skip("Failed to create device, skipping tests.\n");
4202 return;
4204 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4205 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4206 swapchain = create_swapchain(device, window, TRUE);
4207 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
4208 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4210 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4211 vs_code, sizeof(vs_code), &input_layout);
4212 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4214 buffer_desc.ByteWidth = sizeof(stream0);
4215 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
4216 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
4217 buffer_desc.CPUAccessFlags = 0;
4218 buffer_desc.MiscFlags = 0;
4220 resource_data.pSysMem = stream0;
4221 resource_data.SysMemPitch = 0;
4222 resource_data.SysMemSlicePitch = 0;
4224 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
4225 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4227 buffer_desc.ByteWidth = sizeof(stream1);
4228 resource_data.pSysMem = stream1;
4230 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
4231 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4233 buffer_desc.ByteWidth = sizeof(stream2);
4234 resource_data.pSysMem = stream2;
4236 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
4237 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4239 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
4240 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4241 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4242 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4244 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
4245 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4247 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
4248 ID3D10Device_IASetInputLayout(device, input_layout);
4249 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4250 offset = 0;
4251 stride = sizeof(*stream0);
4252 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
4253 stride = sizeof(*stream1);
4254 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
4255 stride = sizeof(*stream2);
4256 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
4257 ID3D10Device_VSSetShader(device, vs);
4258 ID3D10Device_PSSetShader(device, ps);
4260 vp.TopLeftX = 0;
4261 vp.TopLeftY = 0;
4262 vp.Width = 640;
4263 vp.Height = 480;
4264 vp.MinDepth = 0.0f;
4265 vp.MaxDepth = 1.0f;
4266 ID3D10Device_RSSetViewports(device, 1, &vp);
4268 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
4270 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
4272 color = get_texture_color(backbuffer, 80, 240);
4273 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4274 color = get_texture_color(backbuffer, 240, 240);
4275 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4276 color = get_texture_color(backbuffer, 400, 240);
4277 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4278 color = get_texture_color(backbuffer, 560, 240);
4279 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
4281 ID3D10PixelShader_Release(ps);
4282 ID3D10VertexShader_Release(vs);
4283 ID3D10Buffer_Release(vb[2]);
4284 ID3D10Buffer_Release(vb[1]);
4285 ID3D10Buffer_Release(vb[0]);
4286 ID3D10InputLayout_Release(input_layout);
4287 ID3D10RenderTargetView_Release(backbuffer_rtv);
4288 ID3D10Texture2D_Release(backbuffer);
4289 IDXGISwapChain_Release(swapchain);
4290 refcount = ID3D10Device_Release(device);
4291 ok(!refcount, "Device has %u references left.\n", refcount);
4292 DestroyWindow(window);
4295 static void test_fragment_coords(void)
4297 ID3D10RenderTargetView *backbuffer_rtv;
4298 D3D10_SUBRESOURCE_DATA resource_data;
4299 ID3D10InputLayout *input_layout;
4300 ID3D10PixelShader *ps, *ps_frac;
4301 D3D10_BUFFER_DESC buffer_desc;
4302 ID3D10Texture2D *backbuffer;
4303 unsigned int stride, offset;
4304 IDXGISwapChain *swapchain;
4305 ID3D10Buffer *vb, *ps_cb;
4306 ID3D10VertexShader *vs;
4307 ID3D10Device *device;
4308 D3D10_VIEWPORT vp;
4309 ULONG refcount;
4310 DWORD color;
4311 HWND window;
4312 HRESULT hr;
4314 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4316 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4318 static const DWORD vs_code[] =
4320 #if 0
4321 float4 main(float4 position : POSITION) : SV_POSITION
4323 return position;
4325 #endif
4326 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4327 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4328 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4329 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4330 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4331 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4332 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4334 static const DWORD ps_code[] =
4336 #if 0
4337 float2 cutoff;
4339 float4 main(float4 position : SV_POSITION) : SV_TARGET
4341 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
4343 if (position.x > cutoff.x)
4344 ret.y = 1.0;
4345 if (position.y > cutoff.y)
4346 ret.z = 1.0;
4348 return ret;
4350 #endif
4351 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
4352 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4353 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4354 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4355 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
4356 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
4357 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
4358 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
4359 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
4360 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
4361 0x0100003e,
4363 static const DWORD ps_frac_code[] =
4365 #if 0
4366 float4 main(float4 position : SV_POSITION) : SV_TARGET
4368 return float4(frac(position.xy), 0.0, 1.0);
4370 #endif
4371 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
4372 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4373 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4374 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4375 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
4376 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4377 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
4378 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
4380 static const struct
4382 struct vec2 position;
4384 quad[] =
4386 {{-1.0f, -1.0f}},
4387 {{-1.0f, 1.0f}},
4388 {{ 1.0f, -1.0f}},
4389 {{ 1.0f, 1.0f}},
4391 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4392 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
4394 if (!(device = create_device()))
4396 skip("Failed to create device, skipping tests.\n");
4397 return;
4399 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4400 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4401 swapchain = create_swapchain(device, window, TRUE);
4402 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
4403 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4405 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4406 vs_code, sizeof(vs_code), &input_layout);
4407 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4409 buffer_desc.ByteWidth = sizeof(quad);
4410 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
4411 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
4412 buffer_desc.CPUAccessFlags = 0;
4413 buffer_desc.MiscFlags = 0;
4415 resource_data.pSysMem = quad;
4416 resource_data.SysMemPitch = 0;
4417 resource_data.SysMemSlicePitch = 0;
4419 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4420 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4422 buffer_desc.ByteWidth = sizeof(cutoff);
4423 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
4425 resource_data.pSysMem = &cutoff;
4427 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4428 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4430 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
4431 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4432 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4433 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4434 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
4435 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4437 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
4438 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4440 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
4441 ID3D10Device_IASetInputLayout(device, input_layout);
4442 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4443 stride = sizeof(*quad);
4444 offset = 0;
4445 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
4446 ID3D10Device_VSSetShader(device, vs);
4447 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
4448 ID3D10Device_PSSetShader(device, ps);
4450 vp.TopLeftX = 0;
4451 vp.TopLeftY = 0;
4452 vp.Width = 640;
4453 vp.Height = 480;
4454 vp.MinDepth = 0.0f;
4455 vp.MaxDepth = 1.0f;
4456 ID3D10Device_RSSetViewports(device, 1, &vp);
4458 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
4460 ID3D10Device_Draw(device, 4, 0);
4462 color = get_texture_color(backbuffer, 319, 239);
4463 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4464 color = get_texture_color(backbuffer, 320, 239);
4465 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4466 color = get_texture_color(backbuffer, 319, 240);
4467 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4468 color = get_texture_color(backbuffer, 320, 240);
4469 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4471 ID3D10Buffer_Release(ps_cb);
4472 cutoff.x = 16.0f;
4473 cutoff.y = 16.0f;
4474 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4475 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4476 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
4478 ID3D10Device_Draw(device, 4, 0);
4480 color = get_texture_color(backbuffer, 14, 14);
4481 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4482 color = get_texture_color(backbuffer, 18, 14);
4483 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4484 color = get_texture_color(backbuffer, 14, 18);
4485 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4486 color = get_texture_color(backbuffer, 18, 18);
4487 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4489 ID3D10Device_PSSetShader(device, ps_frac);
4490 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
4492 ID3D10Device_Draw(device, 4, 0);
4494 color = get_texture_color(backbuffer, 14, 14);
4495 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
4497 ID3D10Buffer_Release(ps_cb);
4498 ID3D10PixelShader_Release(ps_frac);
4499 ID3D10PixelShader_Release(ps);
4500 ID3D10VertexShader_Release(vs);
4501 ID3D10Buffer_Release(vb);
4502 ID3D10InputLayout_Release(input_layout);
4503 ID3D10RenderTargetView_Release(backbuffer_rtv);
4504 ID3D10Texture2D_Release(backbuffer);
4505 IDXGISwapChain_Release(swapchain);
4506 refcount = ID3D10Device_Release(device);
4507 ok(!refcount, "Device has %u references left.\n", refcount);
4508 DestroyWindow(window);
4511 static void test_update_subresource(void)
4513 ID3D10RenderTargetView *backbuffer_rtv;
4514 D3D10_SUBRESOURCE_DATA resource_data;
4515 D3D10_TEXTURE2D_DESC texture_desc;
4516 ID3D10SamplerState *sampler_state;
4517 ID3D10ShaderResourceView *ps_srv;
4518 D3D10_SAMPLER_DESC sampler_desc;
4519 ID3D10InputLayout *input_layout;
4520 D3D10_BUFFER_DESC buffer_desc;
4521 ID3D10Texture2D *backbuffer;
4522 unsigned int stride, offset;
4523 struct texture_readback rb;
4524 IDXGISwapChain *swapchain;
4525 ID3D10Texture2D *texture;
4526 ID3D10VertexShader *vs;
4527 ID3D10PixelShader *ps;
4528 ID3D10Device *device;
4529 D3D10_VIEWPORT vp;
4530 unsigned int i, j;
4531 ID3D10Buffer *vb;
4532 ULONG refcount;
4533 D3D10_BOX box;
4534 DWORD color;
4535 HWND window;
4536 HRESULT hr;
4538 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4540 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4542 static const DWORD vs_code[] =
4544 #if 0
4545 float4 main(float4 position : POSITION) : SV_POSITION
4547 return position;
4549 #endif
4550 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4551 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4552 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4553 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4554 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4555 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4556 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4558 static const DWORD ps_code[] =
4560 #if 0
4561 Texture2D t;
4562 SamplerState s;
4564 float4 main(float4 position : SV_POSITION) : SV_Target
4566 float2 p;
4568 p.x = position.x / 640.0f;
4569 p.y = position.y / 480.0f;
4570 return t.Sample(s, p);
4572 #endif
4573 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4574 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4575 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4576 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4577 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4578 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4579 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4580 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4581 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4582 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4584 static const struct
4586 float x, y;
4588 quad[] =
4590 {-1.0f, -1.0f},
4591 {-1.0f, 1.0f},
4592 { 1.0f, -1.0f},
4593 { 1.0f, 1.0f},
4595 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4596 static const DWORD bitmap_data[] =
4598 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4599 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4600 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4601 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4603 static const DWORD expected_colors[] =
4605 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
4606 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4607 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
4608 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
4611 if (!(device = create_device()))
4613 skip("Failed to create device, skipping tests.\n");
4614 return;
4616 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4617 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4618 swapchain = create_swapchain(device, window, TRUE);
4619 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
4620 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4622 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4623 vs_code, sizeof(vs_code), &input_layout);
4624 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4626 buffer_desc.ByteWidth = sizeof(quad);
4627 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
4628 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
4629 buffer_desc.CPUAccessFlags = 0;
4630 buffer_desc.MiscFlags = 0;
4632 resource_data.pSysMem = quad;
4633 resource_data.SysMemPitch = 0;
4634 resource_data.SysMemSlicePitch = 0;
4636 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4637 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4639 texture_desc.Width = 4;
4640 texture_desc.Height = 4;
4641 texture_desc.MipLevels = 1;
4642 texture_desc.ArraySize = 1;
4643 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4644 texture_desc.SampleDesc.Count = 1;
4645 texture_desc.SampleDesc.Quality = 0;
4646 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4647 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
4648 texture_desc.CPUAccessFlags = 0;
4649 texture_desc.MiscFlags = 0;
4651 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4652 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
4654 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
4655 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
4657 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
4658 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4659 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4660 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4661 sampler_desc.MipLODBias = 0.0f;
4662 sampler_desc.MaxAnisotropy = 0;
4663 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4664 sampler_desc.BorderColor[0] = 0.0f;
4665 sampler_desc.BorderColor[1] = 0.0f;
4666 sampler_desc.BorderColor[2] = 0.0f;
4667 sampler_desc.BorderColor[3] = 0.0f;
4668 sampler_desc.MinLOD = 0.0f;
4669 sampler_desc.MaxLOD = 0.0f;
4671 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4672 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4674 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
4675 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4676 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4677 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4679 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
4680 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4682 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
4683 ID3D10Device_IASetInputLayout(device, input_layout);
4684 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4685 stride = sizeof(*quad);
4686 offset = 0;
4687 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
4688 ID3D10Device_VSSetShader(device, vs);
4689 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
4690 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
4691 ID3D10Device_PSSetShader(device, ps);
4693 vp.TopLeftX = 0;
4694 vp.TopLeftY = 0;
4695 vp.Width = 640;
4696 vp.Height = 480;
4697 vp.MinDepth = 0.0f;
4698 vp.MaxDepth = 1.0f;
4699 ID3D10Device_RSSetViewports(device, 1, &vp);
4701 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
4703 ID3D10Device_Draw(device, 4, 0);
4704 get_texture_readback(backbuffer, &rb);
4705 for (i = 0; i < 4; ++i)
4707 for (j = 0; j < 4; ++j)
4709 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4710 ok(compare_color(color, 0x00000000, 0),
4711 "Got unexpected color 0x%08x at (%u, %u).\n", color, j, i);
4714 release_texture_readback(&rb);
4716 set_box(&box, 1, 1, 0, 3, 3, 1);
4717 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4718 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4719 set_box(&box, 0, 3, 0, 3, 4, 1);
4720 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4721 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
4722 set_box(&box, 0, 0, 0, 4, 1, 1);
4723 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4724 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
4725 set_box(&box, 0, 1, 0, 1, 3, 1);
4726 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4727 &bitmap_data[2], sizeof(*bitmap_data), 0);
4728 set_box(&box, 4, 4, 0, 3, 1, 1);
4729 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4730 bitmap_data, sizeof(*bitmap_data), 0);
4731 set_box(&box, 0, 0, 0, 4, 4, 0);
4732 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
4733 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4734 ID3D10Device_Draw(device, 4, 0);
4735 get_texture_readback(backbuffer, &rb);
4736 for (i = 0; i < 4; ++i)
4738 for (j = 0; j < 4; ++j)
4740 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4741 ok(compare_color(color, expected_colors[j + i * 4], 1),
4742 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4743 color, j, i, expected_colors[j + i * 4]);
4746 release_texture_readback(&rb);
4748 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
4749 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4750 ID3D10Device_Draw(device, 4, 0);
4751 get_texture_readback(backbuffer, &rb);
4752 for (i = 0; i < 4; ++i)
4754 for (j = 0; j < 4; ++j)
4756 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4757 ok(compare_color(color, bitmap_data[j + i * 4], 1),
4758 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4759 color, j, i, bitmap_data[j + i * 4]);
4762 release_texture_readback(&rb);
4764 ID3D10PixelShader_Release(ps);
4765 ID3D10VertexShader_Release(vs);
4766 ID3D10SamplerState_Release(sampler_state);
4767 ID3D10ShaderResourceView_Release(ps_srv);
4768 ID3D10Texture2D_Release(texture);
4769 ID3D10Buffer_Release(vb);
4770 ID3D10InputLayout_Release(input_layout);
4771 ID3D10RenderTargetView_Release(backbuffer_rtv);
4772 ID3D10Texture2D_Release(backbuffer);
4773 IDXGISwapChain_Release(swapchain);
4774 refcount = ID3D10Device_Release(device);
4775 ok(!refcount, "Device has %u references left.\n", refcount);
4776 DestroyWindow(window);
4779 static void test_copy_subresource_region(void)
4781 ID3D10Texture2D *dst_texture, *src_texture;
4782 ID3D10RenderTargetView *backbuffer_rtv;
4783 D3D10_SUBRESOURCE_DATA resource_data;
4784 D3D10_TEXTURE2D_DESC texture_desc;
4785 ID3D10SamplerState *sampler_state;
4786 ID3D10ShaderResourceView *ps_srv;
4787 D3D10_SAMPLER_DESC sampler_desc;
4788 ID3D10InputLayout *input_layout;
4789 D3D10_BUFFER_DESC buffer_desc;
4790 ID3D10Texture2D *backbuffer;
4791 unsigned int stride, offset;
4792 struct texture_readback rb;
4793 IDXGISwapChain *swapchain;
4794 ID3D10VertexShader *vs;
4795 ID3D10PixelShader *ps;
4796 ID3D10Device *device;
4797 D3D10_VIEWPORT vp;
4798 unsigned int i, j;
4799 ID3D10Buffer *vb;
4800 ULONG refcount;
4801 D3D10_BOX box;
4802 DWORD color;
4803 HWND window;
4804 HRESULT hr;
4806 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4808 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4810 static const DWORD vs_code[] =
4812 #if 0
4813 float4 main(float4 position : POSITION) : SV_POSITION
4815 return position;
4817 #endif
4818 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4819 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4820 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4821 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4822 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4823 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4824 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4826 static const DWORD ps_code[] =
4828 #if 0
4829 Texture2D t;
4830 SamplerState s;
4832 float4 main(float4 position : SV_POSITION) : SV_Target
4834 float2 p;
4836 p.x = position.x / 640.0f;
4837 p.y = position.y / 480.0f;
4838 return t.Sample(s, p);
4840 #endif
4841 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4842 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4843 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4844 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4845 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4846 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4847 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4848 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4849 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4850 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4852 static const struct
4854 float x, y;
4856 quad[] =
4858 {-1.0f, -1.0f},
4859 {-1.0f, 1.0f},
4860 { 1.0f, -1.0f},
4861 { 1.0f, 1.0f},
4863 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4864 static const DWORD bitmap_data[] =
4866 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4867 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4868 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4869 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4871 static const DWORD expected_colors[] =
4873 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4874 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4875 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
4876 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
4879 if (!(device = create_device()))
4881 skip("Failed to create device.\n");
4882 return;
4884 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4885 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4886 swapchain = create_swapchain(device, window, TRUE);
4887 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
4888 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4890 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4891 vs_code, sizeof(vs_code), &input_layout);
4892 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4894 buffer_desc.ByteWidth = sizeof(quad);
4895 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
4896 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
4897 buffer_desc.CPUAccessFlags = 0;
4898 buffer_desc.MiscFlags = 0;
4900 resource_data.pSysMem = quad;
4901 resource_data.SysMemPitch = 0;
4902 resource_data.SysMemSlicePitch = 0;
4904 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4905 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4907 texture_desc.Width = 4;
4908 texture_desc.Height = 4;
4909 texture_desc.MipLevels = 1;
4910 texture_desc.ArraySize = 1;
4911 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4912 texture_desc.SampleDesc.Count = 1;
4913 texture_desc.SampleDesc.Quality = 0;
4914 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4915 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
4916 texture_desc.CPUAccessFlags = 0;
4917 texture_desc.MiscFlags = 0;
4919 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
4920 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4922 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
4924 resource_data.pSysMem = bitmap_data;
4925 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
4927 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
4928 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4930 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
4931 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4933 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
4934 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4935 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4936 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4937 sampler_desc.MipLODBias = 0.0f;
4938 sampler_desc.MaxAnisotropy = 0;
4939 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4940 sampler_desc.BorderColor[0] = 0.0f;
4941 sampler_desc.BorderColor[1] = 0.0f;
4942 sampler_desc.BorderColor[2] = 0.0f;
4943 sampler_desc.BorderColor[3] = 0.0f;
4944 sampler_desc.MinLOD = 0.0f;
4945 sampler_desc.MaxLOD = 0.0f;
4947 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4948 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4950 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
4951 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4952 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4953 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4955 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
4956 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4958 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
4959 ID3D10Device_IASetInputLayout(device, input_layout);
4960 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4961 stride = sizeof(*quad);
4962 offset = 0;
4963 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
4964 ID3D10Device_VSSetShader(device, vs);
4965 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
4966 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
4967 ID3D10Device_PSSetShader(device, ps);
4969 vp.TopLeftX = 0;
4970 vp.TopLeftY = 0;
4971 vp.Width = 640;
4972 vp.Height = 480;
4973 vp.MinDepth = 0.0f;
4974 vp.MaxDepth = 1.0f;
4975 ID3D10Device_RSSetViewports(device, 1, &vp);
4977 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
4979 set_box(&box, 0, 0, 0, 2, 2, 1);
4980 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4981 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
4982 set_box(&box, 1, 2, 0, 4, 3, 1);
4983 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4984 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
4985 set_box(&box, 0, 3, 0, 4, 4, 1);
4986 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4987 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
4988 set_box(&box, 3, 0, 0, 4, 2, 1);
4989 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4990 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
4991 set_box(&box, 3, 1, 0, 4, 2, 1);
4992 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4993 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
4994 set_box(&box, 0, 0, 0, 4, 4, 0);
4995 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
4996 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
4997 ID3D10Device_Draw(device, 4, 0);
4998 get_texture_readback(backbuffer, &rb);
4999 for (i = 0; i < 4; ++i)
5001 for (j = 0; j < 4; ++j)
5003 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5004 ok(compare_color(color, expected_colors[j + i * 4], 1),
5005 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5006 color, j, i, expected_colors[j + i * 4]);
5009 release_texture_readback(&rb);
5011 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
5012 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
5013 ID3D10Device_Draw(device, 4, 0);
5014 get_texture_readback(backbuffer, &rb);
5015 for (i = 0; i < 4; ++i)
5017 for (j = 0; j < 4; ++j)
5019 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5020 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5021 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5022 color, j, i, bitmap_data[j + i * 4]);
5025 release_texture_readback(&rb);
5027 ID3D10PixelShader_Release(ps);
5028 ID3D10VertexShader_Release(vs);
5029 ID3D10SamplerState_Release(sampler_state);
5030 ID3D10ShaderResourceView_Release(ps_srv);
5031 ID3D10Texture2D_Release(dst_texture);
5032 ID3D10Texture2D_Release(src_texture);
5033 ID3D10Buffer_Release(vb);
5034 ID3D10InputLayout_Release(input_layout);
5035 ID3D10RenderTargetView_Release(backbuffer_rtv);
5036 ID3D10Texture2D_Release(backbuffer);
5037 IDXGISwapChain_Release(swapchain);
5038 refcount = ID3D10Device_Release(device);
5039 ok(!refcount, "Device has %u references left.\n", refcount);
5040 DestroyWindow(window);
5043 static void test_multisample_init(void)
5045 D3D10_TEXTURE2D_DESC desc;
5046 ID3D10Texture2D *backbuffer, *multi;
5047 ID3D10Device *device;
5048 ULONG refcount;
5049 DWORD color;
5050 HRESULT hr;
5051 unsigned int x, y;
5052 struct texture_readback rb;
5053 BOOL all_zero = TRUE;
5054 UINT count = 0;
5055 HWND window;
5056 IDXGISwapChain *swapchain;
5057 ID3D10RenderTargetView *rtview;
5058 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5060 if (!(device = create_device()))
5062 skip("Failed to create device, skipping tests.\n");
5063 return;
5066 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
5067 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
5068 if (!count)
5070 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
5071 goto done;
5074 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5075 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5076 swapchain = create_swapchain(device, window, TRUE);
5077 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
5078 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
5079 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtview);
5080 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5081 ID3D10Device_ClearRenderTargetView(device, rtview, white);
5083 desc.Width = 640;
5084 desc.Height = 480;
5085 desc.MipLevels = 1;
5086 desc.ArraySize = 1;
5087 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5088 desc.SampleDesc.Count = 2;
5089 desc.SampleDesc.Quality = 0;
5090 desc.Usage = D3D10_USAGE_DEFAULT;
5091 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5092 desc.CPUAccessFlags = 0;
5093 desc.MiscFlags = 0;
5094 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &multi);
5095 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5097 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)backbuffer, 0,
5098 (ID3D10Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
5100 get_texture_readback(backbuffer, &rb);
5101 for (y = 0; y < 480; ++y)
5103 for (x = 0; x < 640; ++x)
5105 color = get_readback_color(&rb, x, y);
5106 if (!compare_color(color, 0x00000000, 0))
5108 all_zero = FALSE;
5109 break;
5112 if (!all_zero)
5113 break;
5115 release_texture_readback(&rb);
5116 todo_wine ok(all_zero, "Got unexpected color 0x%08x, position %ux%u.\n", color, x, y);
5118 ID3D10RenderTargetView_Release(rtview);
5119 ID3D10Texture2D_Release(backbuffer);
5120 IDXGISwapChain_Release(swapchain);
5121 ID3D10Texture2D_Release(multi);
5122 DestroyWindow(window);
5123 done:
5124 refcount = ID3D10Device_Release(device);
5125 ok(!refcount, "Device has %u references left.\n", refcount);
5128 static void test_check_multisample_quality_levels(void)
5130 ID3D10Device *device;
5131 UINT quality_levels;
5132 ULONG refcount;
5133 HRESULT hr;
5135 if (!(device = create_device()))
5137 skip("Failed to create device.\n");
5138 return;
5141 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5142 if (!quality_levels)
5144 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
5145 goto done;
5148 quality_levels = 0xdeadbeef;
5149 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
5150 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5151 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5152 quality_levels = 0xdeadbeef;
5153 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
5154 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5155 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
5157 quality_levels = 0xdeadbeef;
5158 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
5159 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5160 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
5161 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5162 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5164 quality_levels = 0xdeadbeef;
5165 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
5166 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5167 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
5168 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5169 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
5171 quality_levels = 0xdeadbeef;
5172 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
5173 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5174 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5175 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5176 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5178 /* We assume 15 samples multisampling is never supported in practice. */
5179 quality_levels = 0xdeadbeef;
5180 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
5181 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5182 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5183 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
5184 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5185 quality_levels = 0xdeadbeef;
5186 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
5187 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5188 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5189 quality_levels = 0xdeadbeef;
5190 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
5191 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5192 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5194 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
5195 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5196 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5198 done:
5199 refcount = ID3D10Device_Release(device);
5200 ok(!refcount, "Device has %u references left.\n", refcount);
5203 START_TEST(device)
5205 test_feature_level();
5206 test_device_interfaces();
5207 test_create_texture2d();
5208 test_texture2d_interfaces();
5209 test_create_texture3d();
5210 test_buffer_interfaces();
5211 test_create_depthstencil_view();
5212 test_depthstencil_view_interfaces();
5213 test_create_rendertarget_view();
5214 test_create_shader_resource_view();
5215 test_create_shader();
5216 test_create_sampler_state();
5217 test_create_blend_state();
5218 test_create_depthstencil_state();
5219 test_create_rasterizer_state();
5220 test_create_predicate();
5221 test_device_removed_reason();
5222 test_scissor();
5223 test_clear_state();
5224 test_blend();
5225 test_texture();
5226 test_private_data();
5227 test_il_append_aligned();
5228 test_fragment_coords();
5229 test_update_subresource();
5230 test_copy_subresource_region();
5231 test_multisample_init();
5232 test_check_multisample_quality_levels();