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
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
,
51 static void set_box(D3D11_BOX
*box
, UINT left
, UINT top
, UINT front
, UINT right
, UINT bottom
, UINT 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
)
72 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
75 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
78 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
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
;
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
);
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
);
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
)
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
)
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
;
148 get_texture_readback(texture
, &rb
);
149 color
= get_readback_color(&rb
, x
, y
);
150 release_texture_readback(&rb
);
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
)))
163 if (SUCCEEDED(D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_WARP
, NULL
, 0, feature_level
, feature_level_count
,
164 D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
166 if (SUCCEEDED(D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_REFERENCE
, NULL
, 0, feature_level
, feature_level_count
,
167 D3D11_SDK_VERSION
, &device
, NULL
, 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
;
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
;
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
);
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
;
225 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
, &device
,
229 skip("Failed to create HAL device.\n");
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
,
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
;
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
]);
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");
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
;
514 if (!(device
= create_device(NULL
)))
516 skip("Failed to create device, skipping tests.\n");
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;
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
);
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
);
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
);
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
);
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
;
608 static const struct test
610 BOOL implements_d3d10_interfaces
;
613 UINT expected_bind_flags
;
614 UINT expected_misc_flags
;
616 desc_conversion_tests
[] =
620 D3D11_BIND_SHADER_RESOURCE
, 0,
621 D3D10_BIND_SHADER_RESOURCE
, 0
625 D3D11_BIND_UNORDERED_ACCESS
, 0,
626 D3D11_BIND_UNORDERED_ACCESS
, 0
630 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP
,
635 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
636 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
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");
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;
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
);
677 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
678 ID3D11Device_Release(device
);
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
;
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
);
706 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i
);
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
);
723 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Texture should not implement ID3D10Texture2D.\n", i
);
724 if (SUCCEEDED(hr
)) ID3D10Texture2D_Release(d3d10_texture
);
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
;
775 if (!(device
= create_device(NULL
)))
777 skip("Failed to create ID3D11Device, skipping tests.\n");
785 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
786 desc
.Usage
= D3D11_USAGE_DEFAULT
;
787 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
788 desc
.CPUAccessFlags
= 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
);
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
);
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
);
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
;
855 static const struct test
857 BOOL implements_d3d10_interfaces
;
860 UINT expected_bind_flags
;
861 UINT expected_misc_flags
;
863 desc_conversion_tests
[] =
867 D3D11_BIND_SHADER_RESOURCE
, 0,
868 D3D10_BIND_SHADER_RESOURCE
, 0
872 D3D11_BIND_UNORDERED_ACCESS
, 0,
873 D3D11_BIND_UNORDERED_ACCESS
, 0
877 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP
,
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");
897 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
898 desc
.Usage
= D3D11_USAGE_DEFAULT
;
899 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
900 desc
.CPUAccessFlags
= 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
);
917 win_skip("3D textures do not implement ID3D10Texture3D.\n");
918 ID3D11Device_Release(device
);
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
;
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
);
944 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i
);
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
);
960 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Texture should not implement ID3D10Texture3D.\n", i
);
961 if (SUCCEEDED(hr
)) ID3D10Texture3D_Release(d3d10_texture
);
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
;
1008 static const struct test
1010 BOOL implements_d3d10_interfaces
;
1013 UINT structure_stride
;
1014 UINT expected_bind_flags
;
1015 UINT expected_misc_flags
;
1017 desc_conversion_tests
[] =
1021 D3D11_BIND_VERTEX_BUFFER
, 0, 0,
1022 D3D10_BIND_VERTEX_BUFFER
, 0
1026 D3D11_BIND_INDEX_BUFFER
, 0, 0,
1027 D3D10_BIND_INDEX_BUFFER
, 0
1031 D3D11_BIND_CONSTANT_BUFFER
, 0, 0,
1032 D3D10_BIND_CONSTANT_BUFFER
, 0
1036 D3D11_BIND_SHADER_RESOURCE
, 0, 0,
1037 D3D10_BIND_SHADER_RESOURCE
, 0
1041 D3D11_BIND_STREAM_OUTPUT
, 0, 0,
1042 D3D10_BIND_STREAM_OUTPUT
, 0
1046 D3D11_BIND_RENDER_TARGET
, 0, 0,
1047 D3D10_BIND_RENDER_TARGET
, 0
1051 D3D11_BIND_UNORDERED_ACCESS
, 0, 0,
1052 D3D11_BIND_UNORDERED_ACCESS
, 0
1056 0, D3D11_RESOURCE_MISC_SHARED
, 0,
1057 0, D3D10_RESOURCE_MISC_SHARED
1061 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
, 0,
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,
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");
1087 desc
.ByteWidth
= 1024;
1088 desc
.Usage
= D3D11_USAGE_DEFAULT
;
1089 desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
1090 desc
.CPUAccessFlags
= 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
);
1105 win_skip("Buffers do not implement ID3D10Buffer.\n");
1106 ID3D11Device_Release(device
);
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
);
1128 win_skip("Failed to create a buffer, skipping test %u.\n", i
);
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
);
1141 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Buffer should not implement ID3D10Buffer.\n", i
);
1142 if (SUCCEEDED(hr
)) ID3D10Buffer_Release(d3d10_buffer
);
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
;
1181 if (!(device
= create_device(NULL
)))
1183 skip("Failed to create device.\n");
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
);
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
;
1241 if (!(device
= create_device(NULL
)))
1243 skip("Failed to create device.\n");
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
;
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");
1277 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
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
);
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
;
1311 if (!(device
= create_device(NULL
)))
1313 skip("Failed to create device.\n");
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
);
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
);
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
;
1416 if (!(device
= create_device(NULL
)))
1418 skip("Failed to create device.\n");
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
);
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)
1515 float4 position
: POSITION
;
1516 float3 normal
: NORMAL
;
1521 float4 position
: POSITION
;
1522 float4 diffuse
: COLOR
;
1525 output
main(const input v
)
1529 o
.position
= mul(v
.position
, mat
);
1530 o
.diffuse
= dot((float3
)light
, v
.normal
);
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,
1587 float4
main(const float4 color
: COLOR
) : SV_TARGET
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,
1619 float4 pos
: SV_POSITION
;
1623 void main(point float4 vin
[1] : POSITION
, inout TriangleStream
<gs_out
> vout
)
1625 float offset
= 0.1 * vin
[0].w
;
1628 v
.pos
= float4(vin
[0].x
- offset
, vin
[0].y
- offset
, vin
[0].z
, vin
[0].w
);
1630 v
.pos
= float4(vin
[0].x
- offset
, vin
[0].y
+ offset
, vin
[0].z
, vin
[0].w
);
1632 v
.pos
= float4(vin
[0].x
+ offset
, vin
[0].y
- offset
, vin
[0].z
, vin
[0].w
);
1634 v
.pos
= float4(vin
[0].x
+ offset
, vin
[0].y
+ offset
, vin
[0].z
, vin
[0].w
);
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
;
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
);
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",
1689 if (feature_level
< D3D_FEATURE_LEVEL_10_0
)
1691 refcount
= ID3D11Device_Release(device
);
1692 ok(!refcount
, "Device has %u references left.\n", refcount
);
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
);
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
);
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
);
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
);
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
;
1818 if (!(device
= create_device(NULL
)))
1820 skip("Failed to create device.\n");
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
;
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
);
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
;
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
);
1904 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
1905 ID3D11SamplerState_Release(sampler_state1
);
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
[] =
1961 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1962 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
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
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
;
2052 if (!(device
= create_device(NULL
)))
2054 skip("Failed to create device.\n");
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
);
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");
2148 win_skip("Blend state does not implement ID3D10BlendState.\n");
2149 ID3D11BlendState_Release(blend_state1
);
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
;
2199 if (!(device
= create_device(NULL
)))
2201 skip("Failed to create device.\n");
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
);
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
;
2263 if (!(device
= create_device(NULL
)))
2265 skip("Failed to create device.\n");
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
;
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
);
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");
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
[] =
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
;
2357 if (!(device
= create_device(NULL
)))
2359 skip("Failed to create device.\n");
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
);
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
);
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
;
2410 if (!(device
= create_device(NULL
)))
2412 skip("Failed to create device.\n");
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
;
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");
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
);
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;
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
);
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
);
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
);
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");
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
;
2623 static const DWORD vs_code
[] =
2628 float4 position
: SV_POSITION
;
2629 float4 color
: COLOR
;
2632 struct vs_out
main(float4 position
: POSITION
, float4 color
: COLOR
)
2636 o
.position
= position
;
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
[] =
2658 float4 position
: SV_POSITION
;
2659 float4 color
: COLOR
;
2662 float4
main(struct vs_out i
) : SV_TARGET
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,
2678 struct vec3 position
;
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},
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");
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
);
2766 ID3D11DeviceContext_IASetVertexBuffers(context
, 0, 1, &vb
, &stride
, &offset
);
2767 ID3D11DeviceContext_VSSetShader(context
, vs
, NULL
, 0);
2768 ID3D11DeviceContext_PSSetShader(context
, ps
, NULL
, 0);
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");
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
);
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
);
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 ID3D11RenderTargetView
*backbuffer_rtv
;
2855 D3D11_SUBRESOURCE_DATA resource_data
;
2856 D3D11_TEXTURE2D_DESC texture_desc
;
2857 ID3D11SamplerState
*sampler_state
;
2858 ID3D11ShaderResourceView
*ps_srv
;
2859 D3D11_SAMPLER_DESC sampler_desc
;
2860 ID3D11InputLayout
*input_layout
;
2861 D3D11_BUFFER_DESC buffer_desc
;
2862 ID3D11DeviceContext
*context
;
2863 ID3D11Texture2D
*backbuffer
;
2864 unsigned int stride
, offset
;
2865 struct texture_readback rb
;
2866 IDXGISwapChain
*swapchain
;
2867 ID3D11Texture2D
*texture
;
2868 ID3D11VertexShader
*vs
;
2869 ID3D11PixelShader
*ps
;
2870 ID3D11Device
*device
;
2879 static const D3D11_INPUT_ELEMENT_DESC layout_desc
[] =
2881 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT
, 0, 0, D3D11_INPUT_PER_VERTEX_DATA
, 0},
2883 static const DWORD vs_code
[] =
2886 float4
main(float4 position
: POSITION
) : SV_POSITION
2891 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2892 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2893 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2894 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2895 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2896 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2897 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2899 static const DWORD ps_code
[] =
2905 float4
main(float4 position
: SV_POSITION
) : SV_Target
2909 p
.x
= position
.x
/ 640.0f
;
2910 p
.y
= position
.y
/ 480.0f
;
2911 return t
.Sample(s
, p
);
2914 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
2915 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2916 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2917 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2918 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
2919 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
2920 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
2921 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
2922 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
2923 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
2936 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2937 static const DWORD bitmap_data
[] =
2939 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
2940 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
2941 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
2942 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
2945 if (!(device
= create_device(NULL
)))
2947 skip("Failed to create device.\n");
2950 window
= CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
2951 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2952 swapchain
= create_swapchain(device
, window
, TRUE
);
2953 hr
= IDXGISwapChain_GetBuffer(swapchain
, 0, &IID_ID3D11Texture2D
, (void **)&backbuffer
);
2954 ok(SUCCEEDED(hr
), "Failed to get buffer, hr %#x.\n", hr
);
2956 hr
= ID3D11Device_CreateInputLayout(device
, layout_desc
, sizeof(layout_desc
) / sizeof(*layout_desc
),
2957 vs_code
, sizeof(vs_code
), &input_layout
);
2958 ok(SUCCEEDED(hr
), "Failed to create input layout, hr %#x.\n", hr
);
2960 buffer_desc
.ByteWidth
= sizeof(quad
);
2961 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
2962 buffer_desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
2963 buffer_desc
.CPUAccessFlags
= 0;
2964 buffer_desc
.MiscFlags
= 0;
2965 buffer_desc
.StructureByteStride
= 0;
2967 resource_data
.pSysMem
= quad
;
2968 resource_data
.SysMemPitch
= 0;
2969 resource_data
.SysMemSlicePitch
= 0;
2971 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
);
2972 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
2974 texture_desc
.Width
= 4;
2975 texture_desc
.Height
= 4;
2976 texture_desc
.MipLevels
= 1;
2977 texture_desc
.ArraySize
= 1;
2978 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
2979 texture_desc
.SampleDesc
.Count
= 1;
2980 texture_desc
.SampleDesc
.Quality
= 0;
2981 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
2982 texture_desc
.BindFlags
= D3D11_BIND_SHADER_RESOURCE
;
2983 texture_desc
.CPUAccessFlags
= 0;
2984 texture_desc
.MiscFlags
= 0;
2986 resource_data
.pSysMem
= bitmap_data
;
2987 resource_data
.SysMemPitch
= 4 * sizeof(*bitmap_data
);
2989 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, &resource_data
, &texture
);
2990 ok(SUCCEEDED(hr
), "Failed to create 2d texture, hr %#x.\n", hr
);
2992 hr
= ID3D11Device_CreateShaderResourceView(device
, (ID3D11Resource
*)texture
, NULL
, &ps_srv
);
2993 ok(SUCCEEDED(hr
), "Failed to create shader resource view, hr %#x.\n", hr
);
2995 sampler_desc
.Filter
= D3D11_FILTER_MIN_MAG_MIP_POINT
;
2996 sampler_desc
.AddressU
= D3D11_TEXTURE_ADDRESS_CLAMP
;
2997 sampler_desc
.AddressV
= D3D11_TEXTURE_ADDRESS_CLAMP
;
2998 sampler_desc
.AddressW
= D3D11_TEXTURE_ADDRESS_CLAMP
;
2999 sampler_desc
.MipLODBias
= 0.0f
;
3000 sampler_desc
.MaxAnisotropy
= 0;
3001 sampler_desc
.ComparisonFunc
= D3D11_COMPARISON_NEVER
;
3002 sampler_desc
.BorderColor
[0] = 0.0f
;
3003 sampler_desc
.BorderColor
[1] = 0.0f
;
3004 sampler_desc
.BorderColor
[2] = 0.0f
;
3005 sampler_desc
.BorderColor
[3] = 0.0f
;
3006 sampler_desc
.MinLOD
= 0.0f
;
3007 sampler_desc
.MaxLOD
= 0.0f
;
3009 hr
= ID3D11Device_CreateSamplerState(device
, &sampler_desc
, &sampler_state
);
3010 ok(SUCCEEDED(hr
), "Failed to create sampler state, hr %#x.\n", hr
);
3012 hr
= ID3D11Device_CreateVertexShader(device
, vs_code
, sizeof(vs_code
), NULL
, &vs
);
3013 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3014 hr
= ID3D11Device_CreatePixelShader(device
, ps_code
, sizeof(ps_code
), NULL
, &ps
);
3015 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3017 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)backbuffer
, NULL
, &backbuffer_rtv
);
3018 ok(SUCCEEDED(hr
), "Failed to create rendertarget view, hr %#x.\n", hr
);
3020 ID3D11Device_GetImmediateContext(device
, &context
);
3022 ID3D11DeviceContext_OMSetRenderTargets(context
, 1, &backbuffer_rtv
, NULL
);
3023 ID3D11DeviceContext_IASetInputLayout(context
, input_layout
);
3024 ID3D11DeviceContext_IASetPrimitiveTopology(context
, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
);
3025 stride
= sizeof(*quad
);
3027 ID3D11DeviceContext_IASetVertexBuffers(context
, 0, 1, &vb
, &stride
, &offset
);
3028 ID3D11DeviceContext_VSSetShader(context
, vs
, NULL
, 0);
3029 ID3D11DeviceContext_PSSetShaderResources(context
, 0, 1, &ps_srv
);
3030 ID3D11DeviceContext_PSSetSamplers(context
, 0, 1, &sampler_state
);
3031 ID3D11DeviceContext_PSSetShader(context
, ps
, NULL
, 0);
3039 ID3D11DeviceContext_RSSetViewports(context
, 1, &vp
);
3041 ID3D11DeviceContext_ClearRenderTargetView(context
, backbuffer_rtv
, red
);
3043 ID3D11DeviceContext_Draw(context
, 4, 0);
3045 get_texture_readback(backbuffer
, &rb
);
3046 for (i
= 0; i
< 4; ++i
)
3048 for (j
= 0; j
< 4; ++j
)
3050 color
= get_readback_color(&rb
, 80 + j
* 160, 60 + i
* 120);
3051 ok(compare_color(color
, bitmap_data
[j
+ i
* 4], 1),
3052 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
3053 color
, j
, i
, bitmap_data
[j
+ i
* 4]);
3056 release_texture_readback(&rb
);
3058 ID3D11PixelShader_Release(ps
);
3059 ID3D11VertexShader_Release(vs
);
3060 ID3D11SamplerState_Release(sampler_state
);
3061 ID3D11ShaderResourceView_Release(ps_srv
);
3062 ID3D11Texture2D_Release(texture
);
3063 ID3D11Buffer_Release(vb
);
3064 ID3D11InputLayout_Release(input_layout
);
3065 ID3D11RenderTargetView_Release(backbuffer_rtv
);
3066 ID3D11Texture2D_Release(backbuffer
);
3067 IDXGISwapChain_Release(swapchain
);
3068 ID3D11DeviceContext_Release(context
);
3069 refcount
= ID3D11Device_Release(device
);
3070 ok(!refcount
, "Device has %u references left.\n", refcount
);
3071 DestroyWindow(window
);
3074 static void test_scissor(void)
3076 ID3D11DeviceContext
*immediate_context
;
3077 D3D11_SUBRESOURCE_DATA buffer_data
;
3078 ID3D11InputLayout
*input_layout
;
3079 D3D11_RASTERIZER_DESC rs_desc
;
3080 D3D11_BUFFER_DESC buffer_desc
;
3081 ID3D11RenderTargetView
*rtv
;
3082 ID3D11Texture2D
*backbuffer
;
3083 unsigned int stride
, offset
;
3084 ID3D11RasterizerState
*rs
;
3085 IDXGISwapChain
*swapchain
;
3086 D3D11_RECT scissor_rect
;
3087 ID3D11VertexShader
*vs
;
3088 ID3D11PixelShader
*ps
;
3089 ID3D11Device
*device
;
3097 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3098 static const D3D11_INPUT_ELEMENT_DESC layout_desc
[] =
3100 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT
, 0, 0, D3D11_INPUT_PER_VERTEX_DATA
, 0},
3102 static const DWORD vs_code
[] =
3105 float4
main(float4 position
: POSITION
) : SV_POSITION
3110 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
3111 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
3112 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
3113 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
3114 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3115 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3116 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3117 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3118 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3119 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
3120 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3121 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3122 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3123 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3125 static const DWORD ps_code
[] =
3128 float4
main(float4 position
: SV_POSITION
) : SV_Target
3130 return float4(0.0, 1.0, 0.0, 1.0);
3133 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
3134 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
3135 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
3136 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
3137 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3138 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
3139 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3140 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
3141 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
3142 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
3143 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
3144 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3145 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3146 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3160 if (!(device
= create_device(NULL
)))
3162 skip("Failed to create device.\n");
3165 window
= CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3166 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3167 swapchain
= create_swapchain(device
, window
, TRUE
);
3168 hr
= IDXGISwapChain_GetBuffer(swapchain
, 0, &IID_ID3D11Texture2D
, (void **)&backbuffer
);
3169 ok(SUCCEEDED(hr
), "Failed to get buffer, hr %#x.\n", hr
);
3171 hr
= ID3D11Device_CreateInputLayout(device
, layout_desc
, sizeof(layout_desc
) / sizeof(*layout_desc
),
3172 vs_code
, sizeof(vs_code
), &input_layout
);
3173 ok(SUCCEEDED(hr
), "Failed to create input layout, hr %#x.\n", hr
);
3175 buffer_desc
.ByteWidth
= sizeof(quad
);
3176 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
3177 buffer_desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
3178 buffer_desc
.CPUAccessFlags
= 0;
3179 buffer_desc
.MiscFlags
= 0;
3180 buffer_desc
.StructureByteStride
= 0;
3182 buffer_data
.pSysMem
= quad
;
3183 buffer_data
.SysMemPitch
= 0;
3184 buffer_data
.SysMemSlicePitch
= 0;
3186 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &buffer_data
, &vb
);
3187 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3188 hr
= ID3D11Device_CreateVertexShader(device
, vs_code
, sizeof(vs_code
), NULL
, &vs
);
3189 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3190 hr
= ID3D11Device_CreatePixelShader(device
, ps_code
, sizeof(ps_code
), NULL
, &ps
);
3191 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3193 rs_desc
.FillMode
= D3D11_FILL_SOLID
;
3194 rs_desc
.CullMode
= D3D11_CULL_BACK
;
3195 rs_desc
.FrontCounterClockwise
= FALSE
;
3196 rs_desc
.DepthBias
= 0;
3197 rs_desc
.DepthBiasClamp
= 0.0f
;
3198 rs_desc
.SlopeScaledDepthBias
= 0.0f
;
3199 rs_desc
.DepthClipEnable
= TRUE
;
3200 rs_desc
.ScissorEnable
= TRUE
;
3201 rs_desc
.MultisampleEnable
= FALSE
;
3202 rs_desc
.AntialiasedLineEnable
= FALSE
;
3203 hr
= ID3D11Device_CreateRasterizerState(device
, &rs_desc
, &rs
);
3204 ok(SUCCEEDED(hr
), "Failed to create rasterizer state, hr %#x.\n", hr
);
3206 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)backbuffer
, NULL
, &rtv
);
3207 ok(SUCCEEDED(hr
), "Failed to create rendertarget view, hr %#x.\n", hr
);
3209 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
3211 ID3D11DeviceContext_IASetInputLayout(immediate_context
, input_layout
);
3212 ID3D11DeviceContext_IASetPrimitiveTopology(immediate_context
, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
);
3213 stride
= sizeof(*quad
);
3215 ID3D11DeviceContext_IASetVertexBuffers(immediate_context
, 0, 1, &vb
, &stride
, &offset
);
3216 ID3D11DeviceContext_VSSetShader(immediate_context
, vs
, NULL
, 0);
3217 ID3D11DeviceContext_PSSetShader(immediate_context
, ps
, NULL
, 0);
3225 ID3D11DeviceContext_RSSetViewports(immediate_context
, 1, &vp
);
3227 scissor_rect
.left
= 160;
3228 scissor_rect
.top
= 120;
3229 scissor_rect
.right
= 480;
3230 scissor_rect
.bottom
= 360;
3231 ID3D11DeviceContext_RSSetScissorRects(immediate_context
, 1, &scissor_rect
);
3233 ID3D11DeviceContext_OMSetRenderTargets(immediate_context
, 1, &rtv
, NULL
);
3235 ID3D11DeviceContext_ClearRenderTargetView(immediate_context
, rtv
, red
);
3236 color
= get_texture_color(backbuffer
, 320, 240);
3237 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3239 ID3D11DeviceContext_Draw(immediate_context
, 4, 0);
3240 color
= get_texture_color(backbuffer
, 320, 60);
3241 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3242 color
= get_texture_color(backbuffer
, 80, 240);
3243 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3244 color
= get_texture_color(backbuffer
, 320, 240);
3245 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3246 color
= get_texture_color(backbuffer
, 560, 240);
3247 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3248 color
= get_texture_color(backbuffer
, 320, 420);
3249 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3251 ID3D11DeviceContext_ClearRenderTargetView(immediate_context
, rtv
, red
);
3252 ID3D11DeviceContext_RSSetState(immediate_context
, rs
);
3253 ID3D11DeviceContext_Draw(immediate_context
, 4, 0);
3254 color
= get_texture_color(backbuffer
, 320, 60);
3255 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3256 color
= get_texture_color(backbuffer
, 80, 240);
3257 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3258 color
= get_texture_color(backbuffer
, 320, 240);
3259 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3260 color
= get_texture_color(backbuffer
, 560, 240);
3261 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3262 color
= get_texture_color(backbuffer
, 320, 420);
3263 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3265 ID3D11RenderTargetView_Release(rtv
);
3266 ID3D11RasterizerState_Release(rs
);
3267 ID3D11PixelShader_Release(ps
);
3268 ID3D11VertexShader_Release(vs
);
3269 ID3D11Buffer_Release(vb
);
3270 ID3D11InputLayout_Release(input_layout
);
3271 ID3D11Texture2D_Release(backbuffer
);
3272 IDXGISwapChain_Release(swapchain
);
3273 ID3D11DeviceContext_Release(immediate_context
);
3274 refcount
= ID3D11Device_Release(device
);
3275 ok(!refcount
, "Device has %u references left.\n", refcount
);
3276 DestroyWindow(window
);
3279 static void test_il_append_aligned(void)
3281 ID3D11RenderTargetView
*backbuffer_rtv
;
3282 D3D11_SUBRESOURCE_DATA resource_data
;
3283 ID3D11InputLayout
*input_layout
;
3284 D3D11_BUFFER_DESC buffer_desc
;
3285 ID3D11DeviceContext
*context
;
3286 ID3D11Texture2D
*backbuffer
;
3287 unsigned int stride
, offset
;
3288 IDXGISwapChain
*swapchain
;
3289 ID3D11VertexShader
*vs
;
3290 ID3D11PixelShader
*ps
;
3291 ID3D11Device
*device
;
3292 ID3D11Buffer
*vb
[3];
3299 static const D3D11_INPUT_ELEMENT_DESC layout_desc
[] =
3301 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT
, 1, D3D11_APPEND_ALIGNED_ELEMENT
,
3302 D3D11_INPUT_PER_INSTANCE_DATA
, 2},
3303 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT
, 2, D3D11_APPEND_ALIGNED_ELEMENT
,
3304 D3D11_INPUT_PER_INSTANCE_DATA
, 1},
3305 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT
, 0, D3D11_APPEND_ALIGNED_ELEMENT
,
3306 D3D11_INPUT_PER_VERTEX_DATA
, 0},
3307 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT
, 2, D3D11_APPEND_ALIGNED_ELEMENT
,
3308 D3D11_INPUT_PER_INSTANCE_DATA
, 1},
3309 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT
, 1, D3D11_APPEND_ALIGNED_ELEMENT
,
3310 D3D11_INPUT_PER_INSTANCE_DATA
, 2},
3312 static const DWORD vs_code
[] =
3317 float4 position
: POSITION
;
3318 float2 color_xy
: COLOR0
;
3319 float2 color_zw
: COLOR1
;
3320 unsigned int instance_id
: SV_INSTANCEID
;
3325 float4 position
: SV_POSITION
;
3326 float2 color_xy
: COLOR0
;
3327 float2 color_zw
: COLOR1
;
3330 struct vs_out
main(struct vs_in i
)
3334 o
.position
= i
.position
;
3335 o
.position
.x
+= i
.instance_id
* 0.5;
3336 o
.color_xy
= i
.color_xy
;
3337 o
.color_zw
= i
.color_zw
;
3342 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
3343 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
3344 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
3345 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
3346 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
3347 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
3348 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3349 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
3350 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
3351 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
3352 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
3353 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
3354 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
3355 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
3356 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
3357 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
3358 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
3360 static const DWORD ps_code
[] =
3365 float4 position
: SV_POSITION
;
3366 float2 color_xy
: COLOR0
;
3367 float2 color_zw
: COLOR1
;
3370 float4
main(struct vs_out i
) : SV_TARGET
3372 return float4(i
.color_xy
.xy
, i
.color_zw
.xy
);
3375 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
3376 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
3377 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
3378 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
3379 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3380 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
3381 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
3382 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3383 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3387 struct vec4 position
;
3391 {{-1.0f
, -1.0f
, 0.0f
, 1.0f
}},
3392 {{-1.0f
, 1.0f
, 0.0f
, 1.0f
}},
3393 {{-0.5f
, -1.0f
, 0.0f
, 1.0f
}},
3394 {{-0.5f
, 1.0f
, 0.0f
, 1.0f
}},
3403 {{0.5f
, 0.5f
}, {0.0f
, 1.0f
}},
3404 {{0.5f
, 0.5f
}, {1.0f
, 1.0f
}},
3413 {{0.5f
, 0.5f
}, {1.0f
, 0.0f
}},
3414 {{0.5f
, 0.5f
}, {0.0f
, 1.0f
}},
3415 {{0.5f
, 0.5f
}, {0.0f
, 0.0f
}},
3416 {{0.5f
, 0.5f
}, {1.0f
, 0.0f
}},
3418 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 0.5f
};
3420 if (!(device
= create_device(NULL
)))
3422 skip("Failed to create device.\n");
3425 window
= CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3426 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3427 swapchain
= create_swapchain(device
, window
, TRUE
);
3428 hr
= IDXGISwapChain_GetBuffer(swapchain
, 0, &IID_ID3D11Texture2D
, (void **)&backbuffer
);
3429 ok(SUCCEEDED(hr
), "Failed to get buffer, hr %#x.\n", hr
);
3431 hr
= ID3D11Device_CreateInputLayout(device
, layout_desc
, sizeof(layout_desc
) / sizeof(*layout_desc
),
3432 vs_code
, sizeof(vs_code
), &input_layout
);
3433 ok(SUCCEEDED(hr
), "Failed to create input layout, hr %#x.\n", hr
);
3435 buffer_desc
.ByteWidth
= sizeof(stream0
);
3436 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
3437 buffer_desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
3438 buffer_desc
.CPUAccessFlags
= 0;
3439 buffer_desc
.MiscFlags
= 0;
3440 buffer_desc
.StructureByteStride
= 0;
3442 resource_data
.pSysMem
= stream0
;
3443 resource_data
.SysMemPitch
= 0;
3444 resource_data
.SysMemSlicePitch
= 0;
3446 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
[0]);
3447 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3449 buffer_desc
.ByteWidth
= sizeof(stream1
);
3450 resource_data
.pSysMem
= stream1
;
3452 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
[1]);
3453 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3455 buffer_desc
.ByteWidth
= sizeof(stream2
);
3456 resource_data
.pSysMem
= stream2
;
3458 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
[2]);
3459 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3461 hr
= ID3D11Device_CreateVertexShader(device
, vs_code
, sizeof(vs_code
), NULL
, &vs
);
3462 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3463 hr
= ID3D11Device_CreatePixelShader(device
, ps_code
, sizeof(ps_code
), NULL
, &ps
);
3464 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3466 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)backbuffer
, NULL
, &backbuffer_rtv
);
3467 ok(SUCCEEDED(hr
), "Failed to create rendertarget view, hr %#x.\n", hr
);
3469 ID3D11Device_GetImmediateContext(device
, &context
);
3471 ID3D11DeviceContext_OMSetRenderTargets(context
, 1, &backbuffer_rtv
, NULL
);
3472 ID3D11DeviceContext_IASetInputLayout(context
, input_layout
);
3473 ID3D11DeviceContext_IASetPrimitiveTopology(context
, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
);
3475 stride
= sizeof(*stream0
);
3476 ID3D11DeviceContext_IASetVertexBuffers(context
, 0, 1, &vb
[0], &stride
, &offset
);
3477 stride
= sizeof(*stream1
);
3478 ID3D11DeviceContext_IASetVertexBuffers(context
, 1, 1, &vb
[1], &stride
, &offset
);
3479 stride
= sizeof(*stream2
);
3480 ID3D11DeviceContext_IASetVertexBuffers(context
, 2, 1, &vb
[2], &stride
, &offset
);
3481 ID3D11DeviceContext_VSSetShader(context
, vs
, NULL
, 0);
3482 ID3D11DeviceContext_PSSetShader(context
, ps
, NULL
, 0);
3490 ID3D11DeviceContext_RSSetViewports(context
, 1, &vp
);
3492 ID3D11DeviceContext_ClearRenderTargetView(context
, backbuffer_rtv
, red
);
3494 ID3D11DeviceContext_DrawInstanced(context
, 4, 4, 0, 0);
3496 color
= get_texture_color(backbuffer
, 80, 240);
3497 ok(compare_color(color
, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color
);
3498 color
= get_texture_color(backbuffer
, 240, 240);
3499 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3500 color
= get_texture_color(backbuffer
, 400, 240);
3501 ok(compare_color(color
, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color
);
3502 color
= get_texture_color(backbuffer
, 560, 240);
3503 ok(compare_color(color
, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color
);
3505 ID3D11PixelShader_Release(ps
);
3506 ID3D11VertexShader_Release(vs
);
3507 ID3D11Buffer_Release(vb
[2]);
3508 ID3D11Buffer_Release(vb
[1]);
3509 ID3D11Buffer_Release(vb
[0]);
3510 ID3D11InputLayout_Release(input_layout
);
3511 ID3D11RenderTargetView_Release(backbuffer_rtv
);
3512 ID3D11Texture2D_Release(backbuffer
);
3513 IDXGISwapChain_Release(swapchain
);
3514 ID3D11DeviceContext_Release(context
);
3515 refcount
= ID3D11Device_Release(device
);
3516 ok(!refcount
, "Device has %u references left.\n", refcount
);
3517 DestroyWindow(window
);
3520 static void test_fragment_coords(void)
3522 ID3D11RenderTargetView
*backbuffer_rtv
;
3523 D3D11_SUBRESOURCE_DATA resource_data
;
3524 ID3D11InputLayout
*input_layout
;
3525 ID3D11PixelShader
*ps
, *ps_frac
;
3526 D3D11_BUFFER_DESC buffer_desc
;
3527 ID3D11DeviceContext
*context
;
3528 ID3D11Texture2D
*backbuffer
;
3529 unsigned int stride
, offset
;
3530 IDXGISwapChain
*swapchain
;
3531 ID3D11Buffer
*vb
, *ps_cb
;
3532 ID3D11VertexShader
*vs
;
3533 ID3D11Device
*device
;
3540 static const D3D11_INPUT_ELEMENT_DESC layout_desc
[] =
3542 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT
, 0, 0, D3D11_INPUT_PER_VERTEX_DATA
, 0},
3544 static const DWORD vs_code
[] =
3547 float4
main(float4 position
: POSITION
) : SV_POSITION
3552 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3553 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3554 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3555 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3556 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3557 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3558 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3560 static const DWORD ps_code
[] =
3565 float4
main(float4 position
: SV_POSITION
) : SV_TARGET
3567 float4 ret
= float4(0.0, 0.0, 0.0, 1.0);
3569 if (position
.x
> cutoff
.x
)
3571 if (position
.y
> cutoff
.y
)
3577 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
3578 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3579 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3580 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3581 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
3582 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
3583 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
3584 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
3585 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
3586 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
3589 static const DWORD ps_frac_code
[] =
3592 float4
main(float4 position
: SV_POSITION
) : SV_TARGET
3594 return float4(frac(position
.xy
), 0.0, 1.0);
3597 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
3598 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3599 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3600 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3601 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
3602 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3603 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
3604 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
3608 struct vec2 position
;
3617 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 0.5f
};
3618 struct vec4 cutoff
= {320.0f
, 240.0f
, 0.0f
, 0.0f
};
3620 if (!(device
= create_device(NULL
)))
3622 skip("Failed to create device.\n");
3625 window
= CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3626 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3627 swapchain
= create_swapchain(device
, window
, TRUE
);
3628 hr
= IDXGISwapChain_GetBuffer(swapchain
, 0, &IID_ID3D11Texture2D
, (void **)&backbuffer
);
3629 ok(SUCCEEDED(hr
), "Failed to get buffer, hr %#x.\n", hr
);
3631 hr
= ID3D11Device_CreateInputLayout(device
, layout_desc
, sizeof(layout_desc
) / sizeof(*layout_desc
),
3632 vs_code
, sizeof(vs_code
), &input_layout
);
3633 ok(SUCCEEDED(hr
), "Failed to create input layout, hr %#x.\n", hr
);
3635 buffer_desc
.ByteWidth
= sizeof(quad
);
3636 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
3637 buffer_desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
3638 buffer_desc
.CPUAccessFlags
= 0;
3639 buffer_desc
.MiscFlags
= 0;
3640 buffer_desc
.StructureByteStride
= 0;
3642 resource_data
.pSysMem
= quad
;
3643 resource_data
.SysMemPitch
= 0;
3644 resource_data
.SysMemSlicePitch
= 0;
3646 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
);
3647 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3649 buffer_desc
.ByteWidth
= sizeof(cutoff
);
3650 buffer_desc
.BindFlags
= D3D11_BIND_CONSTANT_BUFFER
;
3652 resource_data
.pSysMem
= &cutoff
;
3654 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &ps_cb
);
3655 ok(SUCCEEDED(hr
), "Failed to create constant buffer, hr %#x.\n", hr
);
3657 hr
= ID3D11Device_CreateVertexShader(device
, vs_code
, sizeof(vs_code
), NULL
, &vs
);
3658 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3659 hr
= ID3D11Device_CreatePixelShader(device
, ps_code
, sizeof(ps_code
), NULL
, &ps
);
3660 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3661 hr
= ID3D11Device_CreatePixelShader(device
, ps_frac_code
, sizeof(ps_frac_code
), NULL
, &ps_frac
);
3662 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3664 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)backbuffer
, NULL
, &backbuffer_rtv
);
3665 ok(SUCCEEDED(hr
), "Failed to create rendertarget view, hr %#x.\n", hr
);
3667 ID3D11Device_GetImmediateContext(device
, &context
);
3669 ID3D11DeviceContext_OMSetRenderTargets(context
, 1, &backbuffer_rtv
, NULL
);
3670 ID3D11DeviceContext_IASetInputLayout(context
, input_layout
);
3671 ID3D11DeviceContext_IASetPrimitiveTopology(context
, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
);
3672 stride
= sizeof(*quad
);
3674 ID3D11DeviceContext_IASetVertexBuffers(context
, 0, 1, &vb
, &stride
, &offset
);
3675 ID3D11DeviceContext_VSSetShader(context
, vs
, NULL
, 0);
3676 ID3D11DeviceContext_PSSetConstantBuffers(context
, 0, 1, &ps_cb
);
3677 ID3D11DeviceContext_PSSetShader(context
, ps
, NULL
, 0);
3685 ID3D11DeviceContext_RSSetViewports(context
, 1, &vp
);
3687 ID3D11DeviceContext_ClearRenderTargetView(context
, backbuffer_rtv
, red
);
3689 ID3D11DeviceContext_Draw(context
, 4, 0);
3691 color
= get_texture_color(backbuffer
, 319, 239);
3692 ok(compare_color(color
, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color
);
3693 color
= get_texture_color(backbuffer
, 320, 239);
3694 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3695 color
= get_texture_color(backbuffer
, 319, 240);
3696 ok(compare_color(color
, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color
);
3697 color
= get_texture_color(backbuffer
, 320, 240);
3698 ok(compare_color(color
, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color
);
3700 ID3D11Buffer_Release(ps_cb
);
3703 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &ps_cb
);
3704 ok(SUCCEEDED(hr
), "Failed to create constant buffer, hr %#x.\n", hr
);
3705 ID3D11DeviceContext_PSSetConstantBuffers(context
, 0, 1, &ps_cb
);
3707 ID3D11DeviceContext_Draw(context
, 4, 0);
3709 color
= get_texture_color(backbuffer
, 14, 14);
3710 ok(compare_color(color
, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color
);
3711 color
= get_texture_color(backbuffer
, 18, 14);
3712 ok(compare_color(color
, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3713 color
= get_texture_color(backbuffer
, 14, 18);
3714 ok(compare_color(color
, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color
);
3715 color
= get_texture_color(backbuffer
, 18, 18);
3716 ok(compare_color(color
, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color
);
3718 ID3D11DeviceContext_PSSetShader(context
, ps_frac
, NULL
, 0);
3719 ID3D11DeviceContext_ClearRenderTargetView(context
, backbuffer_rtv
, red
);
3721 ID3D11DeviceContext_Draw(context
, 4, 0);
3723 color
= get_texture_color(backbuffer
, 14, 14);
3724 ok(compare_color(color
, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color
);
3726 ID3D11Buffer_Release(ps_cb
);
3727 ID3D11PixelShader_Release(ps_frac
);
3728 ID3D11PixelShader_Release(ps
);
3729 ID3D11VertexShader_Release(vs
);
3730 ID3D11Buffer_Release(vb
);
3731 ID3D11InputLayout_Release(input_layout
);
3732 ID3D11RenderTargetView_Release(backbuffer_rtv
);
3733 ID3D11Texture2D_Release(backbuffer
);
3734 IDXGISwapChain_Release(swapchain
);
3735 ID3D11DeviceContext_Release(context
);
3736 refcount
= ID3D11Device_Release(device
);
3737 ok(!refcount
, "Device has %u references left.\n", refcount
);
3738 DestroyWindow(window
);
3741 static void test_update_subresource(void)
3743 ID3D11RenderTargetView
*backbuffer_rtv
;
3744 D3D11_SUBRESOURCE_DATA resource_data
;
3745 D3D11_TEXTURE2D_DESC texture_desc
;
3746 ID3D11SamplerState
*sampler_state
;
3747 ID3D11ShaderResourceView
*ps_srv
;
3748 D3D11_SAMPLER_DESC sampler_desc
;
3749 ID3D11InputLayout
*input_layout
;
3750 D3D11_BUFFER_DESC buffer_desc
;
3751 ID3D11DeviceContext
*context
;
3752 ID3D11Texture2D
*backbuffer
;
3753 unsigned int stride
, offset
;
3754 struct texture_readback rb
;
3755 IDXGISwapChain
*swapchain
;
3756 ID3D11Texture2D
*texture
;
3757 ID3D11VertexShader
*vs
;
3758 ID3D11PixelShader
*ps
;
3759 ID3D11Device
*device
;
3769 static const D3D11_INPUT_ELEMENT_DESC layout_desc
[] =
3771 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT
, 0, 0, D3D11_INPUT_PER_VERTEX_DATA
, 0},
3773 static const DWORD vs_code
[] =
3776 float4
main(float4 position
: POSITION
) : SV_POSITION
3781 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3782 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3783 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3784 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3785 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3786 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3787 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3789 static const DWORD ps_code
[] =
3795 float4
main(float4 position
: SV_POSITION
) : SV_Target
3799 p
.x
= position
.x
/ 640.0f
;
3800 p
.y
= position
.y
/ 480.0f
;
3801 return t
.Sample(s
, p
);
3804 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3805 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3806 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3807 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3808 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3809 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3810 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3811 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3812 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3813 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3826 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 0.5f
};
3827 static const DWORD bitmap_data
[] =
3829 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3830 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3831 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3832 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3834 static const DWORD expected_colors
[] =
3836 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
3837 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
3838 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
3839 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
3842 if (!(device
= create_device(NULL
)))
3844 skip("Failed to create device.\n");
3847 window
= CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3848 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3849 swapchain
= create_swapchain(device
, window
, TRUE
);
3850 hr
= IDXGISwapChain_GetBuffer(swapchain
, 0, &IID_ID3D11Texture2D
, (void **)&backbuffer
);
3851 ok(SUCCEEDED(hr
), "Failed to get buffer, hr %#x.\n", hr
);
3853 hr
= ID3D11Device_CreateInputLayout(device
, layout_desc
, sizeof(layout_desc
) / sizeof(*layout_desc
),
3854 vs_code
, sizeof(vs_code
), &input_layout
);
3855 ok(SUCCEEDED(hr
), "Failed to create input layout, hr %#x.\n", hr
);
3857 buffer_desc
.ByteWidth
= sizeof(quad
);
3858 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
3859 buffer_desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
3860 buffer_desc
.CPUAccessFlags
= 0;
3861 buffer_desc
.MiscFlags
= 0;
3862 buffer_desc
.StructureByteStride
= 0;
3864 resource_data
.pSysMem
= quad
;
3865 resource_data
.SysMemPitch
= 0;
3866 resource_data
.SysMemSlicePitch
= 0;
3868 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &resource_data
, &vb
);
3869 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3871 texture_desc
.Width
= 4;
3872 texture_desc
.Height
= 4;
3873 texture_desc
.MipLevels
= 1;
3874 texture_desc
.ArraySize
= 1;
3875 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
3876 texture_desc
.SampleDesc
.Count
= 1;
3877 texture_desc
.SampleDesc
.Quality
= 0;
3878 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
3879 texture_desc
.BindFlags
= D3D11_BIND_SHADER_RESOURCE
;
3880 texture_desc
.CPUAccessFlags
= 0;
3881 texture_desc
.MiscFlags
= 0;
3883 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
3884 ok(SUCCEEDED(hr
), "Failed to create 2d texture, hr %#x.\n", hr
);
3886 hr
= ID3D11Device_CreateShaderResourceView(device
, (ID3D11Resource
*)texture
, NULL
, &ps_srv
);
3887 ok(SUCCEEDED(hr
), "Failed to create shader resource view, hr %#x.\n", hr
);
3889 sampler_desc
.Filter
= D3D11_FILTER_MIN_MAG_MIP_POINT
;
3890 sampler_desc
.AddressU
= D3D11_TEXTURE_ADDRESS_CLAMP
;
3891 sampler_desc
.AddressV
= D3D11_TEXTURE_ADDRESS_CLAMP
;
3892 sampler_desc
.AddressW
= D3D11_TEXTURE_ADDRESS_CLAMP
;
3893 sampler_desc
.MipLODBias
= 0.0f
;
3894 sampler_desc
.MaxAnisotropy
= 0;
3895 sampler_desc
.ComparisonFunc
= D3D11_COMPARISON_NEVER
;
3896 sampler_desc
.BorderColor
[0] = 0.0f
;
3897 sampler_desc
.BorderColor
[1] = 0.0f
;
3898 sampler_desc
.BorderColor
[2] = 0.0f
;
3899 sampler_desc
.BorderColor
[3] = 0.0f
;
3900 sampler_desc
.MinLOD
= 0.0f
;
3901 sampler_desc
.MaxLOD
= 0.0f
;
3903 hr
= ID3D11Device_CreateSamplerState(device
, &sampler_desc
, &sampler_state
);
3904 ok(SUCCEEDED(hr
), "Failed to create sampler state, hr %#x.\n", hr
);
3906 hr
= ID3D11Device_CreateVertexShader(device
, vs_code
, sizeof(vs_code
), NULL
, &vs
);
3907 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3908 hr
= ID3D11Device_CreatePixelShader(device
, ps_code
, sizeof(ps_code
), NULL
, &ps
);
3909 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
3911 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)backbuffer
, NULL
, &backbuffer_rtv
);
3912 ok(SUCCEEDED(hr
), "Failed to create rendertarget view, hr %#x.\n", hr
);
3914 ID3D11Device_GetImmediateContext(device
, &context
);
3916 ID3D11DeviceContext_OMSetRenderTargets(context
, 1, &backbuffer_rtv
, NULL
);
3917 ID3D11DeviceContext_IASetInputLayout(context
, input_layout
);
3918 ID3D11DeviceContext_IASetPrimitiveTopology(context
, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
);
3919 stride
= sizeof(*quad
);
3921 ID3D11DeviceContext_IASetVertexBuffers(context
, 0, 1, &vb
, &stride
, &offset
);
3922 ID3D11DeviceContext_VSSetShader(context
, vs
, NULL
, 0);
3923 ID3D11DeviceContext_PSSetShaderResources(context
, 0, 1, &ps_srv
);
3924 ID3D11DeviceContext_PSSetSamplers(context
, 0, 1, &sampler_state
);
3925 ID3D11DeviceContext_PSSetShader(context
, ps
, NULL
, 0);
3933 ID3D11DeviceContext_RSSetViewports(context
, 1, &vp
);
3935 ID3D11DeviceContext_ClearRenderTargetView(context
, backbuffer_rtv
, red
);
3937 ID3D11DeviceContext_Draw(context
, 4, 0);
3938 get_texture_readback(backbuffer
, &rb
);
3939 for (i
= 0; i
< 4; ++i
)
3941 for (j
= 0; j
< 4; ++j
)
3943 color
= get_readback_color(&rb
, 80 + j
* 160, 60 + i
* 120);
3944 ok(compare_color(color
, 0x00000000, 0),
3945 "Got unexpected color 0x%08x at (%u, %u).\n", color
, j
, i
);
3948 release_texture_readback(&rb
);
3950 set_box(&box
, 1, 1, 0, 3, 3, 1);
3951 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, &box
,
3952 bitmap_data
, 4 * sizeof(*bitmap_data
), 0);
3953 set_box(&box
, 0, 3, 0, 3, 4, 1);
3954 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, &box
,
3955 &bitmap_data
[6], 4 * sizeof(*bitmap_data
), 0);
3956 set_box(&box
, 0, 0, 0, 4, 1, 1);
3957 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, &box
,
3958 &bitmap_data
[10], 4 * sizeof(*bitmap_data
), 0);
3959 set_box(&box
, 0, 1, 0, 1, 3, 1);
3960 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, &box
,
3961 &bitmap_data
[2], sizeof(*bitmap_data
), 0);
3962 set_box(&box
, 4, 4, 0, 3, 1, 1);
3963 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, &box
,
3964 bitmap_data
, sizeof(*bitmap_data
), 0);
3965 ID3D11DeviceContext_Draw(context
, 4, 0);
3966 get_texture_readback(backbuffer
, &rb
);
3967 for (i
= 0; i
< 4; ++i
)
3969 for (j
= 0; j
< 4; ++j
)
3971 color
= get_readback_color(&rb
, 80 + j
* 160, 60 + i
* 120);
3972 ok(compare_color(color
, expected_colors
[j
+ i
* 4], 1),
3973 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
3974 color
, j
, i
, expected_colors
[j
+ i
* 4]);
3977 release_texture_readback(&rb
);
3979 ID3D11DeviceContext_UpdateSubresource(context
, (ID3D11Resource
*)texture
, 0, NULL
,
3980 bitmap_data
, 4 * sizeof(*bitmap_data
), 0);
3981 ID3D11DeviceContext_Draw(context
, 4, 0);
3982 get_texture_readback(backbuffer
, &rb
);
3983 for (i
= 0; i
< 4; ++i
)
3985 for (j
= 0; j
< 4; ++j
)
3987 color
= get_readback_color(&rb
, 80 + j
* 160, 60 + i
* 120);
3988 ok(compare_color(color
, bitmap_data
[j
+ i
* 4], 1),
3989 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
3990 color
, j
, i
, bitmap_data
[j
+ i
* 4]);
3993 release_texture_readback(&rb
);
3995 ID3D11PixelShader_Release(ps
);
3996 ID3D11VertexShader_Release(vs
);
3997 ID3D11SamplerState_Release(sampler_state
);
3998 ID3D11ShaderResourceView_Release(ps_srv
);
3999 ID3D11Texture2D_Release(texture
);
4000 ID3D11Buffer_Release(vb
);
4001 ID3D11InputLayout_Release(input_layout
);
4002 ID3D11RenderTargetView_Release(backbuffer_rtv
);
4003 ID3D11Texture2D_Release(backbuffer
);
4004 IDXGISwapChain_Release(swapchain
);
4005 ID3D11DeviceContext_Release(context
);
4006 refcount
= ID3D11Device_Release(device
);
4007 ok(!refcount
, "Device has %u references left.\n", refcount
);
4008 DestroyWindow(window
);
4011 static void test_resource_map(void)
4013 D3D11_MAPPED_SUBRESOURCE mapped_subresource
;
4014 D3D11_TEXTURE3D_DESC texture3d_desc
;
4015 D3D11_TEXTURE2D_DESC texture2d_desc
;
4016 D3D11_BUFFER_DESC buffer_desc
;
4017 ID3D11DeviceContext
*context
;
4018 ID3D11Texture3D
*texture3d
;
4019 ID3D11Texture2D
*texture2d
;
4020 ID3D11Buffer
*buffer
;
4021 ID3D11Device
*device
;
4026 if (!(device
= create_device(NULL
)))
4028 skip("Failed to create device.\n");
4032 ID3D11Device_GetImmediateContext(device
, &context
);
4034 buffer_desc
.ByteWidth
= 1024;
4035 buffer_desc
.Usage
= D3D11_USAGE_STAGING
;
4036 buffer_desc
.BindFlags
= 0;
4037 buffer_desc
.CPUAccessFlags
= D3D11_CPU_ACCESS_READ
| D3D11_CPU_ACCESS_WRITE
;
4038 buffer_desc
.MiscFlags
= 0;
4039 buffer_desc
.StructureByteStride
= 0;
4041 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
4042 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x.\n", hr
);
4044 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)buffer
, 1, D3D11_MAP_READ
, 0, &mapped_subresource
);
4045 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
4047 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4048 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)buffer
, 0, D3D11_MAP_WRITE
, 0, &mapped_subresource
);
4049 ok(SUCCEEDED(hr
), "Failed to map buffer, hr %#x.\n", hr
);
4050 ok(mapped_subresource
.RowPitch
== 1024, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4051 ok(mapped_subresource
.DepthPitch
== 1024, "Got unexpected depth pitch %u.\n", mapped_subresource
.DepthPitch
);
4052 *((DWORD
*)mapped_subresource
.pData
) = 0xdeadbeef;
4053 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)buffer
, 0);
4055 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4056 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)buffer
, 0, D3D11_MAP_READ
, 0, &mapped_subresource
);
4057 ok(SUCCEEDED(hr
), "Failed to map buffer, hr %#x.\n", hr
);
4058 ok(mapped_subresource
.RowPitch
== 1024, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4059 ok(mapped_subresource
.DepthPitch
== 1024, "Got unexpected depth pitch %u.\n", mapped_subresource
.DepthPitch
);
4060 data
= *((DWORD
*)mapped_subresource
.pData
);
4061 ok(data
== 0xdeadbeef, "Got unexpected data %#x.\n", data
);
4062 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)buffer
, 0);
4064 refcount
= ID3D11Buffer_Release(buffer
);
4065 ok(!refcount
, "Buffer has %u references left.\n", refcount
);
4067 texture2d_desc
.Width
= 512;
4068 texture2d_desc
.Height
= 512;
4069 texture2d_desc
.MipLevels
= 1;
4070 texture2d_desc
.ArraySize
= 1;
4071 texture2d_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
4072 texture2d_desc
.SampleDesc
.Count
= 1;
4073 texture2d_desc
.SampleDesc
.Quality
= 0;
4074 texture2d_desc
.Usage
= D3D11_USAGE_STAGING
;
4075 texture2d_desc
.BindFlags
= 0;
4076 texture2d_desc
.CPUAccessFlags
= D3D11_CPU_ACCESS_READ
| D3D11_CPU_ACCESS_WRITE
;
4077 texture2d_desc
.MiscFlags
= 0;
4079 hr
= ID3D11Device_CreateTexture2D(device
, &texture2d_desc
, NULL
, &texture2d
);
4080 ok(SUCCEEDED(hr
), "Failed to create 2d texture, hr %#x.\n", hr
);
4082 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture2d
, 1, D3D11_MAP_READ
, 0, &mapped_subresource
);
4083 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
4085 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4086 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture2d
, 0, D3D11_MAP_WRITE
, 0, &mapped_subresource
);
4087 ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
4088 ok(mapped_subresource
.RowPitch
== 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4089 ok(mapped_subresource
.DepthPitch
== 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4090 mapped_subresource
.DepthPitch
);
4091 *((DWORD
*)mapped_subresource
.pData
) = 0xdeadbeef;
4092 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)texture2d
, 0);
4094 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4095 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture2d
, 0, D3D11_MAP_READ
, 0, &mapped_subresource
);
4096 ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
4097 ok(mapped_subresource
.RowPitch
== 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4098 ok(mapped_subresource
.DepthPitch
== 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4099 mapped_subresource
.DepthPitch
);
4100 data
= *((DWORD
*)mapped_subresource
.pData
);
4101 ok(data
== 0xdeadbeef, "Got unexpected data %#x.\n", data
);
4102 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)texture2d
, 0);
4104 refcount
= ID3D11Texture2D_Release(texture2d
);
4105 ok(!refcount
, "2D texture has %u references left.\n", refcount
);
4107 texture3d_desc
.Width
= 64;
4108 texture3d_desc
.Height
= 64;
4109 texture3d_desc
.Depth
= 64;
4110 texture3d_desc
.MipLevels
= 1;
4111 texture3d_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
4112 texture3d_desc
.Usage
= D3D11_USAGE_STAGING
;
4113 texture3d_desc
.BindFlags
= 0;
4114 texture3d_desc
.CPUAccessFlags
= D3D11_CPU_ACCESS_READ
| D3D11_CPU_ACCESS_WRITE
;
4115 texture3d_desc
.MiscFlags
= 0;
4117 hr
= ID3D11Device_CreateTexture3D(device
, &texture3d_desc
, NULL
, &texture3d
);
4118 ok(SUCCEEDED(hr
), "Failed to create 3d texture, hr %#x.\n", hr
);
4120 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture3d
, 1, D3D11_MAP_READ
, 0, &mapped_subresource
);
4121 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
4123 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4124 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture3d
, 0, D3D11_MAP_WRITE
, 0, &mapped_subresource
);
4125 todo_wine
ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
4126 if (FAILED(hr
)) goto done
;
4127 ok(mapped_subresource
.RowPitch
== 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4128 ok(mapped_subresource
.DepthPitch
== 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4129 mapped_subresource
.DepthPitch
);
4130 *((DWORD
*)mapped_subresource
.pData
) = 0xdeadbeef;
4131 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)texture3d
, 0);
4133 memset(&mapped_subresource
, 0, sizeof(mapped_subresource
));
4134 hr
= ID3D11DeviceContext_Map(context
, (ID3D11Resource
*)texture3d
, 0, D3D11_MAP_READ
, 0, &mapped_subresource
);
4135 ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
4136 ok(mapped_subresource
.RowPitch
== 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource
.RowPitch
);
4137 ok(mapped_subresource
.DepthPitch
== 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4138 mapped_subresource
.DepthPitch
);
4139 data
= *((DWORD
*)mapped_subresource
.pData
);
4140 ok(data
== 0xdeadbeef, "Got unexpected data %#x.\n", data
);
4141 ID3D11DeviceContext_Unmap(context
, (ID3D11Resource
*)texture3d
, 0);
4144 refcount
= ID3D11Texture3D_Release(texture3d
);
4145 ok(!refcount
, "3D texture has %u references left.\n", refcount
);
4147 ID3D11DeviceContext_Release(context
);
4149 refcount
= ID3D11Device_Release(device
);
4150 ok(!refcount
, "Device has %u references left.\n", refcount
);
4155 test_create_device();
4156 test_device_interfaces();
4157 test_get_immediate_context();
4158 test_create_texture2d();
4159 test_texture2d_interfaces();
4160 test_create_texture3d();
4161 test_texture3d_interfaces();
4162 test_buffer_interfaces();
4163 test_create_depthstencil_view();
4164 test_depthstencil_view_interfaces();
4165 test_create_rendertarget_view();
4166 test_create_shader_resource_view();
4167 test_create_shader();
4168 test_create_sampler_state();
4169 test_create_blend_state();
4170 test_create_depthstencil_state();
4171 test_create_rasterizer_state();
4172 test_create_predicate();
4173 test_device_removed_reason();
4174 test_private_data();
4178 test_il_append_aligned();
4179 test_fragment_coords();
4180 test_update_subresource();
4181 test_resource_map();