d3d10core: Implement d3d10_device_SetPrivateData().
[wine/multimedia.git] / dlls / d3d10core / tests / device.c
blob24bdddab4a3eeaba8bd329bbdaf725359bc08ebb
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d10.h"
22 #include "wine/test.h"
23 #include <limits.h>
25 struct vec3
27 float x, y, z;
30 static ULONG get_refcount(IUnknown *iface)
32 IUnknown_AddRef(iface);
33 return IUnknown_Release(iface);
36 static BOOL compare_float(float f, float g, unsigned int ulps)
38 int x = *(int *)&f;
39 int y = *(int *)&g;
41 if (x < 0)
42 x = INT_MIN - x;
43 if (y < 0)
44 y = INT_MIN - y;
46 if (abs(x - y) > ulps)
47 return FALSE;
49 return TRUE;
52 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
54 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
55 return FALSE;
56 c1 >>= 8; c2 >>= 8;
57 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
58 return FALSE;
59 c1 >>= 8; c2 >>= 8;
60 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
61 return FALSE;
62 c1 >>= 8; c2 >>= 8;
63 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
64 return FALSE;
65 return TRUE;
68 static DWORD get_texture_color(ID3D10Texture2D *src_texture, unsigned int x, unsigned int y)
70 D3D10_MAPPED_TEXTURE2D mapped_texture;
71 D3D10_TEXTURE2D_DESC texture_desc;
72 ID3D10Texture2D *dst_texture;
73 ID3D10Device *device;
74 DWORD color;
75 HRESULT hr;
77 ID3D10Texture2D_GetDevice(src_texture, &device);
79 ID3D10Texture2D_GetDesc(src_texture, &texture_desc);
80 texture_desc.Usage = D3D10_USAGE_STAGING;
81 texture_desc.BindFlags = 0;
82 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
83 texture_desc.MiscFlags = 0;
84 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
85 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
87 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
88 hr = ID3D10Texture2D_Map(dst_texture, 0, D3D10_MAP_READ, 0, &mapped_texture);
89 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
90 color = *(DWORD *)(((BYTE *)mapped_texture.pData) + mapped_texture.RowPitch * y + x * 4);
91 ID3D10Texture2D_Unmap(dst_texture, 0);
93 ID3D10Texture2D_Release(dst_texture);
94 ID3D10Device_Release(device);
96 return color;
99 static ID3D10Device *create_device(void)
101 ID3D10Device *device;
103 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
104 return device;
105 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
106 return device;
107 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
108 return device;
110 return NULL;
113 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL windowed)
115 IDXGISwapChain *swapchain;
116 DXGI_SWAP_CHAIN_DESC desc;
117 IDXGIDevice *dxgi_device;
118 IDXGIAdapter *adapter;
119 IDXGIFactory *factory;
120 HRESULT hr;
122 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
123 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
124 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
125 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
126 IDXGIDevice_Release(dxgi_device);
127 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
128 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
129 IDXGIAdapter_Release(adapter);
131 desc.BufferDesc.Width = 640;
132 desc.BufferDesc.Height = 480;
133 desc.BufferDesc.RefreshRate.Numerator = 60;
134 desc.BufferDesc.RefreshRate.Denominator = 1;
135 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
136 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
137 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
138 desc.SampleDesc.Count = 1;
139 desc.SampleDesc.Quality = 0;
140 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
141 desc.BufferCount = 1;
142 desc.OutputWindow = window;
143 desc.Windowed = windowed;
144 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
145 desc.Flags = 0;
147 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
148 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
149 IDXGIFactory_Release(factory);
151 return swapchain;
154 static void test_create_texture2d(void)
156 ULONG refcount, expected_refcount;
157 ID3D10Device *device, *tmp;
158 D3D10_TEXTURE2D_DESC desc;
159 ID3D10Texture2D *texture;
160 IDXGISurface *surface;
161 HRESULT hr;
163 if (!(device = create_device()))
165 skip("Failed to create device, skipping tests.\n");
166 return;
169 desc.Width = 512;
170 desc.Height = 512;
171 desc.MipLevels = 1;
172 desc.ArraySize = 1;
173 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
174 desc.SampleDesc.Count = 1;
175 desc.SampleDesc.Quality = 0;
176 desc.Usage = D3D10_USAGE_DEFAULT;
177 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
178 desc.CPUAccessFlags = 0;
179 desc.MiscFlags = 0;
181 expected_refcount = get_refcount((IUnknown *)device) + 1;
182 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
183 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
184 refcount = get_refcount((IUnknown *)device);
185 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
186 tmp = NULL;
187 expected_refcount = refcount + 1;
188 ID3D10Texture2D_GetDevice(texture, &tmp);
189 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
190 refcount = get_refcount((IUnknown *)device);
191 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
192 ID3D10Device_Release(tmp);
194 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
195 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
196 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
197 ID3D10Texture2D_Release(texture);
199 desc.MipLevels = 0;
200 expected_refcount = get_refcount((IUnknown *)device) + 1;
201 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
202 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
203 refcount = get_refcount((IUnknown *)device);
204 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
205 tmp = NULL;
206 expected_refcount = refcount + 1;
207 ID3D10Texture2D_GetDevice(texture, &tmp);
208 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
209 refcount = get_refcount((IUnknown *)device);
210 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
211 ID3D10Device_Release(tmp);
213 ID3D10Texture2D_GetDesc(texture, &desc);
214 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
215 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
216 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
217 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
218 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
219 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
220 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
221 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected MipLevels %u.\n", desc.Usage);
222 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
223 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
224 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
226 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
227 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
228 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
229 ID3D10Texture2D_Release(texture);
231 desc.MipLevels = 1;
232 desc.ArraySize = 2;
233 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
234 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
236 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
237 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
238 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
239 ID3D10Texture2D_Release(texture);
241 refcount = ID3D10Device_Release(device);
242 ok(!refcount, "Device has %u references left.\n", refcount);
245 static void test_create_texture3d(void)
247 ULONG refcount, expected_refcount;
248 ID3D10Device *device, *tmp;
249 D3D10_TEXTURE3D_DESC desc;
250 ID3D10Texture3D *texture;
251 IDXGISurface *surface;
252 HRESULT hr;
254 if (!(device = create_device()))
256 skip("Failed to create device, skipping tests.\n");
257 return;
260 desc.Width = 64;
261 desc.Height = 64;
262 desc.Depth = 64;
263 desc.MipLevels = 1;
264 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
265 desc.Usage = D3D10_USAGE_DEFAULT;
266 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
267 desc.CPUAccessFlags = 0;
268 desc.MiscFlags = 0;
270 expected_refcount = get_refcount((IUnknown *)device) + 1;
271 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
272 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
273 refcount = get_refcount((IUnknown *)device);
274 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
275 tmp = NULL;
276 expected_refcount = refcount + 1;
277 ID3D10Texture3D_GetDevice(texture, &tmp);
278 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
279 refcount = get_refcount((IUnknown *)device);
280 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
281 ID3D10Device_Release(tmp);
283 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
284 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
285 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
286 ID3D10Texture3D_Release(texture);
288 desc.MipLevels = 0;
289 expected_refcount = get_refcount((IUnknown *)device) + 1;
290 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
291 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
292 refcount = get_refcount((IUnknown *)device);
293 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
294 tmp = NULL;
295 expected_refcount = refcount + 1;
296 ID3D10Texture3D_GetDevice(texture, &tmp);
297 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
298 refcount = get_refcount((IUnknown *)device);
299 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
300 ID3D10Device_Release(tmp);
302 ID3D10Texture3D_GetDesc(texture, &desc);
303 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
304 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
305 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
306 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
307 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
308 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected MipLevels %u.\n", desc.Usage);
309 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
310 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
311 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
313 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
314 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
315 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
316 ID3D10Texture3D_Release(texture);
318 refcount = ID3D10Device_Release(device);
319 ok(!refcount, "Device has %u references left.\n", refcount);
322 static void test_create_depthstencil_view(void)
324 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
325 D3D10_TEXTURE2D_DESC texture_desc;
326 ULONG refcount, expected_refcount;
327 ID3D10DepthStencilView *dsview;
328 ID3D10Device *device, *tmp;
329 ID3D10Texture2D *texture;
330 HRESULT hr;
332 if (!(device = create_device()))
334 skip("Failed to create device, skipping tests.\n");
335 return;
338 texture_desc.Width = 512;
339 texture_desc.Height = 512;
340 texture_desc.MipLevels = 1;
341 texture_desc.ArraySize = 1;
342 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
343 texture_desc.SampleDesc.Count = 1;
344 texture_desc.SampleDesc.Quality = 0;
345 texture_desc.Usage = D3D10_USAGE_DEFAULT;
346 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
347 texture_desc.CPUAccessFlags = 0;
348 texture_desc.MiscFlags = 0;
350 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
351 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
353 expected_refcount = get_refcount((IUnknown *)device) + 1;
354 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
355 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr);
356 refcount = get_refcount((IUnknown *)device);
357 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
358 tmp = NULL;
359 expected_refcount = refcount + 1;
360 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
361 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
362 refcount = get_refcount((IUnknown *)device);
363 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
364 ID3D10Device_Release(tmp);
366 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
367 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
368 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
369 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
370 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
372 ID3D10DepthStencilView_Release(dsview);
373 ID3D10Texture2D_Release(texture);
375 refcount = ID3D10Device_Release(device);
376 ok(!refcount, "Device has %u references left.\n", refcount);
379 static void test_create_rendertarget_view(void)
381 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
382 D3D10_TEXTURE2D_DESC texture_desc;
383 ULONG refcount, expected_refcount;
384 D3D10_BUFFER_DESC buffer_desc;
385 ID3D10RenderTargetView *rtview;
386 ID3D10Device *device, *tmp;
387 ID3D10Texture2D *texture;
388 ID3D10Buffer *buffer;
389 HRESULT hr;
391 if (!(device = create_device()))
393 skip("Failed to create device, skipping tests.\n");
394 return;
397 buffer_desc.ByteWidth = 1024;
398 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
399 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
400 buffer_desc.CPUAccessFlags = 0;
401 buffer_desc.MiscFlags = 0;
403 expected_refcount = get_refcount((IUnknown *)device) + 1;
404 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
405 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
406 refcount = get_refcount((IUnknown *)device);
407 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
408 tmp = NULL;
409 expected_refcount = refcount + 1;
410 ID3D10Buffer_GetDevice(buffer, &tmp);
411 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
412 refcount = get_refcount((IUnknown *)device);
413 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
414 ID3D10Device_Release(tmp);
416 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
417 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
418 U(rtv_desc).Buffer.ElementOffset = 0;
419 U(rtv_desc).Buffer.ElementWidth = 64;
421 expected_refcount = get_refcount((IUnknown *)device) + 1;
422 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
423 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
424 refcount = get_refcount((IUnknown *)device);
425 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
426 tmp = NULL;
427 expected_refcount = refcount + 1;
428 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
429 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
430 refcount = get_refcount((IUnknown *)device);
431 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
432 ID3D10Device_Release(tmp);
434 ID3D10RenderTargetView_Release(rtview);
435 ID3D10Buffer_Release(buffer);
437 texture_desc.Width = 512;
438 texture_desc.Height = 512;
439 texture_desc.MipLevels = 1;
440 texture_desc.ArraySize = 1;
441 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
442 texture_desc.SampleDesc.Count = 1;
443 texture_desc.SampleDesc.Quality = 0;
444 texture_desc.Usage = D3D10_USAGE_DEFAULT;
445 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
446 texture_desc.CPUAccessFlags = 0;
447 texture_desc.MiscFlags = 0;
449 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
450 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
452 /* For texture resources it's allowed to specify NULL as desc */
453 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
454 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
456 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
457 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
458 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
459 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
460 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
462 ID3D10RenderTargetView_Release(rtview);
463 ID3D10Texture2D_Release(texture);
465 refcount = ID3D10Device_Release(device);
466 ok(!refcount, "Device has %u references left.\n", refcount);
469 static void test_create_shader_resource_view(void)
471 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
472 D3D10_TEXTURE2D_DESC texture_desc;
473 ULONG refcount, expected_refcount;
474 ID3D10ShaderResourceView *srview;
475 D3D10_BUFFER_DESC buffer_desc;
476 ID3D10Device *device, *tmp;
477 ID3D10Texture2D *texture;
478 ID3D10Buffer *buffer;
479 HRESULT hr;
481 if (!(device = create_device()))
483 skip("Failed to create device, skipping tests.\n");
484 return;
487 buffer_desc.ByteWidth = 1024;
488 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
489 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
490 buffer_desc.CPUAccessFlags = 0;
491 buffer_desc.MiscFlags = 0;
493 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
494 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
496 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
497 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
499 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
500 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
501 U(srv_desc).Buffer.ElementOffset = 0;
502 U(srv_desc).Buffer.ElementWidth = 64;
504 expected_refcount = get_refcount((IUnknown *)device) + 1;
505 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
506 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
507 refcount = get_refcount((IUnknown *)device);
508 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
509 tmp = NULL;
510 expected_refcount = refcount + 1;
511 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
512 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
513 refcount = get_refcount((IUnknown *)device);
514 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
515 ID3D10Device_Release(tmp);
517 ID3D10ShaderResourceView_Release(srview);
518 ID3D10Buffer_Release(buffer);
520 texture_desc.Width = 512;
521 texture_desc.Height = 512;
522 texture_desc.MipLevels = 0;
523 texture_desc.ArraySize = 1;
524 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
525 texture_desc.SampleDesc.Count = 1;
526 texture_desc.SampleDesc.Quality = 0;
527 texture_desc.Usage = D3D10_USAGE_DEFAULT;
528 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
529 texture_desc.CPUAccessFlags = 0;
530 texture_desc.MiscFlags = 0;
532 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
533 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
535 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srview);
536 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
538 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
539 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
540 ok(srv_desc.ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D,
541 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
542 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
543 U(srv_desc).Texture2D.MostDetailedMip);
544 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
546 ID3D10ShaderResourceView_Release(srview);
547 ID3D10Texture2D_Release(texture);
549 refcount = ID3D10Device_Release(device);
550 ok(!refcount, "Device has %u references left.\n", refcount);
553 static void test_create_shader(void)
555 #if 0
556 float4 light;
557 float4x4 mat;
559 struct input
561 float4 position : POSITION;
562 float3 normal : NORMAL;
565 struct output
567 float4 position : POSITION;
568 float4 diffuse : COLOR;
571 output main(const input v)
573 output o;
575 o.position = mul(v.position, mat);
576 o.diffuse = dot((float3)light, v.normal);
578 return o;
580 #endif
581 static const DWORD vs_4_0[] =
583 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
584 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
585 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
586 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
587 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
588 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
589 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
590 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
591 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
592 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
593 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
594 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
595 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
596 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
597 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
598 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
601 static const DWORD vs_2_0[] =
603 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
604 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
605 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
606 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
607 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
608 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
609 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
610 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
611 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
612 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
613 0x90e40001, 0x0000ffff,
616 static const DWORD vs_3_0[] =
618 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
619 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
620 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
621 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
622 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
623 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
624 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
625 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
626 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
627 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
628 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
629 0x0000ffff,
632 #if 0
633 float4 main(const float4 color : COLOR) : SV_TARGET
635 float4 o;
637 o = color;
639 return o;
641 #endif
642 static const DWORD ps_4_0[] =
644 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
645 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
646 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
647 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
648 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
649 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
650 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
651 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
652 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
653 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
654 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
655 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
656 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
657 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
658 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
659 0x00000000, 0x00000000,
662 ULONG refcount, expected_refcount;
663 ID3D10VertexShader *vs = NULL;
664 ID3D10PixelShader *ps = NULL;
665 ID3D10Device *device, *tmp;
666 HRESULT hr;
668 if (!(device = create_device()))
670 skip("Failed to create device, skipping tests.\n");
671 return;
674 expected_refcount = get_refcount((IUnknown *)device) + 1;
675 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
676 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
677 refcount = get_refcount((IUnknown *)device);
678 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
679 tmp = NULL;
680 expected_refcount = refcount + 1;
681 ID3D10VertexShader_GetDevice(vs, &tmp);
682 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
683 refcount = get_refcount((IUnknown *)device);
684 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
685 ID3D10Device_Release(tmp);
686 ID3D10VertexShader_Release(vs);
688 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
689 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
691 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
692 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
694 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
695 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
697 expected_refcount = get_refcount((IUnknown *)device) + 1;
698 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
699 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
700 refcount = get_refcount((IUnknown *)device);
701 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
702 tmp = NULL;
703 expected_refcount = refcount + 1;
704 ID3D10PixelShader_GetDevice(ps, &tmp);
705 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
706 refcount = get_refcount((IUnknown *)device);
707 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
708 ID3D10Device_Release(tmp);
709 ID3D10PixelShader_Release(ps);
711 refcount = ID3D10Device_Release(device);
712 ok(!refcount, "Device has %u references left.\n", refcount);
715 static void test_create_sampler_state(void)
717 ID3D10SamplerState *sampler_state1, *sampler_state2;
718 ULONG refcount, expected_refcount;
719 D3D10_SAMPLER_DESC sampler_desc;
720 ID3D10Device *device, *tmp;
721 HRESULT hr;
723 if (!(device = create_device()))
725 skip("Failed to create device, skipping tests.\n");
726 return;
729 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
730 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
732 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
733 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
734 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
735 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
736 sampler_desc.MipLODBias = 0.0f;
737 sampler_desc.MaxAnisotropy = 16;
738 sampler_desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
739 sampler_desc.BorderColor[0] = 0.0f;
740 sampler_desc.BorderColor[1] = 1.0f;
741 sampler_desc.BorderColor[2] = 0.0f;
742 sampler_desc.BorderColor[3] = 1.0f;
743 sampler_desc.MinLOD = 0.0f;
744 sampler_desc.MaxLOD = 16.0f;
746 expected_refcount = get_refcount((IUnknown *)device) + 1;
747 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state1);
748 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
749 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state2);
750 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
751 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
752 refcount = get_refcount((IUnknown *)device);
753 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
754 tmp = NULL;
755 expected_refcount = refcount + 1;
756 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
757 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
758 refcount = get_refcount((IUnknown *)device);
759 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
760 ID3D10Device_Release(tmp);
762 refcount = ID3D10SamplerState_Release(sampler_state2);
763 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
764 refcount = ID3D10SamplerState_Release(sampler_state1);
765 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
767 refcount = ID3D10Device_Release(device);
768 ok(!refcount, "Device has %u references left.\n", refcount);
771 static void test_create_blend_state(void)
773 ID3D10BlendState *blend_state1, *blend_state2;
774 ULONG refcount, expected_refcount;
775 D3D10_BLEND_DESC blend_desc;
776 ID3D10Device *device, *tmp;
777 HRESULT hr;
779 if (!(device = create_device()))
781 skip("Failed to create device, skipping tests.\n");
782 return;
785 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
786 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
788 blend_desc.AlphaToCoverageEnable = FALSE;
789 blend_desc.BlendEnable[0] = FALSE;
790 blend_desc.BlendEnable[1] = FALSE;
791 blend_desc.BlendEnable[2] = FALSE;
792 blend_desc.BlendEnable[3] = FALSE;
793 blend_desc.BlendEnable[4] = FALSE;
794 blend_desc.BlendEnable[5] = FALSE;
795 blend_desc.BlendEnable[6] = FALSE;
796 blend_desc.BlendEnable[7] = FALSE;
797 blend_desc.SrcBlend = D3D10_BLEND_ONE;
798 blend_desc.DestBlend = D3D10_BLEND_ZERO;
799 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
800 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
801 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
802 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
803 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
804 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
805 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
806 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
807 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
808 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
809 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
810 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
812 expected_refcount = get_refcount((IUnknown *)device) + 1;
813 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
814 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
815 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
816 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
817 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
818 refcount = get_refcount((IUnknown *)device);
819 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
820 tmp = NULL;
821 expected_refcount = refcount + 1;
822 ID3D10BlendState_GetDevice(blend_state1, &tmp);
823 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
824 refcount = get_refcount((IUnknown *)device);
825 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
826 ID3D10Device_Release(tmp);
828 refcount = ID3D10BlendState_Release(blend_state2);
829 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
830 refcount = ID3D10BlendState_Release(blend_state1);
831 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
833 refcount = ID3D10Device_Release(device);
834 ok(!refcount, "Device has %u references left.\n", refcount);
837 static void test_create_depthstencil_state(void)
839 ID3D10DepthStencilState *ds_state1, *ds_state2;
840 ULONG refcount, expected_refcount;
841 D3D10_DEPTH_STENCIL_DESC ds_desc;
842 ID3D10Device *device, *tmp;
843 HRESULT hr;
845 if (!(device = create_device()))
847 skip("Failed to create device, skipping tests.\n");
848 return;
851 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
852 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
854 ds_desc.DepthEnable = TRUE;
855 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
856 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
857 ds_desc.StencilEnable = FALSE;
858 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
859 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
860 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
861 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
862 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
863 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
864 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
865 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
866 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
867 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
869 expected_refcount = get_refcount((IUnknown *)device) + 1;
870 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
871 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
872 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
873 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
874 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
875 refcount = get_refcount((IUnknown *)device);
876 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
877 tmp = NULL;
878 expected_refcount = refcount + 1;
879 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
880 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
881 refcount = get_refcount((IUnknown *)device);
882 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
883 ID3D10Device_Release(tmp);
885 refcount = ID3D10DepthStencilState_Release(ds_state2);
886 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
887 refcount = ID3D10DepthStencilState_Release(ds_state1);
888 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
890 refcount = ID3D10Device_Release(device);
891 ok(!refcount, "Device has %u references left.\n", refcount);
894 static void test_create_rasterizer_state(void)
896 ID3D10RasterizerState *rast_state1, *rast_state2;
897 ULONG refcount, expected_refcount;
898 D3D10_RASTERIZER_DESC rast_desc;
899 ID3D10Device *device, *tmp;
900 HRESULT hr;
902 if (!(device = create_device()))
904 skip("Failed to create device, skipping tests.\n");
905 return;
908 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
909 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
911 rast_desc.FillMode = D3D10_FILL_SOLID;
912 rast_desc.CullMode = D3D10_CULL_BACK;
913 rast_desc.FrontCounterClockwise = FALSE;
914 rast_desc.DepthBias = 0;
915 rast_desc.DepthBiasClamp = 0.0f;
916 rast_desc.SlopeScaledDepthBias = 0.0f;
917 rast_desc.DepthClipEnable = TRUE;
918 rast_desc.ScissorEnable = FALSE;
919 rast_desc.MultisampleEnable = FALSE;
920 rast_desc.AntialiasedLineEnable = FALSE;
922 expected_refcount = get_refcount((IUnknown *)device) + 1;
923 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
924 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
925 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
926 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
927 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
928 refcount = get_refcount((IUnknown *)device);
929 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
930 tmp = NULL;
931 expected_refcount = refcount + 1;
932 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
933 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
934 refcount = get_refcount((IUnknown *)device);
935 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
936 ID3D10Device_Release(tmp);
938 refcount = ID3D10RasterizerState_Release(rast_state2);
939 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
940 refcount = ID3D10RasterizerState_Release(rast_state1);
941 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
943 refcount = ID3D10Device_Release(device);
944 ok(!refcount, "Device has %u references left.\n", refcount);
947 static void test_create_predicate(void)
949 ULONG refcount, expected_refcount;
950 D3D10_QUERY_DESC query_desc;
951 ID3D10Predicate *predicate;
952 ID3D10Device *device, *tmp;
953 HRESULT hr;
955 if (!(device = create_device()))
957 skip("Failed to create device, skipping tests.\n");
958 return;
961 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
962 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
964 query_desc.Query = D3D10_QUERY_OCCLUSION;
965 query_desc.MiscFlags = 0;
966 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
967 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
969 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
970 expected_refcount = get_refcount((IUnknown *)device) + 1;
971 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
972 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
973 refcount = get_refcount((IUnknown *)device);
974 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
975 tmp = NULL;
976 expected_refcount = refcount + 1;
977 ID3D10Predicate_GetDevice(predicate, &tmp);
978 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
979 refcount = get_refcount((IUnknown *)device);
980 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
981 ID3D10Device_Release(tmp);
982 ID3D10Predicate_Release(predicate);
984 query_desc.Query = D3D10_QUERY_SO_OVERFLOW_PREDICATE;
985 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
986 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
987 if (SUCCEEDED(hr))
988 ID3D10Predicate_Release(predicate);
990 refcount = ID3D10Device_Release(device);
991 ok(!refcount, "Device has %u references left.\n", refcount);
994 static void test_device_removed_reason(void)
996 ID3D10Device *device;
997 ULONG refcount;
998 HRESULT hr;
1000 if (!(device = create_device()))
1002 skip("Failed to create device, skipping tests.\n");
1003 return;
1006 hr = ID3D10Device_GetDeviceRemovedReason(device);
1007 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1008 hr = ID3D10Device_GetDeviceRemovedReason(device);
1009 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1011 refcount = ID3D10Device_Release(device);
1012 ok(!refcount, "Device has %u references left.\n", refcount);
1015 static void test_scissor(void)
1017 D3D10_SUBRESOURCE_DATA buffer_data;
1018 ID3D10InputLayout *input_layout;
1019 D3D10_RASTERIZER_DESC rs_desc;
1020 D3D10_BUFFER_DESC buffer_desc;
1021 ID3D10RenderTargetView *rtv;
1022 ID3D10Texture2D *backbuffer;
1023 unsigned int stride, offset;
1024 ID3D10RasterizerState *rs;
1025 IDXGISwapChain *swapchain;
1026 D3D10_RECT scissor_rect;
1027 ID3D10VertexShader *vs;
1028 ID3D10PixelShader *ps;
1029 ID3D10Device *device;
1030 D3D10_VIEWPORT vp;
1031 ID3D10Buffer *vb;
1032 ULONG refcount;
1033 DWORD color;
1034 HWND window;
1035 HRESULT hr;
1037 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
1038 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1040 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1042 static const DWORD vs_code[] =
1044 /* float4 main(float4 position : POSITION) : SV_POSITION
1046 * return position;
1047 * } */
1048 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
1049 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
1050 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1051 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1052 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1053 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1054 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1055 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1056 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1057 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
1058 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1059 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1060 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1061 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1063 static const DWORD ps_code[] =
1065 /* float4 main(float4 position : SV_POSITION) : SV_Target
1067 * return float4(0.0, 1.0, 0.0, 1.0);
1068 * } */
1069 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
1070 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
1071 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1072 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1073 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1074 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1075 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1076 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
1077 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
1078 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
1079 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
1080 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1081 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1082 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1084 static const struct
1086 float x, y;
1088 quad[] =
1090 {-1.0f, -1.0f},
1091 {-1.0f, 1.0f},
1092 { 1.0f, -1.0f},
1093 { 1.0f, 1.0f},
1096 if (!(device = create_device()))
1098 skip("Failed to create device, skipping tests.\n");
1099 return;
1101 window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1102 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1103 swapchain = create_swapchain(device, window, TRUE);
1104 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
1105 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
1107 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1108 vs_code, sizeof(vs_code), &input_layout);
1109 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1111 buffer_desc.ByteWidth = sizeof(quad);
1112 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1113 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
1114 buffer_desc.CPUAccessFlags = 0;
1115 buffer_desc.MiscFlags = 0;
1117 buffer_data.pSysMem = quad;
1118 buffer_data.SysMemPitch = 0;
1119 buffer_data.SysMemSlicePitch = 0;
1121 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
1122 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
1123 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
1124 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1125 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
1126 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1128 rs_desc.FillMode = D3D10_FILL_SOLID;
1129 rs_desc.CullMode = D3D10_CULL_BACK;
1130 rs_desc.FrontCounterClockwise = FALSE;
1131 rs_desc.DepthBias = 0;
1132 rs_desc.DepthBiasClamp = 0.0f;
1133 rs_desc.SlopeScaledDepthBias = 0.0f;
1134 rs_desc.DepthClipEnable = TRUE;
1135 rs_desc.ScissorEnable = TRUE;
1136 rs_desc.MultisampleEnable = FALSE;
1137 rs_desc.AntialiasedLineEnable = FALSE;
1138 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
1139 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1141 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtv);
1142 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1144 ID3D10Device_IASetInputLayout(device, input_layout);
1145 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1146 stride = sizeof(*quad);
1147 offset = 0;
1148 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
1149 ID3D10Device_VSSetShader(device, vs);
1150 ID3D10Device_PSSetShader(device, ps);
1152 vp.TopLeftX = 0;
1153 vp.TopLeftY = 0;
1154 vp.Width = 640;
1155 vp.Height = 480;
1156 vp.MinDepth = 0.0f;
1157 vp.MaxDepth = 1.0f;
1158 ID3D10Device_RSSetViewports(device, 1, &vp);
1160 scissor_rect.left = 160;
1161 scissor_rect.top = 120;
1162 scissor_rect.right = 480;
1163 scissor_rect.bottom = 360;
1164 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
1166 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
1168 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1169 color = get_texture_color(backbuffer, 320, 240);
1170 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1172 ID3D10Device_Draw(device, 4, 0);
1173 color = get_texture_color(backbuffer, 320, 60);
1174 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1175 color = get_texture_color(backbuffer, 80, 240);
1176 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1177 color = get_texture_color(backbuffer, 320, 240);
1178 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1179 color = get_texture_color(backbuffer, 560, 240);
1180 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1181 color = get_texture_color(backbuffer, 320, 420);
1182 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1184 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1185 ID3D10Device_RSSetState(device, rs);
1186 ID3D10Device_Draw(device, 4, 0);
1187 color = get_texture_color(backbuffer, 320, 60);
1188 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1189 color = get_texture_color(backbuffer, 80, 240);
1190 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1191 color = get_texture_color(backbuffer, 320, 240);
1192 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1193 color = get_texture_color(backbuffer, 560, 240);
1194 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1195 color = get_texture_color(backbuffer, 320, 420);
1196 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1198 ID3D10RenderTargetView_Release(rtv);
1199 ID3D10RasterizerState_Release(rs);
1200 ID3D10PixelShader_Release(ps);
1201 ID3D10VertexShader_Release(vs);
1202 ID3D10Buffer_Release(vb);
1203 ID3D10InputLayout_Release(input_layout);
1204 ID3D10Texture2D_Release(backbuffer);
1205 IDXGISwapChain_Release(swapchain);
1206 refcount = ID3D10Device_Release(device);
1207 ok(!refcount, "Device has %u references left.\n", refcount);
1208 DestroyWindow(window);
1211 static void test_clear_state(void)
1213 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1215 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1217 #if 0
1218 float4 main(float4 pos : POSITION) : POSITION
1220 return pos;
1222 #endif
1223 static const DWORD simple_vs[] =
1225 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
1226 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1227 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1228 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1229 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
1230 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
1231 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1234 #if 0
1235 struct gs_out
1237 float4 pos : SV_POSITION;
1240 [maxvertexcount(4)]
1241 void main(point float4 vin[1] : POSTION, inout TriangleStream<gs_out> vout)
1243 float offset = 0.1 * vin[0].w;
1244 gs_out v;
1246 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1247 vout.Append(v);
1248 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1249 vout.Append(v);
1250 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1251 vout.Append(v);
1252 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1253 vout.Append(v);
1255 #endif
1256 static const DWORD simple_gs[] =
1258 0x43425844, 0x9786dfb7, 0xad78ae61, 0x34364b9a, 0xf3b719f8, 0x00000001, 0x00000238, 0x00000003,
1259 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
1260 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x54534f50, 0x004e4f49, 0x4e47534f,
1261 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
1262 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040, 0x00000068,
1263 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c,
1264 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032,
1265 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x3dcccccd,
1266 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000,
1267 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1268 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032, 0x00100052,
1269 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000, 0x3dcccccd,
1270 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010002a,
1271 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013,
1272 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1273 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1274 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x001020c2,
1275 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1278 #if 0
1279 float4 main(float4 color : COLOR) : SV_TARGET
1281 return color;
1283 #endif
1284 static const DWORD simple_ps[] =
1286 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
1287 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
1288 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
1289 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1290 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
1291 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
1292 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1295 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1296 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1297 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1298 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1299 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1300 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1301 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1302 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1303 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
1304 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1305 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1306 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1307 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1308 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1309 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
1310 ID3D10InputLayout *tmp_input_layout, *input_layout;
1311 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
1312 ID3D10BlendState *tmp_blend_state, *blend_state;
1313 ID3D10RasterizerState *tmp_rs_state, *rs_state;
1314 ID3D10Predicate *tmp_predicate, *predicate;
1315 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
1316 ID3D10DepthStencilView *tmp_dsv, *dsv;
1317 D3D10_PRIMITIVE_TOPOLOGY topology;
1318 D3D10_TEXTURE2D_DESC texture_desc;
1319 ID3D10GeometryShader *tmp_gs, *gs;
1320 D3D10_DEPTH_STENCIL_DESC ds_desc;
1321 ID3D10VertexShader *tmp_vs, *vs;
1322 D3D10_SAMPLER_DESC sampler_desc;
1323 D3D10_QUERY_DESC predicate_desc;
1324 ID3D10PixelShader *tmp_ps, *ps;
1325 D3D10_RASTERIZER_DESC rs_desc;
1326 D3D10_BUFFER_DESC buffer_desc;
1327 D3D10_BLEND_DESC blend_desc;
1328 ID3D10Texture2D *ds_texture;
1329 float blend_factor[4];
1330 ID3D10Device *device;
1331 BOOL predicate_value;
1332 DXGI_FORMAT format;
1333 UINT sample_mask;
1334 UINT stencil_ref;
1335 ULONG refcount;
1336 UINT count, i;
1337 HRESULT hr;
1339 if (!(device = create_device()))
1341 skip("Failed to create device, skipping tests.\n");
1342 return;
1345 /* Verify the initial state after device creation. */
1347 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1348 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1350 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1352 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1353 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1355 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1357 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1358 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1360 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1362 ID3D10Device_VSGetShader(device, &tmp_vs);
1363 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1365 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1366 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1368 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1370 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1371 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1373 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1375 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1376 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1378 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1380 ID3D10Device_GSGetShader(device, &tmp_gs);
1381 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1383 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1384 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1386 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1388 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1389 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1391 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1393 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1394 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1396 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1398 ID3D10Device_PSGetShader(device, &tmp_ps);
1399 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1401 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1402 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1404 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1405 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1406 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1408 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1409 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
1410 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
1411 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
1412 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1413 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
1414 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1415 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
1417 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1418 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
1419 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
1420 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
1421 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1422 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1423 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
1424 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1425 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
1426 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
1427 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1428 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1430 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
1432 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
1434 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1435 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
1436 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1437 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1438 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1439 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1441 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1442 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1443 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1445 ID3D10Device_RSGetViewports(device, &count, NULL);
1446 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
1447 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1448 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1449 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1450 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1452 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
1453 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
1454 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1455 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1456 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1458 ID3D10Device_RSGetState(device, &tmp_rs_state);
1459 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
1461 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1462 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1464 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
1465 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1468 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1469 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
1470 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1472 /* Create resources. */
1474 buffer_desc.ByteWidth = 1024;
1475 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1476 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
1477 buffer_desc.CPUAccessFlags = 0;
1478 buffer_desc.MiscFlags = 0;
1480 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1482 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb[i]);
1483 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1486 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE;
1488 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1490 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer[i]);
1491 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1493 stride[i] = (i + 1) * 4;
1494 offset[i] = (i + 1) * 16;
1497 buffer_desc.BindFlags = D3D10_BIND_STREAM_OUTPUT;
1499 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1501 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &so_buffer[i]);
1502 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1505 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1506 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
1507 U(srv_desc).Buffer.ElementOffset = 0;
1508 U(srv_desc).Buffer.ElementWidth = 64;
1510 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1512 hr = ID3D10Device_CreateShaderResourceView(device,
1513 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
1514 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
1517 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
1518 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
1519 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
1520 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
1521 sampler_desc.MipLODBias = 0.0f;
1522 sampler_desc.MaxAnisotropy = 16;
1523 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
1524 sampler_desc.BorderColor[0] = 0.0f;
1525 sampler_desc.BorderColor[1] = 0.0f;
1526 sampler_desc.BorderColor[2] = 0.0f;
1527 sampler_desc.BorderColor[3] = 0.0f;
1528 sampler_desc.MinLOD = 0.0f;
1529 sampler_desc.MaxLOD = 16.0f;
1531 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1533 sampler_desc.MinLOD = (float)i;
1535 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
1536 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1539 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
1540 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1542 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
1543 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
1545 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
1546 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1548 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1549 simple_vs, sizeof(simple_vs), &input_layout);
1550 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1552 blend_desc.AlphaToCoverageEnable = FALSE;
1553 blend_desc.BlendEnable[0] = FALSE;
1554 blend_desc.BlendEnable[1] = FALSE;
1555 blend_desc.BlendEnable[2] = FALSE;
1556 blend_desc.BlendEnable[3] = FALSE;
1557 blend_desc.BlendEnable[4] = FALSE;
1558 blend_desc.BlendEnable[5] = FALSE;
1559 blend_desc.BlendEnable[6] = FALSE;
1560 blend_desc.BlendEnable[7] = FALSE;
1561 blend_desc.SrcBlend = D3D10_BLEND_ONE;
1562 blend_desc.DestBlend = D3D10_BLEND_ZERO;
1563 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
1564 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
1565 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
1566 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
1567 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
1568 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
1569 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
1570 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
1571 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
1572 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
1573 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
1574 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
1576 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
1577 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1579 ds_desc.DepthEnable = TRUE;
1580 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
1581 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
1582 ds_desc.StencilEnable = FALSE;
1583 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
1584 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
1585 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1586 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1587 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1588 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1589 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1590 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1591 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1592 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1594 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
1595 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
1597 texture_desc.Width = 512;
1598 texture_desc.Height = 512;
1599 texture_desc.MipLevels = 1;
1600 texture_desc.ArraySize = 1;
1601 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1602 texture_desc.SampleDesc.Count = 1;
1603 texture_desc.SampleDesc.Quality = 0;
1604 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1605 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1606 texture_desc.CPUAccessFlags = 0;
1607 texture_desc.MiscFlags = 0;
1609 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1611 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
1612 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1615 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1616 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1618 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
1619 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1621 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1623 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
1624 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1627 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
1628 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
1630 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1632 tmp_rect[i].left = i;
1633 tmp_rect[i].top = i * 2;
1634 tmp_rect[i].right = i + 1;
1635 tmp_rect[i].bottom = (i + 1) * 2;
1637 tmp_viewport[i].TopLeftX = i * 3;
1638 tmp_viewport[i].TopLeftY = i * 4;
1639 tmp_viewport[i].Width = 3;
1640 tmp_viewport[i].Height = 4;
1641 tmp_viewport[i].MinDepth = i * 0.01f;
1642 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
1645 rs_desc.FillMode = D3D10_FILL_SOLID;
1646 rs_desc.CullMode = D3D10_CULL_BACK;
1647 rs_desc.FrontCounterClockwise = FALSE;
1648 rs_desc.DepthBias = 0;
1649 rs_desc.DepthBiasClamp = 0.0f;
1650 rs_desc.SlopeScaledDepthBias = 0.0f;
1651 rs_desc.DepthClipEnable = TRUE;
1652 rs_desc.ScissorEnable = FALSE;
1653 rs_desc.MultisampleEnable = FALSE;
1654 rs_desc.AntialiasedLineEnable = FALSE;
1656 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
1657 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1659 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
1660 predicate_desc.MiscFlags = 0;
1662 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
1663 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1665 /* Setup state. */
1666 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1667 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1668 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1669 ID3D10Device_VSSetShader(device, vs);
1671 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1672 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1673 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1674 ID3D10Device_GSSetShader(device, gs);
1676 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1677 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1678 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1679 ID3D10Device_PSSetShader(device, ps);
1681 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
1682 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
1683 ID3D10Device_IASetInputLayout(device, input_layout);
1684 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1686 blend_factor[0] = 0.1f;
1687 blend_factor[1] = 0.2f;
1688 blend_factor[2] = 0.3f;
1689 blend_factor[3] = 0.4f;
1690 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
1691 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
1692 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
1694 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
1695 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
1696 ID3D10Device_RSSetState(device, rs_state);
1698 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
1700 ID3D10Device_SetPredication(device, predicate, TRUE);
1702 /* Verify the set state. */
1704 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1705 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1707 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1708 tmp_buffer[i], i, cb[i]);
1709 ID3D10Buffer_Release(tmp_buffer[i]);
1711 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1712 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1714 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1715 tmp_srv[i], i, srv[i]);
1716 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1718 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1719 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1721 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1722 tmp_sampler[i], i, sampler[i]);
1723 ID3D10SamplerState_Release(tmp_sampler[i]);
1725 ID3D10Device_VSGetShader(device, &tmp_vs);
1726 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
1727 ID3D10VertexShader_Release(tmp_vs);
1729 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1730 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1732 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1733 tmp_buffer[i], i, cb[i]);
1734 ID3D10Buffer_Release(tmp_buffer[i]);
1736 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1737 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1739 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1740 tmp_srv[i], i, srv[i]);
1741 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1743 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1744 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1746 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1747 tmp_sampler[i], i, sampler[i]);
1748 ID3D10SamplerState_Release(tmp_sampler[i]);
1750 ID3D10Device_GSGetShader(device, &tmp_gs);
1751 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
1752 ID3D10GeometryShader_Release(tmp_gs);
1754 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1755 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1757 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1758 tmp_buffer[i], i, cb[i]);
1759 ID3D10Buffer_Release(tmp_buffer[i]);
1761 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1762 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1764 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1765 tmp_srv[i], i, srv[i]);
1766 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1768 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1769 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1771 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1772 tmp_sampler[i], i, sampler[i]);
1773 ID3D10SamplerState_Release(tmp_sampler[i]);
1775 ID3D10Device_PSGetShader(device, &tmp_ps);
1776 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
1777 ID3D10PixelShader_Release(tmp_ps);
1779 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1780 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1782 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
1783 tmp_buffer[i], i, buffer[i]);
1784 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
1785 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
1786 ID3D10Buffer_Release(tmp_buffer[i]);
1788 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1789 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
1790 ID3D10Buffer_Release(tmp_buffer[0]);
1791 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
1792 todo_wine ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
1793 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1794 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
1795 tmp_input_layout, input_layout);
1796 ID3D10InputLayout_Release(tmp_input_layout);
1797 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1798 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
1800 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1801 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
1802 ID3D10BlendState_Release(tmp_blend_state);
1803 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
1804 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
1805 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1806 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1807 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
1808 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1809 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
1810 ID3D10DepthStencilState_Release(tmp_ds_state);
1811 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
1812 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1813 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1815 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
1816 tmp_rtv[i], i, rtv[i]);
1817 ID3D10RenderTargetView_Release(tmp_rtv[i]);
1819 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
1820 ID3D10DepthStencilView_Release(tmp_dsv);
1822 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1823 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1824 "Got unexpected scissor rect count %u.\n", count);
1825 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1826 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1827 for (i = 0; i < count; ++i)
1829 ok(tmp_rect[i].left == i
1830 && tmp_rect[i].top == i * 2
1831 && tmp_rect[i].right == i + 1
1832 && tmp_rect[i].bottom == (i + 1) * 2,
1833 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1834 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1836 ID3D10Device_RSGetViewports(device, &count, NULL);
1837 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1838 "Got unexpected viewport count %u.\n", count);
1839 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1840 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1841 for (i = 0; i < count; ++i)
1843 ok(tmp_viewport[i].TopLeftX == i * 3
1844 && tmp_viewport[i].TopLeftY == i * 4
1845 && tmp_viewport[i].Width == 3
1846 && tmp_viewport[i].Height == 4
1847 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
1848 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
1849 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1850 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1851 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1853 ID3D10Device_RSGetState(device, &tmp_rs_state);
1854 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
1855 ID3D10RasterizerState_Release(tmp_rs_state);
1857 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1858 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1860 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
1861 tmp_buffer[i], i, buffer[i]);
1862 ID3D10Buffer_Release(tmp_buffer[i]);
1863 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1866 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1867 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
1868 ID3D10Predicate_Release(tmp_predicate);
1869 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1871 /* Verify ClearState(). */
1873 ID3D10Device_ClearState(device);
1875 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1876 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1878 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1880 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1881 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1883 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1885 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1886 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1888 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1890 ID3D10Device_VSGetShader(device, &tmp_vs);
1891 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1893 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1894 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1896 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1898 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1899 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1901 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1903 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1904 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1906 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1908 ID3D10Device_GSGetShader(device, &tmp_gs);
1909 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1911 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1912 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1914 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1916 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1917 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1919 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1921 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1922 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1924 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1926 ID3D10Device_PSGetShader(device, &tmp_ps);
1927 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1929 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1930 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1932 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1933 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1934 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1936 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1937 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
1938 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
1939 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
1940 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1941 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
1942 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1943 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
1945 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1946 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
1947 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
1948 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
1949 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1950 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1951 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
1952 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1953 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
1954 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
1955 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1956 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1958 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
1960 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
1962 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1963 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
1964 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1965 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1966 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1967 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1969 if (!i)
1970 todo_wine ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1971 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1972 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1973 else
1974 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1975 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1976 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1978 ID3D10Device_RSGetViewports(device, &count, NULL);
1979 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
1980 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1981 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1982 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1983 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1985 if (!i)
1986 todo_wine ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
1987 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
1988 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1989 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1990 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1991 else
1992 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
1993 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
1994 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1995 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1996 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1998 ID3D10Device_RSGetState(device, &tmp_rs_state);
1999 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
2001 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2002 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2004 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
2005 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2008 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2009 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
2010 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2012 /* Cleanup. */
2014 ID3D10Predicate_Release(predicate);
2015 ID3D10RasterizerState_Release(rs_state);
2016 ID3D10DepthStencilView_Release(dsv);
2017 ID3D10Texture2D_Release(ds_texture);
2019 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2021 ID3D10RenderTargetView_Release(rtv[i]);
2022 ID3D10Texture2D_Release(rt_texture[i]);
2025 ID3D10DepthStencilState_Release(ds_state);
2026 ID3D10BlendState_Release(blend_state);
2027 ID3D10InputLayout_Release(input_layout);
2028 ID3D10VertexShader_Release(vs);
2029 ID3D10GeometryShader_Release(gs);
2030 ID3D10PixelShader_Release(ps);
2032 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2034 ID3D10SamplerState_Release(sampler[i]);
2037 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2039 ID3D10ShaderResourceView_Release(srv[i]);
2042 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2044 ID3D10Buffer_Release(so_buffer[i]);
2047 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2049 ID3D10Buffer_Release(buffer[i]);
2052 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2054 ID3D10Buffer_Release(cb[i]);
2057 refcount = ID3D10Device_Release(device);
2058 ok(!refcount, "Device has %u references left.\n", refcount);
2061 static void test_blend(void)
2063 ID3D10RenderTargetView *backbuffer_rtv, *offscreen_rtv;
2064 ID3D10BlendState *src_blend, *dst_blend;
2065 ID3D10Texture2D *backbuffer, *offscreen;
2066 D3D10_SUBRESOURCE_DATA buffer_data;
2067 D3D10_TEXTURE2D_DESC texture_desc;
2068 ID3D10InputLayout *input_layout;
2069 D3D10_BUFFER_DESC buffer_desc;
2070 D3D10_BLEND_DESC blend_desc;
2071 unsigned int stride, offset;
2072 IDXGISwapChain *swapchain;
2073 ID3D10VertexShader *vs;
2074 ID3D10PixelShader *ps;
2075 ID3D10Device *device;
2076 D3D10_VIEWPORT vp;
2077 ID3D10Buffer *vb;
2078 ULONG refcount;
2079 DWORD color;
2080 HWND window;
2081 HRESULT hr;
2083 static const DWORD vs_code[] =
2085 #if 0
2086 struct vs_out
2088 float4 position : SV_POSITION;
2089 float4 color : COLOR;
2092 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
2094 struct vs_out o;
2096 o.position = position;
2097 o.color = color;
2099 return o;
2101 #endif
2102 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
2103 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2104 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2105 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
2106 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2107 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
2108 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
2109 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
2110 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
2111 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
2113 static const DWORD ps_code[] =
2115 #if 0
2116 struct vs_out
2118 float4 position : SV_POSITION;
2119 float4 color : COLOR;
2122 float4 main(struct vs_out i) : SV_TARGET
2124 return i.color;
2126 #endif
2127 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
2128 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
2129 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
2130 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
2131 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2132 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2133 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2134 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2136 static const struct
2138 struct vec3 position;
2139 DWORD diffuse;
2141 quads[] =
2143 /* quad1 */
2144 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
2145 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
2146 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
2147 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
2148 /* quad2 */
2149 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2150 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2151 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2152 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2154 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2156 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2157 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
2159 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2160 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2162 if (!(device = create_device()))
2164 skip("Failed to create device, skipping tests.\n");
2165 return;
2167 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2168 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2169 swapchain = create_swapchain(device, window, TRUE);
2170 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2171 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2173 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2174 vs_code, sizeof(vs_code), &input_layout);
2175 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2177 buffer_desc.ByteWidth = sizeof(quads);
2178 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2179 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2180 buffer_desc.CPUAccessFlags = 0;
2181 buffer_desc.MiscFlags = 0;
2183 buffer_data.pSysMem = quads;
2184 buffer_data.SysMemPitch = 0;
2185 buffer_data.SysMemSlicePitch = 0;
2187 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
2188 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2189 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2190 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2191 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2192 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2194 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2195 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2197 memset(&blend_desc, 0, sizeof(blend_desc));
2198 blend_desc.BlendEnable[0] = TRUE;
2199 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
2200 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
2201 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
2202 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
2203 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
2204 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
2205 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
2207 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
2208 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2210 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
2211 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
2212 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
2213 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
2215 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
2216 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2218 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2219 ID3D10Device_IASetInputLayout(device, input_layout);
2220 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2221 stride = sizeof(*quads);
2222 offset = 0;
2223 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2224 ID3D10Device_VSSetShader(device, vs);
2225 ID3D10Device_PSSetShader(device, ps);
2227 vp.TopLeftX = 0;
2228 vp.TopLeftY = 0;
2229 vp.Width = 640;
2230 vp.Height = 480;
2231 vp.MinDepth = 0.0f;
2232 vp.MaxDepth = 1.0f;
2233 ID3D10Device_RSSetViewports(device, 1, &vp);
2235 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2237 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2238 ID3D10Device_Draw(device, 4, 0);
2239 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2240 ID3D10Device_Draw(device, 4, 4);
2242 color = get_texture_color(backbuffer, 320, 360);
2243 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
2244 color = get_texture_color(backbuffer, 320, 120);
2245 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
2247 texture_desc.Width = 128;
2248 texture_desc.Height = 128;
2249 texture_desc.MipLevels = 1;
2250 texture_desc.ArraySize = 1;
2251 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
2252 texture_desc.SampleDesc.Count = 1;
2253 texture_desc.SampleDesc.Quality = 0;
2254 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2255 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
2256 texture_desc.CPUAccessFlags = 0;
2257 texture_desc.MiscFlags = 0;
2259 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
2260 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
2262 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
2263 goto done;
2266 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
2267 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2269 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
2271 vp.TopLeftX = 0;
2272 vp.TopLeftY = 0;
2273 vp.Width = 128;
2274 vp.Height = 128;
2275 vp.MinDepth = 0.0f;
2276 vp.MaxDepth = 1.0f;
2277 ID3D10Device_RSSetViewports(device, 1, &vp);
2279 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
2281 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2282 ID3D10Device_Draw(device, 4, 0);
2283 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2284 ID3D10Device_Draw(device, 4, 4);
2286 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
2287 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
2288 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
2289 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
2291 ID3D10RenderTargetView_Release(offscreen_rtv);
2292 ID3D10Texture2D_Release(offscreen);
2293 done:
2294 ID3D10BlendState_Release(dst_blend);
2295 ID3D10BlendState_Release(src_blend);
2296 ID3D10PixelShader_Release(ps);
2297 ID3D10VertexShader_Release(vs);
2298 ID3D10Buffer_Release(vb);
2299 ID3D10InputLayout_Release(input_layout);
2300 ID3D10RenderTargetView_Release(backbuffer_rtv);
2301 ID3D10Texture2D_Release(backbuffer);
2302 IDXGISwapChain_Release(swapchain);
2303 refcount = ID3D10Device_Release(device);
2304 ok(!refcount, "Device has %u references left.\n", refcount);
2305 DestroyWindow(window);
2308 static void test_texture(void)
2310 ID3D10RenderTargetView *backbuffer_rtv;
2311 D3D10_SUBRESOURCE_DATA resource_data;
2312 D3D10_TEXTURE2D_DESC texture_desc;
2313 ID3D10SamplerState *sampler_state;
2314 ID3D10ShaderResourceView *ps_srv;
2315 D3D10_SAMPLER_DESC sampler_desc;
2316 ID3D10InputLayout *input_layout;
2317 D3D10_BUFFER_DESC buffer_desc;
2318 ID3D10Texture2D *backbuffer;
2319 unsigned int stride, offset;
2320 IDXGISwapChain *swapchain;
2321 ID3D10Texture2D *texture;
2322 ID3D10VertexShader *vs;
2323 ID3D10PixelShader *ps;
2324 ID3D10Device *device;
2325 D3D10_VIEWPORT vp;
2326 unsigned int i, j;
2327 ID3D10Buffer *vb;
2328 ULONG refcount;
2329 DWORD color;
2330 HWND window;
2331 HRESULT hr;
2333 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2335 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2337 static const DWORD vs_code[] =
2339 #if 0
2340 float4 main(float4 position : POSITION) : SV_POSITION
2342 return position;
2344 #endif
2345 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2346 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2347 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2348 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2349 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2350 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2351 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2353 static const DWORD ps_code[] =
2355 #if 0
2356 Texture2D t;
2357 SamplerState s;
2359 float4 main(float4 position : SV_POSITION) : SV_Target
2361 float2 p;
2363 p.x = position.x / 640.0f;
2364 p.y = position.y / 480.0f;
2365 return t.Sample(s, p);
2367 #endif
2368 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
2369 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2370 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2371 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2372 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
2373 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
2374 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
2375 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
2376 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
2377 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
2379 static const struct
2381 float x, y;
2383 quad[] =
2385 {-1.0f, -1.0f},
2386 {-1.0f, 1.0f},
2387 { 1.0f, -1.0f},
2388 { 1.0f, 1.0f},
2390 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2391 static const DWORD bitmap_data[] =
2393 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
2394 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
2395 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
2396 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
2399 if (!(device = create_device()))
2401 skip("Failed to create device, skipping tests.\n");
2402 return;
2404 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2405 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2406 swapchain = create_swapchain(device, window, TRUE);
2407 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2408 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2410 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2411 vs_code, sizeof(vs_code), &input_layout);
2412 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2414 buffer_desc.ByteWidth = sizeof(quad);
2415 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2416 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2417 buffer_desc.CPUAccessFlags = 0;
2418 buffer_desc.MiscFlags = 0;
2420 resource_data.pSysMem = quad;
2421 resource_data.SysMemPitch = 0;
2422 resource_data.SysMemSlicePitch = 0;
2424 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
2425 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2427 texture_desc.Width = 4;
2428 texture_desc.Height = 4;
2429 texture_desc.MipLevels = 1;
2430 texture_desc.ArraySize = 1;
2431 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2432 texture_desc.SampleDesc.Count = 1;
2433 texture_desc.SampleDesc.Quality = 0;
2434 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2435 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2436 texture_desc.CPUAccessFlags = 0;
2437 texture_desc.MiscFlags = 0;
2439 resource_data.pSysMem = bitmap_data;
2440 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
2442 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
2443 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2445 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
2446 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
2448 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
2449 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
2450 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
2451 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
2452 sampler_desc.MipLODBias = 0.0f;
2453 sampler_desc.MaxAnisotropy = 0;
2454 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2455 sampler_desc.BorderColor[0] = 0.0f;
2456 sampler_desc.BorderColor[1] = 0.0f;
2457 sampler_desc.BorderColor[2] = 0.0f;
2458 sampler_desc.BorderColor[3] = 0.0f;
2459 sampler_desc.MinLOD = 0.0f;
2460 sampler_desc.MaxLOD = 0.0f;
2462 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
2463 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2465 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2466 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2467 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2468 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2470 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2471 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2473 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2474 ID3D10Device_IASetInputLayout(device, input_layout);
2475 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2476 stride = sizeof(*quad);
2477 offset = 0;
2478 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2479 ID3D10Device_VSSetShader(device, vs);
2480 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
2481 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
2482 ID3D10Device_PSSetShader(device, ps);
2484 vp.TopLeftX = 0;
2485 vp.TopLeftY = 0;
2486 vp.Width = 640;
2487 vp.Height = 480;
2488 vp.MinDepth = 0.0f;
2489 vp.MaxDepth = 1.0f;
2490 ID3D10Device_RSSetViewports(device, 1, &vp);
2492 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2494 ID3D10Device_Draw(device, 4, 0);
2496 for (i = 0; i < 4; ++i)
2498 for (j = 0; j < 4; ++j)
2500 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
2501 ok(compare_color(color, bitmap_data[j + i * 4], 1),
2502 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
2503 color, j, i, bitmap_data[j + i * 4]);
2507 ID3D10PixelShader_Release(ps);
2508 ID3D10VertexShader_Release(vs);
2509 ID3D10SamplerState_Release(sampler_state);
2510 ID3D10ShaderResourceView_Release(ps_srv);
2511 ID3D10Texture2D_Release(texture);
2512 ID3D10Buffer_Release(vb);
2513 ID3D10InputLayout_Release(input_layout);
2514 ID3D10RenderTargetView_Release(backbuffer_rtv);
2515 ID3D10Texture2D_Release(backbuffer);
2516 IDXGISwapChain_Release(swapchain);
2517 refcount = ID3D10Device_Release(device);
2518 ok(!refcount, "Device has %u references left.\n", refcount);
2519 DestroyWindow(window);
2522 static void test_private_data(void)
2524 ULONG refcount, expected_refcount;
2525 ID3D10Device *test_object;
2526 IDXGIDevice *dxgi_device;
2527 ID3D10Device *device;
2528 IUnknown *ptr;
2529 HRESULT hr;
2530 UINT size;
2532 static const GUID test_guid =
2533 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2534 static const GUID test_guid2 =
2535 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2536 static const DWORD data[] = {1, 2, 3, 4};
2538 if (!(device = create_device()))
2540 skip("Failed to create device, skipping tests.\n");
2541 return;
2544 test_object = create_device();
2546 /* SetPrivateData() with a pointer of NULL has the purpose of
2547 * FreePrivateData() in previous D3D versions. A successful clear returns
2548 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
2549 * considered a clear but as setting an interface pointer that happens to
2550 * be NULL. */
2551 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
2552 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2553 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2554 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2555 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2556 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2557 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2558 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2560 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2561 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2562 size = sizeof(ptr) * 2;
2563 ptr = (IUnknown *)0xdeadbeef;
2564 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2565 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2566 todo_wine ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2567 todo_wine ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2569 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2570 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2571 size = sizeof(ptr) * 2;
2572 ptr = (IUnknown *)0xdeadbeef;
2573 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2574 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2575 todo_wine ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2576 todo_wine ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2577 IDXGIDevice_Release(dxgi_device);
2579 refcount = get_refcount((IUnknown *)test_object);
2580 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2581 (IUnknown *)test_object);
2582 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2583 expected_refcount = refcount + 1;
2584 refcount = get_refcount((IUnknown *)test_object);
2585 todo_wine ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2586 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2587 (IUnknown *)test_object);
2588 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2589 refcount = get_refcount((IUnknown *)test_object);
2590 todo_wine ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2592 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2593 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2594 --expected_refcount;
2595 refcount = get_refcount((IUnknown *)test_object);
2596 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2598 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2599 (IUnknown *)test_object);
2600 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2601 size = sizeof(data);
2602 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
2603 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2604 refcount = get_refcount((IUnknown *)test_object);
2605 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2606 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2607 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2608 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2609 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2611 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2612 (IUnknown *)test_object);
2613 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2614 ++expected_refcount;
2615 size = 2 * sizeof(ptr);
2616 ptr = NULL;
2617 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2618 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2619 todo_wine ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2620 ++expected_refcount;
2621 refcount = get_refcount((IUnknown *)test_object);
2622 todo_wine ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2623 if (ptr)
2624 IUnknown_Release(ptr);
2625 --expected_refcount;
2627 ptr = (IUnknown *)0xdeadbeef;
2628 size = 1;
2629 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2630 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2631 todo_wine ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2632 size = 2 * sizeof(ptr);
2633 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2634 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2635 todo_wine ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2636 refcount = get_refcount((IUnknown *)test_object);
2637 todo_wine ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2639 size = 1;
2640 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2641 todo_wine ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2642 todo_wine ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2643 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2644 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2645 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2646 size = 0xdeadbabe;
2647 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2648 todo_wine ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2649 todo_wine ok(size == 0, "Got unexpected size %u.\n", size);
2650 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2651 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2652 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2653 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2655 refcount = ID3D10Device_Release(device);
2656 ok(!refcount, "Device has %u references left.\n", refcount);
2657 refcount = ID3D10Device_Release(test_object);
2658 ok(!refcount, "Test object has %u references left.\n", refcount);
2661 START_TEST(device)
2663 test_create_texture2d();
2664 test_create_texture3d();
2665 test_create_depthstencil_view();
2666 test_create_rendertarget_view();
2667 test_create_shader_resource_view();
2668 test_create_shader();
2669 test_create_sampler_state();
2670 test_create_blend_state();
2671 test_create_depthstencil_state();
2672 test_create_rasterizer_state();
2673 test_create_predicate();
2674 test_device_removed_reason();
2675 test_scissor();
2676 test_clear_state();
2677 test_blend();
2678 test_texture();
2679 test_private_data();