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
24 #include "wine/test.h"
26 static const D3D10_FEATURE_LEVEL1 d3d10_feature_levels
[] =
28 D3D10_FEATURE_LEVEL_10_1
,
29 D3D10_FEATURE_LEVEL_10_0
,
30 D3D10_FEATURE_LEVEL_9_3
,
31 D3D10_FEATURE_LEVEL_9_2
,
32 D3D10_FEATURE_LEVEL_9_1
35 static ULONG
get_refcount(IUnknown
*iface
)
37 IUnknown_AddRef(iface
);
38 return IUnknown_Release(iface
);
43 D3D10_FEATURE_LEVEL1 feature_level
;
47 static ID3D10Device1
*create_device(const struct device_desc
*desc
)
49 D3D10_FEATURE_LEVEL1 feature_level
= D3D10_FEATURE_LEVEL_10_1
;
50 ID3D10Device1
*device
;
55 feature_level
= desc
->feature_level
;
59 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
,
60 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
62 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_WARP
,
63 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
65 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_REFERENCE
,
66 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
72 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
73 static HRESULT
check_interface_(unsigned int line
, void *iface
, REFIID iid
, BOOL supported
, BOOL is_broken
)
75 HRESULT hr
, expected_hr
, broken_hr
;
76 IUnknown
*unknown
= iface
, *out
;
81 broken_hr
= E_NOINTERFACE
;
85 expected_hr
= E_NOINTERFACE
;
89 hr
= IUnknown_QueryInterface(unknown
, iid
, (void **)&out
);
90 ok_(__FILE__
, line
)(hr
== expected_hr
|| broken(is_broken
&& hr
== broken_hr
),
91 "Got unexpected hr %#lx, expected %#lx.\n", hr
, expected_hr
);
93 IUnknown_Release(out
);
97 static void test_create_device(void)
99 D3D10_FEATURE_LEVEL1 feature_level
, supported_feature_level
;
100 DXGI_SWAP_CHAIN_DESC swapchain_desc
, obtained_desc
;
101 IDXGISwapChain
*swapchain
;
102 ID3D10Device1
*device
;
108 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
110 if (SUCCEEDED(hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
111 d3d10_feature_levels
[i
], D3D10_1_SDK_VERSION
, &device
)))
113 supported_feature_level
= d3d10_feature_levels
[i
];
120 skip("Failed to create HAL device.\n");
124 feature_level
= ID3D10Device1_GetFeatureLevel(device
);
125 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
126 feature_level
, supported_feature_level
);
128 ID3D10Device1_Release(device
);
130 hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
131 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
);
132 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
134 device
= (ID3D10Device1
*)0xdeadbeef;
135 hr
= D3D10CreateDevice1(NULL
, 0xffffffff, NULL
, 0,
136 supported_feature_level
, D3D10_1_SDK_VERSION
, &device
);
137 todo_wine
ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
138 ok(!device
, "Got unexpected device pointer %p.\n", device
);
140 device
= (ID3D10Device1
*)0xdeadbeef;
141 hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
142 0, D3D10_1_SDK_VERSION
, &device
);
143 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
144 ok(!device
, "Got unexpected device pointer %p.\n", device
);
146 window
= CreateWindowA("static", "d3d10_1_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
148 swapchain_desc
.BufferDesc
.Width
= 800;
149 swapchain_desc
.BufferDesc
.Height
= 600;
150 swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
= 60;
151 swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
= 60;
152 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
153 swapchain_desc
.BufferDesc
.ScanlineOrdering
= DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
;
154 swapchain_desc
.BufferDesc
.Scaling
= DXGI_MODE_SCALING_UNSPECIFIED
;
155 swapchain_desc
.SampleDesc
.Count
= 1;
156 swapchain_desc
.SampleDesc
.Quality
= 0;
157 swapchain_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
158 swapchain_desc
.BufferCount
= 1;
159 swapchain_desc
.OutputWindow
= window
;
160 swapchain_desc
.Windowed
= TRUE
;
161 swapchain_desc
.SwapEffect
= DXGI_SWAP_EFFECT_DISCARD
;
162 swapchain_desc
.Flags
= 0;
164 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
165 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
166 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
168 check_interface(swapchain
, &IID_IDXGISwapChain1
, TRUE
, FALSE
);
170 memset(&obtained_desc
, 0, sizeof(obtained_desc
));
171 hr
= IDXGISwapChain_GetDesc(swapchain
, &obtained_desc
);
172 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
173 ok(obtained_desc
.BufferDesc
.Width
== swapchain_desc
.BufferDesc
.Width
,
174 "Got unexpected BufferDesc.Width %u.\n", obtained_desc
.BufferDesc
.Width
);
175 ok(obtained_desc
.BufferDesc
.Height
== swapchain_desc
.BufferDesc
.Height
,
176 "Got unexpected BufferDesc.Height %u.\n", obtained_desc
.BufferDesc
.Height
);
177 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Numerator
== swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
,
178 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
179 obtained_desc
.BufferDesc
.RefreshRate
.Numerator
);
180 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Denominator
== swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
,
181 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
182 obtained_desc
.BufferDesc
.RefreshRate
.Denominator
);
183 ok(obtained_desc
.BufferDesc
.Format
== swapchain_desc
.BufferDesc
.Format
,
184 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc
.BufferDesc
.Format
);
185 ok(obtained_desc
.BufferDesc
.ScanlineOrdering
== swapchain_desc
.BufferDesc
.ScanlineOrdering
,
186 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc
.BufferDesc
.ScanlineOrdering
);
187 ok(obtained_desc
.BufferDesc
.Scaling
== swapchain_desc
.BufferDesc
.Scaling
,
188 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc
.BufferDesc
.Scaling
);
189 ok(obtained_desc
.SampleDesc
.Count
== swapchain_desc
.SampleDesc
.Count
,
190 "Got unexpected SampleDesc.Count %u.\n", obtained_desc
.SampleDesc
.Count
);
191 ok(obtained_desc
.SampleDesc
.Quality
== swapchain_desc
.SampleDesc
.Quality
,
192 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc
.SampleDesc
.Quality
);
193 ok(obtained_desc
.BufferUsage
== swapchain_desc
.BufferUsage
,
194 "Got unexpected BufferUsage %#x.\n", obtained_desc
.BufferUsage
);
195 ok(obtained_desc
.BufferCount
== swapchain_desc
.BufferCount
,
196 "Got unexpected BufferCount %u.\n", obtained_desc
.BufferCount
);
197 ok(obtained_desc
.OutputWindow
== swapchain_desc
.OutputWindow
,
198 "Got unexpected OutputWindow %p.\n", obtained_desc
.OutputWindow
);
199 ok(obtained_desc
.Windowed
== swapchain_desc
.Windowed
,
200 "Got unexpected Windowed %#x.\n", obtained_desc
.Windowed
);
201 ok(obtained_desc
.SwapEffect
== swapchain_desc
.SwapEffect
,
202 "Got unexpected SwapEffect %#x.\n", obtained_desc
.SwapEffect
);
203 ok(obtained_desc
.Flags
== swapchain_desc
.Flags
,
204 "Got unexpected Flags %#x.\n", obtained_desc
.Flags
);
206 refcount
= IDXGISwapChain_Release(swapchain
);
207 ok(!refcount
, "Swapchain has %lu references left.\n", refcount
);
209 feature_level
= ID3D10Device1_GetFeatureLevel(device
);
210 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
211 feature_level
, supported_feature_level
);
213 refcount
= ID3D10Device1_Release(device
);
214 ok(!refcount
, "Device has %lu references left.\n", refcount
);
216 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
217 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
, NULL
, &device
);
218 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
219 refcount
= ID3D10Device1_Release(device
);
220 ok(!refcount
, "Device has %lu references left.\n", refcount
);
222 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
223 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
, NULL
, NULL
);
224 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
226 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
227 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, NULL
, NULL
);
228 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
230 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
231 device
= (ID3D10Device1
*)0xdeadbeef;
232 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
233 0, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
234 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
235 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
236 ok(!device
, "Got unexpected device pointer %p.\n", device
);
238 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
239 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
240 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, NULL
);
241 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
242 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
244 swapchain_desc
.OutputWindow
= NULL
;
245 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
246 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, NULL
, &device
);
247 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
248 refcount
= ID3D10Device1_Release(device
);
249 ok(!refcount
, "Device has %lu references left.\n", refcount
);
251 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
252 device
= (ID3D10Device1
*)0xdeadbeef;
253 swapchain_desc
.OutputWindow
= NULL
;
254 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
255 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
256 ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#lx.\n", hr
);
257 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
258 ok(!device
, "Got unexpected device pointer %p.\n", device
);
260 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
261 device
= (ID3D10Device1
*)0xdeadbeef;
262 swapchain_desc
.OutputWindow
= window
;
263 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_BC5_UNORM
;
264 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
265 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
266 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
267 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
268 ok(!device
, "Got unexpected device pointer %p.\n", device
);
270 DestroyWindow(window
);
273 static void test_device_interfaces(void)
275 IDXGIAdapter
*dxgi_adapter
;
276 IDXGIDevice
*dxgi_device
;
277 ID3D10Device1
*device
;
283 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
285 struct device_desc device_desc
;
287 device_desc
.feature_level
= d3d10_feature_levels
[i
];
288 device_desc
.flags
= 0;
290 if (!(device
= create_device(&device_desc
)))
292 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels
[i
]);
296 check_interface(device
, &IID_IUnknown
, TRUE
, FALSE
);
297 check_interface(device
, &IID_IDXGIObject
, TRUE
, FALSE
);
298 check_interface(device
, &IID_IDXGIDevice
, TRUE
, FALSE
);
299 check_interface(device
, &IID_IDXGIDevice1
, TRUE
, FALSE
);
300 check_interface(device
, &IID_ID3D10Multithread
, TRUE
, TRUE
); /* Not available on all Windows versions. */
301 check_interface(device
, &IID_ID3D10Device
, TRUE
, FALSE
);
302 check_interface(device
, &IID_ID3D10InfoQueue
, FALSE
, FALSE
); /* Non-debug mode. */
303 check_interface(device
, &IID_ID3D11Device
, TRUE
, TRUE
); /* Not available on all Windows versions. */
305 hr
= ID3D10Device1_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
306 ok(SUCCEEDED(hr
), "Device should implement IDXGIDevice.\n");
307 hr
= IDXGIDevice_GetParent(dxgi_device
, &IID_IDXGIAdapter
, (void **)&dxgi_adapter
);
308 ok(SUCCEEDED(hr
), "Device parent should implement IDXGIAdapter.\n");
309 hr
= IDXGIAdapter_GetParent(dxgi_adapter
, &IID_IDXGIFactory
, (void **)&iface
);
310 ok(SUCCEEDED(hr
), "Adapter parent should implement IDXGIFactory.\n");
311 IUnknown_Release(iface
);
312 IDXGIAdapter_Release(dxgi_adapter
);
313 hr
= IDXGIDevice_GetParent(dxgi_device
, &IID_IDXGIAdapter1
, (void **)&dxgi_adapter
);
314 ok(SUCCEEDED(hr
), "Device parent should implement IDXGIAdapter1.\n");
315 hr
= IDXGIAdapter_GetParent(dxgi_adapter
, &IID_IDXGIFactory1
, (void **)&iface
);
316 ok(hr
== E_NOINTERFACE
, "Adapter parent should not implement IDXGIFactory1.\n");
317 IDXGIAdapter_Release(dxgi_adapter
);
318 IDXGIDevice_Release(dxgi_device
);
320 refcount
= ID3D10Device1_Release(device
);
321 ok(!refcount
, "Device has %lu references left.\n", refcount
);
324 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
326 struct device_desc device_desc
;
328 device_desc
.feature_level
= d3d10_feature_levels
[i
];
329 device_desc
.flags
= D3D10_CREATE_DEVICE_DEBUG
;
330 if (!(device
= create_device(&device_desc
)))
332 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels
[i
]);
337 check_interface(device
, &IID_ID3D10InfoQueue
, TRUE
, FALSE
);
339 refcount
= ID3D10Device1_Release(device
);
340 ok(!refcount
, "Device has %lu references left.\n", refcount
);
344 static void test_create_shader_resource_view(void)
346 D3D10_SHADER_RESOURCE_VIEW_DESC1 srv_desc
;
347 D3D10_TEXTURE2D_DESC texture_desc
;
348 ULONG refcount
, expected_refcount
;
349 ID3D10ShaderResourceView1
*srview
;
350 D3D10_BUFFER_DESC buffer_desc
;
351 ID3D10Texture2D
*texture
;
352 ID3D10Device
*tmp_device
;
353 ID3D10Device1
*device
;
354 ID3D10Buffer
*buffer
;
357 if (!(device
= create_device(NULL
)))
359 skip("Failed to create device.\n");
363 buffer_desc
.ByteWidth
= 1024;
364 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
365 buffer_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
366 buffer_desc
.CPUAccessFlags
= 0;
367 buffer_desc
.MiscFlags
= 0;
369 hr
= ID3D10Device1_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
370 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
372 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, NULL
, &srview
);
373 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
375 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
376 srv_desc
.ViewDimension
= D3D10_1_SRV_DIMENSION_BUFFER
;
377 U(srv_desc
).Buffer
.ElementOffset
= 0;
378 U(srv_desc
).Buffer
.ElementWidth
= 64;
380 hr
= ID3D10Device1_CreateShaderResourceView1(device
, NULL
, &srv_desc
, &srview
);
381 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
383 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
384 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &srview
);
385 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
386 refcount
= get_refcount((IUnknown
*)device
);
387 ok(refcount
>= expected_refcount
, "Got unexpected refcount %lu, expected >= %lu.\n", refcount
, expected_refcount
);
389 expected_refcount
= refcount
+ 1;
390 ID3D10ShaderResourceView1_GetDevice(srview
, &tmp_device
);
391 ok(tmp_device
== (ID3D10Device
*)device
, "Got unexpected device %p, expected %p.\n", tmp_device
, device
);
392 refcount
= get_refcount((IUnknown
*)device
);
393 ok(refcount
== expected_refcount
, "Got unexpected refcount %lu, expected %lu.\n", refcount
, expected_refcount
);
394 ID3D10Device_Release(tmp_device
);
396 check_interface(srview
, &IID_ID3D10ShaderResourceView
, TRUE
, FALSE
);
397 /* Not available on all Windows versions. */
398 check_interface(srview
, &IID_ID3D11ShaderResourceView
, TRUE
, TRUE
);
400 ID3D10ShaderResourceView1_Release(srview
);
401 ID3D10Buffer_Release(buffer
);
403 /* Without D3D10_BIND_SHADER_RESOURCE. */
404 buffer_desc
.ByteWidth
= 1024;
405 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
406 buffer_desc
.BindFlags
= 0;
407 buffer_desc
.CPUAccessFlags
= 0;
408 buffer_desc
.MiscFlags
= 0;
410 hr
= ID3D10Device1_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
411 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
413 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &srview
);
414 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
416 ID3D10Buffer_Release(buffer
);
418 texture_desc
.Width
= 512;
419 texture_desc
.Height
= 512;
420 texture_desc
.MipLevels
= 0;
421 texture_desc
.ArraySize
= 1;
422 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
423 texture_desc
.SampleDesc
.Count
= 1;
424 texture_desc
.SampleDesc
.Quality
= 0;
425 texture_desc
.Usage
= D3D10_USAGE_DEFAULT
;
426 texture_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
427 texture_desc
.CPUAccessFlags
= 0;
428 texture_desc
.MiscFlags
= 0;
430 hr
= ID3D10Device1_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
431 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
433 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)texture
, NULL
, &srview
);
434 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
436 ID3D10ShaderResourceView1_GetDesc1(srview
, &srv_desc
);
437 ok(srv_desc
.Format
== texture_desc
.Format
, "Got unexpected format %#x.\n", srv_desc
.Format
);
438 ok(srv_desc
.ViewDimension
== D3D10_1_SRV_DIMENSION_TEXTURE2D
,
439 "Got unexpected view dimension %#x.\n", srv_desc
.ViewDimension
);
440 ok(U(srv_desc
).Texture2D
.MostDetailedMip
== 0, "Got unexpected MostDetailedMip %u.\n",
441 U(srv_desc
).Texture2D
.MostDetailedMip
);
442 ok(U(srv_desc
).Texture2D
.MipLevels
== 10, "Got unexpected MipLevels %u.\n", U(srv_desc
).Texture2D
.MipLevels
);
444 check_interface(srview
, &IID_ID3D10ShaderResourceView
, TRUE
, FALSE
);
445 /* Not available on all Windows versions. */
446 check_interface(srview
, &IID_ID3D11ShaderResourceView
, TRUE
, TRUE
);
448 ID3D10ShaderResourceView1_Release(srview
);
449 ID3D10Texture2D_Release(texture
);
451 refcount
= ID3D10Device1_Release(device
);
452 ok(!refcount
, "Device has %lu references left.\n", refcount
);
455 static void test_create_blend_state(void)
457 static const D3D10_BLEND_DESC1 desc_conversion_tests
[] =
463 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
464 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
472 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
473 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
476 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
477 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_RED
480 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
481 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
484 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
485 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_GREEN
488 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
489 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
492 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
493 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
496 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
497 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
500 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
501 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
509 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
510 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
513 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_SUBTRACT
,
514 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
517 TRUE
, D3D10_BLEND_ZERO
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_ADD
,
518 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
521 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
522 D3D10_BLEND_ZERO
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
525 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_MAX
,
526 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
529 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_MIN
,
530 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
533 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
534 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
537 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
538 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
544 ID3D10BlendState1
*blend_state1
, *blend_state2
;
545 D3D10_BLEND_DESC1 desc
, obtained_desc
;
546 ID3D10BlendState
*d3d10_blend_state
;
547 D3D10_BLEND_DESC d3d10_blend_desc
;
548 ULONG refcount
, expected_refcount
;
549 ID3D10Device1
*device
;
554 if (!(device
= create_device(NULL
)))
556 skip("Failed to create device.\n");
560 hr
= ID3D10Device1_CreateBlendState1(device
, NULL
, &blend_state1
);
561 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#lx.\n", hr
);
563 memset(&desc
, 0, sizeof(desc
));
564 desc
.AlphaToCoverageEnable
= FALSE
;
565 desc
.IndependentBlendEnable
= FALSE
;
566 desc
.RenderTarget
[0].BlendEnable
= FALSE
;
567 desc
.RenderTarget
[0].SrcBlend
= D3D10_BLEND_ONE
;
568 desc
.RenderTarget
[0].DestBlend
= D3D10_BLEND_ZERO
;
569 desc
.RenderTarget
[0].BlendOp
= D3D10_BLEND_OP_ADD
;
570 desc
.RenderTarget
[0].SrcBlendAlpha
= D3D10_BLEND_ONE
;
571 desc
.RenderTarget
[0].DestBlendAlpha
= D3D10_BLEND_ZERO
;
572 desc
.RenderTarget
[0].BlendOpAlpha
= D3D10_BLEND_OP_ADD
;
573 desc
.RenderTarget
[0].RenderTargetWriteMask
= D3D10_COLOR_WRITE_ENABLE_ALL
;
575 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
576 hr
= ID3D10Device1_CreateBlendState1(device
, &desc
, &blend_state1
);
577 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
578 hr
= ID3D10Device1_CreateBlendState1(device
, &desc
, &blend_state2
);
579 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
580 ok(blend_state1
== blend_state2
, "Got different blend state objects.\n");
581 refcount
= get_refcount((IUnknown
*)device
);
582 ok(refcount
>= expected_refcount
, "Got unexpected refcount %lu, expected >= %lu.\n", refcount
, expected_refcount
);
584 expected_refcount
= refcount
+ 1;
585 ID3D10BlendState1_GetDevice(blend_state1
, &tmp
);
586 ok(tmp
== (ID3D10Device
*)device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
587 refcount
= get_refcount((IUnknown
*)device
);
588 ok(refcount
== expected_refcount
, "Got unexpected refcount %lu, expected %lu.\n", refcount
, expected_refcount
);
589 ID3D10Device_Release(tmp
);
591 ID3D10BlendState1_GetDesc1(blend_state1
, &obtained_desc
);
592 ok(obtained_desc
.AlphaToCoverageEnable
== FALSE
, "Got unexpected alpha to coverage enable %#x.\n",
593 obtained_desc
.AlphaToCoverageEnable
);
594 ok(obtained_desc
.IndependentBlendEnable
== FALSE
, "Got unexpected independent blend enable %#x.\n",
595 obtained_desc
.IndependentBlendEnable
);
596 for (i
= 0; i
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; ++i
)
598 ok(obtained_desc
.RenderTarget
[i
].BlendEnable
== FALSE
,
599 "Got unexpected blend enable %#x for render target %u.\n",
600 obtained_desc
.RenderTarget
[i
].BlendEnable
, i
);
601 ok(obtained_desc
.RenderTarget
[i
].SrcBlend
== D3D10_BLEND_ONE
,
602 "Got unexpected src blend %u for render target %u.\n",
603 obtained_desc
.RenderTarget
[i
].SrcBlend
, i
);
604 ok(obtained_desc
.RenderTarget
[i
].DestBlend
== D3D10_BLEND_ZERO
,
605 "Got unexpected dest blend %u for render target %u.\n",
606 obtained_desc
.RenderTarget
[i
].DestBlend
, i
);
607 ok(obtained_desc
.RenderTarget
[i
].BlendOp
== D3D10_BLEND_OP_ADD
,
608 "Got unexpected blend op %u for render target %u.\n",
609 obtained_desc
.RenderTarget
[i
].BlendOp
, i
);
610 ok(obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
== D3D10_BLEND_ONE
,
611 "Got unexpected src blend alpha %u for render target %u.\n",
612 obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
, i
);
613 ok(obtained_desc
.RenderTarget
[i
].DestBlendAlpha
== D3D10_BLEND_ZERO
,
614 "Got unexpected dest blend alpha %u for render target %u.\n",
615 obtained_desc
.RenderTarget
[i
].DestBlendAlpha
, i
);
616 ok(obtained_desc
.RenderTarget
[i
].BlendOpAlpha
== D3D10_BLEND_OP_ADD
,
617 "Got unexpected blend op alpha %u for render target %u.\n",
618 obtained_desc
.RenderTarget
[i
].BlendOpAlpha
, i
);
619 ok(obtained_desc
.RenderTarget
[i
].RenderTargetWriteMask
== D3D10_COLOR_WRITE_ENABLE_ALL
,
620 "Got unexpected render target write mask %#x for render target %u.\n",
621 obtained_desc
.RenderTarget
[0].RenderTargetWriteMask
, i
);
624 check_interface(blend_state1
, &IID_ID3D10BlendState
, TRUE
, FALSE
);
625 /* Not available on all Windows versions. */
626 check_interface(blend_state1
, &IID_ID3D11BlendState
, TRUE
, TRUE
);
628 refcount
= ID3D10BlendState1_Release(blend_state1
);
629 ok(refcount
== 1, "Got unexpected refcount %lu.\n", refcount
);
630 refcount
= ID3D10BlendState1_Release(blend_state2
);
631 ok(!refcount
, "Blend state has %lu references left.\n", refcount
);
633 for (i
= 0; i
< ARRAY_SIZE(desc_conversion_tests
); ++i
)
635 const D3D10_BLEND_DESC1
*current_desc
= &desc_conversion_tests
[i
];
637 hr
= ID3D10Device1_CreateBlendState1(device
, current_desc
, &blend_state1
);
638 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
640 hr
= ID3D10BlendState1_QueryInterface(blend_state1
, &IID_ID3D10BlendState
, (void **)&d3d10_blend_state
);
641 ok(SUCCEEDED(hr
), "Blend state should implement ID3D10BlendState.\n");
643 ID3D10BlendState_GetDesc(d3d10_blend_state
, &d3d10_blend_desc
);
644 ok(d3d10_blend_desc
.AlphaToCoverageEnable
== current_desc
->AlphaToCoverageEnable
,
645 "Got unexpected alpha to coverage enable %#x for test %u.\n",
646 d3d10_blend_desc
.AlphaToCoverageEnable
, i
);
647 ok(d3d10_blend_desc
.SrcBlend
== current_desc
->RenderTarget
[0].SrcBlend
,
648 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc
.SrcBlend
, i
);
649 ok(d3d10_blend_desc
.DestBlend
== current_desc
->RenderTarget
[0].DestBlend
,
650 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc
.DestBlend
, i
);
651 ok(d3d10_blend_desc
.BlendOp
== current_desc
->RenderTarget
[0].BlendOp
,
652 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc
.BlendOp
, i
);
653 ok(d3d10_blend_desc
.SrcBlendAlpha
== current_desc
->RenderTarget
[0].SrcBlendAlpha
,
654 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc
.SrcBlendAlpha
, i
);
655 ok(d3d10_blend_desc
.DestBlendAlpha
== current_desc
->RenderTarget
[0].DestBlendAlpha
,
656 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc
.DestBlendAlpha
, i
);
657 ok(d3d10_blend_desc
.BlendOpAlpha
== current_desc
->RenderTarget
[0].BlendOpAlpha
,
658 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc
.BlendOpAlpha
, i
);
659 for (j
= 0; j
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; j
++)
661 unsigned int k
= current_desc
->IndependentBlendEnable
? j
: 0;
662 ok(d3d10_blend_desc
.BlendEnable
[j
] == current_desc
->RenderTarget
[k
].BlendEnable
,
663 "Got unexpected blend enable %#x for test %u, render target %u.\n",
664 d3d10_blend_desc
.BlendEnable
[j
], i
, j
);
665 ok(d3d10_blend_desc
.RenderTargetWriteMask
[j
] == current_desc
->RenderTarget
[k
].RenderTargetWriteMask
,
666 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
667 d3d10_blend_desc
.RenderTargetWriteMask
[j
], i
, j
);
670 ID3D10BlendState_Release(d3d10_blend_state
);
672 refcount
= ID3D10BlendState1_Release(blend_state1
);
673 ok(!refcount
, "Got unexpected refcount %lu.\n", refcount
);
676 refcount
= ID3D10Device1_Release(device
);
677 ok(!refcount
, "Device has %lu references left.\n", refcount
);
680 static void test_getdc(void)
682 struct device_desc device_desc
;
683 D3D10_TEXTURE2D_DESC desc
;
684 ID3D10Texture2D
*texture
;
685 IDXGISurface1
*surface1
;
686 ID3D10Device1
*device
;
691 device_desc
.feature_level
= D3D10_FEATURE_LEVEL_10_1
;
692 device_desc
.flags
= D3D10_CREATE_DEVICE_BGRA_SUPPORT
;
693 if (!(device
= create_device(&device_desc
)))
695 skip("Failed to create device.\n");
699 /* Without D3D10_RESOURCE_MISC_GDI_COMPATIBLE. */
704 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
705 desc
.SampleDesc
.Count
= 1;
706 desc
.SampleDesc
.Quality
= 0;
707 desc
.Usage
= D3D10_USAGE_DEFAULT
;
708 desc
.BindFlags
= D3D10_BIND_RENDER_TARGET
;
709 desc
.CPUAccessFlags
= 0;
711 hr
= ID3D10Device1_CreateTexture2D(device
, &desc
, NULL
, &texture
);
712 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
714 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void**)&surface1
);
715 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
717 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
718 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#lx.\n", hr
);
720 IDXGISurface1_Release(surface1
);
721 ID3D10Texture2D_Release(texture
);
723 desc
.MiscFlags
= D3D10_RESOURCE_MISC_GDI_COMPATIBLE
;
724 hr
= ID3D10Device1_CreateTexture2D(device
, &desc
, NULL
, &texture
);
725 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
727 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void**)&surface1
);
728 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
730 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
731 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#lx.\n", hr
);
733 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
734 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
737 dc
= (HDC
)0xdeadbeef;
738 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
739 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#lx.\n", hr
);
740 ok(dc
== (HDC
)0xdeadbeef, "Got unexpected dc %p.\n", dc
);
742 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
743 ok(hr
== S_OK
, "Got unexpected hr %#lx.\n", hr
);
745 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
746 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#lx.\n", hr
);
748 IDXGISurface1_Release(surface1
);
749 ID3D10Texture2D_Release(texture
);
751 refcount
= ID3D10Device1_Release(device
);
752 ok(!refcount
, "Device has %lu references left.\n", refcount
);
757 test_create_device();
758 test_device_interfaces();
759 test_create_shader_resource_view();
760 test_create_blend_state();