d3d10core/tests: Use win_skip() instead of skip().
[wine/multimedia.git] / dlls / d3d10core / tests / device.c
blob5e12f1418c31c8d01ae43c64a902da508214b8aa
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 "d3d11.h"
22 #include "wine/test.h"
23 #include <limits.h>
25 struct vec2
27 float x, y;
30 struct vec3
32 float x, y, z;
35 struct vec4
37 float x, y, z, w;
40 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
42 box->left = left;
43 box->top = top;
44 box->front = front;
45 box->right = right;
46 box->bottom = bottom;
47 box->back = back;
50 static ULONG get_refcount(IUnknown *iface)
52 IUnknown_AddRef(iface);
53 return IUnknown_Release(iface);
56 static BOOL compare_float(float f, float g, unsigned int ulps)
58 int x = *(int *)&f;
59 int y = *(int *)&g;
61 if (x < 0)
62 x = INT_MIN - x;
63 if (y < 0)
64 y = INT_MIN - y;
66 if (abs(x - y) > ulps)
67 return FALSE;
69 return TRUE;
72 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
74 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
75 return FALSE;
76 c1 >>= 8; c2 >>= 8;
77 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
78 return FALSE;
79 c1 >>= 8; c2 >>= 8;
80 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
81 return FALSE;
82 c1 >>= 8; c2 >>= 8;
83 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
84 return FALSE;
85 return TRUE;
88 static DWORD get_texture_color(ID3D10Texture2D *src_texture, unsigned int x, unsigned int y)
90 D3D10_MAPPED_TEXTURE2D mapped_texture;
91 D3D10_TEXTURE2D_DESC texture_desc;
92 ID3D10Texture2D *dst_texture;
93 ID3D10Device *device;
94 DWORD color;
95 HRESULT hr;
97 ID3D10Texture2D_GetDevice(src_texture, &device);
99 ID3D10Texture2D_GetDesc(src_texture, &texture_desc);
100 texture_desc.Usage = D3D10_USAGE_STAGING;
101 texture_desc.BindFlags = 0;
102 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
103 texture_desc.MiscFlags = 0;
104 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
105 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
107 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
108 hr = ID3D10Texture2D_Map(dst_texture, 0, D3D10_MAP_READ, 0, &mapped_texture);
109 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
110 color = *(DWORD *)(((BYTE *)mapped_texture.pData) + mapped_texture.RowPitch * y + x * 4);
111 ID3D10Texture2D_Unmap(dst_texture, 0);
113 ID3D10Texture2D_Release(dst_texture);
114 ID3D10Device_Release(device);
116 return color;
119 static ID3D10Device *create_device(void)
121 ID3D10Device *device;
123 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
124 return device;
125 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
126 return device;
127 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
128 return device;
130 return NULL;
133 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL windowed)
135 IDXGISwapChain *swapchain;
136 DXGI_SWAP_CHAIN_DESC desc;
137 IDXGIDevice *dxgi_device;
138 IDXGIAdapter *adapter;
139 IDXGIFactory *factory;
140 HRESULT hr;
142 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
143 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
144 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
145 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
146 IDXGIDevice_Release(dxgi_device);
147 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
148 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
149 IDXGIAdapter_Release(adapter);
151 desc.BufferDesc.Width = 640;
152 desc.BufferDesc.Height = 480;
153 desc.BufferDesc.RefreshRate.Numerator = 60;
154 desc.BufferDesc.RefreshRate.Denominator = 1;
155 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
156 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
157 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
158 desc.SampleDesc.Count = 1;
159 desc.SampleDesc.Quality = 0;
160 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
161 desc.BufferCount = 1;
162 desc.OutputWindow = window;
163 desc.Windowed = windowed;
164 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
165 desc.Flags = 0;
167 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
168 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
169 IDXGIFactory_Release(factory);
171 return swapchain;
174 static void test_feature_level(void)
176 D3D_FEATURE_LEVEL feature_level;
177 ID3D11Device *device11;
178 ID3D10Device *device10;
179 HRESULT hr;
181 if (!(device10 = create_device()))
183 skip("Failed to create device, skipping tests.\n");
184 return;
187 hr = ID3D10Device_QueryInterface(device10, &IID_ID3D11Device, (void **)&device11);
188 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
189 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
190 if (FAILED(hr))
192 win_skip("D3D11 is not available.\n");
193 ID3D10Device_Release(device10);
194 return;
197 /* Device was created by D3D10CreateDevice. */
198 feature_level = ID3D11Device_GetFeatureLevel(device11);
199 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
201 ID3D11Device_Release(device11);
202 ID3D10Device_Release(device10);
205 static void test_create_texture2d(void)
207 ULONG refcount, expected_refcount;
208 D3D10_SUBRESOURCE_DATA data = {0};
209 ID3D10Device *device, *tmp;
210 D3D10_TEXTURE2D_DESC desc;
211 ID3D10Texture2D *texture;
212 IDXGISurface *surface;
213 HRESULT hr;
215 if (!(device = create_device()))
217 skip("Failed to create device, skipping tests.\n");
218 return;
221 desc.Width = 512;
222 desc.Height = 512;
223 desc.MipLevels = 1;
224 desc.ArraySize = 1;
225 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
226 desc.SampleDesc.Count = 1;
227 desc.SampleDesc.Quality = 0;
228 desc.Usage = D3D10_USAGE_DEFAULT;
229 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
230 desc.CPUAccessFlags = 0;
231 desc.MiscFlags = 0;
233 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
234 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
236 expected_refcount = get_refcount((IUnknown *)device) + 1;
237 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
238 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
239 refcount = get_refcount((IUnknown *)device);
240 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
241 tmp = NULL;
242 expected_refcount = refcount + 1;
243 ID3D10Texture2D_GetDevice(texture, &tmp);
244 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
245 refcount = get_refcount((IUnknown *)device);
246 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
247 ID3D10Device_Release(tmp);
249 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
250 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
251 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
252 ID3D10Texture2D_Release(texture);
254 desc.MipLevels = 0;
255 expected_refcount = get_refcount((IUnknown *)device) + 1;
256 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
257 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
258 refcount = get_refcount((IUnknown *)device);
259 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
260 tmp = NULL;
261 expected_refcount = refcount + 1;
262 ID3D10Texture2D_GetDevice(texture, &tmp);
263 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
264 refcount = get_refcount((IUnknown *)device);
265 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
266 ID3D10Device_Release(tmp);
268 ID3D10Texture2D_GetDesc(texture, &desc);
269 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
270 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
271 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
272 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
273 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
274 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
275 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
276 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
277 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
278 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
279 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
281 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
282 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
283 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
284 ID3D10Texture2D_Release(texture);
286 desc.MipLevels = 1;
287 desc.ArraySize = 2;
288 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
289 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
291 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
292 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
293 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
294 ID3D10Texture2D_Release(texture);
296 refcount = ID3D10Device_Release(device);
297 ok(!refcount, "Device has %u references left.\n", refcount);
300 static void test_create_texture3d(void)
302 ULONG refcount, expected_refcount;
303 D3D10_SUBRESOURCE_DATA data = {0};
304 ID3D10Device *device, *tmp;
305 D3D10_TEXTURE3D_DESC desc;
306 ID3D10Texture3D *texture;
307 IDXGISurface *surface;
308 HRESULT hr;
310 if (!(device = create_device()))
312 skip("Failed to create device, skipping tests.\n");
313 return;
316 desc.Width = 64;
317 desc.Height = 64;
318 desc.Depth = 64;
319 desc.MipLevels = 1;
320 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
321 desc.Usage = D3D10_USAGE_DEFAULT;
322 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
323 desc.CPUAccessFlags = 0;
324 desc.MiscFlags = 0;
326 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
327 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
329 expected_refcount = get_refcount((IUnknown *)device) + 1;
330 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
331 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
332 refcount = get_refcount((IUnknown *)device);
333 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
334 tmp = NULL;
335 expected_refcount = refcount + 1;
336 ID3D10Texture3D_GetDevice(texture, &tmp);
337 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
338 refcount = get_refcount((IUnknown *)device);
339 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
340 ID3D10Device_Release(tmp);
342 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
343 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
344 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
345 ID3D10Texture3D_Release(texture);
347 desc.MipLevels = 0;
348 expected_refcount = get_refcount((IUnknown *)device) + 1;
349 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
350 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
351 refcount = get_refcount((IUnknown *)device);
352 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
353 tmp = NULL;
354 expected_refcount = refcount + 1;
355 ID3D10Texture3D_GetDevice(texture, &tmp);
356 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
357 refcount = get_refcount((IUnknown *)device);
358 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
359 ID3D10Device_Release(tmp);
361 ID3D10Texture3D_GetDesc(texture, &desc);
362 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
363 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
364 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
365 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
366 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
367 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
368 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
369 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
370 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
372 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
373 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
374 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
375 ID3D10Texture3D_Release(texture);
377 refcount = ID3D10Device_Release(device);
378 ok(!refcount, "Device has %u references left.\n", refcount);
381 static void test_create_depthstencil_view(void)
383 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
384 D3D10_TEXTURE2D_DESC texture_desc;
385 ULONG refcount, expected_refcount;
386 ID3D10DepthStencilView *dsview;
387 ID3D10Device *device, *tmp;
388 ID3D10Texture2D *texture;
389 HRESULT hr;
391 if (!(device = create_device()))
393 skip("Failed to create device, skipping tests.\n");
394 return;
397 texture_desc.Width = 512;
398 texture_desc.Height = 512;
399 texture_desc.MipLevels = 1;
400 texture_desc.ArraySize = 1;
401 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
402 texture_desc.SampleDesc.Count = 1;
403 texture_desc.SampleDesc.Quality = 0;
404 texture_desc.Usage = D3D10_USAGE_DEFAULT;
405 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
406 texture_desc.CPUAccessFlags = 0;
407 texture_desc.MiscFlags = 0;
409 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
410 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
412 expected_refcount = get_refcount((IUnknown *)device) + 1;
413 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
414 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr);
415 refcount = get_refcount((IUnknown *)device);
416 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
417 tmp = NULL;
418 expected_refcount = refcount + 1;
419 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
420 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
421 refcount = get_refcount((IUnknown *)device);
422 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
423 ID3D10Device_Release(tmp);
425 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
426 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
427 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
428 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
429 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
431 ID3D10DepthStencilView_Release(dsview);
432 ID3D10Texture2D_Release(texture);
434 refcount = ID3D10Device_Release(device);
435 ok(!refcount, "Device has %u references left.\n", refcount);
438 static void test_create_rendertarget_view(void)
440 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
441 D3D10_SUBRESOURCE_DATA data = {0};
442 D3D10_TEXTURE2D_DESC texture_desc;
443 ULONG refcount, expected_refcount;
444 D3D10_BUFFER_DESC buffer_desc;
445 ID3D10RenderTargetView *rtview;
446 ID3D10Device *device, *tmp;
447 ID3D10Texture2D *texture;
448 ID3D10Buffer *buffer;
449 HRESULT hr;
451 if (!(device = create_device()))
453 skip("Failed to create device, skipping tests.\n");
454 return;
457 buffer_desc.ByteWidth = 1024;
458 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
459 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
460 buffer_desc.CPUAccessFlags = 0;
461 buffer_desc.MiscFlags = 0;
463 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
464 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
466 expected_refcount = get_refcount((IUnknown *)device) + 1;
467 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
468 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
469 refcount = get_refcount((IUnknown *)device);
470 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
471 tmp = NULL;
472 expected_refcount = refcount + 1;
473 ID3D10Buffer_GetDevice(buffer, &tmp);
474 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
475 refcount = get_refcount((IUnknown *)device);
476 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
477 ID3D10Device_Release(tmp);
479 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
480 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
481 U(rtv_desc).Buffer.ElementOffset = 0;
482 U(rtv_desc).Buffer.ElementWidth = 64;
484 expected_refcount = get_refcount((IUnknown *)device) + 1;
485 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
486 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
487 refcount = get_refcount((IUnknown *)device);
488 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
489 tmp = NULL;
490 expected_refcount = refcount + 1;
491 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
492 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
493 refcount = get_refcount((IUnknown *)device);
494 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
495 ID3D10Device_Release(tmp);
497 ID3D10RenderTargetView_Release(rtview);
498 ID3D10Buffer_Release(buffer);
500 texture_desc.Width = 512;
501 texture_desc.Height = 512;
502 texture_desc.MipLevels = 1;
503 texture_desc.ArraySize = 1;
504 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
505 texture_desc.SampleDesc.Count = 1;
506 texture_desc.SampleDesc.Quality = 0;
507 texture_desc.Usage = D3D10_USAGE_DEFAULT;
508 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
509 texture_desc.CPUAccessFlags = 0;
510 texture_desc.MiscFlags = 0;
512 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
513 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
515 /* For texture resources it's allowed to specify NULL as desc */
516 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
517 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
519 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
520 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
521 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
522 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
523 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
525 ID3D10RenderTargetView_Release(rtview);
526 ID3D10Texture2D_Release(texture);
528 refcount = ID3D10Device_Release(device);
529 ok(!refcount, "Device has %u references left.\n", refcount);
532 static void test_create_shader_resource_view(void)
534 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
535 D3D10_TEXTURE2D_DESC texture_desc;
536 ULONG refcount, expected_refcount;
537 ID3D10ShaderResourceView *srview;
538 D3D10_BUFFER_DESC buffer_desc;
539 ID3D10Device *device, *tmp;
540 ID3D10Texture2D *texture;
541 ID3D10Buffer *buffer;
542 HRESULT hr;
544 if (!(device = create_device()))
546 skip("Failed to create device, skipping tests.\n");
547 return;
550 buffer_desc.ByteWidth = 1024;
551 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
552 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
553 buffer_desc.CPUAccessFlags = 0;
554 buffer_desc.MiscFlags = 0;
556 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
557 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
559 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
560 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
562 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
563 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
564 U(srv_desc).Buffer.ElementOffset = 0;
565 U(srv_desc).Buffer.ElementWidth = 64;
567 expected_refcount = get_refcount((IUnknown *)device) + 1;
568 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
569 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
570 refcount = get_refcount((IUnknown *)device);
571 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
572 tmp = NULL;
573 expected_refcount = refcount + 1;
574 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
575 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
576 refcount = get_refcount((IUnknown *)device);
577 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
578 ID3D10Device_Release(tmp);
580 ID3D10ShaderResourceView_Release(srview);
581 ID3D10Buffer_Release(buffer);
583 texture_desc.Width = 512;
584 texture_desc.Height = 512;
585 texture_desc.MipLevels = 0;
586 texture_desc.ArraySize = 1;
587 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
588 texture_desc.SampleDesc.Count = 1;
589 texture_desc.SampleDesc.Quality = 0;
590 texture_desc.Usage = D3D10_USAGE_DEFAULT;
591 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
592 texture_desc.CPUAccessFlags = 0;
593 texture_desc.MiscFlags = 0;
595 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
596 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
598 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srview);
599 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
601 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
602 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
603 ok(srv_desc.ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D,
604 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
605 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
606 U(srv_desc).Texture2D.MostDetailedMip);
607 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
609 ID3D10ShaderResourceView_Release(srview);
610 ID3D10Texture2D_Release(texture);
612 refcount = ID3D10Device_Release(device);
613 ok(!refcount, "Device has %u references left.\n", refcount);
616 static void test_create_shader(void)
618 #if 0
619 float4 light;
620 float4x4 mat;
622 struct input
624 float4 position : POSITION;
625 float3 normal : NORMAL;
628 struct output
630 float4 position : POSITION;
631 float4 diffuse : COLOR;
634 output main(const input v)
636 output o;
638 o.position = mul(v.position, mat);
639 o.diffuse = dot((float3)light, v.normal);
641 return o;
643 #endif
644 static const DWORD vs_4_0[] =
646 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
647 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
648 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
649 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
650 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
651 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
652 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
653 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
654 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
655 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
656 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
657 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
658 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
659 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
660 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
661 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
664 static const DWORD vs_2_0[] =
666 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
667 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
668 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
669 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
670 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
671 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
672 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
673 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
674 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
675 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
676 0x90e40001, 0x0000ffff,
679 static const DWORD vs_3_0[] =
681 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
682 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
683 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
684 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
685 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
686 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
687 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
688 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
689 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
690 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
691 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
692 0x0000ffff,
695 #if 0
696 float4 main(const float4 color : COLOR) : SV_TARGET
698 float4 o;
700 o = color;
702 return o;
704 #endif
705 static const DWORD ps_4_0[] =
707 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
708 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
709 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
710 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
711 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
712 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
713 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
714 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
715 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
716 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
717 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
718 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
719 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
720 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
721 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
722 0x00000000, 0x00000000,
725 ULONG refcount, expected_refcount;
726 ID3D10VertexShader *vs = NULL;
727 ID3D10PixelShader *ps = NULL;
728 ID3D10Device *device, *tmp;
729 HRESULT hr;
731 if (!(device = create_device()))
733 skip("Failed to create device, skipping tests.\n");
734 return;
737 expected_refcount = get_refcount((IUnknown *)device) + 1;
738 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
739 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
740 refcount = get_refcount((IUnknown *)device);
741 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
742 tmp = NULL;
743 expected_refcount = refcount + 1;
744 ID3D10VertexShader_GetDevice(vs, &tmp);
745 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
746 refcount = get_refcount((IUnknown *)device);
747 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
748 ID3D10Device_Release(tmp);
749 ID3D10VertexShader_Release(vs);
751 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
752 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
754 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
755 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
757 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
758 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
760 expected_refcount = get_refcount((IUnknown *)device) + 1;
761 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
762 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
763 refcount = get_refcount((IUnknown *)device);
764 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
765 tmp = NULL;
766 expected_refcount = refcount + 1;
767 ID3D10PixelShader_GetDevice(ps, &tmp);
768 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
769 refcount = get_refcount((IUnknown *)device);
770 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
771 ID3D10Device_Release(tmp);
772 ID3D10PixelShader_Release(ps);
774 refcount = ID3D10Device_Release(device);
775 ok(!refcount, "Device has %u references left.\n", refcount);
778 static void test_create_sampler_state(void)
780 ID3D10SamplerState *sampler_state1, *sampler_state2;
781 ULONG refcount, expected_refcount;
782 D3D10_SAMPLER_DESC sampler_desc;
783 ID3D10Device *device, *tmp;
784 HRESULT hr;
786 if (!(device = create_device()))
788 skip("Failed to create device, skipping tests.\n");
789 return;
792 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
793 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
795 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
796 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
797 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
798 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
799 sampler_desc.MipLODBias = 0.0f;
800 sampler_desc.MaxAnisotropy = 16;
801 sampler_desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
802 sampler_desc.BorderColor[0] = 0.0f;
803 sampler_desc.BorderColor[1] = 1.0f;
804 sampler_desc.BorderColor[2] = 0.0f;
805 sampler_desc.BorderColor[3] = 1.0f;
806 sampler_desc.MinLOD = 0.0f;
807 sampler_desc.MaxLOD = 16.0f;
809 expected_refcount = get_refcount((IUnknown *)device) + 1;
810 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state1);
811 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
812 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state2);
813 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
814 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
815 refcount = get_refcount((IUnknown *)device);
816 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
817 tmp = NULL;
818 expected_refcount = refcount + 1;
819 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
820 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
821 refcount = get_refcount((IUnknown *)device);
822 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
823 ID3D10Device_Release(tmp);
825 refcount = ID3D10SamplerState_Release(sampler_state2);
826 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
827 refcount = ID3D10SamplerState_Release(sampler_state1);
828 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
830 refcount = ID3D10Device_Release(device);
831 ok(!refcount, "Device has %u references left.\n", refcount);
834 static void test_create_blend_state(void)
836 ID3D10BlendState *blend_state1, *blend_state2;
837 ULONG refcount, expected_refcount;
838 D3D10_BLEND_DESC blend_desc;
839 ID3D10Device *device, *tmp;
840 HRESULT hr;
842 if (!(device = create_device()))
844 skip("Failed to create device, skipping tests.\n");
845 return;
848 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
849 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
851 blend_desc.AlphaToCoverageEnable = FALSE;
852 blend_desc.BlendEnable[0] = FALSE;
853 blend_desc.BlendEnable[1] = FALSE;
854 blend_desc.BlendEnable[2] = FALSE;
855 blend_desc.BlendEnable[3] = FALSE;
856 blend_desc.BlendEnable[4] = FALSE;
857 blend_desc.BlendEnable[5] = FALSE;
858 blend_desc.BlendEnable[6] = FALSE;
859 blend_desc.BlendEnable[7] = FALSE;
860 blend_desc.SrcBlend = D3D10_BLEND_ONE;
861 blend_desc.DestBlend = D3D10_BLEND_ZERO;
862 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
863 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
864 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
865 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
866 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
867 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
868 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
869 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
870 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
871 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
872 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
873 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
875 expected_refcount = get_refcount((IUnknown *)device) + 1;
876 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
877 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
878 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
879 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
880 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
881 refcount = get_refcount((IUnknown *)device);
882 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
883 tmp = NULL;
884 expected_refcount = refcount + 1;
885 ID3D10BlendState_GetDevice(blend_state1, &tmp);
886 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
887 refcount = get_refcount((IUnknown *)device);
888 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
889 ID3D10Device_Release(tmp);
891 refcount = ID3D10BlendState_Release(blend_state2);
892 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
893 refcount = ID3D10BlendState_Release(blend_state1);
894 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
896 refcount = ID3D10Device_Release(device);
897 ok(!refcount, "Device has %u references left.\n", refcount);
900 static void test_create_depthstencil_state(void)
902 ID3D10DepthStencilState *ds_state1, *ds_state2;
903 ULONG refcount, expected_refcount;
904 D3D10_DEPTH_STENCIL_DESC ds_desc;
905 ID3D10Device *device, *tmp;
906 HRESULT hr;
908 if (!(device = create_device()))
910 skip("Failed to create device, skipping tests.\n");
911 return;
914 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
915 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
917 ds_desc.DepthEnable = TRUE;
918 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
919 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
920 ds_desc.StencilEnable = FALSE;
921 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
922 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
923 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
924 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
925 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
926 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
927 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
928 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
929 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
930 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
932 expected_refcount = get_refcount((IUnknown *)device) + 1;
933 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
934 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
935 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
936 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
937 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
938 refcount = get_refcount((IUnknown *)device);
939 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
940 tmp = NULL;
941 expected_refcount = refcount + 1;
942 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
943 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
944 refcount = get_refcount((IUnknown *)device);
945 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
946 ID3D10Device_Release(tmp);
948 refcount = ID3D10DepthStencilState_Release(ds_state2);
949 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
950 refcount = ID3D10DepthStencilState_Release(ds_state1);
951 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
953 refcount = ID3D10Device_Release(device);
954 ok(!refcount, "Device has %u references left.\n", refcount);
957 static void test_create_rasterizer_state(void)
959 ID3D10RasterizerState *rast_state1, *rast_state2;
960 ULONG refcount, expected_refcount;
961 D3D10_RASTERIZER_DESC rast_desc;
962 ID3D10Device *device, *tmp;
963 HRESULT hr;
965 if (!(device = create_device()))
967 skip("Failed to create device, skipping tests.\n");
968 return;
971 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
972 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
974 rast_desc.FillMode = D3D10_FILL_SOLID;
975 rast_desc.CullMode = D3D10_CULL_BACK;
976 rast_desc.FrontCounterClockwise = FALSE;
977 rast_desc.DepthBias = 0;
978 rast_desc.DepthBiasClamp = 0.0f;
979 rast_desc.SlopeScaledDepthBias = 0.0f;
980 rast_desc.DepthClipEnable = TRUE;
981 rast_desc.ScissorEnable = FALSE;
982 rast_desc.MultisampleEnable = FALSE;
983 rast_desc.AntialiasedLineEnable = FALSE;
985 expected_refcount = get_refcount((IUnknown *)device) + 1;
986 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
987 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
988 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
989 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
990 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
991 refcount = get_refcount((IUnknown *)device);
992 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
993 tmp = NULL;
994 expected_refcount = refcount + 1;
995 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
996 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
997 refcount = get_refcount((IUnknown *)device);
998 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
999 ID3D10Device_Release(tmp);
1001 refcount = ID3D10RasterizerState_Release(rast_state2);
1002 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1003 refcount = ID3D10RasterizerState_Release(rast_state1);
1004 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1006 refcount = ID3D10Device_Release(device);
1007 ok(!refcount, "Device has %u references left.\n", refcount);
1010 static void test_create_predicate(void)
1012 ULONG refcount, expected_refcount;
1013 D3D10_QUERY_DESC query_desc;
1014 ID3D10Predicate *predicate;
1015 ID3D10Device *device, *tmp;
1016 HRESULT hr;
1018 if (!(device = create_device()))
1020 skip("Failed to create device, skipping tests.\n");
1021 return;
1024 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
1025 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1027 query_desc.Query = D3D10_QUERY_OCCLUSION;
1028 query_desc.MiscFlags = 0;
1029 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1030 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1032 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
1033 expected_refcount = get_refcount((IUnknown *)device) + 1;
1034 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1035 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1036 refcount = get_refcount((IUnknown *)device);
1037 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1038 tmp = NULL;
1039 expected_refcount = refcount + 1;
1040 ID3D10Predicate_GetDevice(predicate, &tmp);
1041 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1042 refcount = get_refcount((IUnknown *)device);
1043 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1044 ID3D10Device_Release(tmp);
1045 ID3D10Predicate_Release(predicate);
1047 query_desc.Query = D3D10_QUERY_SO_OVERFLOW_PREDICATE;
1048 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1049 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1050 if (SUCCEEDED(hr))
1051 ID3D10Predicate_Release(predicate);
1053 refcount = ID3D10Device_Release(device);
1054 ok(!refcount, "Device has %u references left.\n", refcount);
1057 static void test_device_removed_reason(void)
1059 ID3D10Device *device;
1060 ULONG refcount;
1061 HRESULT hr;
1063 if (!(device = create_device()))
1065 skip("Failed to create device, skipping tests.\n");
1066 return;
1069 hr = ID3D10Device_GetDeviceRemovedReason(device);
1070 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1071 hr = ID3D10Device_GetDeviceRemovedReason(device);
1072 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1074 refcount = ID3D10Device_Release(device);
1075 ok(!refcount, "Device has %u references left.\n", refcount);
1078 static void test_scissor(void)
1080 D3D10_SUBRESOURCE_DATA buffer_data;
1081 ID3D10InputLayout *input_layout;
1082 D3D10_RASTERIZER_DESC rs_desc;
1083 D3D10_BUFFER_DESC buffer_desc;
1084 ID3D10RenderTargetView *rtv;
1085 ID3D10Texture2D *backbuffer;
1086 unsigned int stride, offset;
1087 ID3D10RasterizerState *rs;
1088 IDXGISwapChain *swapchain;
1089 D3D10_RECT scissor_rect;
1090 ID3D10VertexShader *vs;
1091 ID3D10PixelShader *ps;
1092 ID3D10Device *device;
1093 D3D10_VIEWPORT vp;
1094 ID3D10Buffer *vb;
1095 ULONG refcount;
1096 DWORD color;
1097 HWND window;
1098 HRESULT hr;
1100 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
1101 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1103 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1105 static const DWORD vs_code[] =
1107 /* float4 main(float4 position : POSITION) : SV_POSITION
1109 * return position;
1110 * } */
1111 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
1112 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
1113 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1114 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1115 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1116 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1117 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1118 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1119 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1120 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
1121 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1122 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1123 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1124 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1126 static const DWORD ps_code[] =
1128 /* float4 main(float4 position : SV_POSITION) : SV_Target
1130 * return float4(0.0, 1.0, 0.0, 1.0);
1131 * } */
1132 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
1133 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
1134 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1135 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1136 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1137 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1138 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1139 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
1140 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
1141 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
1142 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
1143 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1144 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1145 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1147 static const struct
1149 float x, y;
1151 quad[] =
1153 {-1.0f, -1.0f},
1154 {-1.0f, 1.0f},
1155 { 1.0f, -1.0f},
1156 { 1.0f, 1.0f},
1159 if (!(device = create_device()))
1161 skip("Failed to create device, skipping tests.\n");
1162 return;
1164 window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1165 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1166 swapchain = create_swapchain(device, window, TRUE);
1167 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
1168 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
1170 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1171 vs_code, sizeof(vs_code), &input_layout);
1172 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1174 buffer_desc.ByteWidth = sizeof(quad);
1175 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1176 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
1177 buffer_desc.CPUAccessFlags = 0;
1178 buffer_desc.MiscFlags = 0;
1180 buffer_data.pSysMem = quad;
1181 buffer_data.SysMemPitch = 0;
1182 buffer_data.SysMemSlicePitch = 0;
1184 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
1185 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
1186 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
1187 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1188 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
1189 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1191 rs_desc.FillMode = D3D10_FILL_SOLID;
1192 rs_desc.CullMode = D3D10_CULL_BACK;
1193 rs_desc.FrontCounterClockwise = FALSE;
1194 rs_desc.DepthBias = 0;
1195 rs_desc.DepthBiasClamp = 0.0f;
1196 rs_desc.SlopeScaledDepthBias = 0.0f;
1197 rs_desc.DepthClipEnable = TRUE;
1198 rs_desc.ScissorEnable = TRUE;
1199 rs_desc.MultisampleEnable = FALSE;
1200 rs_desc.AntialiasedLineEnable = FALSE;
1201 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
1202 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1204 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtv);
1205 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1207 ID3D10Device_IASetInputLayout(device, input_layout);
1208 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1209 stride = sizeof(*quad);
1210 offset = 0;
1211 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
1212 ID3D10Device_VSSetShader(device, vs);
1213 ID3D10Device_PSSetShader(device, ps);
1215 vp.TopLeftX = 0;
1216 vp.TopLeftY = 0;
1217 vp.Width = 640;
1218 vp.Height = 480;
1219 vp.MinDepth = 0.0f;
1220 vp.MaxDepth = 1.0f;
1221 ID3D10Device_RSSetViewports(device, 1, &vp);
1223 scissor_rect.left = 160;
1224 scissor_rect.top = 120;
1225 scissor_rect.right = 480;
1226 scissor_rect.bottom = 360;
1227 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
1229 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
1231 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1232 color = get_texture_color(backbuffer, 320, 240);
1233 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1235 ID3D10Device_Draw(device, 4, 0);
1236 color = get_texture_color(backbuffer, 320, 60);
1237 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1238 color = get_texture_color(backbuffer, 80, 240);
1239 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1240 color = get_texture_color(backbuffer, 320, 240);
1241 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1242 color = get_texture_color(backbuffer, 560, 240);
1243 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1244 color = get_texture_color(backbuffer, 320, 420);
1245 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1247 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1248 ID3D10Device_RSSetState(device, rs);
1249 ID3D10Device_Draw(device, 4, 0);
1250 color = get_texture_color(backbuffer, 320, 60);
1251 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1252 color = get_texture_color(backbuffer, 80, 240);
1253 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1254 color = get_texture_color(backbuffer, 320, 240);
1255 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1256 color = get_texture_color(backbuffer, 560, 240);
1257 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1258 color = get_texture_color(backbuffer, 320, 420);
1259 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1261 ID3D10RenderTargetView_Release(rtv);
1262 ID3D10RasterizerState_Release(rs);
1263 ID3D10PixelShader_Release(ps);
1264 ID3D10VertexShader_Release(vs);
1265 ID3D10Buffer_Release(vb);
1266 ID3D10InputLayout_Release(input_layout);
1267 ID3D10Texture2D_Release(backbuffer);
1268 IDXGISwapChain_Release(swapchain);
1269 refcount = ID3D10Device_Release(device);
1270 ok(!refcount, "Device has %u references left.\n", refcount);
1271 DestroyWindow(window);
1274 static void test_clear_state(void)
1276 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1278 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1280 #if 0
1281 float4 main(float4 pos : POSITION) : POSITION
1283 return pos;
1285 #endif
1286 static const DWORD simple_vs[] =
1288 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
1289 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1290 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1291 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1292 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
1293 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
1294 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1297 #if 0
1298 struct gs_out
1300 float4 pos : SV_POSITION;
1303 [maxvertexcount(4)]
1304 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1306 float offset = 0.1 * vin[0].w;
1307 gs_out v;
1309 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1310 vout.Append(v);
1311 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1312 vout.Append(v);
1313 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1314 vout.Append(v);
1315 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1316 vout.Append(v);
1318 #endif
1319 static const DWORD simple_gs[] =
1321 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1322 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1323 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1324 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1325 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1326 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1327 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1328 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1329 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1330 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1331 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1332 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1333 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1334 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1335 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1336 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1337 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1338 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1341 #if 0
1342 float4 main(float4 color : COLOR) : SV_TARGET
1344 return color;
1346 #endif
1347 static const DWORD simple_ps[] =
1349 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
1350 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
1351 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
1352 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1353 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
1354 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
1355 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1358 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1359 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1360 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1361 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1362 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1363 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1364 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1365 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1366 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
1367 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1368 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1369 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1370 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1371 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1372 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
1373 ID3D10InputLayout *tmp_input_layout, *input_layout;
1374 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
1375 ID3D10BlendState *tmp_blend_state, *blend_state;
1376 ID3D10RasterizerState *tmp_rs_state, *rs_state;
1377 ID3D10Predicate *tmp_predicate, *predicate;
1378 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
1379 ID3D10DepthStencilView *tmp_dsv, *dsv;
1380 D3D10_PRIMITIVE_TOPOLOGY topology;
1381 D3D10_TEXTURE2D_DESC texture_desc;
1382 ID3D10GeometryShader *tmp_gs, *gs;
1383 D3D10_DEPTH_STENCIL_DESC ds_desc;
1384 ID3D10VertexShader *tmp_vs, *vs;
1385 D3D10_SAMPLER_DESC sampler_desc;
1386 D3D10_QUERY_DESC predicate_desc;
1387 ID3D10PixelShader *tmp_ps, *ps;
1388 D3D10_RASTERIZER_DESC rs_desc;
1389 D3D10_BUFFER_DESC buffer_desc;
1390 D3D10_BLEND_DESC blend_desc;
1391 ID3D10Texture2D *ds_texture;
1392 float blend_factor[4];
1393 ID3D10Device *device;
1394 BOOL predicate_value;
1395 DXGI_FORMAT format;
1396 UINT sample_mask;
1397 UINT stencil_ref;
1398 ULONG refcount;
1399 UINT count, i;
1400 HRESULT hr;
1402 if (!(device = create_device()))
1404 skip("Failed to create device, skipping tests.\n");
1405 return;
1408 /* Verify the initial state after device creation. */
1410 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1411 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1413 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1415 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1416 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1418 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1420 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1421 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1423 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1425 ID3D10Device_VSGetShader(device, &tmp_vs);
1426 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1428 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1429 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1431 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1433 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1434 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1436 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1438 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1439 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1441 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1443 ID3D10Device_GSGetShader(device, &tmp_gs);
1444 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1446 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1447 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1449 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1451 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1452 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1454 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1456 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1457 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1459 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1461 ID3D10Device_PSGetShader(device, &tmp_ps);
1462 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1464 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1465 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1467 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1468 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1469 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1471 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1472 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
1473 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
1474 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
1475 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1476 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
1477 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1478 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
1480 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1481 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
1482 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
1483 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
1484 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1485 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1486 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
1487 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1488 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
1489 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
1490 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1491 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1493 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
1495 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
1497 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1498 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
1499 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1500 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1501 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1502 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1504 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1505 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1506 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1508 ID3D10Device_RSGetViewports(device, &count, NULL);
1509 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
1510 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1511 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1512 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1513 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1515 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
1516 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
1517 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1518 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1519 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1521 ID3D10Device_RSGetState(device, &tmp_rs_state);
1522 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
1524 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1525 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1527 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
1528 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1531 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1532 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
1533 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1535 /* Create resources. */
1537 buffer_desc.ByteWidth = 1024;
1538 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1539 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
1540 buffer_desc.CPUAccessFlags = 0;
1541 buffer_desc.MiscFlags = 0;
1543 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1545 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb[i]);
1546 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1549 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE;
1551 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1553 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer[i]);
1554 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1556 stride[i] = (i + 1) * 4;
1557 offset[i] = (i + 1) * 16;
1560 buffer_desc.BindFlags = D3D10_BIND_STREAM_OUTPUT;
1562 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1564 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &so_buffer[i]);
1565 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1568 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1569 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
1570 U(srv_desc).Buffer.ElementOffset = 0;
1571 U(srv_desc).Buffer.ElementWidth = 64;
1573 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1575 hr = ID3D10Device_CreateShaderResourceView(device,
1576 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
1577 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
1580 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
1581 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
1582 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
1583 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
1584 sampler_desc.MipLODBias = 0.0f;
1585 sampler_desc.MaxAnisotropy = 16;
1586 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
1587 sampler_desc.BorderColor[0] = 0.0f;
1588 sampler_desc.BorderColor[1] = 0.0f;
1589 sampler_desc.BorderColor[2] = 0.0f;
1590 sampler_desc.BorderColor[3] = 0.0f;
1591 sampler_desc.MinLOD = 0.0f;
1592 sampler_desc.MaxLOD = 16.0f;
1594 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1596 sampler_desc.MinLOD = (float)i;
1598 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
1599 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1602 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
1603 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1605 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
1606 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
1608 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
1609 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1611 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1612 simple_vs, sizeof(simple_vs), &input_layout);
1613 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1615 blend_desc.AlphaToCoverageEnable = FALSE;
1616 blend_desc.BlendEnable[0] = FALSE;
1617 blend_desc.BlendEnable[1] = FALSE;
1618 blend_desc.BlendEnable[2] = FALSE;
1619 blend_desc.BlendEnable[3] = FALSE;
1620 blend_desc.BlendEnable[4] = FALSE;
1621 blend_desc.BlendEnable[5] = FALSE;
1622 blend_desc.BlendEnable[6] = FALSE;
1623 blend_desc.BlendEnable[7] = FALSE;
1624 blend_desc.SrcBlend = D3D10_BLEND_ONE;
1625 blend_desc.DestBlend = D3D10_BLEND_ZERO;
1626 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
1627 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
1628 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
1629 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
1630 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
1631 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
1632 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
1633 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
1634 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
1635 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
1636 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
1637 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
1639 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
1640 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1642 ds_desc.DepthEnable = TRUE;
1643 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
1644 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
1645 ds_desc.StencilEnable = FALSE;
1646 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
1647 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
1648 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1649 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1650 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1651 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1652 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1653 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1654 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1655 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1657 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
1658 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
1660 texture_desc.Width = 512;
1661 texture_desc.Height = 512;
1662 texture_desc.MipLevels = 1;
1663 texture_desc.ArraySize = 1;
1664 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1665 texture_desc.SampleDesc.Count = 1;
1666 texture_desc.SampleDesc.Quality = 0;
1667 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1668 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1669 texture_desc.CPUAccessFlags = 0;
1670 texture_desc.MiscFlags = 0;
1672 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1674 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
1675 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1678 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1679 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1681 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
1682 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1684 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1686 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
1687 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1690 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
1691 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
1693 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1695 tmp_rect[i].left = i;
1696 tmp_rect[i].top = i * 2;
1697 tmp_rect[i].right = i + 1;
1698 tmp_rect[i].bottom = (i + 1) * 2;
1700 tmp_viewport[i].TopLeftX = i * 3;
1701 tmp_viewport[i].TopLeftY = i * 4;
1702 tmp_viewport[i].Width = 3;
1703 tmp_viewport[i].Height = 4;
1704 tmp_viewport[i].MinDepth = i * 0.01f;
1705 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
1708 rs_desc.FillMode = D3D10_FILL_SOLID;
1709 rs_desc.CullMode = D3D10_CULL_BACK;
1710 rs_desc.FrontCounterClockwise = FALSE;
1711 rs_desc.DepthBias = 0;
1712 rs_desc.DepthBiasClamp = 0.0f;
1713 rs_desc.SlopeScaledDepthBias = 0.0f;
1714 rs_desc.DepthClipEnable = TRUE;
1715 rs_desc.ScissorEnable = FALSE;
1716 rs_desc.MultisampleEnable = FALSE;
1717 rs_desc.AntialiasedLineEnable = FALSE;
1719 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
1720 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1722 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
1723 predicate_desc.MiscFlags = 0;
1725 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
1726 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1728 /* Setup state. */
1729 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1730 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1731 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1732 ID3D10Device_VSSetShader(device, vs);
1734 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1735 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1736 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1737 ID3D10Device_GSSetShader(device, gs);
1739 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1740 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1741 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1742 ID3D10Device_PSSetShader(device, ps);
1744 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
1745 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
1746 ID3D10Device_IASetInputLayout(device, input_layout);
1747 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1749 blend_factor[0] = 0.1f;
1750 blend_factor[1] = 0.2f;
1751 blend_factor[2] = 0.3f;
1752 blend_factor[3] = 0.4f;
1753 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
1754 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
1755 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
1757 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
1758 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
1759 ID3D10Device_RSSetState(device, rs_state);
1761 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
1763 ID3D10Device_SetPredication(device, predicate, TRUE);
1765 /* Verify the set state. */
1767 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1768 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1770 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1771 tmp_buffer[i], i, cb[i]);
1772 ID3D10Buffer_Release(tmp_buffer[i]);
1774 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1775 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1777 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1778 tmp_srv[i], i, srv[i]);
1779 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1781 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1782 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1784 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1785 tmp_sampler[i], i, sampler[i]);
1786 ID3D10SamplerState_Release(tmp_sampler[i]);
1788 ID3D10Device_VSGetShader(device, &tmp_vs);
1789 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
1790 ID3D10VertexShader_Release(tmp_vs);
1792 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1793 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1795 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1796 tmp_buffer[i], i, cb[i]);
1797 ID3D10Buffer_Release(tmp_buffer[i]);
1799 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1800 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1802 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1803 tmp_srv[i], i, srv[i]);
1804 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1806 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1807 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1809 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1810 tmp_sampler[i], i, sampler[i]);
1811 ID3D10SamplerState_Release(tmp_sampler[i]);
1813 ID3D10Device_GSGetShader(device, &tmp_gs);
1814 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
1815 ID3D10GeometryShader_Release(tmp_gs);
1817 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1818 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1820 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1821 tmp_buffer[i], i, cb[i]);
1822 ID3D10Buffer_Release(tmp_buffer[i]);
1824 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1825 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1827 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1828 tmp_srv[i], i, srv[i]);
1829 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1831 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1832 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1834 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1835 tmp_sampler[i], i, sampler[i]);
1836 ID3D10SamplerState_Release(tmp_sampler[i]);
1838 ID3D10Device_PSGetShader(device, &tmp_ps);
1839 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
1840 ID3D10PixelShader_Release(tmp_ps);
1842 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1843 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1845 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
1846 tmp_buffer[i], i, buffer[i]);
1847 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
1848 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
1849 ID3D10Buffer_Release(tmp_buffer[i]);
1851 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1852 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
1853 ID3D10Buffer_Release(tmp_buffer[0]);
1854 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
1855 todo_wine ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
1856 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1857 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
1858 tmp_input_layout, input_layout);
1859 ID3D10InputLayout_Release(tmp_input_layout);
1860 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1861 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
1863 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1864 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
1865 ID3D10BlendState_Release(tmp_blend_state);
1866 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
1867 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
1868 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1869 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1870 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
1871 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1872 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
1873 ID3D10DepthStencilState_Release(tmp_ds_state);
1874 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
1875 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1876 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1878 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
1879 tmp_rtv[i], i, rtv[i]);
1880 ID3D10RenderTargetView_Release(tmp_rtv[i]);
1882 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
1883 ID3D10DepthStencilView_Release(tmp_dsv);
1885 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1886 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1887 "Got unexpected scissor rect count %u.\n", count);
1888 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1889 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1890 for (i = 0; i < count; ++i)
1892 ok(tmp_rect[i].left == i
1893 && tmp_rect[i].top == i * 2
1894 && tmp_rect[i].right == i + 1
1895 && tmp_rect[i].bottom == (i + 1) * 2,
1896 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1897 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1899 ID3D10Device_RSGetViewports(device, &count, NULL);
1900 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1901 "Got unexpected viewport count %u.\n", count);
1902 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1903 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1904 for (i = 0; i < count; ++i)
1906 ok(tmp_viewport[i].TopLeftX == i * 3
1907 && tmp_viewport[i].TopLeftY == i * 4
1908 && tmp_viewport[i].Width == 3
1909 && tmp_viewport[i].Height == 4
1910 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
1911 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
1912 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1913 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1914 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1916 ID3D10Device_RSGetState(device, &tmp_rs_state);
1917 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
1918 ID3D10RasterizerState_Release(tmp_rs_state);
1920 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1921 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1923 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
1924 tmp_buffer[i], i, buffer[i]);
1925 ID3D10Buffer_Release(tmp_buffer[i]);
1926 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1929 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1930 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
1931 ID3D10Predicate_Release(tmp_predicate);
1932 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1934 /* Verify ClearState(). */
1936 ID3D10Device_ClearState(device);
1938 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1939 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1941 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1943 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1944 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1946 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1948 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1949 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1951 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1953 ID3D10Device_VSGetShader(device, &tmp_vs);
1954 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1956 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1957 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1959 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1961 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1962 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1964 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1966 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1967 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1969 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1971 ID3D10Device_GSGetShader(device, &tmp_gs);
1972 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1974 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1975 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1977 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1979 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1980 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1982 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1984 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1985 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1987 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1989 ID3D10Device_PSGetShader(device, &tmp_ps);
1990 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1992 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1993 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1995 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1996 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1997 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1999 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
2000 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
2001 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
2002 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
2003 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
2004 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
2005 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
2006 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
2008 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
2009 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
2010 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
2011 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
2012 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
2013 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
2014 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
2015 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
2016 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
2017 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
2018 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
2019 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2021 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
2023 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
2025 ID3D10Device_RSGetScissorRects(device, &count, NULL);
2026 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
2027 memset(tmp_rect, 0x55, sizeof(tmp_rect));
2028 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2029 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
2030 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2032 if (!i)
2033 todo_wine ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
2034 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2035 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2036 else
2037 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
2038 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
2039 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2041 ID3D10Device_RSGetViewports(device, &count, NULL);
2042 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
2043 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
2044 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2045 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
2046 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2048 if (!i)
2049 todo_wine ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2050 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2051 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2052 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2053 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2054 else
2055 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2056 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2057 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2058 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2059 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2061 ID3D10Device_RSGetState(device, &tmp_rs_state);
2062 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
2064 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2065 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2067 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
2068 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2071 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2072 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
2073 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2075 /* Cleanup. */
2077 ID3D10Predicate_Release(predicate);
2078 ID3D10RasterizerState_Release(rs_state);
2079 ID3D10DepthStencilView_Release(dsv);
2080 ID3D10Texture2D_Release(ds_texture);
2082 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2084 ID3D10RenderTargetView_Release(rtv[i]);
2085 ID3D10Texture2D_Release(rt_texture[i]);
2088 ID3D10DepthStencilState_Release(ds_state);
2089 ID3D10BlendState_Release(blend_state);
2090 ID3D10InputLayout_Release(input_layout);
2091 ID3D10VertexShader_Release(vs);
2092 ID3D10GeometryShader_Release(gs);
2093 ID3D10PixelShader_Release(ps);
2095 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2097 ID3D10SamplerState_Release(sampler[i]);
2100 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2102 ID3D10ShaderResourceView_Release(srv[i]);
2105 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2107 ID3D10Buffer_Release(so_buffer[i]);
2110 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2112 ID3D10Buffer_Release(buffer[i]);
2115 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2117 ID3D10Buffer_Release(cb[i]);
2120 refcount = ID3D10Device_Release(device);
2121 ok(!refcount, "Device has %u references left.\n", refcount);
2124 static void test_blend(void)
2126 ID3D10RenderTargetView *backbuffer_rtv, *offscreen_rtv;
2127 ID3D10BlendState *src_blend, *dst_blend;
2128 ID3D10Texture2D *backbuffer, *offscreen;
2129 D3D10_SUBRESOURCE_DATA buffer_data;
2130 D3D10_TEXTURE2D_DESC texture_desc;
2131 ID3D10InputLayout *input_layout;
2132 D3D10_BUFFER_DESC buffer_desc;
2133 D3D10_BLEND_DESC blend_desc;
2134 unsigned int stride, offset;
2135 IDXGISwapChain *swapchain;
2136 ID3D10VertexShader *vs;
2137 ID3D10PixelShader *ps;
2138 ID3D10Device *device;
2139 D3D10_VIEWPORT vp;
2140 ID3D10Buffer *vb;
2141 ULONG refcount;
2142 DWORD color;
2143 HWND window;
2144 HRESULT hr;
2146 static const DWORD vs_code[] =
2148 #if 0
2149 struct vs_out
2151 float4 position : SV_POSITION;
2152 float4 color : COLOR;
2155 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
2157 struct vs_out o;
2159 o.position = position;
2160 o.color = color;
2162 return o;
2164 #endif
2165 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
2166 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2167 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2168 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
2169 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2170 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
2171 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
2172 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
2173 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
2174 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
2176 static const DWORD ps_code[] =
2178 #if 0
2179 struct vs_out
2181 float4 position : SV_POSITION;
2182 float4 color : COLOR;
2185 float4 main(struct vs_out i) : SV_TARGET
2187 return i.color;
2189 #endif
2190 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
2191 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
2192 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
2193 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
2194 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2195 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2196 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2197 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2199 static const struct
2201 struct vec3 position;
2202 DWORD diffuse;
2204 quads[] =
2206 /* quad1 */
2207 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
2208 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
2209 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
2210 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
2211 /* quad2 */
2212 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2213 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2214 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2215 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2217 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2219 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2220 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
2222 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2223 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2225 if (!(device = create_device()))
2227 skip("Failed to create device, skipping tests.\n");
2228 return;
2230 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2231 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2232 swapchain = create_swapchain(device, window, TRUE);
2233 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2234 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2236 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2237 vs_code, sizeof(vs_code), &input_layout);
2238 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2240 buffer_desc.ByteWidth = sizeof(quads);
2241 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2242 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2243 buffer_desc.CPUAccessFlags = 0;
2244 buffer_desc.MiscFlags = 0;
2246 buffer_data.pSysMem = quads;
2247 buffer_data.SysMemPitch = 0;
2248 buffer_data.SysMemSlicePitch = 0;
2250 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
2251 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2252 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2253 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2254 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2255 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2257 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2258 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2260 memset(&blend_desc, 0, sizeof(blend_desc));
2261 blend_desc.BlendEnable[0] = TRUE;
2262 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
2263 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
2264 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
2265 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
2266 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
2267 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
2268 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
2270 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
2271 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2273 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
2274 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
2275 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
2276 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
2278 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
2279 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2281 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2282 ID3D10Device_IASetInputLayout(device, input_layout);
2283 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2284 stride = sizeof(*quads);
2285 offset = 0;
2286 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2287 ID3D10Device_VSSetShader(device, vs);
2288 ID3D10Device_PSSetShader(device, ps);
2290 vp.TopLeftX = 0;
2291 vp.TopLeftY = 0;
2292 vp.Width = 640;
2293 vp.Height = 480;
2294 vp.MinDepth = 0.0f;
2295 vp.MaxDepth = 1.0f;
2296 ID3D10Device_RSSetViewports(device, 1, &vp);
2298 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2300 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2301 ID3D10Device_Draw(device, 4, 0);
2302 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2303 ID3D10Device_Draw(device, 4, 4);
2305 color = get_texture_color(backbuffer, 320, 360);
2306 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
2307 color = get_texture_color(backbuffer, 320, 120);
2308 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
2310 texture_desc.Width = 128;
2311 texture_desc.Height = 128;
2312 texture_desc.MipLevels = 1;
2313 texture_desc.ArraySize = 1;
2314 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
2315 texture_desc.SampleDesc.Count = 1;
2316 texture_desc.SampleDesc.Quality = 0;
2317 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2318 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
2319 texture_desc.CPUAccessFlags = 0;
2320 texture_desc.MiscFlags = 0;
2322 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
2323 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
2325 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
2326 goto done;
2329 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
2330 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2332 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
2334 vp.TopLeftX = 0;
2335 vp.TopLeftY = 0;
2336 vp.Width = 128;
2337 vp.Height = 128;
2338 vp.MinDepth = 0.0f;
2339 vp.MaxDepth = 1.0f;
2340 ID3D10Device_RSSetViewports(device, 1, &vp);
2342 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
2344 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2345 ID3D10Device_Draw(device, 4, 0);
2346 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2347 ID3D10Device_Draw(device, 4, 4);
2349 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
2350 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
2351 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
2352 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
2354 ID3D10RenderTargetView_Release(offscreen_rtv);
2355 ID3D10Texture2D_Release(offscreen);
2356 done:
2357 ID3D10BlendState_Release(dst_blend);
2358 ID3D10BlendState_Release(src_blend);
2359 ID3D10PixelShader_Release(ps);
2360 ID3D10VertexShader_Release(vs);
2361 ID3D10Buffer_Release(vb);
2362 ID3D10InputLayout_Release(input_layout);
2363 ID3D10RenderTargetView_Release(backbuffer_rtv);
2364 ID3D10Texture2D_Release(backbuffer);
2365 IDXGISwapChain_Release(swapchain);
2366 refcount = ID3D10Device_Release(device);
2367 ok(!refcount, "Device has %u references left.\n", refcount);
2368 DestroyWindow(window);
2371 static void test_texture(void)
2373 ID3D10RenderTargetView *backbuffer_rtv;
2374 D3D10_SUBRESOURCE_DATA resource_data;
2375 D3D10_TEXTURE2D_DESC texture_desc;
2376 ID3D10SamplerState *sampler_state;
2377 ID3D10ShaderResourceView *ps_srv;
2378 D3D10_SAMPLER_DESC sampler_desc;
2379 ID3D10InputLayout *input_layout;
2380 D3D10_BUFFER_DESC buffer_desc;
2381 ID3D10Texture2D *backbuffer;
2382 unsigned int stride, offset;
2383 IDXGISwapChain *swapchain;
2384 ID3D10Texture2D *texture;
2385 ID3D10VertexShader *vs;
2386 ID3D10PixelShader *ps;
2387 ID3D10Device *device;
2388 D3D10_VIEWPORT vp;
2389 unsigned int i, j;
2390 ID3D10Buffer *vb;
2391 ULONG refcount;
2392 DWORD color;
2393 HWND window;
2394 HRESULT hr;
2396 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2398 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2400 static const DWORD vs_code[] =
2402 #if 0
2403 float4 main(float4 position : POSITION) : SV_POSITION
2405 return position;
2407 #endif
2408 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2409 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2410 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2411 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2412 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2413 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2414 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2416 static const DWORD ps_code[] =
2418 #if 0
2419 Texture2D t;
2420 SamplerState s;
2422 float4 main(float4 position : SV_POSITION) : SV_Target
2424 float2 p;
2426 p.x = position.x / 640.0f;
2427 p.y = position.y / 480.0f;
2428 return t.Sample(s, p);
2430 #endif
2431 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
2432 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2433 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2434 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2435 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
2436 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
2437 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
2438 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
2439 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
2440 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
2442 static const struct
2444 float x, y;
2446 quad[] =
2448 {-1.0f, -1.0f},
2449 {-1.0f, 1.0f},
2450 { 1.0f, -1.0f},
2451 { 1.0f, 1.0f},
2453 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2454 static const DWORD bitmap_data[] =
2456 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
2457 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
2458 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
2459 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
2462 if (!(device = create_device()))
2464 skip("Failed to create device, skipping tests.\n");
2465 return;
2467 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2468 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2469 swapchain = create_swapchain(device, window, TRUE);
2470 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2471 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2473 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2474 vs_code, sizeof(vs_code), &input_layout);
2475 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2477 buffer_desc.ByteWidth = sizeof(quad);
2478 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2479 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2480 buffer_desc.CPUAccessFlags = 0;
2481 buffer_desc.MiscFlags = 0;
2483 resource_data.pSysMem = quad;
2484 resource_data.SysMemPitch = 0;
2485 resource_data.SysMemSlicePitch = 0;
2487 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
2488 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2490 texture_desc.Width = 4;
2491 texture_desc.Height = 4;
2492 texture_desc.MipLevels = 1;
2493 texture_desc.ArraySize = 1;
2494 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2495 texture_desc.SampleDesc.Count = 1;
2496 texture_desc.SampleDesc.Quality = 0;
2497 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2498 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2499 texture_desc.CPUAccessFlags = 0;
2500 texture_desc.MiscFlags = 0;
2502 resource_data.pSysMem = bitmap_data;
2503 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
2505 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
2506 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2508 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
2509 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
2511 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
2512 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
2513 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
2514 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
2515 sampler_desc.MipLODBias = 0.0f;
2516 sampler_desc.MaxAnisotropy = 0;
2517 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2518 sampler_desc.BorderColor[0] = 0.0f;
2519 sampler_desc.BorderColor[1] = 0.0f;
2520 sampler_desc.BorderColor[2] = 0.0f;
2521 sampler_desc.BorderColor[3] = 0.0f;
2522 sampler_desc.MinLOD = 0.0f;
2523 sampler_desc.MaxLOD = 0.0f;
2525 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
2526 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2528 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2529 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2530 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2531 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2533 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2534 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2536 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2537 ID3D10Device_IASetInputLayout(device, input_layout);
2538 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2539 stride = sizeof(*quad);
2540 offset = 0;
2541 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2542 ID3D10Device_VSSetShader(device, vs);
2543 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
2544 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
2545 ID3D10Device_PSSetShader(device, ps);
2547 vp.TopLeftX = 0;
2548 vp.TopLeftY = 0;
2549 vp.Width = 640;
2550 vp.Height = 480;
2551 vp.MinDepth = 0.0f;
2552 vp.MaxDepth = 1.0f;
2553 ID3D10Device_RSSetViewports(device, 1, &vp);
2555 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2557 ID3D10Device_Draw(device, 4, 0);
2559 for (i = 0; i < 4; ++i)
2561 for (j = 0; j < 4; ++j)
2563 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
2564 ok(compare_color(color, bitmap_data[j + i * 4], 1),
2565 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
2566 color, j, i, bitmap_data[j + i * 4]);
2570 ID3D10PixelShader_Release(ps);
2571 ID3D10VertexShader_Release(vs);
2572 ID3D10SamplerState_Release(sampler_state);
2573 ID3D10ShaderResourceView_Release(ps_srv);
2574 ID3D10Texture2D_Release(texture);
2575 ID3D10Buffer_Release(vb);
2576 ID3D10InputLayout_Release(input_layout);
2577 ID3D10RenderTargetView_Release(backbuffer_rtv);
2578 ID3D10Texture2D_Release(backbuffer);
2579 IDXGISwapChain_Release(swapchain);
2580 refcount = ID3D10Device_Release(device);
2581 ok(!refcount, "Device has %u references left.\n", refcount);
2582 DestroyWindow(window);
2585 static void test_private_data(void)
2587 D3D10_TEXTURE2D_DESC texture_desc;
2588 ULONG refcount, expected_refcount;
2589 ID3D10Device *test_object;
2590 ID3D10Texture2D *texture;
2591 IDXGIDevice *dxgi_device;
2592 IDXGISurface *surface;
2593 ID3D10Device *device;
2594 IUnknown *ptr;
2595 HRESULT hr;
2596 UINT size;
2598 static const GUID test_guid =
2599 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2600 static const GUID test_guid2 =
2601 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2602 static const DWORD data[] = {1, 2, 3, 4};
2604 if (!(device = create_device()))
2606 skip("Failed to create device, skipping tests.\n");
2607 return;
2610 test_object = create_device();
2612 texture_desc.Width = 512;
2613 texture_desc.Height = 512;
2614 texture_desc.MipLevels = 1;
2615 texture_desc.ArraySize = 1;
2616 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2617 texture_desc.SampleDesc.Count = 1;
2618 texture_desc.SampleDesc.Quality = 0;
2619 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2620 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2621 texture_desc.CPUAccessFlags = 0;
2622 texture_desc.MiscFlags = 0;
2624 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2625 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2626 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2627 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
2629 /* SetPrivateData() with a pointer of NULL has the purpose of
2630 * FreePrivateData() in previous D3D versions. A successful clear returns
2631 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
2632 * considered a clear but as setting an interface pointer that happens to
2633 * be NULL. */
2634 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
2635 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2636 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2637 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2638 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2639 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2640 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2641 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2643 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2644 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2645 size = sizeof(ptr) * 2;
2646 ptr = (IUnknown *)0xdeadbeef;
2647 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2648 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2649 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2650 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2652 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2653 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2654 size = sizeof(ptr) * 2;
2655 ptr = (IUnknown *)0xdeadbeef;
2656 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2657 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2658 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2659 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2660 IDXGIDevice_Release(dxgi_device);
2662 refcount = get_refcount((IUnknown *)test_object);
2663 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2664 (IUnknown *)test_object);
2665 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2666 expected_refcount = refcount + 1;
2667 refcount = get_refcount((IUnknown *)test_object);
2668 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2669 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2670 (IUnknown *)test_object);
2671 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2672 refcount = get_refcount((IUnknown *)test_object);
2673 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2675 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2676 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2677 --expected_refcount;
2678 refcount = get_refcount((IUnknown *)test_object);
2679 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2681 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2682 (IUnknown *)test_object);
2683 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2684 size = sizeof(data);
2685 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
2686 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2687 refcount = get_refcount((IUnknown *)test_object);
2688 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2689 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2690 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2691 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2692 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2694 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2695 (IUnknown *)test_object);
2696 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2697 ++expected_refcount;
2698 size = 2 * sizeof(ptr);
2699 ptr = NULL;
2700 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2701 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2702 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2703 ++expected_refcount;
2704 refcount = get_refcount((IUnknown *)test_object);
2705 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2706 IUnknown_Release(ptr);
2707 --expected_refcount;
2709 ptr = (IUnknown *)0xdeadbeef;
2710 size = 1;
2711 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2712 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2713 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2714 size = 2 * sizeof(ptr);
2715 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2716 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2717 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2718 refcount = get_refcount((IUnknown *)test_object);
2719 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2721 size = 1;
2722 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2723 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2724 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2725 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2726 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2727 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2728 size = 0xdeadbabe;
2729 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2730 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2731 ok(size == 0, "Got unexpected size %u.\n", size);
2732 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2733 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2734 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2735 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2737 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
2738 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2739 ptr = NULL;
2740 size = sizeof(ptr);
2741 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
2742 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2743 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2744 IUnknown_Release(ptr);
2746 IDXGISurface_Release(surface);
2747 ID3D10Texture2D_Release(texture);
2748 refcount = ID3D10Device_Release(device);
2749 ok(!refcount, "Device has %u references left.\n", refcount);
2750 refcount = ID3D10Device_Release(test_object);
2751 ok(!refcount, "Test object has %u references left.\n", refcount);
2754 static void test_il_append_aligned(void)
2756 ID3D10RenderTargetView *backbuffer_rtv;
2757 D3D10_SUBRESOURCE_DATA resource_data;
2758 ID3D10InputLayout *input_layout;
2759 D3D10_BUFFER_DESC buffer_desc;
2760 ID3D10Texture2D *backbuffer;
2761 unsigned int stride, offset;
2762 IDXGISwapChain *swapchain;
2763 ID3D10VertexShader *vs;
2764 ID3D10PixelShader *ps;
2765 ID3D10Device *device;
2766 ID3D10Buffer *vb[3];
2767 D3D10_VIEWPORT vp;
2768 ULONG refcount;
2769 DWORD color;
2770 HWND window;
2771 HRESULT hr;
2773 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2775 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
2776 D3D10_INPUT_PER_INSTANCE_DATA, 2},
2777 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
2778 D3D10_INPUT_PER_INSTANCE_DATA, 1},
2779 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
2780 D3D10_INPUT_PER_VERTEX_DATA, 0},
2781 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
2782 D3D10_INPUT_PER_INSTANCE_DATA, 1},
2783 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
2784 D3D10_INPUT_PER_INSTANCE_DATA, 2},
2786 static const DWORD vs_code[] =
2788 #if 0
2789 struct vs_in
2791 float4 position : POSITION;
2792 float2 color_xy : COLOR0;
2793 float2 color_zw : COLOR1;
2794 unsigned int instance_id : SV_INSTANCEID;
2797 struct vs_out
2799 float4 position : SV_POSITION;
2800 float2 color_xy : COLOR0;
2801 float2 color_zw : COLOR1;
2804 struct vs_out main(struct vs_in i)
2806 struct vs_out o;
2808 o.position = i.position;
2809 o.position.x += i.instance_id * 0.5;
2810 o.color_xy = i.color_xy;
2811 o.color_zw = i.color_zw;
2813 return o;
2815 #endif
2816 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
2817 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
2818 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
2819 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
2820 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
2821 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
2822 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2823 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
2824 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
2825 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
2826 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
2827 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
2828 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
2829 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
2830 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
2831 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
2832 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
2834 static const DWORD ps_code[] =
2836 #if 0
2837 struct vs_out
2839 float4 position : SV_POSITION;
2840 float2 color_xy : COLOR0;
2841 float2 color_zw : COLOR1;
2844 float4 main(struct vs_out i) : SV_TARGET
2846 return float4(i.color_xy.xy, i.color_zw.xy);
2848 #endif
2849 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
2850 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
2851 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
2852 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
2853 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2854 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
2855 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
2856 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
2857 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2859 static const struct
2861 struct vec4 position;
2863 stream0[] =
2865 {{-1.0f, -1.0f, 0.0f, 1.0f}},
2866 {{-1.0f, 1.0f, 0.0f, 1.0f}},
2867 {{-0.5f, -1.0f, 0.0f, 1.0f}},
2868 {{-0.5f, 1.0f, 0.0f, 1.0f}},
2870 static const struct
2872 struct vec2 color2;
2873 struct vec2 color1;
2875 stream1[] =
2877 {{0.5f, 0.5f}, {0.0f, 1.0f}},
2878 {{0.5f, 0.5f}, {1.0f, 1.0f}},
2880 static const struct
2882 struct vec2 color3;
2883 struct vec2 color0;
2885 stream2[] =
2887 {{0.5f, 0.5f}, {1.0f, 0.0f}},
2888 {{0.5f, 0.5f}, {0.0f, 1.0f}},
2889 {{0.5f, 0.5f}, {0.0f, 0.0f}},
2890 {{0.5f, 0.5f}, {1.0f, 0.0f}},
2892 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2894 if (!(device = create_device()))
2896 skip("Failed to create device, skipping tests.\n");
2897 return;
2899 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2900 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2901 swapchain = create_swapchain(device, window, TRUE);
2902 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2903 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2905 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2906 vs_code, sizeof(vs_code), &input_layout);
2907 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2909 buffer_desc.ByteWidth = sizeof(stream0);
2910 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2911 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2912 buffer_desc.CPUAccessFlags = 0;
2913 buffer_desc.MiscFlags = 0;
2915 resource_data.pSysMem = stream0;
2916 resource_data.SysMemPitch = 0;
2917 resource_data.SysMemSlicePitch = 0;
2919 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
2920 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2922 buffer_desc.ByteWidth = sizeof(stream1);
2923 resource_data.pSysMem = stream1;
2925 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
2926 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2928 buffer_desc.ByteWidth = sizeof(stream2);
2929 resource_data.pSysMem = stream2;
2931 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
2932 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2934 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2935 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2936 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2937 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2939 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2940 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2942 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2943 ID3D10Device_IASetInputLayout(device, input_layout);
2944 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2945 offset = 0;
2946 stride = sizeof(*stream0);
2947 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
2948 stride = sizeof(*stream1);
2949 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
2950 stride = sizeof(*stream2);
2951 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
2952 ID3D10Device_VSSetShader(device, vs);
2953 ID3D10Device_PSSetShader(device, ps);
2955 vp.TopLeftX = 0;
2956 vp.TopLeftY = 0;
2957 vp.Width = 640;
2958 vp.Height = 480;
2959 vp.MinDepth = 0.0f;
2960 vp.MaxDepth = 1.0f;
2961 ID3D10Device_RSSetViewports(device, 1, &vp);
2963 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2965 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
2967 color = get_texture_color(backbuffer, 80, 240);
2968 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2969 color = get_texture_color(backbuffer, 240, 240);
2970 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2971 color = get_texture_color(backbuffer, 400, 240);
2972 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
2973 color = get_texture_color(backbuffer, 560, 240);
2974 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
2976 ID3D10PixelShader_Release(ps);
2977 ID3D10VertexShader_Release(vs);
2978 ID3D10Buffer_Release(vb[2]);
2979 ID3D10Buffer_Release(vb[1]);
2980 ID3D10Buffer_Release(vb[0]);
2981 ID3D10InputLayout_Release(input_layout);
2982 ID3D10RenderTargetView_Release(backbuffer_rtv);
2983 ID3D10Texture2D_Release(backbuffer);
2984 IDXGISwapChain_Release(swapchain);
2985 refcount = ID3D10Device_Release(device);
2986 ok(!refcount, "Device has %u references left.\n", refcount);
2987 DestroyWindow(window);
2990 static void test_fragment_coords(void)
2992 ID3D10RenderTargetView *backbuffer_rtv;
2993 D3D10_SUBRESOURCE_DATA resource_data;
2994 ID3D10InputLayout *input_layout;
2995 ID3D10PixelShader *ps, *ps_frac;
2996 D3D10_BUFFER_DESC buffer_desc;
2997 ID3D10Texture2D *backbuffer;
2998 unsigned int stride, offset;
2999 IDXGISwapChain *swapchain;
3000 ID3D10Buffer *vb, *ps_cb;
3001 ID3D10VertexShader *vs;
3002 ID3D10Device *device;
3003 D3D10_VIEWPORT vp;
3004 ULONG refcount;
3005 DWORD color;
3006 HWND window;
3007 HRESULT hr;
3009 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
3011 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
3013 static const DWORD vs_code[] =
3015 #if 0
3016 float4 main(float4 position : POSITION) : SV_POSITION
3018 return position;
3020 #endif
3021 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3022 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3023 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3024 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3025 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3026 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3027 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3029 static const DWORD ps_code[] =
3031 #if 0
3032 float2 cutoff;
3034 float4 main(float4 position : SV_POSITION) : SV_TARGET
3036 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
3038 if (position.x > cutoff.x)
3039 ret.y = 1.0;
3040 if (position.y > cutoff.y)
3041 ret.z = 1.0;
3043 return ret;
3045 #endif
3046 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
3047 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3048 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3049 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3050 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
3051 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
3052 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
3053 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
3054 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
3055 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
3056 0x0100003e,
3058 static const DWORD ps_frac_code[] =
3060 #if 0
3061 float4 main(float4 position : SV_POSITION) : SV_TARGET
3063 return float4(frac(position.xy), 0.0, 1.0);
3065 #endif
3066 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
3067 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3068 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3069 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3070 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
3071 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3072 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
3073 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
3075 static const struct
3077 struct vec2 position;
3079 quad[] =
3081 {{-1.0f, -1.0f}},
3082 {{-1.0f, 1.0f}},
3083 {{ 1.0f, -1.0f}},
3084 {{ 1.0f, 1.0f}},
3086 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3087 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
3089 if (!(device = create_device()))
3091 skip("Failed to create device, skipping tests.\n");
3092 return;
3094 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3095 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3096 swapchain = create_swapchain(device, window, TRUE);
3097 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
3098 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3100 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3101 vs_code, sizeof(vs_code), &input_layout);
3102 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3104 buffer_desc.ByteWidth = sizeof(quad);
3105 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3106 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
3107 buffer_desc.CPUAccessFlags = 0;
3108 buffer_desc.MiscFlags = 0;
3110 resource_data.pSysMem = quad;
3111 resource_data.SysMemPitch = 0;
3112 resource_data.SysMemSlicePitch = 0;
3114 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3115 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3117 buffer_desc.ByteWidth = sizeof(cutoff);
3118 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
3120 resource_data.pSysMem = &cutoff;
3122 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3123 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3125 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
3126 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3127 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3128 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3129 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
3130 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3132 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
3133 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3135 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
3136 ID3D10Device_IASetInputLayout(device, input_layout);
3137 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3138 stride = sizeof(*quad);
3139 offset = 0;
3140 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
3141 ID3D10Device_VSSetShader(device, vs);
3142 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
3143 ID3D10Device_PSSetShader(device, ps);
3145 vp.TopLeftX = 0;
3146 vp.TopLeftY = 0;
3147 vp.Width = 640;
3148 vp.Height = 480;
3149 vp.MinDepth = 0.0f;
3150 vp.MaxDepth = 1.0f;
3151 ID3D10Device_RSSetViewports(device, 1, &vp);
3153 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3155 ID3D10Device_Draw(device, 4, 0);
3157 color = get_texture_color(backbuffer, 319, 239);
3158 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3159 color = get_texture_color(backbuffer, 320, 239);
3160 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3161 color = get_texture_color(backbuffer, 319, 240);
3162 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3163 color = get_texture_color(backbuffer, 320, 240);
3164 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3166 ID3D10Buffer_Release(ps_cb);
3167 cutoff.x = 16.0f;
3168 cutoff.y = 16.0f;
3169 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3170 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3171 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
3173 ID3D10Device_Draw(device, 4, 0);
3175 color = get_texture_color(backbuffer, 14, 14);
3176 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3177 color = get_texture_color(backbuffer, 18, 14);
3178 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3179 color = get_texture_color(backbuffer, 14, 18);
3180 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3181 color = get_texture_color(backbuffer, 18, 18);
3182 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3184 ID3D10Device_PSSetShader(device, ps_frac);
3185 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3187 ID3D10Device_Draw(device, 4, 0);
3189 color = get_texture_color(backbuffer, 14, 14);
3190 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
3192 ID3D10Buffer_Release(ps_cb);
3193 ID3D10PixelShader_Release(ps_frac);
3194 ID3D10PixelShader_Release(ps);
3195 ID3D10VertexShader_Release(vs);
3196 ID3D10Buffer_Release(vb);
3197 ID3D10InputLayout_Release(input_layout);
3198 ID3D10RenderTargetView_Release(backbuffer_rtv);
3199 ID3D10Texture2D_Release(backbuffer);
3200 IDXGISwapChain_Release(swapchain);
3201 refcount = ID3D10Device_Release(device);
3202 ok(!refcount, "Device has %u references left.\n", refcount);
3203 DestroyWindow(window);
3206 static void test_update_subresource(void)
3208 ID3D10RenderTargetView *backbuffer_rtv;
3209 D3D10_SUBRESOURCE_DATA resource_data;
3210 D3D10_TEXTURE2D_DESC texture_desc;
3211 ID3D10SamplerState *sampler_state;
3212 ID3D10ShaderResourceView *ps_srv;
3213 D3D10_SAMPLER_DESC sampler_desc;
3214 ID3D10InputLayout *input_layout;
3215 D3D10_BUFFER_DESC buffer_desc;
3216 ID3D10Texture2D *backbuffer;
3217 unsigned int stride, offset;
3218 IDXGISwapChain *swapchain;
3219 ID3D10Texture2D *texture;
3220 ID3D10VertexShader *vs;
3221 ID3D10PixelShader *ps;
3222 ID3D10Device *device;
3223 D3D10_VIEWPORT vp;
3224 unsigned int i, j;
3225 ID3D10Buffer *vb;
3226 ULONG refcount;
3227 D3D10_BOX box;
3228 DWORD color;
3229 HWND window;
3230 HRESULT hr;
3232 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
3234 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
3236 static const DWORD vs_code[] =
3238 #if 0
3239 float4 main(float4 position : POSITION) : SV_POSITION
3241 return position;
3243 #endif
3244 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3245 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3246 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3247 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3248 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3249 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3250 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3252 static const DWORD ps_code[] =
3254 #if 0
3255 Texture2D t;
3256 SamplerState s;
3258 float4 main(float4 position : SV_POSITION) : SV_Target
3260 float2 p;
3262 p.x = position.x / 640.0f;
3263 p.y = position.y / 480.0f;
3264 return t.Sample(s, p);
3266 #endif
3267 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3268 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3269 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3270 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3271 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3272 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3273 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3274 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3275 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3276 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3278 static const struct
3280 float x, y;
3282 quad[] =
3284 {-1.0f, -1.0f},
3285 {-1.0f, 1.0f},
3286 { 1.0f, -1.0f},
3287 { 1.0f, 1.0f},
3289 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3290 static const DWORD bitmap_data[] =
3292 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3293 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3294 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3295 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3297 static const DWORD expected_colors[] =
3299 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
3300 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
3301 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
3302 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
3305 if (!(device = create_device()))
3307 skip("Failed to create device, skipping tests.\n");
3308 return;
3310 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3311 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3312 swapchain = create_swapchain(device, window, TRUE);
3313 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
3314 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3316 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3317 vs_code, sizeof(vs_code), &input_layout);
3318 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3320 buffer_desc.ByteWidth = sizeof(quad);
3321 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3322 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
3323 buffer_desc.CPUAccessFlags = 0;
3324 buffer_desc.MiscFlags = 0;
3326 resource_data.pSysMem = quad;
3327 resource_data.SysMemPitch = 0;
3328 resource_data.SysMemSlicePitch = 0;
3330 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3331 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3333 texture_desc.Width = 4;
3334 texture_desc.Height = 4;
3335 texture_desc.MipLevels = 1;
3336 texture_desc.ArraySize = 1;
3337 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3338 texture_desc.SampleDesc.Count = 1;
3339 texture_desc.SampleDesc.Quality = 0;
3340 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3341 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3342 texture_desc.CPUAccessFlags = 0;
3343 texture_desc.MiscFlags = 0;
3345 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3346 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
3348 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
3349 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
3351 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
3352 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
3353 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
3354 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
3355 sampler_desc.MipLODBias = 0.0f;
3356 sampler_desc.MaxAnisotropy = 0;
3357 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
3358 sampler_desc.BorderColor[0] = 0.0f;
3359 sampler_desc.BorderColor[1] = 0.0f;
3360 sampler_desc.BorderColor[2] = 0.0f;
3361 sampler_desc.BorderColor[3] = 0.0f;
3362 sampler_desc.MinLOD = 0.0f;
3363 sampler_desc.MaxLOD = 0.0f;
3365 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
3366 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3368 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
3369 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3370 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3371 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3373 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
3374 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3376 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
3377 ID3D10Device_IASetInputLayout(device, input_layout);
3378 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3379 stride = sizeof(*quad);
3380 offset = 0;
3381 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
3382 ID3D10Device_VSSetShader(device, vs);
3383 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
3384 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
3385 ID3D10Device_PSSetShader(device, ps);
3387 vp.TopLeftX = 0;
3388 vp.TopLeftY = 0;
3389 vp.Width = 640;
3390 vp.Height = 480;
3391 vp.MinDepth = 0.0f;
3392 vp.MaxDepth = 1.0f;
3393 ID3D10Device_RSSetViewports(device, 1, &vp);
3395 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3397 ID3D10Device_Draw(device, 4, 0);
3398 for (i = 0; i < 4; ++i)
3400 for (j = 0; j < 4; ++j)
3402 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
3403 ok(compare_color(color, 0x00000000, 0),
3404 "Got unexpected color 0x%08x at (%u, %u).\n", color, j, i);
3408 set_box(&box, 1, 1, 0, 3, 3, 1);
3409 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
3410 bitmap_data, 4 * sizeof(*bitmap_data), 0);
3411 set_box(&box, 0, 3, 0, 3, 4, 1);
3412 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
3413 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
3414 set_box(&box, 0, 0, 0, 4, 1, 1);
3415 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
3416 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
3417 set_box(&box, 0, 1, 0, 1, 3, 1);
3418 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
3419 &bitmap_data[2], sizeof(*bitmap_data), 0);
3420 set_box(&box, 4, 4, 0, 3, 1, 1);
3421 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
3422 bitmap_data, sizeof(*bitmap_data), 0);
3423 ID3D10Device_Draw(device, 4, 0);
3424 for (i = 0; i < 4; ++i)
3426 for (j = 0; j < 4; ++j)
3428 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
3429 ok(compare_color(color, expected_colors[j + i * 4], 1),
3430 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
3431 color, j, i, expected_colors[j + i * 4]);
3435 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
3436 bitmap_data, 4 * sizeof(*bitmap_data), 0);
3437 ID3D10Device_Draw(device, 4, 0);
3438 for (i = 0; i < 4; ++i)
3440 for (j = 0; j < 4; ++j)
3442 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
3443 ok(compare_color(color, bitmap_data[j + i * 4], 1),
3444 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
3445 color, j, i, bitmap_data[j + i * 4]);
3449 ID3D10PixelShader_Release(ps);
3450 ID3D10VertexShader_Release(vs);
3451 ID3D10SamplerState_Release(sampler_state);
3452 ID3D10ShaderResourceView_Release(ps_srv);
3453 ID3D10Texture2D_Release(texture);
3454 ID3D10Buffer_Release(vb);
3455 ID3D10InputLayout_Release(input_layout);
3456 ID3D10RenderTargetView_Release(backbuffer_rtv);
3457 ID3D10Texture2D_Release(backbuffer);
3458 IDXGISwapChain_Release(swapchain);
3459 refcount = ID3D10Device_Release(device);
3460 ok(!refcount, "Device has %u references left.\n", refcount);
3461 DestroyWindow(window);
3464 START_TEST(device)
3466 test_feature_level();
3467 test_create_texture2d();
3468 test_create_texture3d();
3469 test_create_depthstencil_view();
3470 test_create_rendertarget_view();
3471 test_create_shader_resource_view();
3472 test_create_shader();
3473 test_create_sampler_state();
3474 test_create_blend_state();
3475 test_create_depthstencil_state();
3476 test_create_rasterizer_state();
3477 test_create_predicate();
3478 test_device_removed_reason();
3479 test_scissor();
3480 test_clear_state();
3481 test_blend();
3482 test_texture();
3483 test_private_data();
3484 test_il_append_aligned();
3485 test_fragment_coords();
3486 test_update_subresource();