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
,
36 static ULONG
get_refcount(IUnknown
*iface
)
38 IUnknown_AddRef(iface
);
39 return IUnknown_Release(iface
);
42 static ID3D11Device
*create_device(const D3D_FEATURE_LEVEL
*feature_level
)
45 UINT feature_level_count
= feature_level
? 1 : 0;
47 if (SUCCEEDED(D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, feature_level
, feature_level_count
,
48 D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
50 if (SUCCEEDED(D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_WARP
, NULL
, 0, feature_level
, feature_level_count
,
51 D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
53 if (SUCCEEDED(D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_REFERENCE
, NULL
, 0, feature_level
, feature_level_count
,
54 D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
60 static void test_create_device(void)
62 D3D_FEATURE_LEVEL feature_level
, supported_feature_level
;
63 DXGI_SWAP_CHAIN_DESC swapchain_desc
, obtained_desc
;
64 ID3D11DeviceContext
*immediate_context
;
65 IDXGISwapChain
*swapchain
;
71 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
, &device
,
75 skip("Failed to create HAL device.\n");
79 supported_feature_level
= ID3D11Device_GetFeatureLevel(device
);
80 ID3D11Device_Release(device
);
82 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
, NULL
, NULL
, NULL
);
83 ok(SUCCEEDED(hr
), "D3D11CreateDevice failed %#x.\n", hr
);
85 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
, NULL
,
86 &feature_level
, NULL
);
87 ok(SUCCEEDED(hr
), "D3D11CreateDevice failed %#x.\n", hr
);
88 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
89 feature_level
, supported_feature_level
);
91 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
, NULL
, NULL
,
93 ok(SUCCEEDED(hr
), "D3D11CreateDevice failed %#x.\n", hr
);
95 ok(!!immediate_context
, "Expected immediate device context pointer, got NULL.\n");
96 refcount
= get_refcount((IUnknown
*)immediate_context
);
97 ok(refcount
== 1, "Got refcount %u, expected 1.\n", refcount
);
99 ID3D11DeviceContext_GetDevice(immediate_context
, &device
);
100 refcount
= ID3D11Device_Release(device
);
101 ok(refcount
== 1, "Got refcount %u, expected 1.\n", refcount
);
103 refcount
= ID3D11DeviceContext_Release(immediate_context
);
104 ok(!refcount
, "ID3D11DeviceContext has %u references left.\n", refcount
);
106 device
= (ID3D11Device
*)0xdeadbeef;
107 feature_level
= 0xdeadbeef;
108 immediate_context
= (ID3D11DeviceContext
*)0xdeadbeef;
109 hr
= D3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_UNKNOWN
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
110 &device
, &feature_level
, &immediate_context
);
111 todo_wine
ok(hr
== E_INVALIDARG
, "D3D11CreateDevice returned %#x.\n", hr
);
112 ok(!device
, "Got unexpected device pointer %p.\n", device
);
113 ok(!feature_level
, "Got unexpected feature level %#x.\n", feature_level
);
114 ok(!immediate_context
, "Got unexpected immediate context pointer %p.\n", immediate_context
);
116 window
= CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
118 swapchain_desc
.BufferDesc
.Width
= 800;
119 swapchain_desc
.BufferDesc
.Height
= 600;
120 swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
= 60;
121 swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
= 60;
122 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
123 swapchain_desc
.BufferDesc
.ScanlineOrdering
= DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
;
124 swapchain_desc
.BufferDesc
.Scaling
= DXGI_MODE_SCALING_UNSPECIFIED
;
125 swapchain_desc
.SampleDesc
.Count
= 1;
126 swapchain_desc
.SampleDesc
.Quality
= 0;
127 swapchain_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
128 swapchain_desc
.BufferCount
= 1;
129 swapchain_desc
.OutputWindow
= window
;
130 swapchain_desc
.Windowed
= TRUE
;
131 swapchain_desc
.SwapEffect
= DXGI_SWAP_EFFECT_DISCARD
;
132 swapchain_desc
.Flags
= 0;
134 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
135 &swapchain_desc
, NULL
, NULL
, NULL
, NULL
);
136 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
138 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
139 &swapchain_desc
, NULL
, NULL
, &feature_level
, NULL
);
140 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
141 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
142 feature_level
, supported_feature_level
);
144 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
145 &swapchain_desc
, &swapchain
, &device
, NULL
, NULL
);
146 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
148 memset(&obtained_desc
, 0, sizeof(obtained_desc
));
149 hr
= IDXGISwapChain_GetDesc(swapchain
, &obtained_desc
);
150 ok(SUCCEEDED(hr
), "GetDesc failed %#x.\n", hr
);
151 ok(obtained_desc
.BufferDesc
.Width
== swapchain_desc
.BufferDesc
.Width
,
152 "Got unexpected BufferDesc.Width %u.\n", obtained_desc
.BufferDesc
.Width
);
153 ok(obtained_desc
.BufferDesc
.Height
== swapchain_desc
.BufferDesc
.Height
,
154 "Got unexpected BufferDesc.Height %u.\n", obtained_desc
.BufferDesc
.Height
);
155 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Numerator
== swapchain_desc
.BufferDesc
.RefreshRate
.Numerator
,
156 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
157 obtained_desc
.BufferDesc
.RefreshRate
.Numerator
);
158 todo_wine
ok(obtained_desc
.BufferDesc
.RefreshRate
.Denominator
== swapchain_desc
.BufferDesc
.RefreshRate
.Denominator
,
159 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
160 obtained_desc
.BufferDesc
.RefreshRate
.Denominator
);
161 ok(obtained_desc
.BufferDesc
.Format
== swapchain_desc
.BufferDesc
.Format
,
162 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc
.BufferDesc
.Format
);
163 ok(obtained_desc
.BufferDesc
.ScanlineOrdering
== swapchain_desc
.BufferDesc
.ScanlineOrdering
,
164 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc
.BufferDesc
.ScanlineOrdering
);
165 ok(obtained_desc
.BufferDesc
.Scaling
== swapchain_desc
.BufferDesc
.Scaling
,
166 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc
.BufferDesc
.Scaling
);
167 ok(obtained_desc
.SampleDesc
.Count
== swapchain_desc
.SampleDesc
.Count
,
168 "Got unexpected SampleDesc.Count %u.\n", obtained_desc
.SampleDesc
.Count
);
169 ok(obtained_desc
.SampleDesc
.Quality
== swapchain_desc
.SampleDesc
.Quality
,
170 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc
.SampleDesc
.Quality
);
171 todo_wine
ok(obtained_desc
.BufferUsage
== swapchain_desc
.BufferUsage
,
172 "Got unexpected BufferUsage %#x.\n", obtained_desc
.BufferUsage
);
173 ok(obtained_desc
.BufferCount
== swapchain_desc
.BufferCount
,
174 "Got unexpected BufferCount %u.\n", obtained_desc
.BufferCount
);
175 ok(obtained_desc
.OutputWindow
== swapchain_desc
.OutputWindow
,
176 "Got unexpected OutputWindow %p.\n", obtained_desc
.OutputWindow
);
177 ok(obtained_desc
.Windowed
== swapchain_desc
.Windowed
,
178 "Got unexpected Windowed %#x.\n", obtained_desc
.Windowed
);
179 ok(obtained_desc
.SwapEffect
== swapchain_desc
.SwapEffect
,
180 "Got unexpected SwapEffect %#x.\n", obtained_desc
.SwapEffect
);
181 ok(obtained_desc
.Flags
== swapchain_desc
.Flags
,
182 "Got unexpected Flags %#x.\n", obtained_desc
.Flags
);
184 refcount
= IDXGISwapChain_Release(swapchain
);
185 ok(!refcount
, "Swapchain has %u references left.\n", refcount
);
187 feature_level
= ID3D11Device_GetFeatureLevel(device
);
188 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
189 feature_level
, supported_feature_level
);
191 refcount
= ID3D11Device_Release(device
);
192 ok(!refcount
, "Device has %u references left.\n", refcount
);
194 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
195 NULL
, NULL
, &device
, NULL
, NULL
);
196 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
197 ID3D11Device_Release(device
);
199 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
200 NULL
, NULL
, NULL
, NULL
, NULL
);
201 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
203 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
204 NULL
, NULL
, NULL
, &feature_level
, NULL
);
205 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
206 ok(feature_level
== supported_feature_level
, "Got feature level %#x, expected %#x.\n",
207 feature_level
, supported_feature_level
);
209 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
210 &swapchain_desc
, NULL
, NULL
, NULL
, NULL
);
211 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
213 swapchain_desc
.OutputWindow
= NULL
;
214 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
215 &swapchain_desc
, NULL
, &device
, NULL
, NULL
);
216 ok(SUCCEEDED(hr
), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr
);
217 ID3D11Device_Release(device
);
219 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
220 device
= (ID3D11Device
*)0xdeadbeef;
221 feature_level
= 0xdeadbeef;
222 immediate_context
= (ID3D11DeviceContext
*)0xdeadbeef;
223 swapchain_desc
.OutputWindow
= NULL
;
224 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
225 &swapchain_desc
, &swapchain
, &device
, &feature_level
, &immediate_context
);
226 todo_wine
ok(hr
== DXGI_ERROR_INVALID_CALL
, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr
);
227 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
228 ok(!device
, "Got unexpected device pointer %p.\n", device
);
229 ok(!feature_level
, "Got unexpected feature level %#x.\n", feature_level
);
230 ok(!immediate_context
, "Got unexpected immediate context pointer %p.\n", immediate_context
);
232 swapchain
= (IDXGISwapChain
*)0xdeadbeef;
233 device
= (ID3D11Device
*)0xdeadbeef;
234 feature_level
= 0xdeadbeef;
235 immediate_context
= (ID3D11DeviceContext
*)0xdeadbeef;
236 swapchain_desc
.OutputWindow
= window
;
237 swapchain_desc
.BufferDesc
.Format
= DXGI_FORMAT_BC5_UNORM
;
238 hr
= D3D11CreateDeviceAndSwapChain(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0, NULL
, 0, D3D11_SDK_VERSION
,
239 &swapchain_desc
, &swapchain
, &device
, &feature_level
, &immediate_context
);
240 todo_wine
ok(hr
== E_INVALIDARG
, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr
);
241 ok(!swapchain
, "Got unexpected swapchain pointer %p.\n", swapchain
);
242 ok(!device
, "Got unexpected device pointer %p.\n", device
);
243 ok(!feature_level
, "Got unexpected feature level %#x.\n", feature_level
);
244 ok(!immediate_context
, "Got unexpected immediate context pointer %p.\n", immediate_context
);
246 DestroyWindow(window
);
249 static void test_device_interfaces(void)
251 ID3D11Device
*device
;
257 for (i
= 0; i
< sizeof(d3d11_feature_levels
) / sizeof(*d3d11_feature_levels
); ++i
)
259 if (!(device
= create_device(&d3d11_feature_levels
[i
])))
261 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels
[i
]);
265 hr
= ID3D11Device_QueryInterface(device
, &IID_IUnknown
, (void **)&iface
);
266 ok(SUCCEEDED(hr
), "Device should implement IUnknown interface, hr %#x.\n", hr
);
267 IUnknown_Release(iface
);
269 hr
= ID3D11Device_QueryInterface(device
, &IID_IDXGIObject
, (void **)&iface
);
270 ok(SUCCEEDED(hr
), "Device should implement IDXGIObject interface, hr %#x.\n", hr
);
271 IUnknown_Release(iface
);
273 hr
= ID3D11Device_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&iface
);
274 ok(SUCCEEDED(hr
), "Device should implement IDXGIDevice interface, hr %#x.\n", hr
);
275 IUnknown_Release(iface
);
277 hr
= ID3D11Device_QueryInterface(device
, &IID_ID3D10Multithread
, (void **)&iface
);
278 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
279 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr
);
280 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
282 hr
= ID3D11Device_QueryInterface(device
, &IID_ID3D10Device
, (void **)&iface
);
283 todo_wine
ok(hr
== E_NOINTERFACE
, "Device should not implement ID3D10Device interface, hr %#x.\n", hr
);
284 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
286 hr
= ID3D11Device_QueryInterface(device
, &IID_ID3D10Device1
, (void **)&iface
);
287 todo_wine
ok(hr
== E_NOINTERFACE
, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr
);
288 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
290 refcount
= ID3D11Device_Release(device
);
291 ok(!refcount
, "Device has %u references left.\n", refcount
);
295 static void test_get_immediate_context(void)
297 ID3D11DeviceContext
*immediate_context
, *previous_immediate_context
;
298 ULONG expected_refcount
, refcount
;
299 ID3D11Device
*device
;
301 if (!(device
= create_device(NULL
)))
303 skip("Failed to create device.\n");
307 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
308 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
309 refcount
= get_refcount((IUnknown
*)device
);
310 ok(refcount
== expected_refcount
, "Got unexpected refcount %u.\n", refcount
);
311 previous_immediate_context
= immediate_context
;
313 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
314 ok(immediate_context
== previous_immediate_context
, "Got different immediate device context objects.\n");
315 refcount
= get_refcount((IUnknown
*)device
);
316 ok(refcount
== expected_refcount
, "Got unexpected refcount %u.\n", refcount
);
318 refcount
= ID3D11DeviceContext_Release(previous_immediate_context
);
319 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
320 refcount
= ID3D11DeviceContext_Release(immediate_context
);
321 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
323 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
324 ok(immediate_context
== previous_immediate_context
, "Got different immediate device context objects.\n");
325 refcount
= ID3D11DeviceContext_Release(immediate_context
);
326 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
328 refcount
= ID3D11Device_Release(device
);
329 ok(!refcount
, "Device has %u references left.\n", refcount
);
332 static void test_create_texture2d(void)
334 ULONG refcount
, expected_refcount
;
335 D3D11_SUBRESOURCE_DATA data
= {0};
336 ID3D11Device
*device
, *tmp
;
337 D3D11_TEXTURE2D_DESC desc
;
338 ID3D11Texture2D
*texture
;
339 IDXGISurface
*surface
;
342 if (!(device
= create_device(NULL
)))
344 skip("Failed to create device, skipping tests.\n");
352 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
353 desc
.SampleDesc
.Count
= 1;
354 desc
.SampleDesc
.Quality
= 0;
355 desc
.Usage
= D3D11_USAGE_DEFAULT
;
356 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
357 desc
.CPUAccessFlags
= 0;
360 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, &data
, &texture
);
361 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
363 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
364 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
365 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
366 refcount
= get_refcount((IUnknown
*)device
);
367 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
369 expected_refcount
= refcount
+ 1;
370 ID3D11Texture2D_GetDevice(texture
, &tmp
);
371 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
372 refcount
= get_refcount((IUnknown
*)device
);
373 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
374 ID3D11Device_Release(tmp
);
376 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
377 ok(SUCCEEDED(hr
), "Texture should implement IDXGISurface.\n");
378 IDXGISurface_Release(surface
);
379 ID3D11Texture2D_Release(texture
);
382 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
383 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
384 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, 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 ID3D11Texture2D_GetDevice(texture
, &tmp
);
390 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
391 refcount
= get_refcount((IUnknown
*)device
);
392 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
393 ID3D11Device_Release(tmp
);
395 ID3D11Texture2D_GetDesc(texture
, &desc
);
396 ok(desc
.Width
== 512, "Got unexpected Width %u.\n", desc
.Width
);
397 ok(desc
.Height
== 512, "Got unexpected Height %u.\n", desc
.Height
);
398 ok(desc
.MipLevels
== 10, "Got unexpected MipLevels %u.\n", desc
.MipLevels
);
399 ok(desc
.ArraySize
== 1, "Got unexpected ArraySize %u.\n", desc
.ArraySize
);
400 ok(desc
.Format
== DXGI_FORMAT_R8G8B8A8_UNORM
, "Got unexpected Format %#x.\n", desc
.Format
);
401 ok(desc
.SampleDesc
.Count
== 1, "Got unexpected SampleDesc.Count %u.\n", desc
.SampleDesc
.Count
);
402 ok(desc
.SampleDesc
.Quality
== 0, "Got unexpected SampleDesc.Quality %u.\n", desc
.SampleDesc
.Quality
);
403 ok(desc
.Usage
== D3D11_USAGE_DEFAULT
, "Got unexpected Usage %u.\n", desc
.Usage
);
404 ok(desc
.BindFlags
== D3D11_BIND_RENDER_TARGET
, "Got unexpected BindFlags %#x.\n", desc
.BindFlags
);
405 ok(desc
.CPUAccessFlags
== 0, "Got unexpected CPUAccessFlags %#x.\n", desc
.CPUAccessFlags
);
406 ok(desc
.MiscFlags
== 0, "Got unexpected MiscFlags %#x.\n", desc
.MiscFlags
);
408 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
409 ok(FAILED(hr
), "Texture should not implement IDXGISurface.\n");
410 ID3D11Texture2D_Release(texture
);
414 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
415 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
417 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
418 ok(FAILED(hr
), "Texture should not implement IDXGISurface.\n");
419 ID3D11Texture2D_Release(texture
);
421 refcount
= ID3D11Device_Release(device
);
422 ok(!refcount
, "Device has %u references left.\n", refcount
);
425 static void test_texture2d_interfaces(void)
427 ID3D10Texture2D
*d3d10_texture
;
428 D3D11_TEXTURE2D_DESC desc
;
429 ID3D11Texture2D
*texture
;
430 IDXGISurface
*surface
;
431 ID3D11Device
*device
;
436 static const struct test
438 BOOL implements_d3d10_interfaces
;
441 UINT expected_bind_flags
;
442 UINT expected_misc_flags
;
444 desc_conversion_tests
[] =
448 D3D11_BIND_SHADER_RESOURCE
, 0,
449 D3D10_BIND_SHADER_RESOURCE
, 0
453 D3D11_BIND_UNORDERED_ACCESS
, 0,
454 D3D11_BIND_UNORDERED_ACCESS
, 0
458 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP
,
463 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
464 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
468 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
| D3D11_RESOURCE_MISC_SHARED_NTHANDLE
,
469 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
473 if (!(device
= create_device(NULL
)))
475 skip("Failed to create ID3D11Device, skipping tests.\n");
483 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
484 desc
.SampleDesc
.Count
= 1;
485 desc
.SampleDesc
.Quality
= 0;
486 desc
.Usage
= D3D11_USAGE_DEFAULT
;
487 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
488 desc
.CPUAccessFlags
= 0;
491 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
492 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
494 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
495 ok(hr
== E_NOINTERFACE
, "Texture should not implement IDXGISurface.\n");
497 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_ID3D10Texture2D
, (void **)&d3d10_texture
);
498 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
499 "Texture should implement ID3D10Texture2D.\n");
500 if (SUCCEEDED(hr
)) ID3D10Texture2D_Release(d3d10_texture
);
501 ID3D11Texture2D_Release(texture
);
505 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
506 ID3D11Device_Release(device
);
510 for (i
= 0; i
< sizeof(desc_conversion_tests
) / sizeof(*desc_conversion_tests
); ++i
)
512 const struct test
*current
= &desc_conversion_tests
[i
];
513 D3D10_TEXTURE2D_DESC d3d10_desc
;
514 ID3D10Device
*d3d10_device
;
520 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
521 desc
.SampleDesc
.Count
= 1;
522 desc
.SampleDesc
.Quality
= 0;
523 desc
.Usage
= D3D11_USAGE_DEFAULT
;
524 desc
.BindFlags
= current
->bind_flags
;
525 desc
.CPUAccessFlags
= 0;
526 desc
.MiscFlags
= current
->misc_flags
;
528 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
529 /* Shared resources are not supported by REF and WARP devices. */
530 ok(SUCCEEDED(hr
) || broken(hr
== E_OUTOFMEMORY
),
531 "Test %u: Failed to create a 2d texture, hr %#x.\n", i
, hr
);
534 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i
);
538 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
539 ok(SUCCEEDED(hr
), "Test %u: Texture should implement IDXGISurface.\n", i
);
540 IDXGISurface_Release(surface
);
542 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_ID3D10Texture2D
, (void **)&d3d10_texture
);
543 ID3D11Texture2D_Release(texture
);
545 if (current
->implements_d3d10_interfaces
)
547 ok(SUCCEEDED(hr
), "Test %u: Texture should implement ID3D10Texture2D.\n", i
);
551 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Texture should not implement ID3D10Texture2D.\n", i
);
552 if (SUCCEEDED(hr
)) ID3D10Texture2D_Release(d3d10_texture
);
556 ID3D10Texture2D_GetDesc(d3d10_texture
, &d3d10_desc
);
558 ok(d3d10_desc
.Width
== desc
.Width
,
559 "Test %u: Got unexpected Width %u.\n", i
, d3d10_desc
.Width
);
560 ok(d3d10_desc
.Height
== desc
.Height
,
561 "Test %u: Got unexpected Height %u.\n", i
, d3d10_desc
.Height
);
562 ok(d3d10_desc
.MipLevels
== desc
.MipLevels
,
563 "Test %u: Got unexpected MipLevels %u.\n", i
, d3d10_desc
.MipLevels
);
564 ok(d3d10_desc
.ArraySize
== desc
.ArraySize
,
565 "Test %u: Got unexpected ArraySize %u.\n", i
, d3d10_desc
.ArraySize
);
566 ok(d3d10_desc
.Format
== desc
.Format
,
567 "Test %u: Got unexpected Format %u.\n", i
, d3d10_desc
.Format
);
568 ok(d3d10_desc
.SampleDesc
.Count
== desc
.SampleDesc
.Count
,
569 "Test %u: Got unexpected SampleDesc.Count %u.\n", i
, d3d10_desc
.SampleDesc
.Count
);
570 ok(d3d10_desc
.SampleDesc
.Quality
== desc
.SampleDesc
.Quality
,
571 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i
, d3d10_desc
.SampleDesc
.Quality
);
572 ok(d3d10_desc
.Usage
== (D3D10_USAGE
)desc
.Usage
,
573 "Test %u: Got unexpected Usage %u.\n", i
, d3d10_desc
.Usage
);
574 ok(d3d10_desc
.BindFlags
== current
->expected_bind_flags
,
575 "Test %u: Got unexpected BindFlags %#x.\n", i
, d3d10_desc
.BindFlags
);
576 ok(d3d10_desc
.CPUAccessFlags
== desc
.CPUAccessFlags
,
577 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i
, d3d10_desc
.CPUAccessFlags
);
578 ok(d3d10_desc
.MiscFlags
== current
->expected_misc_flags
,
579 "Test %u: Got unexpected MiscFlags %#x.\n", i
, d3d10_desc
.MiscFlags
);
581 d3d10_device
= (ID3D10Device
*)0xdeadbeef;
582 ID3D10Texture2D_GetDevice(d3d10_texture
, &d3d10_device
);
583 todo_wine
ok(!d3d10_device
, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i
, d3d10_device
);
584 if (d3d10_device
) ID3D10Device_Release(d3d10_device
);
586 ID3D10Texture2D_Release(d3d10_texture
);
589 refcount
= ID3D11Device_Release(device
);
590 ok(!refcount
, "Device has %u references left.\n", refcount
);
593 static void test_create_texture3d(void)
595 ULONG refcount
, expected_refcount
;
596 D3D11_SUBRESOURCE_DATA data
= {0};
597 ID3D11Device
*device
, *tmp
;
598 D3D11_TEXTURE3D_DESC desc
;
599 ID3D11Texture3D
*texture
;
600 IDXGISurface
*surface
;
603 if (!(device
= create_device(NULL
)))
605 skip("Failed to create ID3D11Device, skipping tests.\n");
613 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
614 desc
.Usage
= D3D11_USAGE_DEFAULT
;
615 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
616 desc
.CPUAccessFlags
= 0;
619 hr
= ID3D11Device_CreateTexture3D(device
, &desc
, &data
, &texture
);
620 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
622 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
623 hr
= ID3D11Device_CreateTexture3D(device
, &desc
, NULL
, &texture
);
624 ok(SUCCEEDED(hr
), "Failed to create a 3d texture, hr %#x.\n", hr
);
625 refcount
= get_refcount((IUnknown
*)device
);
626 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
628 expected_refcount
= refcount
+ 1;
629 ID3D11Texture3D_GetDevice(texture
, &tmp
);
630 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
631 refcount
= get_refcount((IUnknown
*)device
);
632 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
633 ID3D11Device_Release(tmp
);
635 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
636 ok(FAILED(hr
), "Texture should not implement IDXGISurface.\n");
637 ID3D11Texture3D_Release(texture
);
640 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
641 hr
= ID3D11Device_CreateTexture3D(device
, &desc
, NULL
, &texture
);
642 ok(SUCCEEDED(hr
), "Failed to create a 3d texture, hr %#x.\n", hr
);
643 refcount
= get_refcount((IUnknown
*)device
);
644 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
646 expected_refcount
= refcount
+ 1;
647 ID3D11Texture3D_GetDevice(texture
, &tmp
);
648 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
649 refcount
= get_refcount((IUnknown
*)device
);
650 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
651 ID3D11Device_Release(tmp
);
653 ID3D11Texture3D_GetDesc(texture
, &desc
);
654 ok(desc
.Width
== 64, "Got unexpected Width %u.\n", desc
.Width
);
655 ok(desc
.Height
== 64, "Got unexpected Height %u.\n", desc
.Height
);
656 ok(desc
.Depth
== 64, "Got unexpected Depth %u.\n", desc
.Depth
);
657 ok(desc
.MipLevels
== 7, "Got unexpected MipLevels %u.\n", desc
.MipLevels
);
658 ok(desc
.Format
== DXGI_FORMAT_R8G8B8A8_UNORM
, "Got unexpected Format %#x.\n", desc
.Format
);
659 ok(desc
.Usage
== D3D11_USAGE_DEFAULT
, "Got unexpected Usage %u.\n", desc
.Usage
);
660 ok(desc
.BindFlags
== D3D11_BIND_RENDER_TARGET
, "Got unexpected BindFlags %u.\n", desc
.BindFlags
);
661 ok(desc
.CPUAccessFlags
== 0, "Got unexpected CPUAccessFlags %u.\n", desc
.CPUAccessFlags
);
662 ok(desc
.MiscFlags
== 0, "Got unexpected MiscFlags %u.\n", desc
.MiscFlags
);
664 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
665 ok(FAILED(hr
), "Texture should not implement IDXGISurface.\n");
666 ID3D11Texture3D_Release(texture
);
668 refcount
= ID3D11Device_Release(device
);
669 ok(!refcount
, "Device has %u references left.\n", refcount
);
672 static void test_texture3d_interfaces(void)
674 ID3D10Texture3D
*d3d10_texture
;
675 D3D11_TEXTURE3D_DESC desc
;
676 ID3D11Texture3D
*texture
;
677 IDXGISurface
*surface
;
678 ID3D11Device
*device
;
683 static const struct test
685 BOOL implements_d3d10_interfaces
;
688 UINT expected_bind_flags
;
689 UINT expected_misc_flags
;
691 desc_conversion_tests
[] =
695 D3D11_BIND_SHADER_RESOURCE
, 0,
696 D3D10_BIND_SHADER_RESOURCE
, 0
700 D3D11_BIND_UNORDERED_ACCESS
, 0,
701 D3D11_BIND_UNORDERED_ACCESS
, 0
705 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP
,
710 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
711 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
715 if (!(device
= create_device(NULL
)))
717 skip("Failed to create ID3D11Device.\n");
725 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
726 desc
.Usage
= D3D11_USAGE_DEFAULT
;
727 desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
728 desc
.CPUAccessFlags
= 0;
731 hr
= ID3D11Device_CreateTexture3D(device
, &desc
, NULL
, &texture
);
732 ok(SUCCEEDED(hr
), "Failed to create a 3d texture, hr %#x.\n", hr
);
734 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
735 ok(hr
== E_NOINTERFACE
, "Texture should not implement IDXGISurface.\n");
737 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_ID3D10Texture3D
, (void **)&d3d10_texture
);
738 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
739 "Texture should implement ID3D10Texture3D.\n");
740 if (SUCCEEDED(hr
)) ID3D10Texture3D_Release(d3d10_texture
);
741 ID3D11Texture3D_Release(texture
);
745 win_skip("3D textures do not implement ID3D10Texture3D.\n");
746 ID3D11Device_Release(device
);
750 for (i
= 0; i
< sizeof(desc_conversion_tests
) / sizeof(*desc_conversion_tests
); ++i
)
752 const struct test
*current
= &desc_conversion_tests
[i
];
753 D3D10_TEXTURE3D_DESC d3d10_desc
;
754 ID3D10Device
*d3d10_device
;
760 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
761 desc
.Usage
= D3D11_USAGE_DEFAULT
;
762 desc
.BindFlags
= current
->bind_flags
;
763 desc
.CPUAccessFlags
= 0;
764 desc
.MiscFlags
= current
->misc_flags
;
766 hr
= ID3D11Device_CreateTexture3D(device
, &desc
, NULL
, &texture
);
767 /* Shared resources are not supported by REF and WARP devices. */
768 ok(SUCCEEDED(hr
) || broken(hr
== E_OUTOFMEMORY
),
769 "Test %u: Failed to create a 3d texture, hr %#x.\n", i
, hr
);
772 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i
);
776 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
777 ok(hr
== E_NOINTERFACE
, "Texture should not implement IDXGISurface.\n");
779 hr
= ID3D11Texture3D_QueryInterface(texture
, &IID_ID3D10Texture3D
, (void **)&d3d10_texture
);
780 ID3D11Texture3D_Release(texture
);
782 if (current
->implements_d3d10_interfaces
)
784 ok(SUCCEEDED(hr
), "Test %u: Texture should implement ID3D10Texture3D.\n", i
);
788 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Texture should not implement ID3D10Texture3D.\n", i
);
789 if (SUCCEEDED(hr
)) ID3D10Texture3D_Release(d3d10_texture
);
793 ID3D10Texture3D_GetDesc(d3d10_texture
, &d3d10_desc
);
795 ok(d3d10_desc
.Width
== desc
.Width
,
796 "Test %u: Got unexpected Width %u.\n", i
, d3d10_desc
.Width
);
797 ok(d3d10_desc
.Height
== desc
.Height
,
798 "Test %u: Got unexpected Height %u.\n", i
, d3d10_desc
.Height
);
799 ok(d3d10_desc
.Depth
== desc
.Depth
,
800 "Test %u: Got unexpected Depth %u.\n", i
, d3d10_desc
.Depth
);
801 ok(d3d10_desc
.MipLevels
== desc
.MipLevels
,
802 "Test %u: Got unexpected MipLevels %u.\n", i
, d3d10_desc
.MipLevels
);
803 ok(d3d10_desc
.Format
== desc
.Format
,
804 "Test %u: Got unexpected Format %u.\n", i
, d3d10_desc
.Format
);
805 ok(d3d10_desc
.Usage
== (D3D10_USAGE
)desc
.Usage
,
806 "Test %u: Got unexpected Usage %u.\n", i
, d3d10_desc
.Usage
);
807 ok(d3d10_desc
.BindFlags
== current
->expected_bind_flags
,
808 "Test %u: Got unexpected BindFlags %#x.\n", i
, d3d10_desc
.BindFlags
);
809 ok(d3d10_desc
.CPUAccessFlags
== desc
.CPUAccessFlags
,
810 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i
, d3d10_desc
.CPUAccessFlags
);
811 ok(d3d10_desc
.MiscFlags
== current
->expected_misc_flags
,
812 "Test %u: Got unexpected MiscFlags %#x.\n", i
, d3d10_desc
.MiscFlags
);
814 d3d10_device
= (ID3D10Device
*)0xdeadbeef;
815 ID3D10Texture3D_GetDevice(d3d10_texture
, &d3d10_device
);
816 todo_wine
ok(!d3d10_device
, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i
, d3d10_device
);
817 if (d3d10_device
) ID3D10Device_Release(d3d10_device
);
819 ID3D10Texture3D_Release(d3d10_texture
);
822 refcount
= ID3D11Device_Release(device
);
823 ok(!refcount
, "Device has %u references left.\n", refcount
);
826 static void test_buffer_interfaces(void)
828 ID3D10Buffer
*d3d10_buffer
;
829 D3D11_BUFFER_DESC desc
;
830 ID3D11Buffer
*buffer
;
831 ID3D11Device
*device
;
836 static const struct test
838 BOOL implements_d3d10_interfaces
;
841 UINT structure_stride
;
842 UINT expected_bind_flags
;
843 UINT expected_misc_flags
;
845 desc_conversion_tests
[] =
849 D3D11_BIND_VERTEX_BUFFER
, 0, 0,
850 D3D10_BIND_VERTEX_BUFFER
, 0
854 D3D11_BIND_INDEX_BUFFER
, 0, 0,
855 D3D10_BIND_INDEX_BUFFER
, 0
859 D3D11_BIND_CONSTANT_BUFFER
, 0, 0,
860 D3D10_BIND_CONSTANT_BUFFER
, 0
864 D3D11_BIND_SHADER_RESOURCE
, 0, 0,
865 D3D10_BIND_SHADER_RESOURCE
, 0
869 D3D11_BIND_STREAM_OUTPUT
, 0, 0,
870 D3D10_BIND_STREAM_OUTPUT
, 0
874 D3D11_BIND_RENDER_TARGET
, 0, 0,
875 D3D10_BIND_RENDER_TARGET
, 0
879 D3D11_BIND_UNORDERED_ACCESS
, 0, 0,
880 D3D11_BIND_UNORDERED_ACCESS
, 0
884 0, D3D11_RESOURCE_MISC_SHARED
, 0,
885 0, D3D10_RESOURCE_MISC_SHARED
889 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
, 0,
894 D3D11_BIND_SHADER_RESOURCE
, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
, 0,
895 D3D10_BIND_SHADER_RESOURCE
, 0
898 FALSE
/* Structured buffers do not implement ID3D10Buffer. */,
899 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
, 16,
904 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
, 0,
905 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
909 if (!(device
= create_device(NULL
)))
911 skip("Failed to create ID3D11Device.\n");
915 desc
.ByteWidth
= 1024;
916 desc
.Usage
= D3D11_USAGE_DEFAULT
;
917 desc
.BindFlags
= D3D11_BIND_VERTEX_BUFFER
;
918 desc
.CPUAccessFlags
= 0;
920 desc
.StructureByteStride
= 0;
922 hr
= ID3D11Device_CreateBuffer(device
, &desc
, NULL
, &buffer
);
923 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x.\n", hr
);
925 hr
= ID3D11Buffer_QueryInterface(buffer
, &IID_ID3D10Buffer
, (void **)&d3d10_buffer
);
926 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
927 "Buffer should implement ID3D10Buffer.\n");
928 if (SUCCEEDED(hr
)) ID3D10Buffer_Release(d3d10_buffer
);
929 ID3D11Buffer_Release(buffer
);
933 win_skip("Buffers do not implement ID3D10Buffer.\n");
934 ID3D11Device_Release(device
);
938 for (i
= 0; i
< sizeof(desc_conversion_tests
) / sizeof(*desc_conversion_tests
); ++i
)
940 const struct test
*current
= &desc_conversion_tests
[i
];
941 D3D10_BUFFER_DESC d3d10_desc
;
942 ID3D10Device
*d3d10_device
;
944 desc
.ByteWidth
= 1024;
945 desc
.Usage
= D3D11_USAGE_DEFAULT
;
946 desc
.BindFlags
= current
->bind_flags
;
947 desc
.CPUAccessFlags
= 0;
948 desc
.MiscFlags
= current
->misc_flags
;
949 desc
.StructureByteStride
= current
->structure_stride
;
951 hr
= ID3D11Device_CreateBuffer(device
, &desc
, NULL
, &buffer
);
952 /* Shared resources are not supported by REF and WARP devices. */
953 ok(SUCCEEDED(hr
) || broken(hr
== E_OUTOFMEMORY
), "Test %u: Failed to create a buffer, hr %#x.\n", i
, hr
);
956 win_skip("Failed to create a buffer, skipping test %u.\n", i
);
960 hr
= ID3D11Buffer_QueryInterface(buffer
, &IID_ID3D10Buffer
, (void **)&d3d10_buffer
);
961 ID3D11Buffer_Release(buffer
);
963 if (current
->implements_d3d10_interfaces
)
965 ok(SUCCEEDED(hr
), "Test %u: Buffer should implement ID3D10Buffer.\n", i
);
969 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Buffer should not implement ID3D10Buffer.\n", i
);
970 if (SUCCEEDED(hr
)) ID3D10Buffer_Release(d3d10_buffer
);
974 ID3D10Buffer_GetDesc(d3d10_buffer
, &d3d10_desc
);
976 ok(d3d10_desc
.ByteWidth
== desc
.ByteWidth
,
977 "Test %u: Got unexpected ByteWidth %u.\n", i
, d3d10_desc
.ByteWidth
);
978 ok(d3d10_desc
.Usage
== (D3D10_USAGE
)desc
.Usage
,
979 "Test %u: Got unexpected Usage %u.\n", i
, d3d10_desc
.Usage
);
980 ok(d3d10_desc
.BindFlags
== current
->expected_bind_flags
,
981 "Test %u: Got unexpected BindFlags %#x.\n", i
, d3d10_desc
.BindFlags
);
982 ok(d3d10_desc
.CPUAccessFlags
== desc
.CPUAccessFlags
,
983 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i
, d3d10_desc
.CPUAccessFlags
);
984 ok(d3d10_desc
.MiscFlags
== current
->expected_misc_flags
,
985 "Test %u: Got unexpected MiscFlags %#x.\n", i
, d3d10_desc
.MiscFlags
);
987 d3d10_device
= (ID3D10Device
*)0xdeadbeef;
988 ID3D10Buffer_GetDevice(d3d10_buffer
, &d3d10_device
);
989 todo_wine
ok(!d3d10_device
, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i
, d3d10_device
);
990 if (d3d10_device
) ID3D10Device_Release(d3d10_device
);
992 ID3D10Buffer_Release(d3d10_buffer
);
995 refcount
= ID3D11Device_Release(device
);
996 ok(!refcount
, "Device has %u references left.\n", refcount
);
999 static void test_create_depthstencil_view(void)
1001 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc
;
1002 D3D11_TEXTURE2D_DESC texture_desc
;
1003 ULONG refcount
, expected_refcount
;
1004 ID3D11DepthStencilView
*dsview
;
1005 ID3D11Device
*device
, *tmp
;
1006 ID3D11Texture2D
*texture
;
1009 if (!(device
= create_device(NULL
)))
1011 skip("Failed to create device.\n");
1015 texture_desc
.Width
= 512;
1016 texture_desc
.Height
= 512;
1017 texture_desc
.MipLevels
= 1;
1018 texture_desc
.ArraySize
= 1;
1019 texture_desc
.Format
= DXGI_FORMAT_D24_UNORM_S8_UINT
;
1020 texture_desc
.SampleDesc
.Count
= 1;
1021 texture_desc
.SampleDesc
.Quality
= 0;
1022 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1023 texture_desc
.BindFlags
= D3D11_BIND_DEPTH_STENCIL
;
1024 texture_desc
.CPUAccessFlags
= 0;
1025 texture_desc
.MiscFlags
= 0;
1027 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
1028 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
1030 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1031 hr
= ID3D11Device_CreateDepthStencilView(device
, (ID3D11Resource
*)texture
, NULL
, &dsview
);
1032 ok(SUCCEEDED(hr
), "Failed to create a depthstencil view, hr %#x.\n", hr
);
1033 refcount
= get_refcount((IUnknown
*)device
);
1034 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1036 expected_refcount
= refcount
+ 1;
1037 ID3D11DepthStencilView_GetDevice(dsview
, &tmp
);
1038 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1039 refcount
= get_refcount((IUnknown
*)device
);
1040 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1041 ID3D11Device_Release(tmp
);
1043 ID3D11DepthStencilView_GetDesc(dsview
, &dsv_desc
);
1044 ok(dsv_desc
.Format
== texture_desc
.Format
, "Got unexpected format %#x.\n", dsv_desc
.Format
);
1045 ok(dsv_desc
.ViewDimension
== D3D11_DSV_DIMENSION_TEXTURE2D
,
1046 "Got unexpected view dimension %#x.\n", dsv_desc
.ViewDimension
);
1047 ok(!dsv_desc
.Flags
, "Got unexpected flags %#x.\n", dsv_desc
.Flags
);
1048 ok(U(dsv_desc
).Texture2D
.MipSlice
== 0, "Got Unexpected mip slice %u.\n", U(dsv_desc
).Texture2D
.MipSlice
);
1050 ID3D11DepthStencilView_Release(dsview
);
1051 ID3D11Texture2D_Release(texture
);
1053 refcount
= ID3D11Device_Release(device
);
1054 ok(!refcount
, "Device has %u references left.\n", refcount
);
1057 static void test_depthstencil_view_interfaces(void)
1059 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc
;
1060 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc
;
1061 ID3D10DepthStencilView
*d3d10_dsview
;
1062 D3D11_TEXTURE2D_DESC texture_desc
;
1063 ID3D11DepthStencilView
*dsview
;
1064 ID3D11Texture2D
*texture
;
1065 ID3D11Device
*device
;
1069 if (!(device
= create_device(NULL
)))
1071 skip("Failed to create device.\n");
1075 texture_desc
.Width
= 512;
1076 texture_desc
.Height
= 512;
1077 texture_desc
.MipLevels
= 1;
1078 texture_desc
.ArraySize
= 1;
1079 texture_desc
.Format
= DXGI_FORMAT_D24_UNORM_S8_UINT
;
1080 texture_desc
.SampleDesc
.Count
= 1;
1081 texture_desc
.SampleDesc
.Quality
= 0;
1082 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1083 texture_desc
.BindFlags
= D3D11_BIND_DEPTH_STENCIL
;
1084 texture_desc
.CPUAccessFlags
= 0;
1085 texture_desc
.MiscFlags
= 0;
1087 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
1088 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
1090 dsv_desc
.Format
= texture_desc
.Format
;
1091 dsv_desc
.ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2D
;
1093 U(dsv_desc
).Texture2D
.MipSlice
= 0;
1095 hr
= ID3D11Device_CreateDepthStencilView(device
, (ID3D11Resource
*)texture
, &dsv_desc
, &dsview
);
1096 ok(SUCCEEDED(hr
), "Failed to create a depthstencil view, hr %#x.\n", hr
);
1098 hr
= ID3D11DepthStencilView_QueryInterface(dsview
, &IID_ID3D10DepthStencilView
, (void **)&d3d10_dsview
);
1099 ID3D11DepthStencilView_Release(dsview
);
1100 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1101 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1105 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1109 ID3D10DepthStencilView_GetDesc(d3d10_dsview
, &d3d10_dsv_desc
);
1110 ok(d3d10_dsv_desc
.Format
== dsv_desc
.Format
, "Got unexpected format %#x.\n", d3d10_dsv_desc
.Format
);
1111 ok(d3d10_dsv_desc
.ViewDimension
== (D3D10_DSV_DIMENSION
)dsv_desc
.ViewDimension
,
1112 "Got unexpected view dimension %u.\n", d3d10_dsv_desc
.ViewDimension
);
1113 ok(U(d3d10_dsv_desc
).Texture2D
.MipSlice
== U(dsv_desc
).Texture2D
.MipSlice
,
1114 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc
).Texture2D
.MipSlice
);
1116 ID3D10DepthStencilView_Release(d3d10_dsview
);
1119 ID3D11Texture2D_Release(texture
);
1121 refcount
= ID3D11Device_Release(device
);
1122 ok(!refcount
, "Device has %u references left.\n", refcount
);
1125 static void test_create_rendertarget_view(void)
1127 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc
;
1128 D3D11_SUBRESOURCE_DATA data
= {0};
1129 D3D11_TEXTURE2D_DESC texture_desc
;
1130 ULONG refcount
, expected_refcount
;
1131 D3D11_BUFFER_DESC buffer_desc
;
1132 ID3D11RenderTargetView
*rtview
;
1133 ID3D11Device
*device
, *tmp
;
1134 ID3D11Texture2D
*texture
;
1135 ID3D11Buffer
*buffer
;
1139 if (!(device
= create_device(NULL
)))
1141 skip("Failed to create device.\n");
1145 buffer_desc
.ByteWidth
= 1024;
1146 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1147 buffer_desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
1148 buffer_desc
.CPUAccessFlags
= 0;
1149 buffer_desc
.MiscFlags
= 0;
1150 buffer_desc
.StructureByteStride
= 0;
1152 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, &data
, &buffer
);
1153 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1155 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1156 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
1157 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x.\n", hr
);
1158 refcount
= get_refcount((IUnknown
*)device
);
1159 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1161 expected_refcount
= refcount
+ 1;
1162 ID3D11Buffer_GetDevice(buffer
, &tmp
);
1163 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1164 refcount
= get_refcount((IUnknown
*)device
);
1165 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1166 ID3D11Device_Release(tmp
);
1168 rtv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
1169 rtv_desc
.ViewDimension
= D3D11_RTV_DIMENSION_BUFFER
;
1170 U(rtv_desc
).Buffer
.ElementOffset
= 0;
1171 U(rtv_desc
).Buffer
.ElementWidth
= 64;
1173 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1174 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)buffer
, &rtv_desc
, &rtview
);
1175 ok(SUCCEEDED(hr
), "Failed to create a rendertarget view, hr %#x.\n", hr
);
1176 refcount
= get_refcount((IUnknown
*)device
);
1177 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1179 expected_refcount
= refcount
+ 1;
1180 ID3D11RenderTargetView_GetDevice(rtview
, &tmp
);
1181 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1182 refcount
= get_refcount((IUnknown
*)device
);
1183 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1184 ID3D11Device_Release(tmp
);
1186 hr
= ID3D11RenderTargetView_QueryInterface(rtview
, &IID_ID3D10RenderTargetView
, (void **)&iface
);
1187 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1188 "Render target view should implement ID3D10RenderTargetView.\n");
1189 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1191 ID3D11RenderTargetView_Release(rtview
);
1192 ID3D11Buffer_Release(buffer
);
1194 texture_desc
.Width
= 512;
1195 texture_desc
.Height
= 512;
1196 texture_desc
.MipLevels
= 1;
1197 texture_desc
.ArraySize
= 1;
1198 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
1199 texture_desc
.SampleDesc
.Count
= 1;
1200 texture_desc
.SampleDesc
.Quality
= 0;
1201 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1202 texture_desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
1203 texture_desc
.CPUAccessFlags
= 0;
1204 texture_desc
.MiscFlags
= 0;
1206 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
1207 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
1209 /* For texture resources it's allowed to specify NULL as desc */
1210 hr
= ID3D11Device_CreateRenderTargetView(device
, (ID3D11Resource
*)texture
, NULL
, &rtview
);
1211 ok(SUCCEEDED(hr
), "Failed to create a rendertarget view, hr %#x.\n", hr
);
1213 ID3D11RenderTargetView_GetDesc(rtview
, &rtv_desc
);
1214 ok(rtv_desc
.Format
== texture_desc
.Format
, "Got unexpected format %#x.\n", rtv_desc
.Format
);
1215 ok(rtv_desc
.ViewDimension
== D3D11_RTV_DIMENSION_TEXTURE2D
, "Got unexpected view dimension %#x.\n",
1216 rtv_desc
.ViewDimension
);
1217 ok(U(rtv_desc
).Texture2D
.MipSlice
== 0, "Got unexpected mip slice %#x.\n", U(rtv_desc
).Texture2D
.MipSlice
);
1219 hr
= ID3D11RenderTargetView_QueryInterface(rtview
, &IID_ID3D10RenderTargetView
, (void **)&iface
);
1220 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1221 "Render target view should implement ID3D10RenderTargetView.\n");
1222 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1224 ID3D11RenderTargetView_Release(rtview
);
1225 ID3D11Texture2D_Release(texture
);
1227 refcount
= ID3D11Device_Release(device
);
1228 ok(!refcount
, "Device has %u references left.\n", refcount
);
1231 static void test_create_shader_resource_view(void)
1233 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc
;
1234 D3D11_TEXTURE2D_DESC texture_desc
;
1235 ULONG refcount
, expected_refcount
;
1236 ID3D11ShaderResourceView
*srview
;
1237 D3D11_BUFFER_DESC buffer_desc
;
1238 ID3D11Device
*device
, *tmp
;
1239 ID3D11Texture2D
*texture
;
1240 ID3D11Buffer
*buffer
;
1244 if (!(device
= create_device(NULL
)))
1246 skip("Failed to create device.\n");
1250 buffer_desc
.ByteWidth
= 1024;
1251 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1252 buffer_desc
.BindFlags
= D3D11_BIND_SHADER_RESOURCE
;
1253 buffer_desc
.CPUAccessFlags
= 0;
1254 buffer_desc
.MiscFlags
= 0;
1255 buffer_desc
.StructureByteStride
= 0;
1257 hr
= ID3D11Device_CreateBuffer(device
, &buffer_desc
, NULL
, &buffer
);
1258 ok(SUCCEEDED(hr
), "Failed to create a buffer, hr %#x.\n", hr
);
1260 hr
= ID3D11Device_CreateShaderResourceView(device
, (ID3D11Resource
*)buffer
, NULL
, &srview
);
1261 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1263 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
1264 srv_desc
.ViewDimension
= D3D11_SRV_DIMENSION_BUFFER
;
1265 U(srv_desc
).Buffer
.ElementOffset
= 0;
1266 U(srv_desc
).Buffer
.ElementWidth
= 64;
1268 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1269 hr
= ID3D11Device_CreateShaderResourceView(device
, (ID3D11Resource
*)buffer
, &srv_desc
, &srview
);
1270 ok(SUCCEEDED(hr
), "Failed to create a shader resource view, hr %#x.\n", hr
);
1271 refcount
= get_refcount((IUnknown
*)device
);
1272 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1274 expected_refcount
= refcount
+ 1;
1275 ID3D11ShaderResourceView_GetDevice(srview
, &tmp
);
1276 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1277 refcount
= get_refcount((IUnknown
*)device
);
1278 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1279 ID3D11Device_Release(tmp
);
1281 hr
= ID3D11ShaderResourceView_QueryInterface(srview
, &IID_ID3D10ShaderResourceView
, (void **)&iface
);
1282 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1283 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1284 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1285 hr
= ID3D11ShaderResourceView_QueryInterface(srview
, &IID_ID3D10ShaderResourceView1
, (void **)&iface
);
1286 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1287 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1288 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1290 ID3D11ShaderResourceView_Release(srview
);
1291 ID3D11Buffer_Release(buffer
);
1293 texture_desc
.Width
= 512;
1294 texture_desc
.Height
= 512;
1295 texture_desc
.MipLevels
= 0;
1296 texture_desc
.ArraySize
= 1;
1297 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
1298 texture_desc
.SampleDesc
.Count
= 1;
1299 texture_desc
.SampleDesc
.Quality
= 0;
1300 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
1301 texture_desc
.BindFlags
= D3D11_BIND_SHADER_RESOURCE
;
1302 texture_desc
.CPUAccessFlags
= 0;
1303 texture_desc
.MiscFlags
= 0;
1305 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
1306 ok(SUCCEEDED(hr
), "Failed to create a 2d texture, hr %#x.\n", hr
);
1308 hr
= ID3D11Device_CreateShaderResourceView(device
, (ID3D11Resource
*)texture
, NULL
, &srview
);
1309 ok(SUCCEEDED(hr
), "Failed to create a shader resource view, hr %#x.\n", hr
);
1311 hr
= ID3D11ShaderResourceView_QueryInterface(srview
, &IID_ID3D10ShaderResourceView
, (void **)&iface
);
1312 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1313 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1314 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1315 hr
= ID3D11ShaderResourceView_QueryInterface(srview
, &IID_ID3D10ShaderResourceView1
, (void **)&iface
);
1316 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1317 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1318 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1320 ID3D11ShaderResourceView_GetDesc(srview
, &srv_desc
);
1321 ok(srv_desc
.Format
== texture_desc
.Format
, "Got unexpected format %#x.\n", srv_desc
.Format
);
1322 ok(srv_desc
.ViewDimension
== D3D11_SRV_DIMENSION_TEXTURE2D
,
1323 "Got unexpected view dimension %#x.\n", srv_desc
.ViewDimension
);
1324 ok(U(srv_desc
).Texture2D
.MostDetailedMip
== 0, "Got unexpected MostDetailedMip %u.\n",
1325 U(srv_desc
).Texture2D
.MostDetailedMip
);
1326 ok(U(srv_desc
).Texture2D
.MipLevels
== 10, "Got unexpected MipLevels %u.\n", U(srv_desc
).Texture2D
.MipLevels
);
1328 ID3D11ShaderResourceView_Release(srview
);
1329 ID3D11Texture2D_Release(texture
);
1331 refcount
= ID3D11Device_Release(device
);
1332 ok(!refcount
, "Device has %u references left.\n", refcount
);
1335 static void test_create_shader(void)
1343 float4 position
: POSITION
;
1344 float3 normal
: NORMAL
;
1349 float4 position
: POSITION
;
1350 float4 diffuse
: COLOR
;
1353 output
main(const input v
)
1357 o
.position
= mul(v
.position
, mat
);
1358 o
.diffuse
= dot((float3
)light
, v
.normal
);
1363 static const DWORD vs_4_0
[] =
1365 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1366 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1367 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1368 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1369 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1370 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1371 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1372 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1373 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1374 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1375 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1376 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1377 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1378 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1379 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1380 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1383 static const DWORD vs_2_0
[] =
1385 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1386 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1387 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1388 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1389 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1390 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1391 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1392 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
1393 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
1394 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
1395 0x90e40001, 0x0000ffff,
1398 static const DWORD vs_3_0
[] =
1400 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
1401 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1402 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1403 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1404 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1405 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1406 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1407 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
1408 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
1409 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
1410 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
1415 float4
main(const float4 color
: COLOR
) : SV_TARGET
1424 static const DWORD ps_4_0
[] =
1426 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
1427 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
1428 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
1429 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
1430 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
1431 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1432 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
1433 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1434 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
1435 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
1436 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
1437 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
1438 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1439 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1440 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1441 0x00000000, 0x00000000,
1447 float4 pos
: SV_POSITION
;
1451 void main(point float4 vin
[1] : POSITION
, inout TriangleStream
<gs_out
> vout
)
1453 float offset
= 0.1 * vin
[0].w
;
1456 v
.pos
= float4(vin
[0].x
- offset
, vin
[0].y
- offset
, vin
[0].z
, vin
[0].w
);
1458 v
.pos
= float4(vin
[0].x
- offset
, vin
[0].y
+ offset
, vin
[0].z
, vin
[0].w
);
1460 v
.pos
= float4(vin
[0].x
+ offset
, vin
[0].y
- offset
, vin
[0].z
, vin
[0].w
);
1462 v
.pos
= float4(vin
[0].x
+ offset
, vin
[0].y
+ offset
, vin
[0].z
, vin
[0].w
);
1466 static const DWORD gs_4_0
[] =
1468 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1469 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1470 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1471 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1472 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1473 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1474 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1475 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1476 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1477 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1478 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1479 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1480 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1481 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1482 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1483 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1484 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1485 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1488 ULONG refcount
, expected_refcount
;
1489 ID3D11Device
*device
, *tmp
;
1490 ID3D11GeometryShader
*gs
;
1491 ID3D11VertexShader
*vs
;
1492 ID3D11PixelShader
*ps
;
1497 for (i
= 0; i
< sizeof(d3d11_feature_levels
) / sizeof(*d3d11_feature_levels
); ++i
)
1499 D3D_FEATURE_LEVEL feature_level
= d3d11_feature_levels
[i
];
1500 if (!(device
= create_device(&feature_level
)))
1502 skip("Failed to create device for feature level %#x.\n", feature_level
);
1507 hr
= ID3D11Device_CreateVertexShader(device
, vs_2_0
, sizeof(vs_2_0
), NULL
, &vs
);
1508 ok(hr
== E_INVALIDARG
, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr
, feature_level
);
1510 hr
= ID3D11Device_CreateVertexShader(device
, vs_3_0
, sizeof(vs_3_0
), NULL
, &vs
);
1511 ok(hr
== E_INVALIDARG
, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr
, feature_level
);
1513 hr
= ID3D11Device_CreateVertexShader(device
, ps_4_0
, sizeof(ps_4_0
), NULL
, &vs
);
1514 ok(hr
== E_INVALIDARG
, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
1517 if (feature_level
< D3D_FEATURE_LEVEL_10_0
)
1519 refcount
= ID3D11Device_Release(device
);
1520 ok(!refcount
, "Device has %u references left.\n", refcount
);
1524 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1525 hr
= ID3D11Device_CreateVertexShader(device
, vs_4_0
, sizeof(vs_4_0
), NULL
, &vs
);
1526 ok(SUCCEEDED(hr
), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr
, feature_level
);
1528 refcount
= get_refcount((IUnknown
*)device
);
1529 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n",
1530 refcount
, expected_refcount
);
1532 expected_refcount
= refcount
+ 1;
1533 ID3D11VertexShader_GetDevice(vs
, &tmp
);
1534 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1535 refcount
= get_refcount((IUnknown
*)device
);
1536 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n",
1537 refcount
, expected_refcount
);
1538 ID3D11Device_Release(tmp
);
1540 hr
= ID3D11VertexShader_QueryInterface(vs
, &IID_ID3D10VertexShader
, (void **)&iface
);
1541 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1542 "Vertex shader should implement ID3D10VertexShader.\n");
1543 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1545 refcount
= ID3D11VertexShader_Release(vs
);
1546 ok(!refcount
, "Vertex shader has %u references left.\n", refcount
);
1549 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1550 hr
= ID3D11Device_CreatePixelShader(device
, ps_4_0
, sizeof(ps_4_0
), NULL
, &ps
);
1551 ok(SUCCEEDED(hr
), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr
, feature_level
);
1553 refcount
= get_refcount((IUnknown
*)device
);
1554 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n",
1555 refcount
, expected_refcount
);
1557 expected_refcount
= refcount
+ 1;
1558 ID3D11PixelShader_GetDevice(ps
, &tmp
);
1559 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1560 refcount
= get_refcount((IUnknown
*)device
);
1561 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n",
1562 refcount
, expected_refcount
);
1563 ID3D11Device_Release(tmp
);
1565 hr
= ID3D11PixelShader_QueryInterface(ps
, &IID_ID3D10PixelShader
, (void **)&iface
);
1566 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1567 "Pixel shader should implement ID3D10PixelShader.\n");
1568 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1570 refcount
= ID3D11PixelShader_Release(ps
);
1571 ok(!refcount
, "Pixel shader has %u references left.\n", refcount
);
1573 /* geometry shader */
1574 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1575 hr
= ID3D11Device_CreateGeometryShader(device
, gs_4_0
, sizeof(gs_4_0
), NULL
, &gs
);
1576 ok(SUCCEEDED(hr
), "Failed to create SM4 geometry shader, hr %#x.\n", hr
);
1578 refcount
= get_refcount((IUnknown
*)device
);
1579 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n",
1580 refcount
, expected_refcount
);
1582 expected_refcount
= refcount
+ 1;
1583 ID3D11GeometryShader_GetDevice(gs
, &tmp
);
1584 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1585 refcount
= get_refcount((IUnknown
*)device
);
1586 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n",
1587 refcount
, expected_refcount
);
1588 ID3D11Device_Release(tmp
);
1590 hr
= ID3D11GeometryShader_QueryInterface(gs
, &IID_ID3D10GeometryShader
, (void **)&iface
);
1591 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1592 "Geometry shader should implement ID3D10GeometryShader.\n");
1593 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1595 refcount
= ID3D11GeometryShader_Release(gs
);
1596 ok(!refcount
, "Geometry shader has %u references left.\n", refcount
);
1598 refcount
= ID3D11Device_Release(device
);
1599 ok(!refcount
, "Device has %u references left.\n", refcount
);
1603 static void test_create_sampler_state(void)
1605 static const struct test
1607 D3D11_FILTER filter
;
1608 D3D10_FILTER expected_filter
;
1610 desc_conversion_tests
[] =
1612 {D3D11_FILTER_MIN_MAG_MIP_POINT
, D3D10_FILTER_MIN_MAG_MIP_POINT
},
1613 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
},
1614 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT
, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT
},
1615 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR
, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR
},
1616 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT
, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT
},
1617 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR
, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR
},
1618 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT
, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT
},
1619 {D3D11_FILTER_MIN_MAG_MIP_LINEAR
, D3D10_FILTER_MIN_MAG_MIP_LINEAR
},
1620 {D3D11_FILTER_ANISOTROPIC
, D3D10_FILTER_ANISOTROPIC
},
1621 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT
, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT
},
1622 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR
, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR
},
1624 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
,
1625 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
1627 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR
, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR
},
1628 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT
, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT
},
1630 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
,
1631 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
1633 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT
, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT
},
1634 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR
, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR
},
1635 {D3D11_FILTER_COMPARISON_ANISOTROPIC
, D3D10_FILTER_COMPARISON_ANISOTROPIC
},
1638 ID3D11SamplerState
*sampler_state1
, *sampler_state2
;
1639 ID3D10SamplerState
*d3d10_sampler_state
;
1640 ULONG refcount
, expected_refcount
;
1641 ID3D11Device
*device
, *tmp
;
1642 D3D11_SAMPLER_DESC desc
;
1646 if (!(device
= create_device(NULL
)))
1648 skip("Failed to create device.\n");
1652 hr
= ID3D11Device_CreateSamplerState(device
, NULL
, &sampler_state1
);
1653 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1655 desc
.Filter
= D3D11_FILTER_MIN_MAG_MIP_LINEAR
;
1656 desc
.AddressU
= D3D11_TEXTURE_ADDRESS_WRAP
;
1657 desc
.AddressV
= D3D11_TEXTURE_ADDRESS_WRAP
;
1658 desc
.AddressW
= D3D11_TEXTURE_ADDRESS_WRAP
;
1659 desc
.MipLODBias
= 0.0f
;
1660 desc
.MaxAnisotropy
= 16;
1661 desc
.ComparisonFunc
= D3D11_COMPARISON_ALWAYS
;
1662 desc
.BorderColor
[0] = 0.0f
;
1663 desc
.BorderColor
[1] = 1.0f
;
1664 desc
.BorderColor
[2] = 0.0f
;
1665 desc
.BorderColor
[3] = 1.0f
;
1667 desc
.MaxLOD
= 16.0f
;
1669 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1670 hr
= ID3D11Device_CreateSamplerState(device
, &desc
, &sampler_state1
);
1671 ok(SUCCEEDED(hr
), "Failed to create sampler state, hr %#x.\n", hr
);
1672 hr
= ID3D11Device_CreateSamplerState(device
, &desc
, &sampler_state2
);
1673 ok(SUCCEEDED(hr
), "Failed to create sampler state, hr %#x.\n", hr
);
1674 ok(sampler_state1
== sampler_state2
, "Got different sampler state objects.\n");
1675 refcount
= get_refcount((IUnknown
*)device
);
1676 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1678 expected_refcount
= refcount
+ 1;
1679 ID3D11SamplerState_GetDevice(sampler_state1
, &tmp
);
1680 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1681 refcount
= get_refcount((IUnknown
*)device
);
1682 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1683 ID3D11Device_Release(tmp
);
1685 ID3D11SamplerState_GetDesc(sampler_state1
, &desc
);
1686 ok(desc
.Filter
== D3D11_FILTER_MIN_MAG_MIP_LINEAR
, "Got unexpected filter %#x.\n", desc
.Filter
);
1687 ok(desc
.AddressU
== D3D11_TEXTURE_ADDRESS_WRAP
, "Got unexpected address u %u.\n", desc
.AddressU
);
1688 ok(desc
.AddressV
== D3D11_TEXTURE_ADDRESS_WRAP
, "Got unexpected address v %u.\n", desc
.AddressV
);
1689 ok(desc
.AddressW
== D3D11_TEXTURE_ADDRESS_WRAP
, "Got unexpected address w %u.\n", desc
.AddressW
);
1690 ok(!desc
.MipLODBias
, "Got unexpected mip LOD bias %f.\n", desc
.MipLODBias
);
1691 ok(!desc
.MaxAnisotropy
, "Got unexpected max anisotropy %u.\n", desc
.MaxAnisotropy
);
1692 ok(desc
.ComparisonFunc
== D3D11_COMPARISON_NEVER
, "Got unexpected comparison func %u.\n", desc
.ComparisonFunc
);
1693 ok(!desc
.BorderColor
[0] && !desc
.BorderColor
[1] && !desc
.BorderColor
[2] && !desc
.BorderColor
[3],
1694 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
1695 desc
.BorderColor
[0], desc
.BorderColor
[1], desc
.BorderColor
[2], desc
.BorderColor
[3]);
1696 ok(!desc
.MinLOD
, "Got unexpected min LOD %f.\n", desc
.MinLOD
);
1697 ok(desc
.MaxLOD
== 16.0f
, "Got unexpected max LOD %f.\n", desc
.MaxLOD
);
1699 refcount
= ID3D11SamplerState_Release(sampler_state2
);
1700 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1701 refcount
= ID3D11SamplerState_Release(sampler_state1
);
1702 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1704 for (i
= 0; i
< sizeof(desc_conversion_tests
) / sizeof(*desc_conversion_tests
); ++i
)
1706 const struct test
*current
= &desc_conversion_tests
[i
];
1707 D3D10_SAMPLER_DESC d3d10_desc
, expected_desc
;
1709 desc
.Filter
= current
->filter
;
1710 desc
.AddressU
= D3D11_TEXTURE_ADDRESS_WRAP
;
1711 desc
.AddressV
= D3D11_TEXTURE_ADDRESS_WRAP
;
1712 desc
.AddressW
= D3D11_TEXTURE_ADDRESS_BORDER
;
1713 desc
.MipLODBias
= 0.0f
;
1714 desc
.MaxAnisotropy
= 16;
1715 desc
.ComparisonFunc
= D3D11_COMPARISON_ALWAYS
;
1716 desc
.BorderColor
[0] = 0.0f
;
1717 desc
.BorderColor
[1] = 1.0f
;
1718 desc
.BorderColor
[2] = 0.0f
;
1719 desc
.BorderColor
[3] = 1.0f
;
1721 desc
.MaxLOD
= 16.0f
;
1723 hr
= ID3D11Device_CreateSamplerState(device
, &desc
, &sampler_state1
);
1724 ok(SUCCEEDED(hr
), "Test %u: Failed to create sampler state, hr %#x.\n", i
, hr
);
1726 hr
= ID3D11SamplerState_QueryInterface(sampler_state1
, &IID_ID3D10SamplerState
,
1727 (void **)&d3d10_sampler_state
);
1728 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1729 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i
);
1732 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
1733 ID3D11SamplerState_Release(sampler_state1
);
1737 memcpy(&expected_desc
, &desc
, sizeof(expected_desc
));
1738 expected_desc
.Filter
= current
->expected_filter
;
1739 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current
->filter
))
1740 expected_desc
.MaxAnisotropy
= 0;
1741 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current
->filter
))
1742 expected_desc
.ComparisonFunc
= D3D10_COMPARISON_NEVER
;
1744 ID3D10SamplerState_GetDesc(d3d10_sampler_state
, &d3d10_desc
);
1745 ok(d3d10_desc
.Filter
== expected_desc
.Filter
,
1746 "Test %u: Got unexpected filter %#x.\n", i
, d3d10_desc
.Filter
);
1747 ok(d3d10_desc
.AddressU
== expected_desc
.AddressU
,
1748 "Test %u: Got unexpected adress u %u.\n", i
, d3d10_desc
.AddressU
);
1749 ok(d3d10_desc
.AddressV
== expected_desc
.AddressV
,
1750 "Test %u: Got unexpected address v %u.\n", i
, d3d10_desc
.AddressV
);
1751 ok(d3d10_desc
.AddressW
== expected_desc
.AddressW
,
1752 "Test %u: Got unexpected address w %u.\n", i
, d3d10_desc
.AddressW
);
1753 ok(d3d10_desc
.MipLODBias
== expected_desc
.MipLODBias
,
1754 "Test %u: Got unexpected mip LOD bias %f.\n", i
, d3d10_desc
.MipLODBias
);
1755 ok(d3d10_desc
.MaxAnisotropy
== expected_desc
.MaxAnisotropy
,
1756 "Test %u: Got unexpected max anisotropy %u.\n", i
, d3d10_desc
.MaxAnisotropy
);
1757 ok(d3d10_desc
.ComparisonFunc
== expected_desc
.ComparisonFunc
,
1758 "Test %u: Got unexpected comparison func %u.\n", i
, d3d10_desc
.ComparisonFunc
);
1759 ok(d3d10_desc
.BorderColor
[0] == expected_desc
.BorderColor
[0]
1760 && d3d10_desc
.BorderColor
[1] == expected_desc
.BorderColor
[1]
1761 && d3d10_desc
.BorderColor
[2] == expected_desc
.BorderColor
[2]
1762 && d3d10_desc
.BorderColor
[3] == expected_desc
.BorderColor
[3],
1763 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i
,
1764 d3d10_desc
.BorderColor
[0], d3d10_desc
.BorderColor
[1],
1765 d3d10_desc
.BorderColor
[2], d3d10_desc
.BorderColor
[3]);
1766 ok(d3d10_desc
.MinLOD
== expected_desc
.MinLOD
,
1767 "Test %u: Got unexpected min LOD %f.\n", i
, d3d10_desc
.MinLOD
);
1768 ok(d3d10_desc
.MaxLOD
== expected_desc
.MaxLOD
,
1769 "Test %u: Got unexpected max LOD %f.\n", i
, d3d10_desc
.MaxLOD
);
1771 refcount
= ID3D10SamplerState_Release(d3d10_sampler_state
);
1772 ok(refcount
== 1, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
1773 refcount
= ID3D11SamplerState_Release(sampler_state1
);
1774 ok(!refcount
, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
1777 refcount
= ID3D11Device_Release(device
);
1778 ok(!refcount
, "Device has %u references left.\n", refcount
);
1781 static void test_create_blend_state(void)
1783 static const D3D11_BLEND_DESC desc_conversion_tests
[] =
1789 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1790 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
1798 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1799 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1802 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1803 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_RED
1806 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1807 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1810 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1811 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_GREEN
1814 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1815 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1818 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1819 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1822 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1823 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1826 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1827 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1835 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1836 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1839 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_SUBTRACT
,
1840 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1843 TRUE
, D3D11_BLEND_ZERO
, D3D11_BLEND_ONE
, D3D11_BLEND_OP_ADD
,
1844 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1847 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1848 D3D11_BLEND_ZERO
, D3D11_BLEND_ONE
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1851 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ONE
, D3D11_BLEND_OP_MAX
,
1852 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1855 TRUE
, D3D11_BLEND_ONE
, D3D11_BLEND_ONE
, D3D11_BLEND_OP_MIN
,
1856 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1859 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1860 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1863 FALSE
, D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
,
1864 D3D11_BLEND_ONE
, D3D11_BLEND_ZERO
, D3D11_BLEND_OP_ADD
, D3D11_COLOR_WRITE_ENABLE_ALL
1870 ID3D11BlendState
*blend_state1
, *blend_state2
;
1871 D3D11_BLEND_DESC desc
, obtained_desc
;
1872 ID3D10BlendState
*d3d10_blend_state
;
1873 D3D10_BLEND_DESC d3d10_blend_desc
;
1874 ULONG refcount
, expected_refcount
;
1875 ID3D11Device
*device
, *tmp
;
1880 if (!(device
= create_device(NULL
)))
1882 skip("Failed to create device.\n");
1886 hr
= ID3D11Device_CreateBlendState(device
, NULL
, &blend_state1
);
1887 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1889 memset(&desc
, 0, sizeof(desc
));
1890 desc
.AlphaToCoverageEnable
= FALSE
;
1891 desc
.IndependentBlendEnable
= FALSE
;
1892 desc
.RenderTarget
[0].BlendEnable
= FALSE
;
1893 desc
.RenderTarget
[0].SrcBlend
= D3D11_BLEND_ONE
;
1894 desc
.RenderTarget
[0].DestBlend
= D3D11_BLEND_ZERO
;
1895 desc
.RenderTarget
[0].BlendOp
= D3D11_BLEND_OP_ADD
;
1896 desc
.RenderTarget
[0].SrcBlendAlpha
= D3D11_BLEND_ONE
;
1897 desc
.RenderTarget
[0].DestBlendAlpha
= D3D11_BLEND_ZERO
;
1898 desc
.RenderTarget
[0].BlendOpAlpha
= D3D11_BLEND_OP_ADD
;
1899 desc
.RenderTarget
[0].RenderTargetWriteMask
= D3D11_COLOR_WRITE_ENABLE_ALL
;
1901 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
1902 hr
= ID3D11Device_CreateBlendState(device
, &desc
, &blend_state1
);
1903 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
1904 hr
= ID3D11Device_CreateBlendState(device
, &desc
, &blend_state2
);
1905 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
1906 ok(blend_state1
== blend_state2
, "Got different blend state objects.\n");
1907 refcount
= get_refcount((IUnknown
*)device
);
1908 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
1910 expected_refcount
= refcount
+ 1;
1911 ID3D11BlendState_GetDevice(blend_state1
, &tmp
);
1912 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
1913 refcount
= get_refcount((IUnknown
*)device
);
1914 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
1915 ID3D11Device_Release(tmp
);
1917 ID3D11BlendState_GetDesc(blend_state1
, &obtained_desc
);
1918 ok(obtained_desc
.AlphaToCoverageEnable
== FALSE
, "Got unexpected alpha to coverage enable %#x.\n",
1919 obtained_desc
.AlphaToCoverageEnable
);
1920 ok(obtained_desc
.IndependentBlendEnable
== FALSE
, "Got unexpected independent blend enable %#x.\n",
1921 obtained_desc
.IndependentBlendEnable
);
1922 for (i
= 0; i
< D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT
; ++i
)
1924 ok(obtained_desc
.RenderTarget
[i
].BlendEnable
== FALSE
,
1925 "Got unexpected blend enable %#x for render target %u.\n",
1926 obtained_desc
.RenderTarget
[i
].BlendEnable
, i
);
1927 ok(obtained_desc
.RenderTarget
[i
].SrcBlend
== D3D11_BLEND_ONE
,
1928 "Got unexpected src blend %u for render target %u.\n",
1929 obtained_desc
.RenderTarget
[i
].SrcBlend
, i
);
1930 ok(obtained_desc
.RenderTarget
[i
].DestBlend
== D3D11_BLEND_ZERO
,
1931 "Got unexpected dest blend %u for render target %u.\n",
1932 obtained_desc
.RenderTarget
[i
].DestBlend
, i
);
1933 ok(obtained_desc
.RenderTarget
[i
].BlendOp
== D3D11_BLEND_OP_ADD
,
1934 "Got unexpected blend op %u for render target %u.\n",
1935 obtained_desc
.RenderTarget
[i
].BlendOp
, i
);
1936 ok(obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
== D3D11_BLEND_ONE
,
1937 "Got unexpected src blend alpha %u for render target %u.\n",
1938 obtained_desc
.RenderTarget
[i
].SrcBlendAlpha
, i
);
1939 ok(obtained_desc
.RenderTarget
[i
].DestBlendAlpha
== D3D11_BLEND_ZERO
,
1940 "Got unexpected dest blend alpha %u for render target %u.\n",
1941 obtained_desc
.RenderTarget
[i
].DestBlendAlpha
, i
);
1942 ok(obtained_desc
.RenderTarget
[i
].BlendOpAlpha
== D3D11_BLEND_OP_ADD
,
1943 "Got unexpected blend op alpha %u for render target %u.\n",
1944 obtained_desc
.RenderTarget
[i
].BlendOpAlpha
, i
);
1945 ok(obtained_desc
.RenderTarget
[i
].RenderTargetWriteMask
== D3D11_COLOR_WRITE_ENABLE_ALL
,
1946 "Got unexpected render target write mask %#x for render target %u.\n",
1947 obtained_desc
.RenderTarget
[0].RenderTargetWriteMask
, i
);
1950 hr
= ID3D11BlendState_QueryInterface(blend_state1
, &IID_ID3D10BlendState
, (void **)&iface
);
1951 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1952 "Blend state should implement ID3D10BlendState.\n");
1953 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1954 hr
= ID3D11BlendState_QueryInterface(blend_state1
, &IID_ID3D10BlendState1
, (void **)&iface
);
1955 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1956 "Blend state should implement ID3D10BlendState1.\n");
1957 if (SUCCEEDED(hr
)) IUnknown_Release(iface
);
1959 refcount
= ID3D11BlendState_Release(blend_state1
);
1960 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1961 refcount
= ID3D11BlendState_Release(blend_state2
);
1962 ok(!refcount
, "Blend state has %u references left.\n", refcount
);
1964 for (i
= 0; i
< sizeof(desc_conversion_tests
) / sizeof(*desc_conversion_tests
); ++i
)
1966 const D3D11_BLEND_DESC
*current_desc
= &desc_conversion_tests
[i
];
1968 hr
= ID3D11Device_CreateBlendState(device
, current_desc
, &blend_state1
);
1969 ok(SUCCEEDED(hr
), "Failed to create blend state, hr %#x.\n", hr
);
1971 hr
= ID3D11BlendState_QueryInterface(blend_state1
, &IID_ID3D10BlendState
, (void **)&d3d10_blend_state
);
1972 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
1973 "Blend state should implement ID3D10BlendState.\n");
1976 win_skip("Blend state does not implement ID3D10BlendState.\n");
1977 ID3D11BlendState_Release(blend_state1
);
1981 ID3D10BlendState_GetDesc(d3d10_blend_state
, &d3d10_blend_desc
);
1982 ok(d3d10_blend_desc
.AlphaToCoverageEnable
== current_desc
->AlphaToCoverageEnable
,
1983 "Got unexpected alpha to coverage enable %#x for test %u.\n",
1984 d3d10_blend_desc
.AlphaToCoverageEnable
, i
);
1985 ok(d3d10_blend_desc
.SrcBlend
== (D3D10_BLEND
)current_desc
->RenderTarget
[0].SrcBlend
,
1986 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc
.SrcBlend
, i
);
1987 ok(d3d10_blend_desc
.DestBlend
== (D3D10_BLEND
)current_desc
->RenderTarget
[0].DestBlend
,
1988 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc
.DestBlend
, i
);
1989 ok(d3d10_blend_desc
.BlendOp
== (D3D10_BLEND_OP
)current_desc
->RenderTarget
[0].BlendOp
,
1990 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc
.BlendOp
, i
);
1991 ok(d3d10_blend_desc
.SrcBlendAlpha
== (D3D10_BLEND
)current_desc
->RenderTarget
[0].SrcBlendAlpha
,
1992 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc
.SrcBlendAlpha
, i
);
1993 ok(d3d10_blend_desc
.DestBlendAlpha
== (D3D10_BLEND
)current_desc
->RenderTarget
[0].DestBlendAlpha
,
1994 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc
.DestBlendAlpha
, i
);
1995 ok(d3d10_blend_desc
.BlendOpAlpha
== (D3D10_BLEND_OP
)current_desc
->RenderTarget
[0].BlendOpAlpha
,
1996 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc
.BlendOpAlpha
, i
);
1997 for (j
= 0; j
< D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT
; j
++)
1999 unsigned int k
= current_desc
->IndependentBlendEnable
? j
: 0;
2000 ok(d3d10_blend_desc
.BlendEnable
[j
] == current_desc
->RenderTarget
[k
].BlendEnable
,
2001 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2002 d3d10_blend_desc
.BlendEnable
[j
], i
, j
);
2003 ok(d3d10_blend_desc
.RenderTargetWriteMask
[j
] == current_desc
->RenderTarget
[k
].RenderTargetWriteMask
,
2004 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2005 d3d10_blend_desc
.RenderTargetWriteMask
[j
], i
, j
);
2008 ID3D10BlendState_Release(d3d10_blend_state
);
2010 refcount
= ID3D11BlendState_Release(blend_state1
);
2011 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2014 refcount
= ID3D11Device_Release(device
);
2015 ok(!refcount
, "Device has %u references left.\n", refcount
);
2018 static void test_create_depthstencil_state(void)
2020 ID3D11DepthStencilState
*ds_state1
, *ds_state2
;
2021 ID3D10DepthStencilState
*d3d10_ds_state
;
2022 ULONG refcount
, expected_refcount
;
2023 D3D11_DEPTH_STENCIL_DESC ds_desc
;
2024 ID3D11Device
*device
, *tmp
;
2027 if (!(device
= create_device(NULL
)))
2029 skip("Failed to create device.\n");
2033 hr
= ID3D11Device_CreateDepthStencilState(device
, NULL
, &ds_state1
);
2034 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2036 ds_desc
.DepthEnable
= TRUE
;
2037 ds_desc
.DepthWriteMask
= D3D11_DEPTH_WRITE_MASK_ALL
;
2038 ds_desc
.DepthFunc
= D3D11_COMPARISON_LESS
;
2039 ds_desc
.StencilEnable
= FALSE
;
2040 ds_desc
.StencilReadMask
= D3D11_DEFAULT_STENCIL_READ_MASK
;
2041 ds_desc
.StencilWriteMask
= D3D11_DEFAULT_STENCIL_WRITE_MASK
;
2042 ds_desc
.FrontFace
.StencilFailOp
= D3D11_STENCIL_OP_KEEP
;
2043 ds_desc
.FrontFace
.StencilDepthFailOp
= D3D11_STENCIL_OP_KEEP
;
2044 ds_desc
.FrontFace
.StencilPassOp
= D3D11_STENCIL_OP_KEEP
;
2045 ds_desc
.FrontFace
.StencilFunc
= D3D11_COMPARISON_ALWAYS
;
2046 ds_desc
.BackFace
.StencilFailOp
= D3D11_STENCIL_OP_KEEP
;
2047 ds_desc
.BackFace
.StencilDepthFailOp
= D3D11_STENCIL_OP_KEEP
;
2048 ds_desc
.BackFace
.StencilPassOp
= D3D11_STENCIL_OP_KEEP
;
2049 ds_desc
.BackFace
.StencilFunc
= D3D11_COMPARISON_ALWAYS
;
2051 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
2052 hr
= ID3D11Device_CreateDepthStencilState(device
, &ds_desc
, &ds_state1
);
2053 ok(SUCCEEDED(hr
), "Failed to create depthstencil state, hr %#x.\n", hr
);
2054 hr
= ID3D11Device_CreateDepthStencilState(device
, &ds_desc
, &ds_state2
);
2055 ok(SUCCEEDED(hr
), "Failed to create depthstencil state, hr %#x.\n", hr
);
2056 ok(ds_state1
== ds_state2
, "Got different depthstencil state objects.\n");
2057 refcount
= get_refcount((IUnknown
*)device
);
2058 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
2060 expected_refcount
= refcount
+ 1;
2061 ID3D11DepthStencilState_GetDevice(ds_state1
, &tmp
);
2062 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
2063 refcount
= get_refcount((IUnknown
*)device
);
2064 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2065 ID3D11Device_Release(tmp
);
2067 hr
= ID3D11DepthStencilState_QueryInterface(ds_state1
, &IID_ID3D10DepthStencilState
, (void **)&d3d10_ds_state
);
2068 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
2069 "Depth stencil state should implement ID3D10DepthStencilState.\n");
2070 if (SUCCEEDED(hr
)) ID3D10DepthStencilState_Release(d3d10_ds_state
);
2072 refcount
= ID3D11DepthStencilState_Release(ds_state2
);
2073 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
2074 refcount
= ID3D11DepthStencilState_Release(ds_state1
);
2075 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2077 refcount
= ID3D11Device_Release(device
);
2078 ok(!refcount
, "Device has %u references left.\n", refcount
);
2081 static void test_create_rasterizer_state(void)
2083 ID3D11RasterizerState
*rast_state1
, *rast_state2
;
2084 ID3D10RasterizerState
*d3d10_rast_state
;
2085 ULONG refcount
, expected_refcount
;
2086 D3D10_RASTERIZER_DESC d3d10_desc
;
2087 D3D11_RASTERIZER_DESC desc
;
2088 ID3D11Device
*device
, *tmp
;
2091 if (!(device
= create_device(NULL
)))
2093 skip("Failed to create device.\n");
2097 hr
= ID3D11Device_CreateRasterizerState(device
, NULL
, &rast_state1
);
2098 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2100 desc
.FillMode
= D3D11_FILL_SOLID
;
2101 desc
.CullMode
= D3D11_CULL_BACK
;
2102 desc
.FrontCounterClockwise
= FALSE
;
2104 desc
.DepthBiasClamp
= 0.0f
;
2105 desc
.SlopeScaledDepthBias
= 0.0f
;
2106 desc
.DepthClipEnable
= TRUE
;
2107 desc
.ScissorEnable
= FALSE
;
2108 desc
.MultisampleEnable
= FALSE
;
2109 desc
.AntialiasedLineEnable
= FALSE
;
2111 expected_refcount
= get_refcount((IUnknown
*)device
) + 1;
2112 hr
= ID3D11Device_CreateRasterizerState(device
, &desc
, &rast_state1
);
2113 ok(SUCCEEDED(hr
), "Failed to create rasterizer state, hr %#x.\n", hr
);
2114 hr
= ID3D11Device_CreateRasterizerState(device
, &desc
, &rast_state2
);
2115 ok(SUCCEEDED(hr
), "Failed to create rasterizer state, hr %#x.\n", hr
);
2116 ok(rast_state1
== rast_state2
, "Got different rasterizer state objects.\n");
2117 refcount
= get_refcount((IUnknown
*)device
);
2118 ok(refcount
>= expected_refcount
, "Got unexpected refcount %u, expected >= %u.\n", refcount
, expected_refcount
);
2120 expected_refcount
= refcount
+ 1;
2121 ID3D11RasterizerState_GetDevice(rast_state1
, &tmp
);
2122 ok(tmp
== device
, "Got unexpected device %p, expected %p.\n", tmp
, device
);
2123 refcount
= get_refcount((IUnknown
*)device
);
2124 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2125 ID3D11Device_Release(tmp
);
2127 hr
= ID3D11RasterizerState_QueryInterface(rast_state1
, &IID_ID3D10RasterizerState
, (void **)&d3d10_rast_state
);
2128 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
2129 "Rasterizer state should implement ID3D10RasterizerState.\n");
2132 ID3D10RasterizerState_GetDesc(d3d10_rast_state
, &d3d10_desc
);
2133 ok(d3d10_desc
.FillMode
== D3D10_FILL_SOLID
, "Got unexpected fill mode %u.\n", d3d10_desc
.FillMode
);
2134 ok(d3d10_desc
.CullMode
== D3D10_CULL_BACK
, "Got unexpected cull mode %u.\n", d3d10_desc
.CullMode
);
2135 ok(!d3d10_desc
.FrontCounterClockwise
, "Got unexpected front counter clockwise %#x.\n",
2136 d3d10_desc
.FrontCounterClockwise
);
2137 ok(!d3d10_desc
.DepthBias
, "Got unexpected depth bias %d.\n", d3d10_desc
.DepthBias
);
2138 ok(!d3d10_desc
.DepthBiasClamp
, "Got unexpected depth bias clamp %f.\n", d3d10_desc
.DepthBiasClamp
);
2139 ok(!d3d10_desc
.SlopeScaledDepthBias
, "Got unexpected slope scaled depth bias %f.\n",
2140 d3d10_desc
.SlopeScaledDepthBias
);
2141 ok(!!d3d10_desc
.DepthClipEnable
, "Got unexpected depth clip enable %#x.\n", d3d10_desc
.DepthClipEnable
);
2142 ok(!d3d10_desc
.ScissorEnable
, "Got unexpected scissor enable %#x.\n", d3d10_desc
.ScissorEnable
);
2143 ok(!d3d10_desc
.MultisampleEnable
, "Got unexpected multisample enable %#x.\n",
2144 d3d10_desc
.MultisampleEnable
);
2145 ok(!d3d10_desc
.AntialiasedLineEnable
, "Got unexpected antialiased line enable %#x.\n",
2146 d3d10_desc
.AntialiasedLineEnable
);
2148 refcount
= ID3D10RasterizerState_Release(d3d10_rast_state
);
2149 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
2152 refcount
= ID3D11RasterizerState_Release(rast_state2
);
2153 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
2154 refcount
= ID3D11RasterizerState_Release(rast_state1
);
2155 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2157 refcount
= ID3D11Device_Release(device
);
2158 ok(!refcount
, "Device has %u references left.\n", refcount
);
2161 static void test_device_removed_reason(void)
2163 ID3D11Device
*device
;
2167 if (!(device
= create_device(NULL
)))
2169 skip("Failed to create device.\n");
2173 hr
= ID3D11Device_GetDeviceRemovedReason(device
);
2174 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2175 hr
= ID3D11Device_GetDeviceRemovedReason(device
);
2176 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2178 refcount
= ID3D11Device_Release(device
);
2179 ok(!refcount
, "Device has %u references left.\n", refcount
);
2182 static void test_private_data(void)
2184 ULONG refcount
, expected_refcount
;
2185 D3D11_TEXTURE2D_DESC texture_desc
;
2186 ID3D10Texture2D
*d3d10_texture
;
2187 ID3D11Device
*test_object
;
2188 ID3D11Texture2D
*texture
;
2189 IDXGIDevice
*dxgi_device
;
2190 IDXGISurface
*surface
;
2191 ID3D11Device
*device
;
2196 static const GUID test_guid
=
2197 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2198 static const GUID test_guid2
=
2199 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2200 static const DWORD data
[] = {1, 2, 3, 4};
2202 if (!(device
= create_device(NULL
)))
2204 skip("Failed to create device.\n");
2208 test_object
= create_device(NULL
);
2210 texture_desc
.Width
= 512;
2211 texture_desc
.Height
= 512;
2212 texture_desc
.MipLevels
= 1;
2213 texture_desc
.ArraySize
= 1;
2214 texture_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
2215 texture_desc
.SampleDesc
.Count
= 1;
2216 texture_desc
.SampleDesc
.Quality
= 0;
2217 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
2218 texture_desc
.BindFlags
= D3D11_BIND_RENDER_TARGET
;
2219 texture_desc
.CPUAccessFlags
= 0;
2220 texture_desc
.MiscFlags
= 0;
2222 hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
2223 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
2224 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&surface
);
2225 ok(SUCCEEDED(hr
), "Failed to get IDXGISurface, hr %#x.\n", hr
);
2227 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, 0, NULL
);
2228 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
2229 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, NULL
);
2230 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2231 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, ~0u, NULL
);
2232 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2233 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, ~0u, NULL
);
2234 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
2236 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, NULL
);
2237 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2238 size
= sizeof(ptr
) * 2;
2239 ptr
= (IUnknown
*)0xdeadbeef;
2240 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, &size
, &ptr
);
2241 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2242 ok(!ptr
, "Got unexpected pointer %p.\n", ptr
);
2243 ok(size
== sizeof(IUnknown
*), "Got unexpected size %u.\n", size
);
2245 hr
= ID3D11Device_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
2246 ok(SUCCEEDED(hr
), "Failed to get DXGI device, hr %#x.\n", hr
);
2247 size
= sizeof(ptr
) * 2;
2248 ptr
= (IUnknown
*)0xdeadbeef;
2249 hr
= IDXGIDevice_GetPrivateData(dxgi_device
, &test_guid
, &size
, &ptr
);
2250 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2251 ok(!ptr
, "Got unexpected pointer %p.\n", ptr
);
2252 ok(size
== sizeof(IUnknown
*), "Got unexpected size %u.\n", size
);
2253 IDXGIDevice_Release(dxgi_device
);
2255 refcount
= get_refcount((IUnknown
*)test_object
);
2256 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, (IUnknown
*)test_object
);
2257 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2258 expected_refcount
= refcount
+ 1;
2259 refcount
= get_refcount((IUnknown
*)test_object
);
2260 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2261 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, (IUnknown
*)test_object
);
2262 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2263 refcount
= get_refcount((IUnknown
*)test_object
);
2264 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2266 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, NULL
);
2267 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2268 --expected_refcount
;
2269 refcount
= get_refcount((IUnknown
*)test_object
);
2270 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2272 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, (IUnknown
*)test_object
);
2273 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2274 size
= sizeof(data
);
2275 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, size
, data
);
2276 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2277 refcount
= get_refcount((IUnknown
*)test_object
);
2278 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2279 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, 42, NULL
);
2280 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2281 hr
= ID3D11Device_SetPrivateData(device
, &test_guid
, 42, NULL
);
2282 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
2284 hr
= ID3D11Device_SetPrivateDataInterface(device
, &test_guid
, (IUnknown
*)test_object
);
2285 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2286 ++expected_refcount
;
2287 size
= 2 * sizeof(ptr
);
2289 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, &size
, &ptr
);
2290 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2291 ok(size
== sizeof(test_object
), "Got unexpected size %u.\n", size
);
2292 ++expected_refcount
;
2293 refcount
= get_refcount((IUnknown
*)test_object
);
2294 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2295 IUnknown_Release(ptr
);
2296 --expected_refcount
;
2298 ptr
= (IUnknown
*)0xdeadbeef;
2300 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, &size
, NULL
);
2301 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2302 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
2303 size
= 2 * sizeof(ptr
);
2304 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, &size
, NULL
);
2305 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2306 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
2307 refcount
= get_refcount((IUnknown
*)test_object
);
2308 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
2311 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, &size
, &ptr
);
2312 ok(hr
== DXGI_ERROR_MORE_DATA
, "Got unexpected hr %#x.\n", hr
);
2313 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
2314 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
2315 hr
= ID3D11Device_GetPrivateData(device
, &test_guid2
, NULL
, NULL
);
2316 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2318 hr
= ID3D11Device_GetPrivateData(device
, &test_guid2
, &size
, &ptr
);
2319 ok(hr
== DXGI_ERROR_NOT_FOUND
, "Got unexpected hr %#x.\n", hr
);
2320 ok(size
== 0, "Got unexpected size %u.\n", size
);
2321 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
2322 hr
= ID3D11Device_GetPrivateData(device
, &test_guid
, NULL
, &ptr
);
2323 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2324 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
2326 hr
= ID3D11Texture2D_SetPrivateDataInterface(texture
, &test_guid
, (IUnknown
*)test_object
);
2327 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2330 hr
= IDXGISurface_GetPrivateData(surface
, &test_guid
, &size
, &ptr
);
2331 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2332 ok(ptr
== (IUnknown
*)test_object
, "Got unexpected ptr %p, expected %p.\n", ptr
, test_object
);
2333 IUnknown_Release(ptr
);
2335 hr
= ID3D11Texture2D_QueryInterface(texture
, &IID_ID3D10Texture2D
, (void **)&d3d10_texture
);
2336 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
2337 "Texture should implement ID3D10Texture2D.\n");
2342 hr
= ID3D10Texture2D_GetPrivateData(d3d10_texture
, &test_guid
, &size
, &ptr
);
2343 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
2344 ok(ptr
== (IUnknown
*)test_object
, "Got unexpected ptr %p, expected %p.\n", ptr
, test_object
);
2345 IUnknown_Release(ptr
);
2346 ID3D10Texture2D_Release(d3d10_texture
);
2349 IDXGISurface_Release(surface
);
2350 ID3D11Texture2D_Release(texture
);
2351 refcount
= ID3D11Device_Release(device
);
2352 ok(!refcount
, "Device has %u references left.\n", refcount
);
2353 refcount
= ID3D11Device_Release(test_object
);
2354 ok(!refcount
, "Test object has %u references left.\n", refcount
);
2359 test_create_device();
2360 test_device_interfaces();
2361 test_get_immediate_context();
2362 test_create_texture2d();
2363 test_texture2d_interfaces();
2364 test_create_texture3d();
2365 test_texture3d_interfaces();
2366 test_buffer_interfaces();
2367 test_create_depthstencil_view();
2368 test_depthstencil_view_interfaces();
2369 test_create_rendertarget_view();
2370 test_create_shader_resource_view();
2371 test_create_shader();
2372 test_create_sampler_state();
2373 test_create_blend_state();
2374 test_create_depthstencil_state();
2375 test_create_rasterizer_state();
2376 test_device_removed_reason();
2377 test_private_data();