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 D3D10_FEATURE_LEVEL1 d3d10_feature_levels
[] =
27 D3D10_FEATURE_LEVEL_10_1
,
28 D3D10_FEATURE_LEVEL_10_0
,
29 D3D10_FEATURE_LEVEL_9_3
,
30 D3D10_FEATURE_LEVEL_9_2
,
31 D3D10_FEATURE_LEVEL_9_1
34 static ULONG
get_refcount(IUnknown
*iface
)
36 IUnknown_AddRef(iface
);
37 return IUnknown_Release(iface
);
42 D3D10_FEATURE_LEVEL1 feature_level
;
46 static ID3D10Device1
*create_device(const struct device_desc
*desc
)
48 D3D10_FEATURE_LEVEL1 feature_level
= D3D10_FEATURE_LEVEL_10_1
;
49 ID3D10Device1
*device
;
54 feature_level
= desc
->feature_level
;
58 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
,
59 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
61 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_WARP
,
62 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
64 if (SUCCEEDED(D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_REFERENCE
,
65 NULL
, flags
, feature_level
, D3D10_1_SDK_VERSION
, &device
)))
71 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
72 static HRESULT
check_interface_(unsigned int line
, void *iface
, REFIID iid
, BOOL supported
, BOOL is_broken
)
74 HRESULT hr
, expected_hr
, broken_hr
;
75 IUnknown
*unknown
= iface
, *out
;
80 broken_hr
= E_NOINTERFACE
;
84 expected_hr
= E_NOINTERFACE
;
88 hr
= IUnknown_QueryInterface(unknown
, iid
, (void **)&out
);
89 ok_(__FILE__
, line
)(hr
== expected_hr
|| broken(is_broken
&& hr
== broken_hr
),
90 "Got hr %#x, expected %#x.\n", hr
, expected_hr
);
92 IUnknown_Release(out
);
96 static void test_create_device(void)
98 D3D10_FEATURE_LEVEL1 feature_level
, supported_feature_level
;
99 DXGI_SWAP_CHAIN_DESC swapchain_desc
, obtained_desc
;
100 IDXGISwapChain
*swapchain
;
101 ID3D10Device1
*device
;
107 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
109 if (SUCCEEDED(hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
110 d3d10_feature_levels
[i
], D3D10_1_SDK_VERSION
, &device
)))
112 supported_feature_level
= d3d10_feature_levels
[i
];
119 skip("Failed to create HAL device.\n");
123 feature_level
= ID3D10Device1_GetFeatureLevel(device
);
124 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
125 feature_level
, supported_feature_level
);
127 ID3D10Device1_Release(device
);
129 hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
130 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
);
131 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
133 device
= (ID3D10Device1
*)0xdeadbeef;
134 hr
= D3D10CreateDevice1(NULL
, 0xffffffff, NULL
, 0,
135 supported_feature_level
, D3D10_1_SDK_VERSION
, &device
);
136 todo_wine
ok(hr
== E_INVALIDARG
, "D3D10CreateDevice1 returned %#x.\n", hr
);
137 ok(!device
, "Got unexpected device pointer %p.\n", device
);
139 device
= (ID3D10Device1
*)0xdeadbeef;
140 hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
141 0, D3D10_1_SDK_VERSION
, &device
);
142 ok(hr
== E_INVALIDARG
, "D3D10CreateDevice1 returned %#x.\n", hr
);
143 ok(!device
, "Got unexpected device pointer %p.\n", device
);
145 window
= CreateWindowA("static", "d3d10_1_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
147 swapchain_desc
.BufferDesc
.Width
= 800;
148 swapchain_desc
.BufferDesc
.Height
= 600;
149 swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
= 60;
150 swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
= 60;
151 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
152 swapchain_desc
.BufferDesc
.ScanlineOrdering
= DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
;
153 swapchain_desc
.BufferDesc
.Scaling
= DXGI_MODE_SCALING_UNSPECIFIED
;
154 swapchain_desc
.SampleDesc
.Count
= 1;
155 swapchain_desc
.SampleDesc
.Quality
= 0;
156 swapchain_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
157 swapchain_desc
.BufferCount
= 1;
158 swapchain_desc
.OutputWindow
= window
;
159 swapchain_desc
.Windowed
= TRUE
;
160 swapchain_desc
.SwapEffect
= DXGI_SWAP_EFFECT_DISCARD
;
161 swapchain_desc
.Flags
= 0;
163 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
164 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
165 ok(SUCCEEDED(hr
), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr
);
167 check_interface(swapchain
, &IID_IDXGISwapChain1
, TRUE
, FALSE
);
169 memset(&obtained_desc
, 0, sizeof(obtained_desc
));
170 hr
= IDXGISwapChain_GetDesc(swapchain
, &obtained_desc
);
171 ok(SUCCEEDED(hr
), "GetDesc failed %#x.\n", hr
);
172 ok(obtained_desc
.BufferDesc
.Width
== swapchain_desc
.BufferDesc
.Width
,
173 "Got unexpected BufferDesc.Width %u.\n", obtained_desc
.BufferDesc
.Width
);
174 ok(obtained_desc
.BufferDesc
.Height
== swapchain_desc
.BufferDesc
.Height
,
175 "Got unexpected BufferDesc.Height %u.\n", obtained_desc
.BufferDesc
.Height
);
176 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Numerator
== swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
,
177 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
178 obtained_desc
.BufferDesc
.RefreshRate
.Numerator
);
179 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Denominator
== swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
,
180 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
181 obtained_desc
.BufferDesc
.RefreshRate
.Denominator
);
182 ok(obtained_desc
.BufferDesc
.Format
== swapchain_desc
.BufferDesc
.Format
,
183 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc
.BufferDesc
.Format
);
184 ok(obtained_desc
.BufferDesc
.ScanlineOrdering
== swapchain_desc
.BufferDesc
.ScanlineOrdering
,
185 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc
.BufferDesc
.ScanlineOrdering
);
186 ok(obtained_desc
.BufferDesc
.Scaling
== swapchain_desc
.BufferDesc
.Scaling
,
187 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc
.BufferDesc
.Scaling
);
188 ok(obtained_desc
.SampleDesc
.Count
== swapchain_desc
.SampleDesc
.Count
,
189 "Got unexpected SampleDesc.Count %u.\n", obtained_desc
.SampleDesc
.Count
);
190 ok(obtained_desc
.SampleDesc
.Quality
== swapchain_desc
.SampleDesc
.Quality
,
191 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc
.SampleDesc
.Quality
);
192 ok(obtained_desc
.BufferUsage
== swapchain_desc
.BufferUsage
,
193 "Got unexpected BufferUsage %#x.\n", obtained_desc
.BufferUsage
);
194 ok(obtained_desc
.BufferCount
== swapchain_desc
.BufferCount
,
195 "Got unexpected BufferCount %u.\n", obtained_desc
.BufferCount
);
196 ok(obtained_desc
.OutputWindow
== swapchain_desc
.OutputWindow
,
197 "Got unexpected OutputWindow %p.\n", obtained_desc
.OutputWindow
);
198 ok(obtained_desc
.Windowed
== swapchain_desc
.Windowed
,
199 "Got unexpected Windowed %#x.\n", obtained_desc
.Windowed
);
200 ok(obtained_desc
.SwapEffect
== swapchain_desc
.SwapEffect
,
201 "Got unexpected SwapEffect %#x.\n", obtained_desc
.SwapEffect
);
202 ok(obtained_desc
.Flags
== swapchain_desc
.Flags
,
203 "Got unexpected Flags %#x.\n", obtained_desc
.Flags
);
205 refcount
= IDXGISwapChain_Release(swapchain
);
206 ok(!refcount
, "Swapchain has %u references left.\n", refcount
);
208 feature_level
= ID3D10Device1_GetFeatureLevel(device
);
209 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
210 feature_level
, supported_feature_level
);
212 refcount
= ID3D10Device1_Release(device
);
213 ok(!refcount
, "Device has %u references left.\n", refcount
);
215 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
216 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
, NULL
, &device
);
217 ok(SUCCEEDED(hr
), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr
);
218 refcount
= ID3D10Device1_Release(device
);
219 ok(!refcount
, "Device has %u references left.\n", refcount
);
221 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
222 supported_feature_level
, D3D10_1_SDK_VERSION
, NULL
, NULL
, NULL
);
223 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
225 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
226 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, NULL
, NULL
);
227 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
229 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
230 device
= (ID3D10Device1
*)0xdeadbeef;
231 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
232 0, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
233 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
234 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
235 ok(!device
, "Got unexpected device pointer %p.\n", device
);
237 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
238 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
239 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, NULL
);
240 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
241 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
243 swapchain_desc
.OutputWindow
= NULL
;
244 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
245 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, NULL
, &device
);
246 ok(SUCCEEDED(hr
), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr
);
247 refcount
= ID3D10Device1_Release(device
);
248 ok(!refcount
, "Device has %u references left.\n", refcount
);
250 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
251 device
= (ID3D10Device1
*)0xdeadbeef;
252 swapchain_desc
.OutputWindow
= NULL
;
253 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
254 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
255 ok(hr
== DXGI_ERROR_INVALID_CALL
, "D3D10CreateDeviceAndSwapChain1 returned %#x.\n", hr
);
256 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
257 ok(!device
, "Got unexpected device pointer %p.\n", device
);
259 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
260 device
= (ID3D10Device1
*)0xdeadbeef;
261 swapchain_desc
.OutputWindow
= window
;
262 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_BC5_UNORM
;
263 hr
= D3D10CreateDeviceAndSwapChain1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0,
264 supported_feature_level
, D3D10_1_SDK_VERSION
, &swapchain_desc
, &swapchain
, &device
);
265 ok(hr
== E_INVALIDARG
, "D3D10CreateDeviceAndSwapChain1 returned %#x.\n", hr
);
266 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
267 ok(!device
, "Got unexpected device pointer %p.\n", device
);
269 DestroyWindow(window
);
272 static void test_device_interfaces(void)
274 IDXGIAdapter
*dxgi_adapter
;
275 IDXGIDevice
*dxgi_device
;
276 ID3D10Device1
*device
;
282 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
284 struct device_desc device_desc
;
286 device_desc
.feature_level
= d3d10_feature_levels
[i
];
287 device_desc
.flags
= 0;
289 if (!(device
= create_device(&device_desc
)))
291 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels
[i
]);
295 check_interface(device
, &IID_IUnknown
, TRUE
, FALSE
);
296 check_interface(device
, &IID_IDXGIObject
, TRUE
, FALSE
);
297 check_interface(device
, &IID_IDXGIDevice
, TRUE
, FALSE
);
298 check_interface(device
, &IID_IDXGIDevice1
, TRUE
, FALSE
);
299 check_interface(device
, &IID_ID3D10Multithread
, TRUE
, TRUE
); /* Not available on all Windows versions. */
300 check_interface(device
, &IID_ID3D10Device
, TRUE
, FALSE
);
301 check_interface(device
, &IID_ID3D10InfoQueue
, FALSE
, FALSE
); /* Non-debug mode. */
302 check_interface(device
, &IID_ID3D11Device
, TRUE
, TRUE
); /* Not available on all Windows versions. */
304 hr
= ID3D10Device1_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
305 ok(SUCCEEDED(hr
), "Device should implement IDXGIDevice.\n");
306 hr
= IDXGIDevice_GetParent(dxgi_device
, &IID_IDXGIAdapter
, (void **)&dxgi_adapter
);
307 ok(SUCCEEDED(hr
), "Device parent should implement IDXGIAdapter.\n");
308 hr
= IDXGIAdapter_GetParent(dxgi_adapter
, &IID_IDXGIFactory
, (void **)&iface
);
309 ok(SUCCEEDED(hr
), "Adapter parent should implement IDXGIFactory.\n");
310 IUnknown_Release(iface
);
311 IDXGIAdapter_Release(dxgi_adapter
);
312 hr
= IDXGIDevice_GetParent(dxgi_device
, &IID_IDXGIAdapter1
, (void **)&dxgi_adapter
);
313 ok(SUCCEEDED(hr
), "Device parent should implement IDXGIAdapter1.\n");
314 hr
= IDXGIAdapter_GetParent(dxgi_adapter
, &IID_IDXGIFactory1
, (void **)&iface
);
315 ok(hr
== E_NOINTERFACE
, "Adapter parent should not implement IDXGIFactory1.\n");
316 IDXGIAdapter_Release(dxgi_adapter
);
317 IDXGIDevice_Release(dxgi_device
);
319 refcount
= ID3D10Device1_Release(device
);
320 ok(!refcount
, "Device has %u references left.\n", refcount
);
323 for (i
= 0; i
< ARRAY_SIZE(d3d10_feature_levels
); ++i
)
325 struct device_desc device_desc
;
327 device_desc
.feature_level
= d3d10_feature_levels
[i
];
328 device_desc
.flags
= D3D10_CREATE_DEVICE_DEBUG
;
329 if (!(device
= create_device(&device_desc
)))
331 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels
[i
]);
336 check_interface(device
, &IID_ID3D10InfoQueue
, TRUE
, FALSE
);
338 refcount
= ID3D10Device1_Release(device
);
339 ok(!refcount
, "Device has %u references left.\n", refcount
);
343 static void test_create_shader_resource_view(void)
345 D3D10_SHADER_RESOURCE_VIEW_DESC1 srv_desc
;
346 D3D10_TEXTURE2D_DESC texture_desc
;
347 ULONG refcount
, expected_refcount
;
348 ID3D10ShaderResourceView1
*srview
;
349 D3D10_BUFFER_DESC buffer_desc
;
350 ID3D10Texture2D
*texture
;
351 ID3D10Device
*tmp_device
;
352 ID3D10Device1
*device
;
353 ID3D10Buffer
*buffer
;
356 if (!(device
= create_device(NULL
)))
358 skip("Failed to create device.\n");
362 buffer_desc
.ByteWidth
= 1024;
363 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
364 buffer_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
365 buffer_desc
.CPUAccessFlags
= 0;
366 buffer_desc
.MiscFlags
= 0;
368 hr
= ID3D10Device1_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
369 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x\n", hr
);
371 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, NULL
, &srview
);
372 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
374 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
375 srv_desc
.ViewDimension
= D3D10_1_SRV_DIMENSION_BUFFER
;
376 U(srv_desc
).Buffer
.ElementOffset
= 0;
377 U(srv_desc
).Buffer
.ElementWidth
= 64;
379 hr
= ID3D10Device1_CreateShaderResourceView1(device
, NULL
, &srv_desc
, &srview
);
380 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
382 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
383 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &srview
);
384 ok(SUCCEEDED(hr
), "Failed to create a shader resource view, hr %#x\n", hr
);
385 refcount
= get_refcount((IUnknown
*)device
);
386 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
388 expected_refcount
= refcount
+ 1;
389 ID3D10ShaderResourceView1_GetDevice(srview
, &tmp_device
);
390 ok(tmp_device
== (ID3D10Device
*)device
, "Got unexpected device %p, expected %p.\n", tmp_device
, device
);
391 refcount
= get_refcount((IUnknown
*)device
);
392 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
393 ID3D10Device_Release(tmp_device
);
395 check_interface(srview
, &IID_ID3D10ShaderResourceView
, TRUE
, FALSE
);
396 /* Not available on all Windows versions. */
397 check_interface(srview
, &IID_ID3D11ShaderResourceView
, TRUE
, TRUE
);
399 ID3D10ShaderResourceView1_Release(srview
);
400 ID3D10Buffer_Release(buffer
);
402 /* Without D3D10_BIND_SHADER_RESOURCE. */
403 buffer_desc
.ByteWidth
= 1024;
404 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
405 buffer_desc
.BindFlags
= 0;
406 buffer_desc
.CPUAccessFlags
= 0;
407 buffer_desc
.MiscFlags
= 0;
409 hr
= ID3D10Device1_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
410 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x\n", hr
);
412 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &srview
);
413 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
415 ID3D10Buffer_Release(buffer
);
417 texture_desc
.Width
= 512;
418 texture_desc
.Height
= 512;
419 texture_desc
.MipLevels
= 0;
420 texture_desc
.ArraySize
= 1;
421 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
422 texture_desc
.SampleDesc
.Count
= 1;
423 texture_desc
.SampleDesc
.Quality
= 0;
424 texture_desc
.Usage
= D3D10_USAGE_DEFAULT
;
425 texture_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
426 texture_desc
.CPUAccessFlags
= 0;
427 texture_desc
.MiscFlags
= 0;
429 hr
= ID3D10Device1_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
430 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x\n", hr
);
432 hr
= ID3D10Device1_CreateShaderResourceView1(device
, (ID3D10Resource
*)texture
, NULL
, &srview
);
433 ok(SUCCEEDED(hr
), "Failed to create a shader resource view, hr %#x\n", hr
);
435 ID3D10ShaderResourceView1_GetDesc1(srview
, &srv_desc
);
436 ok(srv_desc
.Format
== texture_desc
.Format
, "Got unexpected format %#x.\n", srv_desc
.Format
);
437 ok(srv_desc
.ViewDimension
== D3D10_1_SRV_DIMENSION_TEXTURE2D
,
438 "Got unexpected view dimension %#x.\n", srv_desc
.ViewDimension
);
439 ok(U(srv_desc
).Texture2D
.MostDetailedMip
== 0, "Got unexpected MostDetailedMip %u.\n",
440 U(srv_desc
).Texture2D
.MostDetailedMip
);
441 ok(U(srv_desc
).Texture2D
.MipLevels
== 10, "Got unexpected MipLevels %u.\n", U(srv_desc
).Texture2D
.MipLevels
);
443 check_interface(srview
, &IID_ID3D10ShaderResourceView
, TRUE
, FALSE
);
444 /* Not available on all Windows versions. */
445 check_interface(srview
, &IID_ID3D11ShaderResourceView
, TRUE
, TRUE
);
447 ID3D10ShaderResourceView1_Release(srview
);
448 ID3D10Texture2D_Release(texture
);
450 refcount
= ID3D10Device1_Release(device
);
451 ok(!refcount
, "Device has %u references left.\n", refcount
);
454 static void test_create_blend_state(void)
456 static const D3D10_BLEND_DESC1 desc_conversion_tests
[] =
462 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
463 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
471 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
472 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
475 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
476 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_RED
479 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
480 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
483 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
484 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_GREEN
487 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
488 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
491 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
492 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
495 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
496 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
499 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
500 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
508 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
509 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
512 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_SUBTRACT
,
513 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
516 TRUE
, D3D10_BLEND_ZERO
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_ADD
,
517 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
520 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
521 D3D10_BLEND_ZERO
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
524 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_MAX
,
525 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
528 TRUE
, D3D10_BLEND_ONE
, D3D10_BLEND_ONE
, D3D10_BLEND_OP_MIN
,
529 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
532 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
533 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
536 FALSE
, D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
,
537 D3D10_BLEND_ONE
, D3D10_BLEND_ZERO
, D3D10_BLEND_OP_ADD
, D3D10_COLOR_WRITE_ENABLE_ALL
543 ID3D10BlendState1
*blend_state1
, *blend_state2
;
544 D3D10_BLEND_DESC1 desc
, obtained_desc
;
545 ID3D10BlendState
*d3d10_blend_state
;
546 D3D10_BLEND_DESC d3d10_blend_desc
;
547 ULONG refcount
, expected_refcount
;
548 ID3D10Device1
*device
;
553 if (!(device
= create_device(NULL
)))
555 skip("Failed to create device.\n");
559 hr
= ID3D10Device1_CreateBlendState1(device
, NULL
, &blend_state1
);
560 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
562 memset(&desc
, 0, sizeof(desc
));
563 desc
.AlphaToCoverageEnable
= FALSE
;
564 desc
.IndependentBlendEnable
= FALSE
;
565 desc
.RenderTarget
[0].BlendEnable
= FALSE
;
566 desc
.RenderTarget
[0].SrcBlend
= D3D10_BLEND_ONE
;
567 desc
.RenderTarget
[0].DestBlend
= D3D10_BLEND_ZERO
;
568 desc
.RenderTarget
[0].BlendOp
= D3D10_BLEND_OP_ADD
;
569 desc
.RenderTarget
[0].SrcBlendAlpha
= D3D10_BLEND_ONE
;
570 desc
.RenderTarget
[0].DestBlendAlpha
= D3D10_BLEND_ZERO
;
571 desc
.RenderTarget
[0].BlendOpAlpha
= D3D10_BLEND_OP_ADD
;
572 desc
.RenderTarget
[0].RenderTargetWriteMask
= D3D10_COLOR_WRITE_ENABLE_ALL
;
574 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
575 hr
= ID3D10Device1_CreateBlendState1(device
, &desc
, &blend_state1
);
576 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
577 hr
= ID3D10Device1_CreateBlendState1(device
, &desc
, &blend_state2
);
578 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
579 ok(blend_state1
== blend_state2
, "Got different blend state objects.\n");
580 refcount
= get_refcount((IUnknown
*)device
);
581 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
583 expected_refcount
= refcount
+ 1;
584 ID3D10BlendState1_GetDevice(blend_state1
, &tmp
);
585 ok(tmp
== (ID3D10Device
*)device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
586 refcount
= get_refcount((IUnknown
*)device
);
587 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
588 ID3D10Device_Release(tmp
);
590 ID3D10BlendState1_GetDesc1(blend_state1
, &obtained_desc
);
591 ok(obtained_desc
.AlphaToCoverageEnable
== FALSE
, "Got unexpected alpha to coverage enable %#x.\n",
592 obtained_desc
.AlphaToCoverageEnable
);
593 ok(obtained_desc
.IndependentBlendEnable
== FALSE
, "Got unexpected independent blend enable %#x.\n",
594 obtained_desc
.IndependentBlendEnable
);
595 for (i
= 0; i
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; ++i
)
597 ok(obtained_desc
.RenderTarget
[i
].BlendEnable
== FALSE
,
598 "Got unexpected blend enable %#x for render target %u.\n",
599 obtained_desc
.RenderTarget
[i
].BlendEnable
, i
);
600 ok(obtained_desc
.RenderTarget
[i
].SrcBlend
== D3D10_BLEND_ONE
,
601 "Got unexpected src blend %u for render target %u.\n",
602 obtained_desc
.RenderTarget
[i
].SrcBlend
, i
);
603 ok(obtained_desc
.RenderTarget
[i
].DestBlend
== D3D10_BLEND_ZERO
,
604 "Got unexpected dest blend %u for render target %u.\n",
605 obtained_desc
.RenderTarget
[i
].DestBlend
, i
);
606 ok(obtained_desc
.RenderTarget
[i
].BlendOp
== D3D10_BLEND_OP_ADD
,
607 "Got unexpected blend op %u for render target %u.\n",
608 obtained_desc
.RenderTarget
[i
].BlendOp
, i
);
609 ok(obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
== D3D10_BLEND_ONE
,
610 "Got unexpected src blend alpha %u for render target %u.\n",
611 obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
, i
);
612 ok(obtained_desc
.RenderTarget
[i
].DestBlendAlpha
== D3D10_BLEND_ZERO
,
613 "Got unexpected dest blend alpha %u for render target %u.\n",
614 obtained_desc
.RenderTarget
[i
].DestBlendAlpha
, i
);
615 ok(obtained_desc
.RenderTarget
[i
].BlendOpAlpha
== D3D10_BLEND_OP_ADD
,
616 "Got unexpected blend op alpha %u for render target %u.\n",
617 obtained_desc
.RenderTarget
[i
].BlendOpAlpha
, i
);
618 ok(obtained_desc
.RenderTarget
[i
].RenderTargetWriteMask
== D3D10_COLOR_WRITE_ENABLE_ALL
,
619 "Got unexpected render target write mask %#x for render target %u.\n",
620 obtained_desc
.RenderTarget
[0].RenderTargetWriteMask
, i
);
623 check_interface(blend_state1
, &IID_ID3D10BlendState
, TRUE
, FALSE
);
624 /* Not available on all Windows versions. */
625 check_interface(blend_state1
, &IID_ID3D11BlendState
, TRUE
, TRUE
);
627 refcount
= ID3D10BlendState1_Release(blend_state1
);
628 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
629 refcount
= ID3D10BlendState1_Release(blend_state2
);
630 ok(!refcount
, "Blend state has %u references left.\n", refcount
);
632 for (i
= 0; i
< ARRAY_SIZE(desc_conversion_tests
); ++i
)
634 const D3D10_BLEND_DESC1
*current_desc
= &desc_conversion_tests
[i
];
636 hr
= ID3D10Device1_CreateBlendState1(device
, current_desc
, &blend_state1
);
637 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
639 hr
= ID3D10BlendState1_QueryInterface(blend_state1
, &IID_ID3D10BlendState
, (void **)&d3d10_blend_state
);
640 ok(SUCCEEDED(hr
), "Blend state should implement ID3D10BlendState.\n");
642 ID3D10BlendState_GetDesc(d3d10_blend_state
, &d3d10_blend_desc
);
643 ok(d3d10_blend_desc
.AlphaToCoverageEnable
== current_desc
->AlphaToCoverageEnable
,
644 "Got unexpected alpha to coverage enable %#x for test %u.\n",
645 d3d10_blend_desc
.AlphaToCoverageEnable
, i
);
646 ok(d3d10_blend_desc
.SrcBlend
== current_desc
->RenderTarget
[0].SrcBlend
,
647 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc
.SrcBlend
, i
);
648 ok(d3d10_blend_desc
.DestBlend
== current_desc
->RenderTarget
[0].DestBlend
,
649 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc
.DestBlend
, i
);
650 ok(d3d10_blend_desc
.BlendOp
== current_desc
->RenderTarget
[0].BlendOp
,
651 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc
.BlendOp
, i
);
652 ok(d3d10_blend_desc
.SrcBlendAlpha
== current_desc
->RenderTarget
[0].SrcBlendAlpha
,
653 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc
.SrcBlendAlpha
, i
);
654 ok(d3d10_blend_desc
.DestBlendAlpha
== current_desc
->RenderTarget
[0].DestBlendAlpha
,
655 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc
.DestBlendAlpha
, i
);
656 ok(d3d10_blend_desc
.BlendOpAlpha
== current_desc
->RenderTarget
[0].BlendOpAlpha
,
657 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc
.BlendOpAlpha
, i
);
658 for (j
= 0; j
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; j
++)
660 unsigned int k
= current_desc
->IndependentBlendEnable
? j
: 0;
661 ok(d3d10_blend_desc
.BlendEnable
[j
] == current_desc
->RenderTarget
[k
].BlendEnable
,
662 "Got unexpected blend enable %#x for test %u, render target %u.\n",
663 d3d10_blend_desc
.BlendEnable
[j
], i
, j
);
664 ok(d3d10_blend_desc
.RenderTargetWriteMask
[j
] == current_desc
->RenderTarget
[k
].RenderTargetWriteMask
,
665 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
666 d3d10_blend_desc
.RenderTargetWriteMask
[j
], i
, j
);
669 ID3D10BlendState_Release(d3d10_blend_state
);
671 refcount
= ID3D10BlendState1_Release(blend_state1
);
672 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
675 refcount
= ID3D10Device1_Release(device
);
676 ok(!refcount
, "Device has %u references left.\n", refcount
);
679 static void test_getdc(void)
681 struct device_desc device_desc
;
682 D3D10_TEXTURE2D_DESC desc
;
683 ID3D10Texture2D
*texture
;
684 IDXGISurface1
*surface1
;
685 ID3D10Device1
*device
;
690 device_desc
.feature_level
= D3D10_FEATURE_LEVEL_10_1
;
691 device_desc
.flags
= D3D10_CREATE_DEVICE_BGRA_SUPPORT
;
692 if (!(device
= create_device(&device_desc
)))
694 skip("Failed to create device.\n");
698 /* Without D3D10_RESOURCE_MISC_GDI_COMPATIBLE. */
703 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
704 desc
.SampleDesc
.Count
= 1;
705 desc
.SampleDesc
.Quality
= 0;
706 desc
.Usage
= D3D10_USAGE_DEFAULT
;
707 desc
.BindFlags
= D3D10_BIND_RENDER_TARGET
;
708 desc
.CPUAccessFlags
= 0;
710 hr
= ID3D10Device1_CreateTexture2D(device
, &desc
, NULL
, &texture
);
711 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
713 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void**)&surface1
);
714 ok(SUCCEEDED(hr
), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr
);
716 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
717 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
719 IDXGISurface1_Release(surface1
);
720 ID3D10Texture2D_Release(texture
);
722 desc
.MiscFlags
= D3D10_RESOURCE_MISC_GDI_COMPATIBLE
;
723 hr
= ID3D10Device1_CreateTexture2D(device
, &desc
, NULL
, &texture
);
724 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
726 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void**)&surface1
);
727 ok(SUCCEEDED(hr
), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr
);
729 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
730 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
732 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
733 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
736 dc
= (HDC
)0xdeadbeef;
737 hr
= IDXGISurface1_GetDC(surface1
, FALSE
, &dc
);
738 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
739 ok(dc
== (HDC
)0xdeadbeef, "Got unexpected dc %p.\n", dc
);
741 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
742 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
744 hr
= IDXGISurface1_ReleaseDC(surface1
, NULL
);
745 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
747 IDXGISurface1_Release(surface1
);
748 ID3D10Texture2D_Release(texture
);
750 refcount
= ID3D10Device1_Release(device
);
751 ok(!refcount
, "Device has %u references left.\n", refcount
);
756 test_create_device();
757 test_device_interfaces();
758 test_create_shader_resource_view();
759 test_create_blend_state();