d3d11/tests: Multisampled render targets are zeroed on creation.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobd295f1922266014da31b2b884c58037499331218
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
21 #include "initguid.h"
22 #include "d3d11.h"
23 #include "wine/test.h"
25 static const D3D_FEATURE_LEVEL d3d11_feature_levels[] =
27 D3D_FEATURE_LEVEL_11_1,
28 D3D_FEATURE_LEVEL_11_0,
29 D3D_FEATURE_LEVEL_10_1,
30 D3D_FEATURE_LEVEL_10_0,
31 D3D_FEATURE_LEVEL_9_3,
32 D3D_FEATURE_LEVEL_9_2,
33 D3D_FEATURE_LEVEL_9_1
36 struct vec2
38 float x, y;
41 struct vec3
43 float x, y, z;
46 struct vec4
48 float x, y, z, w;
51 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
53 box->left = left;
54 box->top = top;
55 box->front = front;
56 box->right = right;
57 box->bottom = bottom;
58 box->back = back;
61 static ULONG get_refcount(IUnknown *iface)
63 IUnknown_AddRef(iface);
64 return IUnknown_Release(iface);
67 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
69 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
70 return FALSE;
71 c1 >>= 8; c2 >>= 8;
72 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
73 return FALSE;
74 c1 >>= 8; c2 >>= 8;
75 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
76 return FALSE;
77 c1 >>= 8; c2 >>= 8;
78 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
79 return FALSE;
80 return TRUE;
83 struct texture_readback
85 ID3D11Resource *texture;
86 D3D11_MAPPED_SUBRESOURCE map_desc;
87 ID3D11DeviceContext *immediate_context;
90 static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readback *rb)
92 D3D11_TEXTURE2D_DESC texture_desc;
93 ID3D11Device *device;
94 HRESULT hr;
96 memset(rb, 0, sizeof(*rb));
98 ID3D11Texture2D_GetDevice(texture, &device);
100 ID3D11Texture2D_GetDesc(texture, &texture_desc);
101 texture_desc.Usage = D3D11_USAGE_STAGING;
102 texture_desc.BindFlags = 0;
103 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
104 texture_desc.MiscFlags = 0;
105 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->texture)))
107 trace("Failed to create texture, hr %#x.\n", hr);
108 ID3D11Device_Release(device);
109 return;
112 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
114 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
115 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->texture, 0, D3D11_MAP_READ, 0, &rb->map_desc)))
117 trace("Failed to map texture, hr %#x.\n", hr);
118 ID3D11Resource_Release(rb->texture);
119 rb->texture = NULL;
120 ID3D11DeviceContext_Release(rb->immediate_context);
121 rb->immediate_context = NULL;
124 ID3D11Device_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->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x] : 0xdeadbeef;
133 static void release_texture_readback(struct texture_readback *rb)
135 if (!rb->texture)
136 return;
138 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->texture, 0);
139 ID3D11Resource_Release(rb->texture);
140 ID3D11DeviceContext_Release(rb->immediate_context);
143 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
145 struct texture_readback rb;
146 DWORD color;
148 get_texture_readback(texture, &rb);
149 color = get_readback_color(&rb, x, y);
150 release_texture_readback(&rb);
152 return color;
155 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
157 ID3D11Device *device;
158 UINT feature_level_count = feature_level ? 1 : 0;
160 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, feature_level, feature_level_count,
161 D3D11_SDK_VERSION, &device, NULL, NULL)))
162 return device;
163 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, feature_level, feature_level_count,
164 D3D11_SDK_VERSION, &device, NULL, NULL)))
165 return device;
166 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, feature_level, feature_level_count,
167 D3D11_SDK_VERSION, &device, NULL, NULL)))
168 return device;
170 return NULL;
173 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, BOOL windowed)
175 IDXGISwapChain *swapchain;
176 DXGI_SWAP_CHAIN_DESC desc;
177 IDXGIDevice *dxgi_device;
178 IDXGIAdapter *adapter;
179 IDXGIFactory *factory;
180 HRESULT hr;
182 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
183 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
184 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
185 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
186 IDXGIDevice_Release(dxgi_device);
187 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
188 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
189 IDXGIAdapter_Release(adapter);
191 desc.BufferDesc.Width = 640;
192 desc.BufferDesc.Height = 480;
193 desc.BufferDesc.RefreshRate.Numerator = 60;
194 desc.BufferDesc.RefreshRate.Denominator = 1;
195 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
196 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
197 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
198 desc.SampleDesc.Count = 1;
199 desc.SampleDesc.Quality = 0;
200 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
201 desc.BufferCount = 1;
202 desc.OutputWindow = window;
203 desc.Windowed = windowed;
204 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
205 desc.Flags = 0;
207 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
208 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
209 IDXGIFactory_Release(factory);
211 return swapchain;
214 static void test_create_device(void)
216 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
217 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
218 ID3D11DeviceContext *immediate_context;
219 IDXGISwapChain *swapchain;
220 ID3D11Device *device;
221 ULONG refcount;
222 HWND window;
223 HRESULT hr;
225 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device,
226 NULL, NULL);
227 if (FAILED(hr))
229 skip("Failed to create HAL device.\n");
230 return;
233 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
234 ID3D11Device_Release(device);
236 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
237 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
239 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
240 &feature_level, NULL);
241 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
242 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
243 feature_level, supported_feature_level);
245 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
246 &immediate_context);
247 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
249 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
250 refcount = get_refcount((IUnknown *)immediate_context);
251 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
253 ID3D11DeviceContext_GetDevice(immediate_context, &device);
254 refcount = ID3D11Device_Release(device);
255 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
257 refcount = ID3D11DeviceContext_Release(immediate_context);
258 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
260 device = (ID3D11Device *)0xdeadbeef;
261 feature_level = 0xdeadbeef;
262 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
263 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
264 &device, &feature_level, &immediate_context);
265 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
266 ok(!device, "Got unexpected device pointer %p.\n", device);
267 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
268 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
270 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
272 swapchain_desc.BufferDesc.Width = 800;
273 swapchain_desc.BufferDesc.Height = 600;
274 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
275 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
276 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
277 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
278 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
279 swapchain_desc.SampleDesc.Count = 1;
280 swapchain_desc.SampleDesc.Quality = 0;
281 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
282 swapchain_desc.BufferCount = 1;
283 swapchain_desc.OutputWindow = window;
284 swapchain_desc.Windowed = TRUE;
285 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
286 swapchain_desc.Flags = 0;
288 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
289 &swapchain_desc, NULL, NULL, NULL, NULL);
290 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
292 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
293 &swapchain_desc, NULL, NULL, &feature_level, NULL);
294 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
295 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
296 feature_level, supported_feature_level);
298 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
299 &swapchain_desc, &swapchain, &device, NULL, NULL);
300 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
302 memset(&obtained_desc, 0, sizeof(obtained_desc));
303 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
304 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
305 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
306 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
307 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
308 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
309 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
310 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
311 obtained_desc.BufferDesc.RefreshRate.Numerator);
312 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
313 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
314 obtained_desc.BufferDesc.RefreshRate.Denominator);
315 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
316 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
317 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
318 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
319 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
320 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
321 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
322 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
323 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
324 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
325 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
326 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
327 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
328 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
329 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
330 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
331 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
332 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
333 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
334 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
335 ok(obtained_desc.Flags == swapchain_desc.Flags,
336 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
338 refcount = IDXGISwapChain_Release(swapchain);
339 ok(!refcount, "Swapchain has %u references left.\n", refcount);
341 feature_level = ID3D11Device_GetFeatureLevel(device);
342 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
343 feature_level, supported_feature_level);
345 refcount = ID3D11Device_Release(device);
346 ok(!refcount, "Device has %u references left.\n", refcount);
348 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
349 NULL, NULL, &device, NULL, NULL);
350 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
351 ID3D11Device_Release(device);
353 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
354 NULL, NULL, NULL, NULL, NULL);
355 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
357 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
358 NULL, NULL, NULL, &feature_level, NULL);
359 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
360 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
361 feature_level, supported_feature_level);
363 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
364 &swapchain_desc, NULL, NULL, NULL, NULL);
365 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
367 swapchain_desc.OutputWindow = NULL;
368 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
369 &swapchain_desc, NULL, &device, NULL, NULL);
370 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
371 ID3D11Device_Release(device);
373 swapchain = (IDXGISwapChain *)0xdeadbeef;
374 device = (ID3D11Device *)0xdeadbeef;
375 feature_level = 0xdeadbeef;
376 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
377 swapchain_desc.OutputWindow = NULL;
378 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
379 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
380 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
381 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
382 ok(!device, "Got unexpected device pointer %p.\n", device);
383 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
384 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
386 swapchain = (IDXGISwapChain *)0xdeadbeef;
387 device = (ID3D11Device *)0xdeadbeef;
388 feature_level = 0xdeadbeef;
389 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
390 swapchain_desc.OutputWindow = window;
391 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
392 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
393 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
394 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
395 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
396 ok(!device, "Got unexpected device pointer %p.\n", device);
397 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
398 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
400 DestroyWindow(window);
403 static void test_device_interfaces(void)
405 IDXGIAdapter *dxgi_adapter;
406 IDXGIDevice *dxgi_device;
407 ID3D11Device *device;
408 IUnknown *iface;
409 ULONG refcount;
410 unsigned int i;
411 HRESULT hr;
413 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
415 if (!(device = create_device(&d3d11_feature_levels[i])))
417 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels[i]);
418 continue;
421 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
422 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
423 IUnknown_Release(iface);
425 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
426 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
427 IUnknown_Release(iface);
429 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
430 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
431 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
432 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
433 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
434 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
435 IUnknown_Release(iface);
436 IDXGIAdapter_Release(dxgi_adapter);
437 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
438 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
439 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
440 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
441 IUnknown_Release(iface);
442 IDXGIAdapter_Release(dxgi_adapter);
443 IDXGIDevice_Release(dxgi_device);
445 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
446 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
447 IUnknown_Release(iface);
449 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
450 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
451 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
452 if (SUCCEEDED(hr)) IUnknown_Release(iface);
454 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
455 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
456 if (SUCCEEDED(hr)) IUnknown_Release(iface);
458 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
459 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
460 if (SUCCEEDED(hr)) IUnknown_Release(iface);
462 refcount = ID3D11Device_Release(device);
463 ok(!refcount, "Device has %u references left.\n", refcount);
467 static void test_get_immediate_context(void)
469 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
470 ULONG expected_refcount, refcount;
471 ID3D11Device *device;
473 if (!(device = create_device(NULL)))
475 skip("Failed to create device.\n");
476 return;
479 expected_refcount = get_refcount((IUnknown *)device) + 1;
480 ID3D11Device_GetImmediateContext(device, &immediate_context);
481 refcount = get_refcount((IUnknown *)device);
482 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
483 previous_immediate_context = immediate_context;
485 ID3D11Device_GetImmediateContext(device, &immediate_context);
486 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
487 refcount = get_refcount((IUnknown *)device);
488 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
490 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
491 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
492 refcount = ID3D11DeviceContext_Release(immediate_context);
493 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
495 ID3D11Device_GetImmediateContext(device, &immediate_context);
496 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
497 refcount = ID3D11DeviceContext_Release(immediate_context);
498 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
500 refcount = ID3D11Device_Release(device);
501 ok(!refcount, "Device has %u references left.\n", refcount);
504 static void test_create_texture2d(void)
506 ULONG refcount, expected_refcount;
507 D3D11_SUBRESOURCE_DATA data = {0};
508 ID3D11Device *device, *tmp;
509 D3D11_TEXTURE2D_DESC desc;
510 ID3D11Texture2D *texture;
511 IDXGISurface *surface;
512 HRESULT hr;
514 if (!(device = create_device(NULL)))
516 skip("Failed to create device, skipping tests.\n");
517 return;
520 desc.Width = 512;
521 desc.Height = 512;
522 desc.MipLevels = 1;
523 desc.ArraySize = 1;
524 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
525 desc.SampleDesc.Count = 1;
526 desc.SampleDesc.Quality = 0;
527 desc.Usage = D3D11_USAGE_DEFAULT;
528 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
529 desc.CPUAccessFlags = 0;
530 desc.MiscFlags = 0;
532 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
533 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
535 expected_refcount = get_refcount((IUnknown *)device) + 1;
536 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
537 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
538 refcount = get_refcount((IUnknown *)device);
539 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
540 tmp = NULL;
541 expected_refcount = refcount + 1;
542 ID3D11Texture2D_GetDevice(texture, &tmp);
543 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
544 refcount = get_refcount((IUnknown *)device);
545 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
546 ID3D11Device_Release(tmp);
548 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
549 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
550 IDXGISurface_Release(surface);
551 ID3D11Texture2D_Release(texture);
553 desc.MipLevels = 0;
554 expected_refcount = get_refcount((IUnknown *)device) + 1;
555 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
556 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
557 refcount = get_refcount((IUnknown *)device);
558 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
559 tmp = NULL;
560 expected_refcount = refcount + 1;
561 ID3D11Texture2D_GetDevice(texture, &tmp);
562 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
563 refcount = get_refcount((IUnknown *)device);
564 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
565 ID3D11Device_Release(tmp);
567 ID3D11Texture2D_GetDesc(texture, &desc);
568 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
569 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
570 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
571 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
572 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
573 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
574 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
575 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
576 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
577 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
578 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
580 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
581 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
582 ID3D11Texture2D_Release(texture);
584 desc.MipLevels = 1;
585 desc.ArraySize = 2;
586 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
587 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
589 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
590 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
591 ID3D11Texture2D_Release(texture);
593 refcount = ID3D11Device_Release(device);
594 ok(!refcount, "Device has %u references left.\n", refcount);
597 static void test_texture2d_interfaces(void)
599 ID3D10Texture2D *d3d10_texture;
600 D3D11_TEXTURE2D_DESC desc;
601 ID3D11Texture2D *texture;
602 IDXGISurface *surface;
603 ID3D11Device *device;
604 unsigned int i;
605 ULONG refcount;
606 HRESULT hr;
608 static const struct test
610 BOOL implements_d3d10_interfaces;
611 UINT bind_flags;
612 UINT misc_flags;
613 UINT expected_bind_flags;
614 UINT expected_misc_flags;
616 desc_conversion_tests[] =
619 TRUE,
620 D3D11_BIND_SHADER_RESOURCE, 0,
621 D3D10_BIND_SHADER_RESOURCE, 0
624 TRUE,
625 D3D11_BIND_UNORDERED_ACCESS, 0,
626 D3D11_BIND_UNORDERED_ACCESS, 0
629 FALSE,
630 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
631 0, 0
634 TRUE,
635 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
636 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
639 TRUE,
640 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
641 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
645 if (!(device = create_device(NULL)))
647 skip("Failed to create ID3D11Device, skipping tests.\n");
648 return;
651 desc.Width = 512;
652 desc.Height = 512;
653 desc.MipLevels = 0;
654 desc.ArraySize = 1;
655 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
656 desc.SampleDesc.Count = 1;
657 desc.SampleDesc.Quality = 0;
658 desc.Usage = D3D11_USAGE_DEFAULT;
659 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
660 desc.CPUAccessFlags = 0;
661 desc.MiscFlags = 0;
663 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
664 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
666 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
667 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
669 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
670 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
671 "Texture should implement ID3D10Texture2D.\n");
672 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
673 ID3D11Texture2D_Release(texture);
675 if (FAILED(hr))
677 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
678 ID3D11Device_Release(device);
679 return;
682 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
684 const struct test *current = &desc_conversion_tests[i];
685 D3D10_TEXTURE2D_DESC d3d10_desc;
686 ID3D10Device *d3d10_device;
688 desc.Width = 512;
689 desc.Height = 512;
690 desc.MipLevels = 1;
691 desc.ArraySize = 1;
692 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
693 desc.SampleDesc.Count = 1;
694 desc.SampleDesc.Quality = 0;
695 desc.Usage = D3D11_USAGE_DEFAULT;
696 desc.BindFlags = current->bind_flags;
697 desc.CPUAccessFlags = 0;
698 desc.MiscFlags = current->misc_flags;
700 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
701 /* Shared resources are not supported by REF and WARP devices. */
702 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
703 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
704 if (FAILED(hr))
706 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
707 continue;
710 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
711 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
712 IDXGISurface_Release(surface);
714 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
715 ID3D11Texture2D_Release(texture);
717 if (current->implements_d3d10_interfaces)
719 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
721 else
723 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
724 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
725 continue;
728 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
730 ok(d3d10_desc.Width == desc.Width,
731 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
732 ok(d3d10_desc.Height == desc.Height,
733 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
734 ok(d3d10_desc.MipLevels == desc.MipLevels,
735 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
736 ok(d3d10_desc.ArraySize == desc.ArraySize,
737 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
738 ok(d3d10_desc.Format == desc.Format,
739 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
740 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
741 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
742 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
743 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
744 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
745 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
746 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
747 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
748 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
749 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
750 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
751 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
753 d3d10_device = (ID3D10Device *)0xdeadbeef;
754 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
755 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
756 if (d3d10_device) ID3D10Device_Release(d3d10_device);
758 ID3D10Texture2D_Release(d3d10_texture);
761 refcount = ID3D11Device_Release(device);
762 ok(!refcount, "Device has %u references left.\n", refcount);
765 static void test_create_texture3d(void)
767 ULONG refcount, expected_refcount;
768 D3D11_SUBRESOURCE_DATA data = {0};
769 ID3D11Device *device, *tmp;
770 D3D11_TEXTURE3D_DESC desc;
771 ID3D11Texture3D *texture;
772 IDXGISurface *surface;
773 HRESULT hr;
775 if (!(device = create_device(NULL)))
777 skip("Failed to create ID3D11Device, skipping tests.\n");
778 return;
781 desc.Width = 64;
782 desc.Height = 64;
783 desc.Depth = 64;
784 desc.MipLevels = 1;
785 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
786 desc.Usage = D3D11_USAGE_DEFAULT;
787 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
788 desc.CPUAccessFlags = 0;
789 desc.MiscFlags = 0;
791 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
792 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
794 expected_refcount = get_refcount((IUnknown *)device) + 1;
795 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
796 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
797 refcount = get_refcount((IUnknown *)device);
798 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
799 tmp = NULL;
800 expected_refcount = refcount + 1;
801 ID3D11Texture3D_GetDevice(texture, &tmp);
802 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
803 refcount = get_refcount((IUnknown *)device);
804 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
805 ID3D11Device_Release(tmp);
807 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
808 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
809 ID3D11Texture3D_Release(texture);
811 desc.MipLevels = 0;
812 expected_refcount = get_refcount((IUnknown *)device) + 1;
813 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
814 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
815 refcount = get_refcount((IUnknown *)device);
816 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
817 tmp = NULL;
818 expected_refcount = refcount + 1;
819 ID3D11Texture3D_GetDevice(texture, &tmp);
820 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
821 refcount = get_refcount((IUnknown *)device);
822 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
823 ID3D11Device_Release(tmp);
825 ID3D11Texture3D_GetDesc(texture, &desc);
826 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
827 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
828 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
829 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
830 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
831 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
832 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
833 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
834 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
836 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
837 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
838 ID3D11Texture3D_Release(texture);
840 refcount = ID3D11Device_Release(device);
841 ok(!refcount, "Device has %u references left.\n", refcount);
844 static void test_texture3d_interfaces(void)
846 ID3D10Texture3D *d3d10_texture;
847 D3D11_TEXTURE3D_DESC desc;
848 ID3D11Texture3D *texture;
849 IDXGISurface *surface;
850 ID3D11Device *device;
851 unsigned int i;
852 ULONG refcount;
853 HRESULT hr;
855 static const struct test
857 BOOL implements_d3d10_interfaces;
858 UINT bind_flags;
859 UINT misc_flags;
860 UINT expected_bind_flags;
861 UINT expected_misc_flags;
863 desc_conversion_tests[] =
866 TRUE,
867 D3D11_BIND_SHADER_RESOURCE, 0,
868 D3D10_BIND_SHADER_RESOURCE, 0
871 TRUE,
872 D3D11_BIND_UNORDERED_ACCESS, 0,
873 D3D11_BIND_UNORDERED_ACCESS, 0
876 FALSE,
877 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
878 0, 0
881 TRUE,
882 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
883 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
887 if (!(device = create_device(NULL)))
889 skip("Failed to create ID3D11Device.\n");
890 return;
893 desc.Width = 64;
894 desc.Height = 64;
895 desc.Depth = 64;
896 desc.MipLevels = 0;
897 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
898 desc.Usage = D3D11_USAGE_DEFAULT;
899 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
900 desc.CPUAccessFlags = 0;
901 desc.MiscFlags = 0;
903 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
904 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
906 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
907 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
909 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
910 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
911 "Texture should implement ID3D10Texture3D.\n");
912 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
913 ID3D11Texture3D_Release(texture);
915 if (FAILED(hr))
917 win_skip("3D textures do not implement ID3D10Texture3D.\n");
918 ID3D11Device_Release(device);
919 return;
922 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
924 const struct test *current = &desc_conversion_tests[i];
925 D3D10_TEXTURE3D_DESC d3d10_desc;
926 ID3D10Device *d3d10_device;
928 desc.Width = 64;
929 desc.Height = 64;
930 desc.Depth = 64;
931 desc.MipLevels = 1;
932 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
933 desc.Usage = D3D11_USAGE_DEFAULT;
934 desc.BindFlags = current->bind_flags;
935 desc.CPUAccessFlags = 0;
936 desc.MiscFlags = current->misc_flags;
938 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
939 /* Shared resources are not supported by REF and WARP devices. */
940 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
941 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
942 if (FAILED(hr))
944 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
945 continue;
948 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
949 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
951 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
952 ID3D11Texture3D_Release(texture);
954 if (current->implements_d3d10_interfaces)
956 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
958 else
960 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
961 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
962 continue;
965 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
967 ok(d3d10_desc.Width == desc.Width,
968 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
969 ok(d3d10_desc.Height == desc.Height,
970 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
971 ok(d3d10_desc.Depth == desc.Depth,
972 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
973 ok(d3d10_desc.MipLevels == desc.MipLevels,
974 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
975 ok(d3d10_desc.Format == desc.Format,
976 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
977 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
978 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
979 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
980 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
981 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
982 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
983 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
984 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
986 d3d10_device = (ID3D10Device *)0xdeadbeef;
987 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
988 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
989 if (d3d10_device) ID3D10Device_Release(d3d10_device);
991 ID3D10Texture3D_Release(d3d10_texture);
994 refcount = ID3D11Device_Release(device);
995 ok(!refcount, "Device has %u references left.\n", refcount);
998 static void test_buffer_interfaces(void)
1000 ID3D10Buffer *d3d10_buffer;
1001 D3D11_BUFFER_DESC desc;
1002 ID3D11Buffer *buffer;
1003 ID3D11Device *device;
1004 unsigned int i;
1005 ULONG refcount;
1006 HRESULT hr;
1008 static const struct test
1010 BOOL implements_d3d10_interfaces;
1011 UINT bind_flags;
1012 UINT misc_flags;
1013 UINT structure_stride;
1014 UINT expected_bind_flags;
1015 UINT expected_misc_flags;
1017 desc_conversion_tests[] =
1020 TRUE,
1021 D3D11_BIND_VERTEX_BUFFER, 0, 0,
1022 D3D10_BIND_VERTEX_BUFFER, 0
1025 TRUE,
1026 D3D11_BIND_INDEX_BUFFER, 0, 0,
1027 D3D10_BIND_INDEX_BUFFER, 0
1030 TRUE,
1031 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
1032 D3D10_BIND_CONSTANT_BUFFER, 0
1035 TRUE,
1036 D3D11_BIND_SHADER_RESOURCE, 0, 0,
1037 D3D10_BIND_SHADER_RESOURCE, 0
1040 TRUE,
1041 D3D11_BIND_STREAM_OUTPUT, 0, 0,
1042 D3D10_BIND_STREAM_OUTPUT, 0
1045 TRUE,
1046 D3D11_BIND_RENDER_TARGET, 0, 0,
1047 D3D10_BIND_RENDER_TARGET, 0
1050 TRUE,
1051 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
1052 D3D11_BIND_UNORDERED_ACCESS, 0
1055 TRUE,
1056 0, D3D11_RESOURCE_MISC_SHARED, 0,
1057 0, D3D10_RESOURCE_MISC_SHARED
1060 TRUE,
1061 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
1062 0, 0
1065 TRUE,
1066 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
1067 D3D10_BIND_SHADER_RESOURCE, 0
1070 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
1071 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
1072 0, 0
1075 TRUE,
1076 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
1077 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1081 if (!(device = create_device(NULL)))
1083 skip("Failed to create ID3D11Device.\n");
1084 return;
1087 desc.ByteWidth = 1024;
1088 desc.Usage = D3D11_USAGE_DEFAULT;
1089 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1090 desc.CPUAccessFlags = 0;
1091 desc.MiscFlags = 0;
1092 desc.StructureByteStride = 0;
1094 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1095 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1097 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1098 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1099 "Buffer should implement ID3D10Buffer.\n");
1100 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1101 ID3D11Buffer_Release(buffer);
1103 if (FAILED(hr))
1105 win_skip("Buffers do not implement ID3D10Buffer.\n");
1106 ID3D11Device_Release(device);
1107 return;
1110 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1112 const struct test *current = &desc_conversion_tests[i];
1113 D3D10_BUFFER_DESC d3d10_desc;
1114 ID3D10Device *d3d10_device;
1116 desc.ByteWidth = 1024;
1117 desc.Usage = D3D11_USAGE_DEFAULT;
1118 desc.BindFlags = current->bind_flags;
1119 desc.CPUAccessFlags = 0;
1120 desc.MiscFlags = current->misc_flags;
1121 desc.StructureByteStride = current->structure_stride;
1123 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1124 /* Shared resources are not supported by REF and WARP devices. */
1125 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1126 if (FAILED(hr))
1128 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1129 continue;
1132 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1133 ID3D11Buffer_Release(buffer);
1135 if (current->implements_d3d10_interfaces)
1137 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
1139 else
1141 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
1142 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1143 continue;
1146 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
1148 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
1149 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
1150 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1151 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1152 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1153 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1154 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1155 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1156 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1157 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1159 d3d10_device = (ID3D10Device *)0xdeadbeef;
1160 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
1161 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1162 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1164 ID3D10Buffer_Release(d3d10_buffer);
1167 refcount = ID3D11Device_Release(device);
1168 ok(!refcount, "Device has %u references left.\n", refcount);
1171 static void test_create_depthstencil_view(void)
1173 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1174 D3D11_TEXTURE2D_DESC texture_desc;
1175 ULONG refcount, expected_refcount;
1176 ID3D11DepthStencilView *dsview;
1177 ID3D11Device *device, *tmp;
1178 ID3D11Texture2D *texture;
1179 HRESULT hr;
1181 if (!(device = create_device(NULL)))
1183 skip("Failed to create device.\n");
1184 return;
1187 texture_desc.Width = 512;
1188 texture_desc.Height = 512;
1189 texture_desc.MipLevels = 1;
1190 texture_desc.ArraySize = 1;
1191 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1192 texture_desc.SampleDesc.Count = 1;
1193 texture_desc.SampleDesc.Quality = 0;
1194 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1195 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1196 texture_desc.CPUAccessFlags = 0;
1197 texture_desc.MiscFlags = 0;
1199 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1200 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1202 expected_refcount = get_refcount((IUnknown *)device) + 1;
1203 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1204 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1205 refcount = get_refcount((IUnknown *)device);
1206 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1207 tmp = NULL;
1208 expected_refcount = refcount + 1;
1209 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
1210 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1211 refcount = get_refcount((IUnknown *)device);
1212 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1213 ID3D11Device_Release(tmp);
1215 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1216 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1217 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1218 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1219 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1220 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1222 ID3D11DepthStencilView_Release(dsview);
1223 ID3D11Texture2D_Release(texture);
1225 refcount = ID3D11Device_Release(device);
1226 ok(!refcount, "Device has %u references left.\n", refcount);
1229 static void test_depthstencil_view_interfaces(void)
1231 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
1232 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1233 ID3D10DepthStencilView *d3d10_dsview;
1234 D3D11_TEXTURE2D_DESC texture_desc;
1235 ID3D11DepthStencilView *dsview;
1236 ID3D11Texture2D *texture;
1237 ID3D11Device *device;
1238 ULONG refcount;
1239 HRESULT hr;
1241 if (!(device = create_device(NULL)))
1243 skip("Failed to create device.\n");
1244 return;
1247 texture_desc.Width = 512;
1248 texture_desc.Height = 512;
1249 texture_desc.MipLevels = 1;
1250 texture_desc.ArraySize = 1;
1251 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1252 texture_desc.SampleDesc.Count = 1;
1253 texture_desc.SampleDesc.Quality = 0;
1254 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1255 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1256 texture_desc.CPUAccessFlags = 0;
1257 texture_desc.MiscFlags = 0;
1259 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1260 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1262 dsv_desc.Format = texture_desc.Format;
1263 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
1264 dsv_desc.Flags = 0;
1265 U(dsv_desc).Texture2D.MipSlice = 0;
1267 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1268 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1270 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
1271 ID3D11DepthStencilView_Release(dsview);
1272 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1273 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1275 if (FAILED(hr))
1277 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1278 goto done;
1281 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
1282 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
1283 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
1284 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
1285 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
1286 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
1288 ID3D10DepthStencilView_Release(d3d10_dsview);
1290 done:
1291 ID3D11Texture2D_Release(texture);
1293 refcount = ID3D11Device_Release(device);
1294 ok(!refcount, "Device has %u references left.\n", refcount);
1297 static void test_create_rendertarget_view(void)
1299 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
1300 D3D11_SUBRESOURCE_DATA data = {0};
1301 D3D11_TEXTURE2D_DESC texture_desc;
1302 ULONG refcount, expected_refcount;
1303 D3D11_BUFFER_DESC buffer_desc;
1304 ID3D11RenderTargetView *rtview;
1305 ID3D11Device *device, *tmp;
1306 ID3D11Texture2D *texture;
1307 ID3D11Buffer *buffer;
1308 IUnknown *iface;
1309 HRESULT hr;
1311 if (!(device = create_device(NULL)))
1313 skip("Failed to create device.\n");
1314 return;
1317 buffer_desc.ByteWidth = 1024;
1318 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1319 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1320 buffer_desc.CPUAccessFlags = 0;
1321 buffer_desc.MiscFlags = 0;
1322 buffer_desc.StructureByteStride = 0;
1324 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
1325 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1327 expected_refcount = get_refcount((IUnknown *)device) + 1;
1328 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1329 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1330 refcount = get_refcount((IUnknown *)device);
1331 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1332 tmp = NULL;
1333 expected_refcount = refcount + 1;
1334 ID3D11Buffer_GetDevice(buffer, &tmp);
1335 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1336 refcount = get_refcount((IUnknown *)device);
1337 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1338 ID3D11Device_Release(tmp);
1340 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1341 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
1342 U(rtv_desc).Buffer.ElementOffset = 0;
1343 U(rtv_desc).Buffer.ElementWidth = 64;
1345 expected_refcount = get_refcount((IUnknown *)device) + 1;
1346 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
1347 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1348 refcount = get_refcount((IUnknown *)device);
1349 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1350 tmp = NULL;
1351 expected_refcount = refcount + 1;
1352 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
1353 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1354 refcount = get_refcount((IUnknown *)device);
1355 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1356 ID3D11Device_Release(tmp);
1358 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1359 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1360 "Render target view should implement ID3D10RenderTargetView.\n");
1361 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1363 ID3D11RenderTargetView_Release(rtview);
1364 ID3D11Buffer_Release(buffer);
1366 texture_desc.Width = 512;
1367 texture_desc.Height = 512;
1368 texture_desc.MipLevels = 1;
1369 texture_desc.ArraySize = 1;
1370 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1371 texture_desc.SampleDesc.Count = 1;
1372 texture_desc.SampleDesc.Quality = 0;
1373 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1374 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1375 texture_desc.CPUAccessFlags = 0;
1376 texture_desc.MiscFlags = 0;
1378 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1379 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1381 /* For texture resources it's allowed to specify NULL as desc */
1382 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1383 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1385 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1386 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1387 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1388 rtv_desc.ViewDimension);
1389 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1391 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1392 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1393 "Render target view should implement ID3D10RenderTargetView.\n");
1394 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1396 ID3D11RenderTargetView_Release(rtview);
1397 ID3D11Texture2D_Release(texture);
1399 refcount = ID3D11Device_Release(device);
1400 ok(!refcount, "Device has %u references left.\n", refcount);
1403 static void test_create_shader_resource_view(void)
1405 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
1406 D3D11_TEXTURE2D_DESC texture_desc;
1407 ULONG refcount, expected_refcount;
1408 ID3D11ShaderResourceView *srview;
1409 D3D11_BUFFER_DESC buffer_desc;
1410 ID3D11Device *device, *tmp;
1411 ID3D11Texture2D *texture;
1412 ID3D11Buffer *buffer;
1413 IUnknown *iface;
1414 HRESULT hr;
1416 if (!(device = create_device(NULL)))
1418 skip("Failed to create device.\n");
1419 return;
1422 buffer_desc.ByteWidth = 1024;
1423 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1424 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1425 buffer_desc.CPUAccessFlags = 0;
1426 buffer_desc.MiscFlags = 0;
1427 buffer_desc.StructureByteStride = 0;
1429 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1430 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1432 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
1433 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1435 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1436 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
1437 U(srv_desc).Buffer.ElementOffset = 0;
1438 U(srv_desc).Buffer.ElementWidth = 64;
1440 expected_refcount = get_refcount((IUnknown *)device) + 1;
1441 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
1442 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1443 refcount = get_refcount((IUnknown *)device);
1444 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1445 tmp = NULL;
1446 expected_refcount = refcount + 1;
1447 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
1448 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1449 refcount = get_refcount((IUnknown *)device);
1450 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1451 ID3D11Device_Release(tmp);
1453 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1454 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1455 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1456 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1457 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1458 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1459 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1460 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1462 ID3D11ShaderResourceView_Release(srview);
1463 ID3D11Buffer_Release(buffer);
1465 texture_desc.Width = 512;
1466 texture_desc.Height = 512;
1467 texture_desc.MipLevels = 0;
1468 texture_desc.ArraySize = 1;
1469 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1470 texture_desc.SampleDesc.Count = 1;
1471 texture_desc.SampleDesc.Quality = 0;
1472 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1473 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1474 texture_desc.CPUAccessFlags = 0;
1475 texture_desc.MiscFlags = 0;
1477 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1478 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1480 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
1481 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1483 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1484 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1485 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1486 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1487 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1488 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1489 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1490 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1492 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1493 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1494 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1495 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1496 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1497 U(srv_desc).Texture2D.MostDetailedMip);
1498 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1500 ID3D11ShaderResourceView_Release(srview);
1501 ID3D11Texture2D_Release(texture);
1503 refcount = ID3D11Device_Release(device);
1504 ok(!refcount, "Device has %u references left.\n", refcount);
1507 static void test_create_shader(void)
1509 #if 0
1510 float4 light;
1511 float4x4 mat;
1513 struct input
1515 float4 position : POSITION;
1516 float3 normal : NORMAL;
1519 struct output
1521 float4 position : POSITION;
1522 float4 diffuse : COLOR;
1525 output main(const input v)
1527 output o;
1529 o.position = mul(v.position, mat);
1530 o.diffuse = dot((float3)light, v.normal);
1532 return o;
1534 #endif
1535 static const DWORD vs_4_0[] =
1537 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1538 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1539 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1540 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1541 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1542 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1543 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1544 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1545 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1546 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1547 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1548 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1549 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1550 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1551 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1552 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1555 static const DWORD vs_2_0[] =
1557 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1558 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1559 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1560 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1561 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1562 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1563 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1564 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
1565 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
1566 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
1567 0x90e40001, 0x0000ffff,
1570 static const DWORD vs_3_0[] =
1572 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
1573 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1574 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1575 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1576 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1577 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1578 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1579 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
1580 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
1581 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
1582 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
1583 0x0000ffff,
1586 #if 0
1587 float4 main(const float4 color : COLOR) : SV_TARGET
1589 float4 o;
1591 o = color;
1593 return o;
1595 #endif
1596 static const DWORD ps_4_0[] =
1598 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
1599 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
1600 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
1601 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
1602 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
1603 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1604 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
1605 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1606 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
1607 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
1608 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
1609 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
1610 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1611 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1612 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1613 0x00000000, 0x00000000,
1616 #if 0
1617 struct gs_out
1619 float4 pos : SV_POSITION;
1622 [maxvertexcount(4)]
1623 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1625 float offset = 0.1 * vin[0].w;
1626 gs_out v;
1628 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1629 vout.Append(v);
1630 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1631 vout.Append(v);
1632 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1633 vout.Append(v);
1634 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1635 vout.Append(v);
1637 #endif
1638 static const DWORD gs_4_0[] =
1640 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1641 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1642 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1643 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1644 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1645 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1646 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1647 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1648 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1649 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1650 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1651 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1652 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1653 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1654 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1655 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1656 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1657 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1660 ULONG refcount, expected_refcount;
1661 ID3D11Device *device, *tmp;
1662 ID3D11GeometryShader *gs;
1663 ID3D11VertexShader *vs;
1664 ID3D11PixelShader *ps;
1665 IUnknown *iface;
1666 unsigned int i;
1667 HRESULT hr;
1669 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
1671 D3D_FEATURE_LEVEL feature_level = d3d11_feature_levels[i];
1672 if (!(device = create_device(&feature_level)))
1674 skip("Failed to create device for feature level %#x.\n", feature_level);
1675 continue;
1678 /* vertex shader */
1679 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
1680 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1682 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
1683 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1685 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
1686 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
1687 hr, feature_level);
1689 if (feature_level < D3D_FEATURE_LEVEL_10_0)
1691 refcount = ID3D11Device_Release(device);
1692 ok(!refcount, "Device has %u references left.\n", refcount);
1693 continue;
1696 expected_refcount = get_refcount((IUnknown *)device) + 1;
1697 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
1698 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1700 refcount = get_refcount((IUnknown *)device);
1701 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1702 refcount, expected_refcount);
1703 tmp = NULL;
1704 expected_refcount = refcount + 1;
1705 ID3D11VertexShader_GetDevice(vs, &tmp);
1706 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1707 refcount = get_refcount((IUnknown *)device);
1708 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1709 refcount, expected_refcount);
1710 ID3D11Device_Release(tmp);
1712 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
1713 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1714 "Vertex shader should implement ID3D10VertexShader.\n");
1715 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1717 refcount = ID3D11VertexShader_Release(vs);
1718 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
1720 /* pixel shader */
1721 expected_refcount = get_refcount((IUnknown *)device) + 1;
1722 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
1723 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1725 refcount = get_refcount((IUnknown *)device);
1726 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1727 refcount, expected_refcount);
1728 tmp = NULL;
1729 expected_refcount = refcount + 1;
1730 ID3D11PixelShader_GetDevice(ps, &tmp);
1731 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1732 refcount = get_refcount((IUnknown *)device);
1733 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1734 refcount, expected_refcount);
1735 ID3D11Device_Release(tmp);
1737 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
1738 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1739 "Pixel shader should implement ID3D10PixelShader.\n");
1740 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1742 refcount = ID3D11PixelShader_Release(ps);
1743 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
1745 /* geometry shader */
1746 expected_refcount = get_refcount((IUnknown *)device) + 1;
1747 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
1748 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
1750 refcount = get_refcount((IUnknown *)device);
1751 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1752 refcount, expected_refcount);
1753 tmp = NULL;
1754 expected_refcount = refcount + 1;
1755 ID3D11GeometryShader_GetDevice(gs, &tmp);
1756 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1757 refcount = get_refcount((IUnknown *)device);
1758 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1759 refcount, expected_refcount);
1760 ID3D11Device_Release(tmp);
1762 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
1763 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1764 "Geometry shader should implement ID3D10GeometryShader.\n");
1765 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1767 refcount = ID3D11GeometryShader_Release(gs);
1768 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
1770 refcount = ID3D11Device_Release(device);
1771 ok(!refcount, "Device has %u references left.\n", refcount);
1775 static void test_create_sampler_state(void)
1777 static const struct test
1779 D3D11_FILTER filter;
1780 D3D10_FILTER expected_filter;
1782 desc_conversion_tests[] =
1784 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
1785 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
1786 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
1787 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
1788 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
1789 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
1790 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
1791 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
1792 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
1793 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
1794 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
1796 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
1797 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
1799 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
1800 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
1802 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
1803 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
1805 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
1806 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
1807 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
1810 ID3D11SamplerState *sampler_state1, *sampler_state2;
1811 ID3D10SamplerState *d3d10_sampler_state;
1812 ULONG refcount, expected_refcount;
1813 ID3D11Device *device, *tmp;
1814 D3D11_SAMPLER_DESC desc;
1815 unsigned int i;
1816 HRESULT hr;
1818 if (!(device = create_device(NULL)))
1820 skip("Failed to create device.\n");
1821 return;
1824 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
1825 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1827 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1828 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
1829 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
1830 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
1831 desc.MipLODBias = 0.0f;
1832 desc.MaxAnisotropy = 16;
1833 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1834 desc.BorderColor[0] = 0.0f;
1835 desc.BorderColor[1] = 1.0f;
1836 desc.BorderColor[2] = 0.0f;
1837 desc.BorderColor[3] = 1.0f;
1838 desc.MinLOD = 0.0f;
1839 desc.MaxLOD = 16.0f;
1841 expected_refcount = get_refcount((IUnknown *)device) + 1;
1842 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
1843 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1844 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
1845 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1846 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
1847 refcount = get_refcount((IUnknown *)device);
1848 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1849 tmp = NULL;
1850 expected_refcount = refcount + 1;
1851 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
1852 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1853 refcount = get_refcount((IUnknown *)device);
1854 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1855 ID3D11Device_Release(tmp);
1857 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
1858 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
1859 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
1860 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
1861 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
1862 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
1863 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
1864 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
1865 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
1866 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
1867 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
1868 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
1869 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
1871 refcount = ID3D11SamplerState_Release(sampler_state2);
1872 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1873 refcount = ID3D11SamplerState_Release(sampler_state1);
1874 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1876 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1878 const struct test *current = &desc_conversion_tests[i];
1879 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
1881 desc.Filter = current->filter;
1882 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
1883 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
1884 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
1885 desc.MipLODBias = 0.0f;
1886 desc.MaxAnisotropy = 16;
1887 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1888 desc.BorderColor[0] = 0.0f;
1889 desc.BorderColor[1] = 1.0f;
1890 desc.BorderColor[2] = 0.0f;
1891 desc.BorderColor[3] = 1.0f;
1892 desc.MinLOD = 0.0f;
1893 desc.MaxLOD = 16.0f;
1895 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
1896 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
1898 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
1899 (void **)&d3d10_sampler_state);
1900 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1901 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
1902 if (FAILED(hr))
1904 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
1905 ID3D11SamplerState_Release(sampler_state1);
1906 break;
1909 memcpy(&expected_desc, &desc, sizeof(expected_desc));
1910 expected_desc.Filter = current->expected_filter;
1911 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
1912 expected_desc.MaxAnisotropy = 0;
1913 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
1914 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
1916 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
1917 ok(d3d10_desc.Filter == expected_desc.Filter,
1918 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
1919 ok(d3d10_desc.AddressU == expected_desc.AddressU,
1920 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
1921 ok(d3d10_desc.AddressV == expected_desc.AddressV,
1922 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
1923 ok(d3d10_desc.AddressW == expected_desc.AddressW,
1924 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
1925 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
1926 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
1927 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
1928 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
1929 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
1930 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
1931 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
1932 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
1933 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
1934 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
1935 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
1936 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
1937 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
1938 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
1939 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
1940 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
1941 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
1943 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
1944 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1945 refcount = ID3D11SamplerState_Release(sampler_state1);
1946 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1949 refcount = ID3D11Device_Release(device);
1950 ok(!refcount, "Device has %u references left.\n", refcount);
1953 static void test_create_blend_state(void)
1955 static const D3D11_BLEND_DESC desc_conversion_tests[] =
1958 FALSE, FALSE,
1961 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1962 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
1967 FALSE, TRUE,
1970 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1971 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1974 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1975 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
1978 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1979 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1982 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1983 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
1986 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1987 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1990 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1991 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1994 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1995 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1998 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1999 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2004 FALSE, TRUE,
2007 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2008 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2011 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
2012 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2015 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
2016 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2019 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2020 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2023 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
2024 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2027 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
2028 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2031 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2032 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2035 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2036 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2042 ID3D11BlendState *blend_state1, *blend_state2;
2043 D3D11_BLEND_DESC desc, obtained_desc;
2044 ID3D10BlendState *d3d10_blend_state;
2045 D3D10_BLEND_DESC d3d10_blend_desc;
2046 ULONG refcount, expected_refcount;
2047 ID3D11Device *device, *tmp;
2048 unsigned int i, j;
2049 IUnknown *iface;
2050 HRESULT hr;
2052 if (!(device = create_device(NULL)))
2054 skip("Failed to create device.\n");
2055 return;
2058 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
2059 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2061 memset(&desc, 0, sizeof(desc));
2062 desc.AlphaToCoverageEnable = FALSE;
2063 desc.IndependentBlendEnable = FALSE;
2064 desc.RenderTarget[0].BlendEnable = FALSE;
2065 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
2066 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
2067 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2068 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
2069 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2070 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2071 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2073 expected_refcount = get_refcount((IUnknown *)device) + 1;
2074 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
2075 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2076 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
2077 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2078 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
2079 refcount = get_refcount((IUnknown *)device);
2080 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2081 tmp = NULL;
2082 expected_refcount = refcount + 1;
2083 ID3D11BlendState_GetDevice(blend_state1, &tmp);
2084 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2085 refcount = get_refcount((IUnknown *)device);
2086 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2087 ID3D11Device_Release(tmp);
2089 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
2090 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
2091 obtained_desc.AlphaToCoverageEnable);
2092 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
2093 obtained_desc.IndependentBlendEnable);
2094 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2096 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
2097 "Got unexpected blend enable %#x for render target %u.\n",
2098 obtained_desc.RenderTarget[i].BlendEnable, i);
2099 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
2100 "Got unexpected src blend %u for render target %u.\n",
2101 obtained_desc.RenderTarget[i].SrcBlend, i);
2102 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
2103 "Got unexpected dest blend %u for render target %u.\n",
2104 obtained_desc.RenderTarget[i].DestBlend, i);
2105 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
2106 "Got unexpected blend op %u for render target %u.\n",
2107 obtained_desc.RenderTarget[i].BlendOp, i);
2108 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
2109 "Got unexpected src blend alpha %u for render target %u.\n",
2110 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
2111 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
2112 "Got unexpected dest blend alpha %u for render target %u.\n",
2113 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
2114 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
2115 "Got unexpected blend op alpha %u for render target %u.\n",
2116 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
2117 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
2118 "Got unexpected render target write mask %#x for render target %u.\n",
2119 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
2122 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
2123 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2124 "Blend state should implement ID3D10BlendState.\n");
2125 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2126 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
2127 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2128 "Blend state should implement ID3D10BlendState1.\n");
2129 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2131 refcount = ID3D11BlendState_Release(blend_state1);
2132 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2133 refcount = ID3D11BlendState_Release(blend_state2);
2134 ok(!refcount, "Blend state has %u references left.\n", refcount);
2136 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2138 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
2140 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
2141 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2143 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
2144 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2145 "Blend state should implement ID3D10BlendState.\n");
2146 if (FAILED(hr))
2148 win_skip("Blend state does not implement ID3D10BlendState.\n");
2149 ID3D11BlendState_Release(blend_state1);
2150 break;
2153 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
2154 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
2155 "Got unexpected alpha to coverage enable %#x for test %u.\n",
2156 d3d10_blend_desc.AlphaToCoverageEnable, i);
2157 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
2158 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
2159 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
2160 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
2161 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
2162 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
2163 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
2164 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
2165 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
2166 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
2167 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
2168 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
2169 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
2171 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
2172 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
2173 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2174 d3d10_blend_desc.BlendEnable[j], i, j);
2175 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
2176 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2177 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
2180 ID3D10BlendState_Release(d3d10_blend_state);
2182 refcount = ID3D11BlendState_Release(blend_state1);
2183 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2186 refcount = ID3D11Device_Release(device);
2187 ok(!refcount, "Device has %u references left.\n", refcount);
2190 static void test_create_depthstencil_state(void)
2192 ID3D11DepthStencilState *ds_state1, *ds_state2;
2193 ID3D10DepthStencilState *d3d10_ds_state;
2194 ULONG refcount, expected_refcount;
2195 D3D11_DEPTH_STENCIL_DESC ds_desc;
2196 ID3D11Device *device, *tmp;
2197 HRESULT hr;
2199 if (!(device = create_device(NULL)))
2201 skip("Failed to create device.\n");
2202 return;
2205 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
2206 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2208 ds_desc.DepthEnable = TRUE;
2209 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2210 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
2211 ds_desc.StencilEnable = FALSE;
2212 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2213 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2214 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2215 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2216 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2217 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2218 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2219 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2220 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2221 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2223 expected_refcount = get_refcount((IUnknown *)device) + 1;
2224 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
2225 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2226 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
2227 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2228 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
2229 refcount = get_refcount((IUnknown *)device);
2230 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2231 tmp = NULL;
2232 expected_refcount = refcount + 1;
2233 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
2234 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2235 refcount = get_refcount((IUnknown *)device);
2236 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2237 ID3D11Device_Release(tmp);
2239 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
2240 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2241 "Depth stencil state should implement ID3D10DepthStencilState.\n");
2242 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
2244 refcount = ID3D11DepthStencilState_Release(ds_state2);
2245 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2246 refcount = ID3D11DepthStencilState_Release(ds_state1);
2247 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2249 refcount = ID3D11Device_Release(device);
2250 ok(!refcount, "Device has %u references left.\n", refcount);
2253 static void test_create_rasterizer_state(void)
2255 ID3D11RasterizerState *rast_state1, *rast_state2;
2256 ID3D10RasterizerState *d3d10_rast_state;
2257 ULONG refcount, expected_refcount;
2258 D3D10_RASTERIZER_DESC d3d10_desc;
2259 D3D11_RASTERIZER_DESC desc;
2260 ID3D11Device *device, *tmp;
2261 HRESULT hr;
2263 if (!(device = create_device(NULL)))
2265 skip("Failed to create device.\n");
2266 return;
2269 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
2270 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2272 desc.FillMode = D3D11_FILL_SOLID;
2273 desc.CullMode = D3D11_CULL_BACK;
2274 desc.FrontCounterClockwise = FALSE;
2275 desc.DepthBias = 0;
2276 desc.DepthBiasClamp = 0.0f;
2277 desc.SlopeScaledDepthBias = 0.0f;
2278 desc.DepthClipEnable = TRUE;
2279 desc.ScissorEnable = FALSE;
2280 desc.MultisampleEnable = FALSE;
2281 desc.AntialiasedLineEnable = FALSE;
2283 expected_refcount = get_refcount((IUnknown *)device) + 1;
2284 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
2285 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2286 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
2287 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2288 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
2289 refcount = get_refcount((IUnknown *)device);
2290 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2291 tmp = NULL;
2292 expected_refcount = refcount + 1;
2293 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
2294 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2295 refcount = get_refcount((IUnknown *)device);
2296 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2297 ID3D11Device_Release(tmp);
2299 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
2300 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2301 "Rasterizer state should implement ID3D10RasterizerState.\n");
2302 if (SUCCEEDED(hr))
2304 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
2305 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
2306 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
2307 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
2308 d3d10_desc.FrontCounterClockwise);
2309 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
2310 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
2311 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
2312 d3d10_desc.SlopeScaledDepthBias);
2313 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
2314 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
2315 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
2316 d3d10_desc.MultisampleEnable);
2317 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
2318 d3d10_desc.AntialiasedLineEnable);
2320 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
2321 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
2324 refcount = ID3D11RasterizerState_Release(rast_state2);
2325 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2326 refcount = ID3D11RasterizerState_Release(rast_state1);
2327 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2329 refcount = ID3D11Device_Release(device);
2330 ok(!refcount, "Device has %u references left.\n", refcount);
2333 static void test_create_predicate(void)
2335 static const D3D11_QUERY other_queries[] =
2337 D3D11_QUERY_EVENT,
2338 D3D11_QUERY_OCCLUSION,
2339 D3D11_QUERY_TIMESTAMP,
2340 D3D11_QUERY_TIMESTAMP_DISJOINT,
2341 D3D11_QUERY_PIPELINE_STATISTICS,
2342 D3D11_QUERY_SO_STATISTICS,
2343 D3D11_QUERY_SO_STATISTICS_STREAM0,
2344 D3D11_QUERY_SO_STATISTICS_STREAM1,
2345 D3D11_QUERY_SO_STATISTICS_STREAM2,
2346 D3D11_QUERY_SO_STATISTICS_STREAM3,
2349 ULONG refcount, expected_refcount;
2350 D3D11_QUERY_DESC query_desc;
2351 ID3D11Predicate *predicate;
2352 ID3D11Device *device, *tmp;
2353 IUnknown *iface;
2354 unsigned int i;
2355 HRESULT hr;
2357 if (!(device = create_device(NULL)))
2359 skip("Failed to create device.\n");
2360 return;
2363 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
2364 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2366 query_desc.MiscFlags = 0;
2368 for (i = 0; i < sizeof(other_queries) / sizeof(*other_queries); ++i)
2370 query_desc.Query = other_queries[i];
2371 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2372 ok(hr == E_INVALIDARG, "Got unexpected hr %#x for query type %u.\n", hr, other_queries[i]);
2375 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
2376 expected_refcount = get_refcount((IUnknown *)device) + 1;
2377 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2378 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2379 refcount = get_refcount((IUnknown *)device);
2380 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2381 tmp = NULL;
2382 expected_refcount = refcount + 1;
2383 ID3D11Predicate_GetDevice(predicate, &tmp);
2384 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2385 refcount = get_refcount((IUnknown *)device);
2386 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2387 ID3D11Device_Release(tmp);
2388 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
2389 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2390 "Predicate should implement ID3D10Predicate.\n");
2391 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2392 ID3D11Predicate_Release(predicate);
2394 query_desc.Query = D3D11_QUERY_SO_OVERFLOW_PREDICATE;
2395 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2396 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2397 if (SUCCEEDED(hr))
2398 ID3D11Predicate_Release(predicate);
2400 refcount = ID3D11Device_Release(device);
2401 ok(!refcount, "Device has %u references left.\n", refcount);
2404 static void test_device_removed_reason(void)
2406 ID3D11Device *device;
2407 ULONG refcount;
2408 HRESULT hr;
2410 if (!(device = create_device(NULL)))
2412 skip("Failed to create device.\n");
2413 return;
2416 hr = ID3D11Device_GetDeviceRemovedReason(device);
2417 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2418 hr = ID3D11Device_GetDeviceRemovedReason(device);
2419 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2421 refcount = ID3D11Device_Release(device);
2422 ok(!refcount, "Device has %u references left.\n", refcount);
2425 static void test_private_data(void)
2427 ULONG refcount, expected_refcount;
2428 D3D11_TEXTURE2D_DESC texture_desc;
2429 ID3D10Texture2D *d3d10_texture;
2430 ID3D11Device *test_object;
2431 ID3D11Texture2D *texture;
2432 IDXGIDevice *dxgi_device;
2433 IDXGISurface *surface;
2434 ID3D11Device *device;
2435 IUnknown *ptr;
2436 HRESULT hr;
2437 UINT size;
2439 static const GUID test_guid =
2440 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2441 static const GUID test_guid2 =
2442 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2443 static const DWORD data[] = {1, 2, 3, 4};
2445 if (!(device = create_device(NULL)))
2447 skip("Failed to create device.\n");
2448 return;
2451 test_object = create_device(NULL);
2453 texture_desc.Width = 512;
2454 texture_desc.Height = 512;
2455 texture_desc.MipLevels = 1;
2456 texture_desc.ArraySize = 1;
2457 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2458 texture_desc.SampleDesc.Count = 1;
2459 texture_desc.SampleDesc.Quality = 0;
2460 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2461 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2462 texture_desc.CPUAccessFlags = 0;
2463 texture_desc.MiscFlags = 0;
2465 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2466 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2467 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2468 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
2470 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
2471 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2472 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2473 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2474 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2475 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2476 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2477 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2479 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2480 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2481 size = sizeof(ptr) * 2;
2482 ptr = (IUnknown *)0xdeadbeef;
2483 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2484 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2485 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2486 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2488 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2489 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2490 size = sizeof(ptr) * 2;
2491 ptr = (IUnknown *)0xdeadbeef;
2492 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2493 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2494 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2495 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2496 IDXGIDevice_Release(dxgi_device);
2498 refcount = get_refcount((IUnknown *)test_object);
2499 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2500 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2501 expected_refcount = refcount + 1;
2502 refcount = get_refcount((IUnknown *)test_object);
2503 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2504 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2505 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2506 refcount = get_refcount((IUnknown *)test_object);
2507 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2509 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2510 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2511 --expected_refcount;
2512 refcount = get_refcount((IUnknown *)test_object);
2513 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2515 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2516 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2517 size = sizeof(data);
2518 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
2519 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2520 refcount = get_refcount((IUnknown *)test_object);
2521 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2522 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2523 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2524 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2525 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2527 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2528 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2529 ++expected_refcount;
2530 size = 2 * sizeof(ptr);
2531 ptr = NULL;
2532 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2533 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2534 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2535 ++expected_refcount;
2536 refcount = get_refcount((IUnknown *)test_object);
2537 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2538 IUnknown_Release(ptr);
2539 --expected_refcount;
2541 ptr = (IUnknown *)0xdeadbeef;
2542 size = 1;
2543 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2544 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2545 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2546 size = 2 * sizeof(ptr);
2547 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2548 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2549 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2550 refcount = get_refcount((IUnknown *)test_object);
2551 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2553 size = 1;
2554 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2555 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2556 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2557 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2558 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2559 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2560 size = 0xdeadbabe;
2561 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2562 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2563 ok(size == 0, "Got unexpected size %u.\n", size);
2564 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2565 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2566 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2567 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2569 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
2570 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2571 ptr = NULL;
2572 size = sizeof(ptr);
2573 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
2574 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2575 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2576 IUnknown_Release(ptr);
2578 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2579 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2580 "Texture should implement ID3D10Texture2D.\n");
2581 if (SUCCEEDED(hr))
2583 ptr = NULL;
2584 size = sizeof(ptr);
2585 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
2586 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2587 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2588 IUnknown_Release(ptr);
2589 ID3D10Texture2D_Release(d3d10_texture);
2592 IDXGISurface_Release(surface);
2593 ID3D11Texture2D_Release(texture);
2594 refcount = ID3D11Device_Release(device);
2595 ok(!refcount, "Device has %u references left.\n", refcount);
2596 refcount = ID3D11Device_Release(test_object);
2597 ok(!refcount, "Test object has %u references left.\n", refcount);
2600 static void test_blend(void)
2602 ID3D11RenderTargetView *backbuffer_rtv, *offscreen_rtv;
2603 ID3D11BlendState *src_blend, *dst_blend;
2604 ID3D11Texture2D *backbuffer, *offscreen;
2605 D3D11_SUBRESOURCE_DATA buffer_data;
2606 D3D11_TEXTURE2D_DESC texture_desc;
2607 ID3D11InputLayout *input_layout;
2608 D3D11_BUFFER_DESC buffer_desc;
2609 ID3D11DeviceContext *context;
2610 D3D11_BLEND_DESC blend_desc;
2611 unsigned int stride, offset;
2612 IDXGISwapChain *swapchain;
2613 ID3D11VertexShader *vs;
2614 ID3D11PixelShader *ps;
2615 ID3D11Device *device;
2616 D3D11_VIEWPORT vp;
2617 ID3D11Buffer *vb;
2618 ULONG refcount;
2619 DWORD color;
2620 HWND window;
2621 HRESULT hr;
2623 static const DWORD vs_code[] =
2625 #if 0
2626 struct vs_out
2628 float4 position : SV_POSITION;
2629 float4 color : COLOR;
2632 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
2634 struct vs_out o;
2636 o.position = position;
2637 o.color = color;
2639 return o;
2641 #endif
2642 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
2643 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2644 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2645 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
2646 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2647 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
2648 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
2649 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
2650 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
2651 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
2653 static const DWORD ps_code[] =
2655 #if 0
2656 struct vs_out
2658 float4 position : SV_POSITION;
2659 float4 color : COLOR;
2662 float4 main(struct vs_out i) : SV_TARGET
2664 return i.color;
2666 #endif
2667 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
2668 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
2669 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
2670 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
2671 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2672 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2673 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2674 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2676 static const struct
2678 struct vec3 position;
2679 DWORD diffuse;
2681 quads[] =
2683 /* quad1 */
2684 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
2685 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
2686 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
2687 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
2688 /* quad2 */
2689 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2690 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2691 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2692 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2694 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
2696 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
2697 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
2699 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2700 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2702 if (!(device = create_device(NULL)))
2704 skip("Failed to create device.\n");
2705 return;
2707 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2708 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2709 swapchain = create_swapchain(device, window, TRUE);
2710 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
2711 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2713 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2714 vs_code, sizeof(vs_code), &input_layout);
2715 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2717 buffer_desc.ByteWidth = sizeof(quads);
2718 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
2719 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
2720 buffer_desc.CPUAccessFlags = 0;
2721 buffer_desc.MiscFlags = 0;
2722 buffer_desc.StructureByteStride = 0;
2724 buffer_data.pSysMem = quads;
2725 buffer_data.SysMemPitch = 0;
2726 buffer_data.SysMemSlicePitch = 0;
2728 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
2729 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2730 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
2731 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2732 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
2733 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2735 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
2736 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2738 memset(&blend_desc, 0, sizeof(blend_desc));
2739 blend_desc.RenderTarget[0].BlendEnable = TRUE;
2740 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
2741 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
2742 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2743 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
2744 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
2745 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2746 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2748 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
2749 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2751 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
2752 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
2753 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
2754 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
2756 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
2757 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2759 ID3D11Device_GetImmediateContext(device, &context);
2761 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &backbuffer_rtv, NULL);
2762 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
2763 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2764 stride = sizeof(*quads);
2765 offset = 0;
2766 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
2767 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
2768 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
2770 vp.TopLeftX = 0.0f;
2771 vp.TopLeftY = 0.0f;
2772 vp.Width = 640.0f;
2773 vp.Height = 480.0f;
2774 vp.MinDepth = 0.0f;
2775 vp.MaxDepth = 1.0f;
2776 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
2778 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
2780 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2781 ID3D11DeviceContext_Draw(context, 4, 0);
2782 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2783 ID3D11DeviceContext_Draw(context, 4, 4);
2785 color = get_texture_color(backbuffer, 320, 360);
2786 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
2787 color = get_texture_color(backbuffer, 320, 120);
2788 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
2790 texture_desc.Width = 128;
2791 texture_desc.Height = 128;
2792 texture_desc.MipLevels = 1;
2793 texture_desc.ArraySize = 1;
2794 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
2795 texture_desc.SampleDesc.Count = 1;
2796 texture_desc.SampleDesc.Quality = 0;
2797 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2798 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
2799 texture_desc.CPUAccessFlags = 0;
2800 texture_desc.MiscFlags = 0;
2802 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
2803 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
2805 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
2806 goto done;
2809 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
2810 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2812 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
2814 vp.TopLeftX = 0.0f;
2815 vp.TopLeftY = 0.0f;
2816 vp.Width = 128.0f;
2817 vp.Height = 128.0f;
2818 vp.MinDepth = 0.0f;
2819 vp.MaxDepth = 1.0f;
2820 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
2822 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
2824 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2825 ID3D11DeviceContext_Draw(context, 4, 0);
2826 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2827 ID3D11DeviceContext_Draw(context, 4, 4);
2829 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
2830 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
2831 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
2832 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
2834 ID3D11RenderTargetView_Release(offscreen_rtv);
2835 ID3D11Texture2D_Release(offscreen);
2836 done:
2837 ID3D11BlendState_Release(dst_blend);
2838 ID3D11BlendState_Release(src_blend);
2839 ID3D11PixelShader_Release(ps);
2840 ID3D11VertexShader_Release(vs);
2841 ID3D11Buffer_Release(vb);
2842 ID3D11InputLayout_Release(input_layout);
2843 ID3D11RenderTargetView_Release(backbuffer_rtv);
2844 ID3D11Texture2D_Release(backbuffer);
2845 IDXGISwapChain_Release(swapchain);
2846 ID3D11DeviceContext_Release(context);
2847 refcount = ID3D11Device_Release(device);
2848 ok(!refcount, "Device has %u references left.\n", refcount);
2849 DestroyWindow(window);
2852 static void test_texture(void)
2854 struct shader
2856 const DWORD *code;
2857 size_t size;
2859 struct texture
2861 UINT width;
2862 UINT height;
2863 UINT miplevel_count;
2864 DXGI_FORMAT format;
2865 D3D11_SUBRESOURCE_DATA data[3];
2868 D3D11_SUBRESOURCE_DATA resource_data;
2869 const struct texture *current_texture;
2870 D3D11_TEXTURE2D_DESC texture_desc;
2871 D3D11_SAMPLER_DESC sampler_desc;
2872 ID3D11InputLayout *input_layout;
2873 const struct shader *current_ps;
2874 ID3D11ShaderResourceView *srv;
2875 D3D11_BUFFER_DESC buffer_desc;
2876 ID3D11DeviceContext *context;
2877 ID3D11Texture2D *backbuffer;
2878 ID3D11RenderTargetView *rtv;
2879 ID3D11SamplerState *sampler;
2880 unsigned int stride, offset;
2881 struct texture_readback rb;
2882 IDXGISwapChain *swapchain;
2883 ID3D11Texture2D *texture;
2884 ID3D11VertexShader *vs;
2885 ID3D11PixelShader *ps;
2886 ID3D11Buffer *vb, *cb;
2887 ID3D11Device *device;
2888 unsigned int i, x, y;
2889 struct vec4 miplevel;
2890 D3D11_VIEWPORT vp;
2891 ULONG refcount;
2892 HWND window;
2893 DWORD color;
2894 HRESULT hr;
2896 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
2898 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
2900 static const DWORD vs_code[] =
2902 #if 0
2903 float4 main(float4 position : POSITION) : SV_POSITION
2905 return position;
2907 #endif
2908 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2909 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2910 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2911 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2912 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2913 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2914 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2916 static const DWORD ps_ld_0_code[] =
2918 #if 0
2919 Texture2D t;
2921 float4 main(float4 position : SV_POSITION) : SV_TARGET
2923 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
2924 p *= float3(4.0f, 4.0f, 1.0f);
2925 return t.Load(int3(p));
2927 #endif
2928 0x43425844, 0x0aef49ac, 0x02fa5594, 0xfb8a34cd, 0x8e03ee1d, 0x00000001, 0x00000168, 0x00000003,
2929 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2930 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2931 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2932 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000cc, 0x00000040,
2933 0x00000033, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
2934 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00100032,
2935 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
2936 0x00000000, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
2937 0x00004002, 0x3bcccccd, 0x3c088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2, 0x00000000,
2938 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
2939 0x00000000, 0x0100003e,
2941 static const DWORD ps_ld_1_code[] =
2943 #if 0
2944 Texture2D t;
2946 float4 main(float4 position : SV_POSITION) : SV_TARGET
2948 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
2949 p *= float3(2.0f, 2.0f, 1.0f);
2950 return t.Load(int3(p));
2952 #endif
2953 0x43425844, 0xd43b0155, 0x1ae5af92, 0x34e50992, 0x5e7a0d1a, 0x00000001, 0x00000154, 0x00000003,
2954 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2955 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2956 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2957 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b8, 0x00000040,
2958 0x0000002e, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
2959 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
2960 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3b4ccccd, 0x3b888889, 0x00000000, 0x00000000,
2961 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
2962 0x00004002, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x0700002d, 0x001020f2, 0x00000000,
2963 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
2965 static const DWORD ps_sample_code[] =
2967 #if 0
2968 Texture2D t;
2969 SamplerState s;
2971 float4 main(float4 position : SV_POSITION) : SV_Target
2973 float2 p;
2975 p.x = position.x / 640.0f;
2976 p.y = position.y / 480.0f;
2977 return t.Sample(s, p);
2979 #endif
2980 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
2981 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2982 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2983 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2984 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
2985 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
2986 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
2987 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
2988 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
2989 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
2991 static const DWORD ps_sample_l_code[] =
2993 #if 0
2994 Texture2D t;
2995 SamplerState s;
2997 float level;
2999 float4 main(float4 position : SV_POSITION) : SV_Target
3001 float2 p;
3003 p.x = position.x / 640.0f;
3004 p.y = position.y / 480.0f;
3005 return t.SampleLevel(s, p, level);
3007 #endif
3008 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
3009 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3010 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3011 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3012 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3013 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3014 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3015 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3016 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
3017 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3018 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3020 static const struct shader ps_ld_0 = {ps_ld_0_code, sizeof(ps_ld_0_code)};
3021 static const struct shader ps_ld_1 = {ps_ld_1_code, sizeof(ps_ld_1_code)};
3022 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
3023 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
3024 static const struct
3026 struct vec2 position;
3028 quad[] =
3030 {{-1.0f, -1.0f}},
3031 {{-1.0f, 1.0f}},
3032 {{ 1.0f, -1.0f}},
3033 {{ 1.0f, 1.0f}},
3035 static const DWORD rgba_level_0[] =
3037 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3038 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3039 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3040 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3042 static const DWORD rgba_level_1[] =
3044 0xffffffff, 0xff0000ff,
3045 0xff000000, 0xff00ff00,
3047 static const DWORD rgba_level_2[] =
3049 0xffff0000,
3051 static const BYTE bc1_data[4 * 8] =
3053 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3054 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3055 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3056 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3058 static const BYTE bc2_data[4 * 16] =
3060 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3061 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3062 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3063 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3065 static const BYTE bc3_data[4 * 16] =
3067 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3068 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3069 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3070 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3072 static const struct texture rgba_texture =
3074 4, 4, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
3076 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
3077 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
3078 {rgba_level_2, sizeof(*rgba_level_2), 0},
3081 static const struct texture bc1_texture = {8, 8, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
3082 static const struct texture bc2_texture = {8, 8, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
3083 static const struct texture bc3_texture = {8, 8, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
3084 static const DWORD level_1_colors[] =
3086 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3087 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3088 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3089 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3091 static const DWORD lerp_1_2_colors[] =
3093 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3094 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3095 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3096 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3098 static const DWORD level_2_colors[] =
3100 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3101 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3102 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3103 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3105 static const DWORD bc_colors[] =
3107 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3108 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3109 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3110 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3112 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3114 static const struct test
3116 const struct shader *ps;
3117 const struct texture *texture;
3118 D3D11_FILTER filter;
3119 float lod_bias;
3120 float min_lod;
3121 float max_lod;
3122 float miplevel;
3123 const DWORD *expected_colors;
3125 tests[] =
3127 {&ps_ld_0, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3128 {&ps_ld_1, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, level_1_colors},
3129 {&ps_sample, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3130 {&ps_sample, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3131 {&ps_sample, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3132 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3133 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3134 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, rgba_level_0},
3135 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3136 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.4f, rgba_level_0},
3137 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.5f, level_1_colors},
3138 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_1_colors},
3139 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.4f, level_1_colors},
3140 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3141 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 2.0f, level_2_colors},
3142 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 3.0f, level_2_colors},
3143 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 4.0f, level_2_colors},
3144 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, lerp_1_2_colors},
3145 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -2.0f, rgba_level_0},
3146 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_1_colors},
3147 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_2_colors},
3148 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_2_colors},
3149 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3150 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3151 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3152 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3153 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3154 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3155 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3156 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3157 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3158 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3159 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3162 if (!(device = create_device(NULL)))
3164 skip("Failed to create device.\n");
3165 return;
3167 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3168 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3169 swapchain = create_swapchain(device, window, TRUE);
3170 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
3171 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3173 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3174 vs_code, sizeof(vs_code), &input_layout);
3175 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3177 buffer_desc.ByteWidth = sizeof(quad);
3178 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3179 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3180 buffer_desc.CPUAccessFlags = 0;
3181 buffer_desc.MiscFlags = 0;
3182 buffer_desc.StructureByteStride = 0;
3184 resource_data.pSysMem = quad;
3185 resource_data.SysMemPitch = 0;
3186 resource_data.SysMemSlicePitch = 0;
3188 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3189 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3191 buffer_desc.ByteWidth = sizeof(miplevel);
3192 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3194 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
3195 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3197 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3198 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3200 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &rtv);
3201 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3203 ID3D11Device_GetImmediateContext(device, &context);
3205 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
3206 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3207 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3208 stride = sizeof(*quad);
3209 offset = 0;
3210 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3211 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3212 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
3214 vp.TopLeftX = 0.0f;
3215 vp.TopLeftY = 0.0f;
3216 vp.Width = 640.0f;
3217 vp.Height = 480.0f;
3218 vp.MinDepth = 0.0f;
3219 vp.MaxDepth = 1.0f;
3220 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3222 texture_desc.Width = 4;
3223 texture_desc.Height = 4;
3224 texture_desc.MipLevels = 3;
3225 texture_desc.ArraySize = 1;
3226 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3227 texture_desc.SampleDesc.Count = 1;
3228 texture_desc.SampleDesc.Quality = 0;
3229 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3230 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3231 texture_desc.CPUAccessFlags = 0;
3232 texture_desc.MiscFlags = 0;
3234 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
3235 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
3236 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
3237 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
3238 sampler_desc.MipLODBias = 0.0f;
3239 sampler_desc.MaxAnisotropy = 0;
3240 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3241 sampler_desc.BorderColor[0] = 0.0f;
3242 sampler_desc.BorderColor[1] = 0.0f;
3243 sampler_desc.BorderColor[2] = 0.0f;
3244 sampler_desc.BorderColor[3] = 0.0f;
3245 sampler_desc.MinLOD = 0.0f;
3246 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
3248 ps = NULL;
3249 srv = NULL;
3250 sampler = NULL;
3251 texture = NULL;
3252 current_ps = NULL;
3253 current_texture = NULL;
3254 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3256 const struct test *test = &tests[i];
3258 if (current_ps != test->ps)
3260 if (ps)
3261 ID3D11PixelShader_Release(ps);
3263 current_ps = test->ps;
3265 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
3266 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
3268 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3271 if (current_texture != test->texture)
3273 if (texture)
3274 ID3D11Texture2D_Release(texture);
3275 if (srv)
3276 ID3D11ShaderResourceView_Release(srv);
3278 current_texture = test->texture;
3280 texture_desc.Width = current_texture->width;
3281 texture_desc.Height = current_texture->height;
3282 texture_desc.MipLevels = current_texture->miplevel_count;
3283 texture_desc.Format = current_texture->format;
3285 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
3286 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3288 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
3289 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
3291 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
3294 if (!sampler || (sampler_desc.Filter != test->filter
3295 || sampler_desc.MipLODBias != test->lod_bias
3296 || sampler_desc.MinLOD != test->min_lod
3297 || sampler_desc.MaxLOD != test->max_lod))
3299 if (sampler)
3300 ID3D11SamplerState_Release(sampler);
3302 sampler_desc.Filter = test->filter;
3303 sampler_desc.MipLODBias = test->lod_bias;
3304 sampler_desc.MinLOD = test->min_lod;
3305 sampler_desc.MaxLOD = test->max_lod;
3307 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
3308 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3310 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
3313 miplevel.x = test->miplevel;
3314 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &miplevel, 0, 0);
3316 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
3317 ID3D11DeviceContext_Draw(context, 4, 0);
3319 get_texture_readback(backbuffer, &rb);
3320 for (x = 0; x < 4; ++x)
3322 for (y = 0; y < 4; ++y)
3324 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
3325 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
3326 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
3329 release_texture_readback(&rb);
3331 ID3D11ShaderResourceView_Release(srv);
3332 ID3D11SamplerState_Release(sampler);
3333 ID3D11Texture2D_Release(texture);
3334 ID3D11PixelShader_Release(ps);
3336 ID3D11Buffer_Release(cb);
3337 ID3D11VertexShader_Release(vs);
3338 ID3D11Buffer_Release(vb);
3339 ID3D11InputLayout_Release(input_layout);
3340 ID3D11RenderTargetView_Release(rtv);
3341 ID3D11Texture2D_Release(backbuffer);
3342 ID3D11DeviceContext_Release(context);
3343 IDXGISwapChain_Release(swapchain);
3344 refcount = ID3D11Device_Release(device);
3345 ok(!refcount, "Device has %u references left.\n", refcount);
3346 DestroyWindow(window);
3349 static void test_scissor(void)
3351 ID3D11DeviceContext *immediate_context;
3352 D3D11_SUBRESOURCE_DATA buffer_data;
3353 ID3D11InputLayout *input_layout;
3354 D3D11_RASTERIZER_DESC rs_desc;
3355 D3D11_BUFFER_DESC buffer_desc;
3356 ID3D11RenderTargetView *rtv;
3357 ID3D11Texture2D *backbuffer;
3358 unsigned int stride, offset;
3359 ID3D11RasterizerState *rs;
3360 IDXGISwapChain *swapchain;
3361 D3D11_RECT scissor_rect;
3362 ID3D11VertexShader *vs;
3363 ID3D11PixelShader *ps;
3364 ID3D11Device *device;
3365 D3D11_VIEWPORT vp;
3366 ID3D11Buffer *vb;
3367 ULONG refcount;
3368 DWORD color;
3369 HWND window;
3370 HRESULT hr;
3372 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
3373 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3375 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3377 static const DWORD vs_code[] =
3379 #if 0
3380 float4 main(float4 position : POSITION) : SV_POSITION
3382 return position;
3384 #endif
3385 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
3386 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
3387 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
3388 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
3389 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3390 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3391 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3392 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3393 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3394 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
3395 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3396 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3397 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3398 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3400 static const DWORD ps_code[] =
3402 #if 0
3403 float4 main(float4 position : SV_POSITION) : SV_Target
3405 return float4(0.0, 1.0, 0.0, 1.0);
3407 #endif
3408 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
3409 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
3410 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
3411 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
3412 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3413 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
3414 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3415 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
3416 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
3417 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
3418 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
3419 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3420 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3421 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3423 static const struct
3425 float x, y;
3427 quad[] =
3429 {-1.0f, -1.0f},
3430 {-1.0f, 1.0f},
3431 { 1.0f, -1.0f},
3432 { 1.0f, 1.0f},
3435 if (!(device = create_device(NULL)))
3437 skip("Failed to create device.\n");
3438 return;
3440 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3441 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3442 swapchain = create_swapchain(device, window, TRUE);
3443 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
3444 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3446 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3447 vs_code, sizeof(vs_code), &input_layout);
3448 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3450 buffer_desc.ByteWidth = sizeof(quad);
3451 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3452 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3453 buffer_desc.CPUAccessFlags = 0;
3454 buffer_desc.MiscFlags = 0;
3455 buffer_desc.StructureByteStride = 0;
3457 buffer_data.pSysMem = quad;
3458 buffer_data.SysMemPitch = 0;
3459 buffer_data.SysMemSlicePitch = 0;
3461 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
3462 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3463 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3464 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3465 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3466 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3468 rs_desc.FillMode = D3D11_FILL_SOLID;
3469 rs_desc.CullMode = D3D11_CULL_BACK;
3470 rs_desc.FrontCounterClockwise = FALSE;
3471 rs_desc.DepthBias = 0;
3472 rs_desc.DepthBiasClamp = 0.0f;
3473 rs_desc.SlopeScaledDepthBias = 0.0f;
3474 rs_desc.DepthClipEnable = TRUE;
3475 rs_desc.ScissorEnable = TRUE;
3476 rs_desc.MultisampleEnable = FALSE;
3477 rs_desc.AntialiasedLineEnable = FALSE;
3478 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
3479 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3481 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &rtv);
3482 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3484 ID3D11Device_GetImmediateContext(device, &immediate_context);
3486 ID3D11DeviceContext_IASetInputLayout(immediate_context, input_layout);
3487 ID3D11DeviceContext_IASetPrimitiveTopology(immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3488 stride = sizeof(*quad);
3489 offset = 0;
3490 ID3D11DeviceContext_IASetVertexBuffers(immediate_context, 0, 1, &vb, &stride, &offset);
3491 ID3D11DeviceContext_VSSetShader(immediate_context, vs, NULL, 0);
3492 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
3494 vp.TopLeftX = 0.0f;
3495 vp.TopLeftY = 0.0f;
3496 vp.Width = 640.0f;
3497 vp.Height = 480.0f;
3498 vp.MinDepth = 0.0f;
3499 vp.MaxDepth = 1.0f;
3500 ID3D11DeviceContext_RSSetViewports(immediate_context, 1, &vp);
3502 scissor_rect.left = 160;
3503 scissor_rect.top = 120;
3504 scissor_rect.right = 480;
3505 scissor_rect.bottom = 360;
3506 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
3508 ID3D11DeviceContext_OMSetRenderTargets(immediate_context, 1, &rtv, NULL);
3510 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
3511 color = get_texture_color(backbuffer, 320, 240);
3512 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3514 ID3D11DeviceContext_Draw(immediate_context, 4, 0);
3515 color = get_texture_color(backbuffer, 320, 60);
3516 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3517 color = get_texture_color(backbuffer, 80, 240);
3518 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3519 color = get_texture_color(backbuffer, 320, 240);
3520 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3521 color = get_texture_color(backbuffer, 560, 240);
3522 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3523 color = get_texture_color(backbuffer, 320, 420);
3524 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3526 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
3527 ID3D11DeviceContext_RSSetState(immediate_context, rs);
3528 ID3D11DeviceContext_Draw(immediate_context, 4, 0);
3529 color = get_texture_color(backbuffer, 320, 60);
3530 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3531 color = get_texture_color(backbuffer, 80, 240);
3532 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3533 color = get_texture_color(backbuffer, 320, 240);
3534 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3535 color = get_texture_color(backbuffer, 560, 240);
3536 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3537 color = get_texture_color(backbuffer, 320, 420);
3538 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3540 ID3D11RenderTargetView_Release(rtv);
3541 ID3D11RasterizerState_Release(rs);
3542 ID3D11PixelShader_Release(ps);
3543 ID3D11VertexShader_Release(vs);
3544 ID3D11Buffer_Release(vb);
3545 ID3D11InputLayout_Release(input_layout);
3546 ID3D11Texture2D_Release(backbuffer);
3547 IDXGISwapChain_Release(swapchain);
3548 ID3D11DeviceContext_Release(immediate_context);
3549 refcount = ID3D11Device_Release(device);
3550 ok(!refcount, "Device has %u references left.\n", refcount);
3551 DestroyWindow(window);
3554 static void test_il_append_aligned(void)
3556 ID3D11RenderTargetView *backbuffer_rtv;
3557 D3D11_SUBRESOURCE_DATA resource_data;
3558 ID3D11InputLayout *input_layout;
3559 D3D11_BUFFER_DESC buffer_desc;
3560 ID3D11DeviceContext *context;
3561 ID3D11Texture2D *backbuffer;
3562 unsigned int stride, offset;
3563 IDXGISwapChain *swapchain;
3564 ID3D11VertexShader *vs;
3565 ID3D11PixelShader *ps;
3566 ID3D11Device *device;
3567 ID3D11Buffer *vb[3];
3568 D3D11_VIEWPORT vp;
3569 ULONG refcount;
3570 DWORD color;
3571 HWND window;
3572 HRESULT hr;
3574 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3576 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
3577 D3D11_INPUT_PER_INSTANCE_DATA, 2},
3578 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
3579 D3D11_INPUT_PER_INSTANCE_DATA, 1},
3580 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
3581 D3D11_INPUT_PER_VERTEX_DATA, 0},
3582 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
3583 D3D11_INPUT_PER_INSTANCE_DATA, 1},
3584 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
3585 D3D11_INPUT_PER_INSTANCE_DATA, 2},
3587 static const DWORD vs_code[] =
3589 #if 0
3590 struct vs_in
3592 float4 position : POSITION;
3593 float2 color_xy : COLOR0;
3594 float2 color_zw : COLOR1;
3595 unsigned int instance_id : SV_INSTANCEID;
3598 struct vs_out
3600 float4 position : SV_POSITION;
3601 float2 color_xy : COLOR0;
3602 float2 color_zw : COLOR1;
3605 struct vs_out main(struct vs_in i)
3607 struct vs_out o;
3609 o.position = i.position;
3610 o.position.x += i.instance_id * 0.5;
3611 o.color_xy = i.color_xy;
3612 o.color_zw = i.color_zw;
3614 return o;
3616 #endif
3617 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
3618 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
3619 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
3620 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
3621 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
3622 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
3623 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3624 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
3625 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
3626 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
3627 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
3628 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
3629 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
3630 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
3631 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
3632 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
3633 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
3635 static const DWORD ps_code[] =
3637 #if 0
3638 struct vs_out
3640 float4 position : SV_POSITION;
3641 float2 color_xy : COLOR0;
3642 float2 color_zw : COLOR1;
3645 float4 main(struct vs_out i) : SV_TARGET
3647 return float4(i.color_xy.xy, i.color_zw.xy);
3649 #endif
3650 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
3651 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
3652 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
3653 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
3654 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3655 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
3656 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
3657 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3658 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3660 static const struct
3662 struct vec4 position;
3664 stream0[] =
3666 {{-1.0f, -1.0f, 0.0f, 1.0f}},
3667 {{-1.0f, 1.0f, 0.0f, 1.0f}},
3668 {{-0.5f, -1.0f, 0.0f, 1.0f}},
3669 {{-0.5f, 1.0f, 0.0f, 1.0f}},
3671 static const struct
3673 struct vec2 color2;
3674 struct vec2 color1;
3676 stream1[] =
3678 {{0.5f, 0.5f}, {0.0f, 1.0f}},
3679 {{0.5f, 0.5f}, {1.0f, 1.0f}},
3681 static const struct
3683 struct vec2 color3;
3684 struct vec2 color0;
3686 stream2[] =
3688 {{0.5f, 0.5f}, {1.0f, 0.0f}},
3689 {{0.5f, 0.5f}, {0.0f, 1.0f}},
3690 {{0.5f, 0.5f}, {0.0f, 0.0f}},
3691 {{0.5f, 0.5f}, {1.0f, 0.0f}},
3693 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3695 if (!(device = create_device(NULL)))
3697 skip("Failed to create device.\n");
3698 return;
3700 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3701 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3702 swapchain = create_swapchain(device, window, TRUE);
3703 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
3704 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3706 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3707 vs_code, sizeof(vs_code), &input_layout);
3708 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3710 buffer_desc.ByteWidth = sizeof(stream0);
3711 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3712 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3713 buffer_desc.CPUAccessFlags = 0;
3714 buffer_desc.MiscFlags = 0;
3715 buffer_desc.StructureByteStride = 0;
3717 resource_data.pSysMem = stream0;
3718 resource_data.SysMemPitch = 0;
3719 resource_data.SysMemSlicePitch = 0;
3721 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
3722 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3724 buffer_desc.ByteWidth = sizeof(stream1);
3725 resource_data.pSysMem = stream1;
3727 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
3728 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3730 buffer_desc.ByteWidth = sizeof(stream2);
3731 resource_data.pSysMem = stream2;
3733 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
3734 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3736 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3737 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3738 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3739 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3741 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
3742 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3744 ID3D11Device_GetImmediateContext(device, &context);
3746 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &backbuffer_rtv, NULL);
3747 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3748 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3749 offset = 0;
3750 stride = sizeof(*stream0);
3751 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
3752 stride = sizeof(*stream1);
3753 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
3754 stride = sizeof(*stream2);
3755 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
3756 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3757 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3759 vp.TopLeftX = 0.0f;
3760 vp.TopLeftY = 0.0f;
3761 vp.Width = 640.0f;
3762 vp.Height = 480.0f;
3763 vp.MinDepth = 0.0f;
3764 vp.MaxDepth = 1.0f;
3765 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3767 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
3769 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
3771 color = get_texture_color(backbuffer, 80, 240);
3772 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3773 color = get_texture_color(backbuffer, 240, 240);
3774 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3775 color = get_texture_color(backbuffer, 400, 240);
3776 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3777 color = get_texture_color(backbuffer, 560, 240);
3778 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
3780 ID3D11PixelShader_Release(ps);
3781 ID3D11VertexShader_Release(vs);
3782 ID3D11Buffer_Release(vb[2]);
3783 ID3D11Buffer_Release(vb[1]);
3784 ID3D11Buffer_Release(vb[0]);
3785 ID3D11InputLayout_Release(input_layout);
3786 ID3D11RenderTargetView_Release(backbuffer_rtv);
3787 ID3D11Texture2D_Release(backbuffer);
3788 IDXGISwapChain_Release(swapchain);
3789 ID3D11DeviceContext_Release(context);
3790 refcount = ID3D11Device_Release(device);
3791 ok(!refcount, "Device has %u references left.\n", refcount);
3792 DestroyWindow(window);
3795 static void test_fragment_coords(void)
3797 ID3D11RenderTargetView *backbuffer_rtv;
3798 D3D11_SUBRESOURCE_DATA resource_data;
3799 ID3D11InputLayout *input_layout;
3800 ID3D11PixelShader *ps, *ps_frac;
3801 D3D11_BUFFER_DESC buffer_desc;
3802 ID3D11DeviceContext *context;
3803 ID3D11Texture2D *backbuffer;
3804 unsigned int stride, offset;
3805 IDXGISwapChain *swapchain;
3806 ID3D11Buffer *vb, *ps_cb;
3807 ID3D11VertexShader *vs;
3808 ID3D11Device *device;
3809 D3D11_VIEWPORT vp;
3810 ULONG refcount;
3811 DWORD color;
3812 HWND window;
3813 HRESULT hr;
3815 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3817 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3819 static const DWORD vs_code[] =
3821 #if 0
3822 float4 main(float4 position : POSITION) : SV_POSITION
3824 return position;
3826 #endif
3827 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3828 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3829 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3830 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3831 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3832 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3833 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3835 static const DWORD ps_code[] =
3837 #if 0
3838 float2 cutoff;
3840 float4 main(float4 position : SV_POSITION) : SV_TARGET
3842 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
3844 if (position.x > cutoff.x)
3845 ret.y = 1.0;
3846 if (position.y > cutoff.y)
3847 ret.z = 1.0;
3849 return ret;
3851 #endif
3852 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
3853 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3854 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3855 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3856 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
3857 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
3858 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
3859 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
3860 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
3861 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
3862 0x0100003e,
3864 static const DWORD ps_frac_code[] =
3866 #if 0
3867 float4 main(float4 position : SV_POSITION) : SV_TARGET
3869 return float4(frac(position.xy), 0.0, 1.0);
3871 #endif
3872 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
3873 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3874 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3875 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3876 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
3877 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3878 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
3879 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
3881 static const struct
3883 struct vec2 position;
3885 quad[] =
3887 {{-1.0f, -1.0f}},
3888 {{-1.0f, 1.0f}},
3889 {{ 1.0f, -1.0f}},
3890 {{ 1.0f, 1.0f}},
3892 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3893 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
3895 if (!(device = create_device(NULL)))
3897 skip("Failed to create device.\n");
3898 return;
3900 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3901 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3902 swapchain = create_swapchain(device, window, TRUE);
3903 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
3904 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3906 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3907 vs_code, sizeof(vs_code), &input_layout);
3908 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3910 buffer_desc.ByteWidth = sizeof(quad);
3911 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3912 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3913 buffer_desc.CPUAccessFlags = 0;
3914 buffer_desc.MiscFlags = 0;
3915 buffer_desc.StructureByteStride = 0;
3917 resource_data.pSysMem = quad;
3918 resource_data.SysMemPitch = 0;
3919 resource_data.SysMemSlicePitch = 0;
3921 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3922 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3924 buffer_desc.ByteWidth = sizeof(cutoff);
3925 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3927 resource_data.pSysMem = &cutoff;
3929 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3930 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3932 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3933 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3934 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3935 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3936 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
3937 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3939 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
3940 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3942 ID3D11Device_GetImmediateContext(device, &context);
3944 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &backbuffer_rtv, NULL);
3945 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3946 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3947 stride = sizeof(*quad);
3948 offset = 0;
3949 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3950 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3951 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
3952 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3954 vp.TopLeftX = 0.0f;
3955 vp.TopLeftY = 0.0f;
3956 vp.Width = 640.0f;
3957 vp.Height = 480.0f;
3958 vp.MinDepth = 0.0f;
3959 vp.MaxDepth = 1.0f;
3960 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3962 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
3964 ID3D11DeviceContext_Draw(context, 4, 0);
3966 color = get_texture_color(backbuffer, 319, 239);
3967 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3968 color = get_texture_color(backbuffer, 320, 239);
3969 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3970 color = get_texture_color(backbuffer, 319, 240);
3971 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3972 color = get_texture_color(backbuffer, 320, 240);
3973 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3975 ID3D11Buffer_Release(ps_cb);
3976 cutoff.x = 16.0f;
3977 cutoff.y = 16.0f;
3978 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3979 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3980 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
3982 ID3D11DeviceContext_Draw(context, 4, 0);
3984 color = get_texture_color(backbuffer, 14, 14);
3985 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3986 color = get_texture_color(backbuffer, 18, 14);
3987 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3988 color = get_texture_color(backbuffer, 14, 18);
3989 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3990 color = get_texture_color(backbuffer, 18, 18);
3991 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3993 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
3994 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
3996 ID3D11DeviceContext_Draw(context, 4, 0);
3998 color = get_texture_color(backbuffer, 14, 14);
3999 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
4001 ID3D11Buffer_Release(ps_cb);
4002 ID3D11PixelShader_Release(ps_frac);
4003 ID3D11PixelShader_Release(ps);
4004 ID3D11VertexShader_Release(vs);
4005 ID3D11Buffer_Release(vb);
4006 ID3D11InputLayout_Release(input_layout);
4007 ID3D11RenderTargetView_Release(backbuffer_rtv);
4008 ID3D11Texture2D_Release(backbuffer);
4009 IDXGISwapChain_Release(swapchain);
4010 ID3D11DeviceContext_Release(context);
4011 refcount = ID3D11Device_Release(device);
4012 ok(!refcount, "Device has %u references left.\n", refcount);
4013 DestroyWindow(window);
4016 static void test_update_subresource(void)
4018 ID3D11RenderTargetView *backbuffer_rtv;
4019 D3D11_SUBRESOURCE_DATA resource_data;
4020 D3D11_TEXTURE2D_DESC texture_desc;
4021 ID3D11SamplerState *sampler_state;
4022 ID3D11ShaderResourceView *ps_srv;
4023 D3D11_SAMPLER_DESC sampler_desc;
4024 ID3D11InputLayout *input_layout;
4025 D3D11_BUFFER_DESC buffer_desc;
4026 ID3D11DeviceContext *context;
4027 ID3D11Texture2D *backbuffer;
4028 unsigned int stride, offset;
4029 struct texture_readback rb;
4030 IDXGISwapChain *swapchain;
4031 ID3D11Texture2D *texture;
4032 ID3D11VertexShader *vs;
4033 ID3D11PixelShader *ps;
4034 ID3D11Device *device;
4035 D3D11_VIEWPORT vp;
4036 unsigned int i, j;
4037 ID3D11Buffer *vb;
4038 ULONG refcount;
4039 D3D11_BOX box;
4040 DWORD color;
4041 HWND window;
4042 HRESULT hr;
4044 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4046 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
4048 static const DWORD vs_code[] =
4050 #if 0
4051 float4 main(float4 position : POSITION) : SV_POSITION
4053 return position;
4055 #endif
4056 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4057 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4058 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4059 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4060 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4061 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4062 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4064 static const DWORD ps_code[] =
4066 #if 0
4067 Texture2D t;
4068 SamplerState s;
4070 float4 main(float4 position : SV_POSITION) : SV_Target
4072 float2 p;
4074 p.x = position.x / 640.0f;
4075 p.y = position.y / 480.0f;
4076 return t.Sample(s, p);
4078 #endif
4079 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4080 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4081 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4082 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4083 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4084 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4085 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4086 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4087 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4088 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4090 static const struct
4092 float x, y;
4094 quad[] =
4096 {-1.0f, -1.0f},
4097 {-1.0f, 1.0f},
4098 { 1.0f, -1.0f},
4099 { 1.0f, 1.0f},
4101 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4102 static const DWORD bitmap_data[] =
4104 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4105 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4106 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4107 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4109 static const DWORD expected_colors[] =
4111 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
4112 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4113 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
4114 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
4117 if (!(device = create_device(NULL)))
4119 skip("Failed to create device.\n");
4120 return;
4122 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4123 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4124 swapchain = create_swapchain(device, window, TRUE);
4125 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
4126 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4128 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4129 vs_code, sizeof(vs_code), &input_layout);
4130 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4132 buffer_desc.ByteWidth = sizeof(quad);
4133 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4134 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4135 buffer_desc.CPUAccessFlags = 0;
4136 buffer_desc.MiscFlags = 0;
4137 buffer_desc.StructureByteStride = 0;
4139 resource_data.pSysMem = quad;
4140 resource_data.SysMemPitch = 0;
4141 resource_data.SysMemSlicePitch = 0;
4143 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4144 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4146 texture_desc.Width = 4;
4147 texture_desc.Height = 4;
4148 texture_desc.MipLevels = 1;
4149 texture_desc.ArraySize = 1;
4150 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4151 texture_desc.SampleDesc.Count = 1;
4152 texture_desc.SampleDesc.Quality = 0;
4153 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4154 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4155 texture_desc.CPUAccessFlags = 0;
4156 texture_desc.MiscFlags = 0;
4158 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4159 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4161 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
4162 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4164 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4165 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4166 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4167 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4168 sampler_desc.MipLODBias = 0.0f;
4169 sampler_desc.MaxAnisotropy = 0;
4170 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4171 sampler_desc.BorderColor[0] = 0.0f;
4172 sampler_desc.BorderColor[1] = 0.0f;
4173 sampler_desc.BorderColor[2] = 0.0f;
4174 sampler_desc.BorderColor[3] = 0.0f;
4175 sampler_desc.MinLOD = 0.0f;
4176 sampler_desc.MaxLOD = 0.0f;
4178 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4179 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4181 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4182 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4183 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4184 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4186 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
4187 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4189 ID3D11Device_GetImmediateContext(device, &context);
4191 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &backbuffer_rtv, NULL);
4192 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4193 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4194 stride = sizeof(*quad);
4195 offset = 0;
4196 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
4197 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4198 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
4199 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
4200 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4202 vp.TopLeftX = 0.0f;
4203 vp.TopLeftY = 0.0f;
4204 vp.Width = 640.0f;
4205 vp.Height = 480.0f;
4206 vp.MinDepth = 0.0f;
4207 vp.MaxDepth = 1.0f;
4208 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4210 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
4212 ID3D11DeviceContext_Draw(context, 4, 0);
4213 get_texture_readback(backbuffer, &rb);
4214 for (i = 0; i < 4; ++i)
4216 for (j = 0; j < 4; ++j)
4218 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4219 ok(compare_color(color, 0x00000000, 0),
4220 "Got unexpected color 0x%08x at (%u, %u).\n", color, j, i);
4223 release_texture_readback(&rb);
4225 set_box(&box, 1, 1, 0, 3, 3, 1);
4226 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4227 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4228 set_box(&box, 0, 3, 0, 3, 4, 1);
4229 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4230 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
4231 set_box(&box, 0, 0, 0, 4, 1, 1);
4232 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4233 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
4234 set_box(&box, 0, 1, 0, 1, 3, 1);
4235 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4236 &bitmap_data[2], sizeof(*bitmap_data), 0);
4237 set_box(&box, 4, 4, 0, 3, 1, 1);
4238 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4239 bitmap_data, sizeof(*bitmap_data), 0);
4240 ID3D11DeviceContext_Draw(context, 4, 0);
4241 get_texture_readback(backbuffer, &rb);
4242 for (i = 0; i < 4; ++i)
4244 for (j = 0; j < 4; ++j)
4246 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4247 ok(compare_color(color, expected_colors[j + i * 4], 1),
4248 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4249 color, j, i, expected_colors[j + i * 4]);
4252 release_texture_readback(&rb);
4254 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
4255 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4256 ID3D11DeviceContext_Draw(context, 4, 0);
4257 get_texture_readback(backbuffer, &rb);
4258 for (i = 0; i < 4; ++i)
4260 for (j = 0; j < 4; ++j)
4262 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4263 ok(compare_color(color, bitmap_data[j + i * 4], 1),
4264 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4265 color, j, i, bitmap_data[j + i * 4]);
4268 release_texture_readback(&rb);
4270 ID3D11PixelShader_Release(ps);
4271 ID3D11VertexShader_Release(vs);
4272 ID3D11SamplerState_Release(sampler_state);
4273 ID3D11ShaderResourceView_Release(ps_srv);
4274 ID3D11Texture2D_Release(texture);
4275 ID3D11Buffer_Release(vb);
4276 ID3D11InputLayout_Release(input_layout);
4277 ID3D11RenderTargetView_Release(backbuffer_rtv);
4278 ID3D11Texture2D_Release(backbuffer);
4279 IDXGISwapChain_Release(swapchain);
4280 ID3D11DeviceContext_Release(context);
4281 refcount = ID3D11Device_Release(device);
4282 ok(!refcount, "Device has %u references left.\n", refcount);
4283 DestroyWindow(window);
4286 static void test_resource_map(void)
4288 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
4289 D3D11_TEXTURE3D_DESC texture3d_desc;
4290 D3D11_TEXTURE2D_DESC texture2d_desc;
4291 D3D11_BUFFER_DESC buffer_desc;
4292 ID3D11DeviceContext *context;
4293 ID3D11Texture3D *texture3d;
4294 ID3D11Texture2D *texture2d;
4295 ID3D11Buffer *buffer;
4296 ID3D11Device *device;
4297 ULONG refcount;
4298 HRESULT hr;
4299 DWORD data;
4301 if (!(device = create_device(NULL)))
4303 skip("Failed to create device.\n");
4304 return;
4307 ID3D11Device_GetImmediateContext(device, &context);
4309 buffer_desc.ByteWidth = 1024;
4310 buffer_desc.Usage = D3D11_USAGE_STAGING;
4311 buffer_desc.BindFlags = 0;
4312 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4313 buffer_desc.MiscFlags = 0;
4314 buffer_desc.StructureByteStride = 0;
4316 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4317 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4319 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4320 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4322 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4323 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4324 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
4325 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4326 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
4327 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4328 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
4330 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4331 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4332 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
4333 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4334 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
4335 data = *((DWORD *)mapped_subresource.pData);
4336 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4337 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
4339 refcount = ID3D11Buffer_Release(buffer);
4340 ok(!refcount, "Buffer has %u references left.\n", refcount);
4342 texture2d_desc.Width = 512;
4343 texture2d_desc.Height = 512;
4344 texture2d_desc.MipLevels = 1;
4345 texture2d_desc.ArraySize = 1;
4346 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4347 texture2d_desc.SampleDesc.Count = 1;
4348 texture2d_desc.SampleDesc.Quality = 0;
4349 texture2d_desc.Usage = D3D11_USAGE_STAGING;
4350 texture2d_desc.BindFlags = 0;
4351 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4352 texture2d_desc.MiscFlags = 0;
4354 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4355 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4357 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4358 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4360 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4361 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4362 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4363 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4364 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4365 mapped_subresource.DepthPitch);
4366 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4367 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
4369 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4370 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4371 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4372 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4373 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4374 mapped_subresource.DepthPitch);
4375 data = *((DWORD *)mapped_subresource.pData);
4376 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4377 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
4379 refcount = ID3D11Texture2D_Release(texture2d);
4380 ok(!refcount, "2D texture has %u references left.\n", refcount);
4382 texture3d_desc.Width = 64;
4383 texture3d_desc.Height = 64;
4384 texture3d_desc.Depth = 64;
4385 texture3d_desc.MipLevels = 1;
4386 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4387 texture3d_desc.Usage = D3D11_USAGE_STAGING;
4388 texture3d_desc.BindFlags = 0;
4389 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4390 texture3d_desc.MiscFlags = 0;
4392 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4393 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
4395 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4396 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4398 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4399 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4400 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4401 if (FAILED(hr)) goto done;
4402 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4403 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4404 mapped_subresource.DepthPitch);
4405 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4406 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
4408 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4409 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4410 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4411 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4412 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4413 mapped_subresource.DepthPitch);
4414 data = *((DWORD *)mapped_subresource.pData);
4415 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4416 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
4418 done:
4419 refcount = ID3D11Texture3D_Release(texture3d);
4420 ok(!refcount, "3D texture has %u references left.\n", refcount);
4422 ID3D11DeviceContext_Release(context);
4424 refcount = ID3D11Device_Release(device);
4425 ok(!refcount, "Device has %u references left.\n", refcount);
4428 static void test_multisample_init(void)
4430 D3D11_TEXTURE2D_DESC desc;
4431 ID3D11Texture2D *backbuffer, *multi;
4432 ID3D11Device *device;
4433 ID3D11DeviceContext *context;
4434 ULONG refcount;
4435 DWORD color;
4436 HRESULT hr;
4437 unsigned int x, y;
4438 struct texture_readback rb;
4439 BOOL all_zero = TRUE;
4440 UINT count = 0;
4441 HWND window;
4442 IDXGISwapChain *swapchain;
4443 ID3D11RenderTargetView *rtview;
4444 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4446 if (!(device = create_device(NULL)))
4448 skip("Failed to create device, skipping tests.\n");
4449 return;
4452 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
4453 todo_wine ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
4454 if (!count)
4456 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
4457 goto done;
4460 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4461 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4462 swapchain = create_swapchain(device, window, TRUE);
4463 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
4464 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
4465 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &rtview);
4466 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4468 ID3D11Device_GetImmediateContext(device, &context);
4469 ID3D11DeviceContext_ClearRenderTargetView(context, rtview, white);
4471 desc.Width = 640;
4472 desc.Height = 480;
4473 desc.MipLevels = 1;
4474 desc.ArraySize = 1;
4475 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4476 desc.SampleDesc.Count = 2;
4477 desc.SampleDesc.Quality = 0;
4478 desc.Usage = D3D11_USAGE_DEFAULT;
4479 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4480 desc.CPUAccessFlags = 0;
4481 desc.MiscFlags = 0;
4482 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &multi);
4483 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4485 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4486 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)backbuffer, 0,
4487 (ID3D11Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
4489 get_texture_readback(backbuffer, &rb);
4490 for (y = 0; y < 480; ++y)
4492 for (x = 0; x < 640; ++x)
4494 color = get_readback_color(&rb, x, y);
4495 if (!compare_color(color, 0x00000000, 0))
4497 all_zero = FALSE;
4498 break;
4501 if (!all_zero)
4502 break;
4504 release_texture_readback(&rb);
4505 ok(all_zero, "Got unexpected color 0x%08x, position %ux%u.\n", color, x, y);
4507 ID3D11DeviceContext_Release(context);
4508 ID3D11RenderTargetView_Release(rtview);
4509 ID3D11Texture2D_Release(backbuffer);
4510 IDXGISwapChain_Release(swapchain);
4511 ID3D11Texture2D_Release(multi);
4512 DestroyWindow(window);
4513 done:
4514 refcount = ID3D11Device_Release(device);
4515 ok(!refcount, "Device has %u references left.\n", refcount);
4518 START_TEST(d3d11)
4520 test_create_device();
4521 test_device_interfaces();
4522 test_get_immediate_context();
4523 test_create_texture2d();
4524 test_texture2d_interfaces();
4525 test_create_texture3d();
4526 test_texture3d_interfaces();
4527 test_buffer_interfaces();
4528 test_create_depthstencil_view();
4529 test_depthstencil_view_interfaces();
4530 test_create_rendertarget_view();
4531 test_create_shader_resource_view();
4532 test_create_shader();
4533 test_create_sampler_state();
4534 test_create_blend_state();
4535 test_create_depthstencil_state();
4536 test_create_rasterizer_state();
4537 test_create_predicate();
4538 test_device_removed_reason();
4539 test_private_data();
4540 test_blend();
4541 test_texture();
4542 test_scissor();
4543 test_il_append_aligned();
4544 test_fragment_coords();
4545 test_update_subresource();
4546 test_resource_map();
4547 test_multisample_init();