d3d10core/tests: Fix copy-paste mistake.
[wine.git] / dlls / d3d10core / tests / device.c
blob55dce67e0297047108cee1d802fc059347135a7f
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d10.h"
22 #include "wine/test.h"
23 #include <limits.h>
25 struct vec2
27 float x, y;
30 struct vec3
32 float x, y, z;
35 struct vec4
37 float x, y, z, w;
40 static ULONG get_refcount(IUnknown *iface)
42 IUnknown_AddRef(iface);
43 return IUnknown_Release(iface);
46 static BOOL compare_float(float f, float g, unsigned int ulps)
48 int x = *(int *)&f;
49 int y = *(int *)&g;
51 if (x < 0)
52 x = INT_MIN - x;
53 if (y < 0)
54 y = INT_MIN - y;
56 if (abs(x - y) > ulps)
57 return FALSE;
59 return TRUE;
62 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
64 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
65 return FALSE;
66 c1 >>= 8; c2 >>= 8;
67 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
68 return FALSE;
69 c1 >>= 8; c2 >>= 8;
70 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
71 return FALSE;
72 c1 >>= 8; c2 >>= 8;
73 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
74 return FALSE;
75 return TRUE;
78 static DWORD get_texture_color(ID3D10Texture2D *src_texture, unsigned int x, unsigned int y)
80 D3D10_MAPPED_TEXTURE2D mapped_texture;
81 D3D10_TEXTURE2D_DESC texture_desc;
82 ID3D10Texture2D *dst_texture;
83 ID3D10Device *device;
84 DWORD color;
85 HRESULT hr;
87 ID3D10Texture2D_GetDevice(src_texture, &device);
89 ID3D10Texture2D_GetDesc(src_texture, &texture_desc);
90 texture_desc.Usage = D3D10_USAGE_STAGING;
91 texture_desc.BindFlags = 0;
92 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
93 texture_desc.MiscFlags = 0;
94 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
95 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
97 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
98 hr = ID3D10Texture2D_Map(dst_texture, 0, D3D10_MAP_READ, 0, &mapped_texture);
99 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
100 color = *(DWORD *)(((BYTE *)mapped_texture.pData) + mapped_texture.RowPitch * y + x * 4);
101 ID3D10Texture2D_Unmap(dst_texture, 0);
103 ID3D10Texture2D_Release(dst_texture);
104 ID3D10Device_Release(device);
106 return color;
109 static ID3D10Device *create_device(void)
111 ID3D10Device *device;
113 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
114 return device;
115 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
116 return device;
117 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
118 return device;
120 return NULL;
123 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, BOOL windowed)
125 IDXGISwapChain *swapchain;
126 DXGI_SWAP_CHAIN_DESC desc;
127 IDXGIDevice *dxgi_device;
128 IDXGIAdapter *adapter;
129 IDXGIFactory *factory;
130 HRESULT hr;
132 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
133 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
134 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
135 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
136 IDXGIDevice_Release(dxgi_device);
137 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
138 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
139 IDXGIAdapter_Release(adapter);
141 desc.BufferDesc.Width = 640;
142 desc.BufferDesc.Height = 480;
143 desc.BufferDesc.RefreshRate.Numerator = 60;
144 desc.BufferDesc.RefreshRate.Denominator = 1;
145 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
146 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
147 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
148 desc.SampleDesc.Count = 1;
149 desc.SampleDesc.Quality = 0;
150 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
151 desc.BufferCount = 1;
152 desc.OutputWindow = window;
153 desc.Windowed = windowed;
154 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
155 desc.Flags = 0;
157 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
158 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
159 IDXGIFactory_Release(factory);
161 return swapchain;
164 static void test_create_texture2d(void)
166 ULONG refcount, expected_refcount;
167 D3D10_SUBRESOURCE_DATA data = {0};
168 ID3D10Device *device, *tmp;
169 D3D10_TEXTURE2D_DESC desc;
170 ID3D10Texture2D *texture;
171 IDXGISurface *surface;
172 HRESULT hr;
174 if (!(device = create_device()))
176 skip("Failed to create device, skipping tests.\n");
177 return;
180 desc.Width = 512;
181 desc.Height = 512;
182 desc.MipLevels = 1;
183 desc.ArraySize = 1;
184 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
185 desc.SampleDesc.Count = 1;
186 desc.SampleDesc.Quality = 0;
187 desc.Usage = D3D10_USAGE_DEFAULT;
188 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
189 desc.CPUAccessFlags = 0;
190 desc.MiscFlags = 0;
192 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
193 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
195 expected_refcount = get_refcount((IUnknown *)device) + 1;
196 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
197 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
198 refcount = get_refcount((IUnknown *)device);
199 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
200 tmp = NULL;
201 expected_refcount = refcount + 1;
202 ID3D10Texture2D_GetDevice(texture, &tmp);
203 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
204 refcount = get_refcount((IUnknown *)device);
205 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
206 ID3D10Device_Release(tmp);
208 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
209 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
210 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
211 ID3D10Texture2D_Release(texture);
213 desc.MipLevels = 0;
214 expected_refcount = get_refcount((IUnknown *)device) + 1;
215 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
216 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
217 refcount = get_refcount((IUnknown *)device);
218 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
219 tmp = NULL;
220 expected_refcount = refcount + 1;
221 ID3D10Texture2D_GetDevice(texture, &tmp);
222 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
223 refcount = get_refcount((IUnknown *)device);
224 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
225 ID3D10Device_Release(tmp);
227 ID3D10Texture2D_GetDesc(texture, &desc);
228 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
229 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
230 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
231 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
232 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
233 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
234 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
235 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
236 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
237 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
238 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
240 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
241 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
242 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
243 ID3D10Texture2D_Release(texture);
245 desc.MipLevels = 1;
246 desc.ArraySize = 2;
247 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
248 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
250 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
251 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
252 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
253 ID3D10Texture2D_Release(texture);
255 refcount = ID3D10Device_Release(device);
256 ok(!refcount, "Device has %u references left.\n", refcount);
259 static void test_create_texture3d(void)
261 ULONG refcount, expected_refcount;
262 D3D10_SUBRESOURCE_DATA data = {0};
263 ID3D10Device *device, *tmp;
264 D3D10_TEXTURE3D_DESC desc;
265 ID3D10Texture3D *texture;
266 IDXGISurface *surface;
267 HRESULT hr;
269 if (!(device = create_device()))
271 skip("Failed to create device, skipping tests.\n");
272 return;
275 desc.Width = 64;
276 desc.Height = 64;
277 desc.Depth = 64;
278 desc.MipLevels = 1;
279 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
280 desc.Usage = D3D10_USAGE_DEFAULT;
281 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
282 desc.CPUAccessFlags = 0;
283 desc.MiscFlags = 0;
285 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
286 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
288 expected_refcount = get_refcount((IUnknown *)device) + 1;
289 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
290 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
291 refcount = get_refcount((IUnknown *)device);
292 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
293 tmp = NULL;
294 expected_refcount = refcount + 1;
295 ID3D10Texture3D_GetDevice(texture, &tmp);
296 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
297 refcount = get_refcount((IUnknown *)device);
298 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
299 ID3D10Device_Release(tmp);
301 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
302 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
303 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
304 ID3D10Texture3D_Release(texture);
306 desc.MipLevels = 0;
307 expected_refcount = get_refcount((IUnknown *)device) + 1;
308 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
309 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
310 refcount = get_refcount((IUnknown *)device);
311 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
312 tmp = NULL;
313 expected_refcount = refcount + 1;
314 ID3D10Texture3D_GetDevice(texture, &tmp);
315 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
316 refcount = get_refcount((IUnknown *)device);
317 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
318 ID3D10Device_Release(tmp);
320 ID3D10Texture3D_GetDesc(texture, &desc);
321 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
322 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
323 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
324 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
325 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
326 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
327 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
328 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
329 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
331 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
332 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
333 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
334 ID3D10Texture3D_Release(texture);
336 refcount = ID3D10Device_Release(device);
337 ok(!refcount, "Device has %u references left.\n", refcount);
340 static void test_create_depthstencil_view(void)
342 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
343 D3D10_TEXTURE2D_DESC texture_desc;
344 ULONG refcount, expected_refcount;
345 ID3D10DepthStencilView *dsview;
346 ID3D10Device *device, *tmp;
347 ID3D10Texture2D *texture;
348 HRESULT hr;
350 if (!(device = create_device()))
352 skip("Failed to create device, skipping tests.\n");
353 return;
356 texture_desc.Width = 512;
357 texture_desc.Height = 512;
358 texture_desc.MipLevels = 1;
359 texture_desc.ArraySize = 1;
360 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
361 texture_desc.SampleDesc.Count = 1;
362 texture_desc.SampleDesc.Quality = 0;
363 texture_desc.Usage = D3D10_USAGE_DEFAULT;
364 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
365 texture_desc.CPUAccessFlags = 0;
366 texture_desc.MiscFlags = 0;
368 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
369 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
371 expected_refcount = get_refcount((IUnknown *)device) + 1;
372 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
373 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr);
374 refcount = get_refcount((IUnknown *)device);
375 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
376 tmp = NULL;
377 expected_refcount = refcount + 1;
378 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
379 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
380 refcount = get_refcount((IUnknown *)device);
381 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
382 ID3D10Device_Release(tmp);
384 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
385 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
386 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
387 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
388 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
390 ID3D10DepthStencilView_Release(dsview);
391 ID3D10Texture2D_Release(texture);
393 refcount = ID3D10Device_Release(device);
394 ok(!refcount, "Device has %u references left.\n", refcount);
397 static void test_create_rendertarget_view(void)
399 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
400 D3D10_SUBRESOURCE_DATA data = {0};
401 D3D10_TEXTURE2D_DESC texture_desc;
402 ULONG refcount, expected_refcount;
403 D3D10_BUFFER_DESC buffer_desc;
404 ID3D10RenderTargetView *rtview;
405 ID3D10Device *device, *tmp;
406 ID3D10Texture2D *texture;
407 ID3D10Buffer *buffer;
408 HRESULT hr;
410 if (!(device = create_device()))
412 skip("Failed to create device, skipping tests.\n");
413 return;
416 buffer_desc.ByteWidth = 1024;
417 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
418 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
419 buffer_desc.CPUAccessFlags = 0;
420 buffer_desc.MiscFlags = 0;
422 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
423 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
425 expected_refcount = get_refcount((IUnknown *)device) + 1;
426 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
427 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
428 refcount = get_refcount((IUnknown *)device);
429 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
430 tmp = NULL;
431 expected_refcount = refcount + 1;
432 ID3D10Buffer_GetDevice(buffer, &tmp);
433 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
434 refcount = get_refcount((IUnknown *)device);
435 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
436 ID3D10Device_Release(tmp);
438 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
439 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
440 U(rtv_desc).Buffer.ElementOffset = 0;
441 U(rtv_desc).Buffer.ElementWidth = 64;
443 expected_refcount = get_refcount((IUnknown *)device) + 1;
444 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
445 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
446 refcount = get_refcount((IUnknown *)device);
447 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
448 tmp = NULL;
449 expected_refcount = refcount + 1;
450 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
451 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
452 refcount = get_refcount((IUnknown *)device);
453 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
454 ID3D10Device_Release(tmp);
456 ID3D10RenderTargetView_Release(rtview);
457 ID3D10Buffer_Release(buffer);
459 texture_desc.Width = 512;
460 texture_desc.Height = 512;
461 texture_desc.MipLevels = 1;
462 texture_desc.ArraySize = 1;
463 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
464 texture_desc.SampleDesc.Count = 1;
465 texture_desc.SampleDesc.Quality = 0;
466 texture_desc.Usage = D3D10_USAGE_DEFAULT;
467 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
468 texture_desc.CPUAccessFlags = 0;
469 texture_desc.MiscFlags = 0;
471 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
472 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
474 /* For texture resources it's allowed to specify NULL as desc */
475 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
476 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
478 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
479 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
480 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
481 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
482 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
484 ID3D10RenderTargetView_Release(rtview);
485 ID3D10Texture2D_Release(texture);
487 refcount = ID3D10Device_Release(device);
488 ok(!refcount, "Device has %u references left.\n", refcount);
491 static void test_create_shader_resource_view(void)
493 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
494 D3D10_TEXTURE2D_DESC texture_desc;
495 ULONG refcount, expected_refcount;
496 ID3D10ShaderResourceView *srview;
497 D3D10_BUFFER_DESC buffer_desc;
498 ID3D10Device *device, *tmp;
499 ID3D10Texture2D *texture;
500 ID3D10Buffer *buffer;
501 HRESULT hr;
503 if (!(device = create_device()))
505 skip("Failed to create device, skipping tests.\n");
506 return;
509 buffer_desc.ByteWidth = 1024;
510 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
511 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
512 buffer_desc.CPUAccessFlags = 0;
513 buffer_desc.MiscFlags = 0;
515 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
516 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
518 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
519 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
521 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
522 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
523 U(srv_desc).Buffer.ElementOffset = 0;
524 U(srv_desc).Buffer.ElementWidth = 64;
526 expected_refcount = get_refcount((IUnknown *)device) + 1;
527 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
528 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
529 refcount = get_refcount((IUnknown *)device);
530 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
531 tmp = NULL;
532 expected_refcount = refcount + 1;
533 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
534 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
535 refcount = get_refcount((IUnknown *)device);
536 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
537 ID3D10Device_Release(tmp);
539 ID3D10ShaderResourceView_Release(srview);
540 ID3D10Buffer_Release(buffer);
542 texture_desc.Width = 512;
543 texture_desc.Height = 512;
544 texture_desc.MipLevels = 0;
545 texture_desc.ArraySize = 1;
546 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
547 texture_desc.SampleDesc.Count = 1;
548 texture_desc.SampleDesc.Quality = 0;
549 texture_desc.Usage = D3D10_USAGE_DEFAULT;
550 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
551 texture_desc.CPUAccessFlags = 0;
552 texture_desc.MiscFlags = 0;
554 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
555 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
557 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srview);
558 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
560 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
561 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
562 ok(srv_desc.ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D,
563 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
564 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
565 U(srv_desc).Texture2D.MostDetailedMip);
566 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
568 ID3D10ShaderResourceView_Release(srview);
569 ID3D10Texture2D_Release(texture);
571 refcount = ID3D10Device_Release(device);
572 ok(!refcount, "Device has %u references left.\n", refcount);
575 static void test_create_shader(void)
577 #if 0
578 float4 light;
579 float4x4 mat;
581 struct input
583 float4 position : POSITION;
584 float3 normal : NORMAL;
587 struct output
589 float4 position : POSITION;
590 float4 diffuse : COLOR;
593 output main(const input v)
595 output o;
597 o.position = mul(v.position, mat);
598 o.diffuse = dot((float3)light, v.normal);
600 return o;
602 #endif
603 static const DWORD vs_4_0[] =
605 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
606 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
607 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
608 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
609 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
610 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
611 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
612 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
613 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
614 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
615 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
616 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
617 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
618 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
619 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
620 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
623 static const DWORD vs_2_0[] =
625 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
626 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
627 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
628 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
629 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
630 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
631 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
632 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
633 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
634 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
635 0x90e40001, 0x0000ffff,
638 static const DWORD vs_3_0[] =
640 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
641 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
642 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
643 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
644 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
645 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
646 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
647 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
648 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
649 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
650 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
651 0x0000ffff,
654 #if 0
655 float4 main(const float4 color : COLOR) : SV_TARGET
657 float4 o;
659 o = color;
661 return o;
663 #endif
664 static const DWORD ps_4_0[] =
666 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
667 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
668 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
669 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
670 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
671 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
672 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
673 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
674 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
675 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
676 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
677 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
678 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
679 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
680 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
681 0x00000000, 0x00000000,
684 ULONG refcount, expected_refcount;
685 ID3D10VertexShader *vs = NULL;
686 ID3D10PixelShader *ps = NULL;
687 ID3D10Device *device, *tmp;
688 HRESULT hr;
690 if (!(device = create_device()))
692 skip("Failed to create device, skipping tests.\n");
693 return;
696 expected_refcount = get_refcount((IUnknown *)device) + 1;
697 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
698 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
699 refcount = get_refcount((IUnknown *)device);
700 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
701 tmp = NULL;
702 expected_refcount = refcount + 1;
703 ID3D10VertexShader_GetDevice(vs, &tmp);
704 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
705 refcount = get_refcount((IUnknown *)device);
706 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
707 ID3D10Device_Release(tmp);
708 ID3D10VertexShader_Release(vs);
710 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
711 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
713 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
714 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
716 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
717 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
719 expected_refcount = get_refcount((IUnknown *)device) + 1;
720 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
721 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
722 refcount = get_refcount((IUnknown *)device);
723 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
724 tmp = NULL;
725 expected_refcount = refcount + 1;
726 ID3D10PixelShader_GetDevice(ps, &tmp);
727 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
728 refcount = get_refcount((IUnknown *)device);
729 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
730 ID3D10Device_Release(tmp);
731 ID3D10PixelShader_Release(ps);
733 refcount = ID3D10Device_Release(device);
734 ok(!refcount, "Device has %u references left.\n", refcount);
737 static void test_create_sampler_state(void)
739 ID3D10SamplerState *sampler_state1, *sampler_state2;
740 ULONG refcount, expected_refcount;
741 D3D10_SAMPLER_DESC sampler_desc;
742 ID3D10Device *device, *tmp;
743 HRESULT hr;
745 if (!(device = create_device()))
747 skip("Failed to create device, skipping tests.\n");
748 return;
751 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
752 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
754 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
755 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
756 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
757 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
758 sampler_desc.MipLODBias = 0.0f;
759 sampler_desc.MaxAnisotropy = 16;
760 sampler_desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
761 sampler_desc.BorderColor[0] = 0.0f;
762 sampler_desc.BorderColor[1] = 1.0f;
763 sampler_desc.BorderColor[2] = 0.0f;
764 sampler_desc.BorderColor[3] = 1.0f;
765 sampler_desc.MinLOD = 0.0f;
766 sampler_desc.MaxLOD = 16.0f;
768 expected_refcount = get_refcount((IUnknown *)device) + 1;
769 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state1);
770 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
771 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state2);
772 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
773 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
774 refcount = get_refcount((IUnknown *)device);
775 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
776 tmp = NULL;
777 expected_refcount = refcount + 1;
778 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
779 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
780 refcount = get_refcount((IUnknown *)device);
781 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
782 ID3D10Device_Release(tmp);
784 refcount = ID3D10SamplerState_Release(sampler_state2);
785 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
786 refcount = ID3D10SamplerState_Release(sampler_state1);
787 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
789 refcount = ID3D10Device_Release(device);
790 ok(!refcount, "Device has %u references left.\n", refcount);
793 static void test_create_blend_state(void)
795 ID3D10BlendState *blend_state1, *blend_state2;
796 ULONG refcount, expected_refcount;
797 D3D10_BLEND_DESC blend_desc;
798 ID3D10Device *device, *tmp;
799 HRESULT hr;
801 if (!(device = create_device()))
803 skip("Failed to create device, skipping tests.\n");
804 return;
807 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
808 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
810 blend_desc.AlphaToCoverageEnable = FALSE;
811 blend_desc.BlendEnable[0] = FALSE;
812 blend_desc.BlendEnable[1] = FALSE;
813 blend_desc.BlendEnable[2] = FALSE;
814 blend_desc.BlendEnable[3] = FALSE;
815 blend_desc.BlendEnable[4] = FALSE;
816 blend_desc.BlendEnable[5] = FALSE;
817 blend_desc.BlendEnable[6] = FALSE;
818 blend_desc.BlendEnable[7] = FALSE;
819 blend_desc.SrcBlend = D3D10_BLEND_ONE;
820 blend_desc.DestBlend = D3D10_BLEND_ZERO;
821 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
822 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
823 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
824 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
825 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
826 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
827 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
828 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
829 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
830 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
831 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
832 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
834 expected_refcount = get_refcount((IUnknown *)device) + 1;
835 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
836 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
837 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
838 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
839 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
840 refcount = get_refcount((IUnknown *)device);
841 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
842 tmp = NULL;
843 expected_refcount = refcount + 1;
844 ID3D10BlendState_GetDevice(blend_state1, &tmp);
845 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
846 refcount = get_refcount((IUnknown *)device);
847 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
848 ID3D10Device_Release(tmp);
850 refcount = ID3D10BlendState_Release(blend_state2);
851 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
852 refcount = ID3D10BlendState_Release(blend_state1);
853 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
855 refcount = ID3D10Device_Release(device);
856 ok(!refcount, "Device has %u references left.\n", refcount);
859 static void test_create_depthstencil_state(void)
861 ID3D10DepthStencilState *ds_state1, *ds_state2;
862 ULONG refcount, expected_refcount;
863 D3D10_DEPTH_STENCIL_DESC ds_desc;
864 ID3D10Device *device, *tmp;
865 HRESULT hr;
867 if (!(device = create_device()))
869 skip("Failed to create device, skipping tests.\n");
870 return;
873 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
874 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
876 ds_desc.DepthEnable = TRUE;
877 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
878 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
879 ds_desc.StencilEnable = FALSE;
880 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
881 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
882 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
883 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
884 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
885 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
886 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
887 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
888 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
889 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
891 expected_refcount = get_refcount((IUnknown *)device) + 1;
892 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
893 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
894 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
895 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
896 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
897 refcount = get_refcount((IUnknown *)device);
898 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
899 tmp = NULL;
900 expected_refcount = refcount + 1;
901 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
902 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
903 refcount = get_refcount((IUnknown *)device);
904 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
905 ID3D10Device_Release(tmp);
907 refcount = ID3D10DepthStencilState_Release(ds_state2);
908 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
909 refcount = ID3D10DepthStencilState_Release(ds_state1);
910 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
912 refcount = ID3D10Device_Release(device);
913 ok(!refcount, "Device has %u references left.\n", refcount);
916 static void test_create_rasterizer_state(void)
918 ID3D10RasterizerState *rast_state1, *rast_state2;
919 ULONG refcount, expected_refcount;
920 D3D10_RASTERIZER_DESC rast_desc;
921 ID3D10Device *device, *tmp;
922 HRESULT hr;
924 if (!(device = create_device()))
926 skip("Failed to create device, skipping tests.\n");
927 return;
930 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
931 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
933 rast_desc.FillMode = D3D10_FILL_SOLID;
934 rast_desc.CullMode = D3D10_CULL_BACK;
935 rast_desc.FrontCounterClockwise = FALSE;
936 rast_desc.DepthBias = 0;
937 rast_desc.DepthBiasClamp = 0.0f;
938 rast_desc.SlopeScaledDepthBias = 0.0f;
939 rast_desc.DepthClipEnable = TRUE;
940 rast_desc.ScissorEnable = FALSE;
941 rast_desc.MultisampleEnable = FALSE;
942 rast_desc.AntialiasedLineEnable = FALSE;
944 expected_refcount = get_refcount((IUnknown *)device) + 1;
945 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
946 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
947 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
948 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
949 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
950 refcount = get_refcount((IUnknown *)device);
951 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
952 tmp = NULL;
953 expected_refcount = refcount + 1;
954 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
955 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
956 refcount = get_refcount((IUnknown *)device);
957 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
958 ID3D10Device_Release(tmp);
960 refcount = ID3D10RasterizerState_Release(rast_state2);
961 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
962 refcount = ID3D10RasterizerState_Release(rast_state1);
963 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
965 refcount = ID3D10Device_Release(device);
966 ok(!refcount, "Device has %u references left.\n", refcount);
969 static void test_create_predicate(void)
971 ULONG refcount, expected_refcount;
972 D3D10_QUERY_DESC query_desc;
973 ID3D10Predicate *predicate;
974 ID3D10Device *device, *tmp;
975 HRESULT hr;
977 if (!(device = create_device()))
979 skip("Failed to create device, skipping tests.\n");
980 return;
983 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
984 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
986 query_desc.Query = D3D10_QUERY_OCCLUSION;
987 query_desc.MiscFlags = 0;
988 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
989 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
991 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
992 expected_refcount = get_refcount((IUnknown *)device) + 1;
993 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
994 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
995 refcount = get_refcount((IUnknown *)device);
996 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
997 tmp = NULL;
998 expected_refcount = refcount + 1;
999 ID3D10Predicate_GetDevice(predicate, &tmp);
1000 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1001 refcount = get_refcount((IUnknown *)device);
1002 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1003 ID3D10Device_Release(tmp);
1004 ID3D10Predicate_Release(predicate);
1006 query_desc.Query = D3D10_QUERY_SO_OVERFLOW_PREDICATE;
1007 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
1008 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1009 if (SUCCEEDED(hr))
1010 ID3D10Predicate_Release(predicate);
1012 refcount = ID3D10Device_Release(device);
1013 ok(!refcount, "Device has %u references left.\n", refcount);
1016 static void test_device_removed_reason(void)
1018 ID3D10Device *device;
1019 ULONG refcount;
1020 HRESULT hr;
1022 if (!(device = create_device()))
1024 skip("Failed to create device, skipping tests.\n");
1025 return;
1028 hr = ID3D10Device_GetDeviceRemovedReason(device);
1029 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1030 hr = ID3D10Device_GetDeviceRemovedReason(device);
1031 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1033 refcount = ID3D10Device_Release(device);
1034 ok(!refcount, "Device has %u references left.\n", refcount);
1037 static void test_scissor(void)
1039 D3D10_SUBRESOURCE_DATA buffer_data;
1040 ID3D10InputLayout *input_layout;
1041 D3D10_RASTERIZER_DESC rs_desc;
1042 D3D10_BUFFER_DESC buffer_desc;
1043 ID3D10RenderTargetView *rtv;
1044 ID3D10Texture2D *backbuffer;
1045 unsigned int stride, offset;
1046 ID3D10RasterizerState *rs;
1047 IDXGISwapChain *swapchain;
1048 D3D10_RECT scissor_rect;
1049 ID3D10VertexShader *vs;
1050 ID3D10PixelShader *ps;
1051 ID3D10Device *device;
1052 D3D10_VIEWPORT vp;
1053 ID3D10Buffer *vb;
1054 ULONG refcount;
1055 DWORD color;
1056 HWND window;
1057 HRESULT hr;
1059 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
1060 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1062 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1064 static const DWORD vs_code[] =
1066 /* float4 main(float4 position : POSITION) : SV_POSITION
1068 * return position;
1069 * } */
1070 0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
1071 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
1072 0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1073 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1074 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1075 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1076 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1077 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1078 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1079 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
1080 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1081 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1082 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1083 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1085 static const DWORD ps_code[] =
1087 /* float4 main(float4 position : SV_POSITION) : SV_Target
1089 * return float4(0.0, 1.0, 0.0, 1.0);
1090 * } */
1091 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
1092 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
1093 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
1094 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
1095 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1096 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1097 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1098 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
1099 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
1100 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
1101 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
1102 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1103 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1104 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1106 static const struct
1108 float x, y;
1110 quad[] =
1112 {-1.0f, -1.0f},
1113 {-1.0f, 1.0f},
1114 { 1.0f, -1.0f},
1115 { 1.0f, 1.0f},
1118 if (!(device = create_device()))
1120 skip("Failed to create device, skipping tests.\n");
1121 return;
1123 window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1124 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1125 swapchain = create_swapchain(device, window, TRUE);
1126 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
1127 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
1129 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1130 vs_code, sizeof(vs_code), &input_layout);
1131 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1133 buffer_desc.ByteWidth = sizeof(quad);
1134 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1135 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
1136 buffer_desc.CPUAccessFlags = 0;
1137 buffer_desc.MiscFlags = 0;
1139 buffer_data.pSysMem = quad;
1140 buffer_data.SysMemPitch = 0;
1141 buffer_data.SysMemSlicePitch = 0;
1143 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
1144 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
1145 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
1146 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1147 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
1148 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1150 rs_desc.FillMode = D3D10_FILL_SOLID;
1151 rs_desc.CullMode = D3D10_CULL_BACK;
1152 rs_desc.FrontCounterClockwise = FALSE;
1153 rs_desc.DepthBias = 0;
1154 rs_desc.DepthBiasClamp = 0.0f;
1155 rs_desc.SlopeScaledDepthBias = 0.0f;
1156 rs_desc.DepthClipEnable = TRUE;
1157 rs_desc.ScissorEnable = TRUE;
1158 rs_desc.MultisampleEnable = FALSE;
1159 rs_desc.AntialiasedLineEnable = FALSE;
1160 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
1161 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1163 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &rtv);
1164 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1166 ID3D10Device_IASetInputLayout(device, input_layout);
1167 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1168 stride = sizeof(*quad);
1169 offset = 0;
1170 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
1171 ID3D10Device_VSSetShader(device, vs);
1172 ID3D10Device_PSSetShader(device, ps);
1174 vp.TopLeftX = 0;
1175 vp.TopLeftY = 0;
1176 vp.Width = 640;
1177 vp.Height = 480;
1178 vp.MinDepth = 0.0f;
1179 vp.MaxDepth = 1.0f;
1180 ID3D10Device_RSSetViewports(device, 1, &vp);
1182 scissor_rect.left = 160;
1183 scissor_rect.top = 120;
1184 scissor_rect.right = 480;
1185 scissor_rect.bottom = 360;
1186 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
1188 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
1190 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1191 color = get_texture_color(backbuffer, 320, 240);
1192 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1194 ID3D10Device_Draw(device, 4, 0);
1195 color = get_texture_color(backbuffer, 320, 60);
1196 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1197 color = get_texture_color(backbuffer, 80, 240);
1198 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1199 color = get_texture_color(backbuffer, 320, 240);
1200 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1201 color = get_texture_color(backbuffer, 560, 240);
1202 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1203 color = get_texture_color(backbuffer, 320, 420);
1204 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1206 ID3D10Device_ClearRenderTargetView(device, rtv, red);
1207 ID3D10Device_RSSetState(device, rs);
1208 ID3D10Device_Draw(device, 4, 0);
1209 color = get_texture_color(backbuffer, 320, 60);
1210 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1211 color = get_texture_color(backbuffer, 80, 240);
1212 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1213 color = get_texture_color(backbuffer, 320, 240);
1214 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
1215 color = get_texture_color(backbuffer, 560, 240);
1216 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1217 color = get_texture_color(backbuffer, 320, 420);
1218 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
1220 ID3D10RenderTargetView_Release(rtv);
1221 ID3D10RasterizerState_Release(rs);
1222 ID3D10PixelShader_Release(ps);
1223 ID3D10VertexShader_Release(vs);
1224 ID3D10Buffer_Release(vb);
1225 ID3D10InputLayout_Release(input_layout);
1226 ID3D10Texture2D_Release(backbuffer);
1227 IDXGISwapChain_Release(swapchain);
1228 refcount = ID3D10Device_Release(device);
1229 ok(!refcount, "Device has %u references left.\n", refcount);
1230 DestroyWindow(window);
1233 static void test_clear_state(void)
1235 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
1237 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1239 #if 0
1240 float4 main(float4 pos : POSITION) : POSITION
1242 return pos;
1244 #endif
1245 static const DWORD simple_vs[] =
1247 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
1248 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1249 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1250 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
1251 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
1252 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
1253 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1256 #if 0
1257 struct gs_out
1259 float4 pos : SV_POSITION;
1262 [maxvertexcount(4)]
1263 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1265 float offset = 0.1 * vin[0].w;
1266 gs_out v;
1268 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1269 vout.Append(v);
1270 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1271 vout.Append(v);
1272 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1273 vout.Append(v);
1274 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1275 vout.Append(v);
1277 #endif
1278 static const DWORD simple_gs[] =
1280 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1281 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1282 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1283 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1284 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1285 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1286 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1287 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1288 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1289 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1290 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1291 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1292 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1293 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1294 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1295 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1296 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1297 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1300 #if 0
1301 float4 main(float4 color : COLOR) : SV_TARGET
1303 return color;
1305 #endif
1306 static const DWORD simple_ps[] =
1308 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
1309 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
1310 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
1311 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1312 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
1313 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
1314 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1317 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1318 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1319 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
1320 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1321 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
1322 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1323 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1324 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
1325 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
1326 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1327 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
1328 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1329 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1330 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
1331 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
1332 ID3D10InputLayout *tmp_input_layout, *input_layout;
1333 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
1334 ID3D10BlendState *tmp_blend_state, *blend_state;
1335 ID3D10RasterizerState *tmp_rs_state, *rs_state;
1336 ID3D10Predicate *tmp_predicate, *predicate;
1337 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
1338 ID3D10DepthStencilView *tmp_dsv, *dsv;
1339 D3D10_PRIMITIVE_TOPOLOGY topology;
1340 D3D10_TEXTURE2D_DESC texture_desc;
1341 ID3D10GeometryShader *tmp_gs, *gs;
1342 D3D10_DEPTH_STENCIL_DESC ds_desc;
1343 ID3D10VertexShader *tmp_vs, *vs;
1344 D3D10_SAMPLER_DESC sampler_desc;
1345 D3D10_QUERY_DESC predicate_desc;
1346 ID3D10PixelShader *tmp_ps, *ps;
1347 D3D10_RASTERIZER_DESC rs_desc;
1348 D3D10_BUFFER_DESC buffer_desc;
1349 D3D10_BLEND_DESC blend_desc;
1350 ID3D10Texture2D *ds_texture;
1351 float blend_factor[4];
1352 ID3D10Device *device;
1353 BOOL predicate_value;
1354 DXGI_FORMAT format;
1355 UINT sample_mask;
1356 UINT stencil_ref;
1357 ULONG refcount;
1358 UINT count, i;
1359 HRESULT hr;
1361 if (!(device = create_device()))
1363 skip("Failed to create device, skipping tests.\n");
1364 return;
1367 /* Verify the initial state after device creation. */
1369 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1370 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1372 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1374 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1375 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1377 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1379 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1380 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1382 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1384 ID3D10Device_VSGetShader(device, &tmp_vs);
1385 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1387 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1388 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1390 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1392 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1393 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1395 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1397 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1398 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1400 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1402 ID3D10Device_GSGetShader(device, &tmp_gs);
1403 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1405 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1406 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1408 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1410 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1411 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1413 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1415 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1416 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1418 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1420 ID3D10Device_PSGetShader(device, &tmp_ps);
1421 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1423 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1424 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1426 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1427 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1428 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1430 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1431 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
1432 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
1433 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
1434 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1435 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
1436 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1437 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
1439 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1440 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
1441 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
1442 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
1443 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1444 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1445 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
1446 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1447 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
1448 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
1449 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1450 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1452 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
1454 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
1456 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1457 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
1458 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1459 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1460 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1461 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1463 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1464 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1465 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1467 ID3D10Device_RSGetViewports(device, &count, NULL);
1468 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
1469 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1470 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1471 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1472 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1474 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
1475 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
1476 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1477 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1478 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1480 ID3D10Device_RSGetState(device, &tmp_rs_state);
1481 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
1483 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1484 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1486 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
1487 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1490 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1491 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
1492 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1494 /* Create resources. */
1496 buffer_desc.ByteWidth = 1024;
1497 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
1498 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
1499 buffer_desc.CPUAccessFlags = 0;
1500 buffer_desc.MiscFlags = 0;
1502 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1504 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb[i]);
1505 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1508 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE;
1510 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1512 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer[i]);
1513 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1515 stride[i] = (i + 1) * 4;
1516 offset[i] = (i + 1) * 16;
1519 buffer_desc.BindFlags = D3D10_BIND_STREAM_OUTPUT;
1521 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1523 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &so_buffer[i]);
1524 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
1527 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1528 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
1529 U(srv_desc).Buffer.ElementOffset = 0;
1530 U(srv_desc).Buffer.ElementWidth = 64;
1532 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1534 hr = ID3D10Device_CreateShaderResourceView(device,
1535 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
1536 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
1539 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
1540 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
1541 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
1542 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
1543 sampler_desc.MipLODBias = 0.0f;
1544 sampler_desc.MaxAnisotropy = 16;
1545 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
1546 sampler_desc.BorderColor[0] = 0.0f;
1547 sampler_desc.BorderColor[1] = 0.0f;
1548 sampler_desc.BorderColor[2] = 0.0f;
1549 sampler_desc.BorderColor[3] = 0.0f;
1550 sampler_desc.MinLOD = 0.0f;
1551 sampler_desc.MaxLOD = 16.0f;
1553 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1555 sampler_desc.MinLOD = (float)i;
1557 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
1558 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1561 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
1562 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1564 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
1565 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
1567 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
1568 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1570 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
1571 simple_vs, sizeof(simple_vs), &input_layout);
1572 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1574 blend_desc.AlphaToCoverageEnable = FALSE;
1575 blend_desc.BlendEnable[0] = FALSE;
1576 blend_desc.BlendEnable[1] = FALSE;
1577 blend_desc.BlendEnable[2] = FALSE;
1578 blend_desc.BlendEnable[3] = FALSE;
1579 blend_desc.BlendEnable[4] = FALSE;
1580 blend_desc.BlendEnable[5] = FALSE;
1581 blend_desc.BlendEnable[6] = FALSE;
1582 blend_desc.BlendEnable[7] = FALSE;
1583 blend_desc.SrcBlend = D3D10_BLEND_ONE;
1584 blend_desc.DestBlend = D3D10_BLEND_ZERO;
1585 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
1586 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
1587 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
1588 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
1589 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
1590 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
1591 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
1592 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
1593 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
1594 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
1595 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
1596 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
1598 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
1599 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1601 ds_desc.DepthEnable = TRUE;
1602 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
1603 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
1604 ds_desc.StencilEnable = FALSE;
1605 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
1606 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
1607 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1608 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1609 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1610 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1611 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
1612 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
1613 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
1614 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
1616 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
1617 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
1619 texture_desc.Width = 512;
1620 texture_desc.Height = 512;
1621 texture_desc.MipLevels = 1;
1622 texture_desc.ArraySize = 1;
1623 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1624 texture_desc.SampleDesc.Count = 1;
1625 texture_desc.SampleDesc.Quality = 0;
1626 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1627 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1628 texture_desc.CPUAccessFlags = 0;
1629 texture_desc.MiscFlags = 0;
1631 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1633 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
1634 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1637 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1638 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1640 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
1641 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
1643 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1645 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
1646 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1649 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
1650 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
1652 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1654 tmp_rect[i].left = i;
1655 tmp_rect[i].top = i * 2;
1656 tmp_rect[i].right = i + 1;
1657 tmp_rect[i].bottom = (i + 1) * 2;
1659 tmp_viewport[i].TopLeftX = i * 3;
1660 tmp_viewport[i].TopLeftY = i * 4;
1661 tmp_viewport[i].Width = 3;
1662 tmp_viewport[i].Height = 4;
1663 tmp_viewport[i].MinDepth = i * 0.01f;
1664 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
1667 rs_desc.FillMode = D3D10_FILL_SOLID;
1668 rs_desc.CullMode = D3D10_CULL_BACK;
1669 rs_desc.FrontCounterClockwise = FALSE;
1670 rs_desc.DepthBias = 0;
1671 rs_desc.DepthBiasClamp = 0.0f;
1672 rs_desc.SlopeScaledDepthBias = 0.0f;
1673 rs_desc.DepthClipEnable = TRUE;
1674 rs_desc.ScissorEnable = FALSE;
1675 rs_desc.MultisampleEnable = FALSE;
1676 rs_desc.AntialiasedLineEnable = FALSE;
1678 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
1679 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
1681 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
1682 predicate_desc.MiscFlags = 0;
1684 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
1685 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
1687 /* Setup state. */
1688 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1689 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1690 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1691 ID3D10Device_VSSetShader(device, vs);
1693 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1694 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1695 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1696 ID3D10Device_GSSetShader(device, gs);
1698 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
1699 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
1700 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
1701 ID3D10Device_PSSetShader(device, ps);
1703 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
1704 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
1705 ID3D10Device_IASetInputLayout(device, input_layout);
1706 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1708 blend_factor[0] = 0.1f;
1709 blend_factor[1] = 0.2f;
1710 blend_factor[2] = 0.3f;
1711 blend_factor[3] = 0.4f;
1712 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
1713 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
1714 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
1716 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
1717 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
1718 ID3D10Device_RSSetState(device, rs_state);
1720 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
1722 ID3D10Device_SetPredication(device, predicate, TRUE);
1724 /* Verify the set state. */
1726 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1727 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1729 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1730 tmp_buffer[i], i, cb[i]);
1731 ID3D10Buffer_Release(tmp_buffer[i]);
1733 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1734 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1736 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1737 tmp_srv[i], i, srv[i]);
1738 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1740 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1741 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1743 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1744 tmp_sampler[i], i, sampler[i]);
1745 ID3D10SamplerState_Release(tmp_sampler[i]);
1747 ID3D10Device_VSGetShader(device, &tmp_vs);
1748 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
1749 ID3D10VertexShader_Release(tmp_vs);
1751 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1752 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1754 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1755 tmp_buffer[i], i, cb[i]);
1756 ID3D10Buffer_Release(tmp_buffer[i]);
1758 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1759 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1761 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1762 tmp_srv[i], i, srv[i]);
1763 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1765 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1766 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1768 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1769 tmp_sampler[i], i, sampler[i]);
1770 ID3D10SamplerState_Release(tmp_sampler[i]);
1772 ID3D10Device_GSGetShader(device, &tmp_gs);
1773 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
1774 ID3D10GeometryShader_Release(tmp_gs);
1776 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1777 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1779 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
1780 tmp_buffer[i], i, cb[i]);
1781 ID3D10Buffer_Release(tmp_buffer[i]);
1783 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1784 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1786 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
1787 tmp_srv[i], i, srv[i]);
1788 ID3D10ShaderResourceView_Release(tmp_srv[i]);
1790 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1791 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1793 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
1794 tmp_sampler[i], i, sampler[i]);
1795 ID3D10SamplerState_Release(tmp_sampler[i]);
1797 ID3D10Device_PSGetShader(device, &tmp_ps);
1798 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
1799 ID3D10PixelShader_Release(tmp_ps);
1801 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1802 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1804 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
1805 tmp_buffer[i], i, buffer[i]);
1806 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
1807 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
1808 ID3D10Buffer_Release(tmp_buffer[i]);
1810 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1811 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
1812 ID3D10Buffer_Release(tmp_buffer[0]);
1813 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
1814 todo_wine ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
1815 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1816 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
1817 tmp_input_layout, input_layout);
1818 ID3D10InputLayout_Release(tmp_input_layout);
1819 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1820 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
1822 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1823 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
1824 ID3D10BlendState_Release(tmp_blend_state);
1825 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
1826 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
1827 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1828 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1829 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
1830 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1831 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
1832 ID3D10DepthStencilState_Release(tmp_ds_state);
1833 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
1834 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1835 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1837 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
1838 tmp_rtv[i], i, rtv[i]);
1839 ID3D10RenderTargetView_Release(tmp_rtv[i]);
1841 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
1842 ID3D10DepthStencilView_Release(tmp_dsv);
1844 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1845 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1846 "Got unexpected scissor rect count %u.\n", count);
1847 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1848 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1849 for (i = 0; i < count; ++i)
1851 ok(tmp_rect[i].left == i
1852 && tmp_rect[i].top == i * 2
1853 && tmp_rect[i].right == i + 1
1854 && tmp_rect[i].bottom == (i + 1) * 2,
1855 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1856 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1858 ID3D10Device_RSGetViewports(device, &count, NULL);
1859 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
1860 "Got unexpected viewport count %u.\n", count);
1861 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
1862 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
1863 for (i = 0; i < count; ++i)
1865 ok(tmp_viewport[i].TopLeftX == i * 3
1866 && tmp_viewport[i].TopLeftY == i * 4
1867 && tmp_viewport[i].Width == 3
1868 && tmp_viewport[i].Height == 4
1869 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
1870 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
1871 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
1872 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
1873 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
1875 ID3D10Device_RSGetState(device, &tmp_rs_state);
1876 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
1877 ID3D10RasterizerState_Release(tmp_rs_state);
1879 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
1880 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1882 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
1883 tmp_buffer[i], i, buffer[i]);
1884 ID3D10Buffer_Release(tmp_buffer[i]);
1885 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
1888 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
1889 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
1890 ID3D10Predicate_Release(tmp_predicate);
1891 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
1893 /* Verify ClearState(). */
1895 ID3D10Device_ClearState(device);
1897 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1898 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1900 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1902 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1903 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1905 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1907 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1908 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1910 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1912 ID3D10Device_VSGetShader(device, &tmp_vs);
1913 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
1915 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1916 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1918 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1920 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1921 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1923 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1925 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1926 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1928 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1930 ID3D10Device_GSGetShader(device, &tmp_gs);
1931 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
1933 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
1934 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1936 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
1938 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
1939 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1941 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
1943 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
1944 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1946 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
1948 ID3D10Device_PSGetShader(device, &tmp_ps);
1949 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
1951 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
1952 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1954 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
1955 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
1956 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
1958 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
1959 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
1960 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
1961 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
1962 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
1963 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
1964 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
1965 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
1967 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
1968 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
1969 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
1970 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
1971 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
1972 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1973 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
1974 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
1975 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
1976 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
1977 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
1978 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1980 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
1982 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
1984 ID3D10Device_RSGetScissorRects(device, &count, NULL);
1985 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
1986 memset(tmp_rect, 0x55, sizeof(tmp_rect));
1987 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
1988 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
1989 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
1991 if (!i)
1992 todo_wine ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1993 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1994 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
1995 else
1996 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
1997 "Got unexpected scissor rect {%d, %d, %d, %d} in slot %u.\n",
1998 tmp_rect[i].left, tmp_rect[i].top, tmp_rect[i].right, tmp_rect[i].bottom, i);
2000 ID3D10Device_RSGetViewports(device, &count, NULL);
2001 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
2002 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
2003 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
2004 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
2005 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
2007 if (!i)
2008 todo_wine ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2009 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2010 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2011 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2012 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2013 else
2014 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
2015 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
2016 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
2017 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
2018 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
2020 ID3D10Device_RSGetState(device, &tmp_rs_state);
2021 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
2023 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
2024 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2026 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
2027 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
2030 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
2031 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
2032 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
2034 /* Cleanup. */
2036 ID3D10Predicate_Release(predicate);
2037 ID3D10RasterizerState_Release(rs_state);
2038 ID3D10DepthStencilView_Release(dsv);
2039 ID3D10Texture2D_Release(ds_texture);
2041 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2043 ID3D10RenderTargetView_Release(rtv[i]);
2044 ID3D10Texture2D_Release(rt_texture[i]);
2047 ID3D10DepthStencilState_Release(ds_state);
2048 ID3D10BlendState_Release(blend_state);
2049 ID3D10InputLayout_Release(input_layout);
2050 ID3D10VertexShader_Release(vs);
2051 ID3D10GeometryShader_Release(gs);
2052 ID3D10PixelShader_Release(ps);
2054 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2056 ID3D10SamplerState_Release(sampler[i]);
2059 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2061 ID3D10ShaderResourceView_Release(srv[i]);
2064 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2066 ID3D10Buffer_Release(so_buffer[i]);
2069 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2071 ID3D10Buffer_Release(buffer[i]);
2074 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2076 ID3D10Buffer_Release(cb[i]);
2079 refcount = ID3D10Device_Release(device);
2080 ok(!refcount, "Device has %u references left.\n", refcount);
2083 static void test_blend(void)
2085 ID3D10RenderTargetView *backbuffer_rtv, *offscreen_rtv;
2086 ID3D10BlendState *src_blend, *dst_blend;
2087 ID3D10Texture2D *backbuffer, *offscreen;
2088 D3D10_SUBRESOURCE_DATA buffer_data;
2089 D3D10_TEXTURE2D_DESC texture_desc;
2090 ID3D10InputLayout *input_layout;
2091 D3D10_BUFFER_DESC buffer_desc;
2092 D3D10_BLEND_DESC blend_desc;
2093 unsigned int stride, offset;
2094 IDXGISwapChain *swapchain;
2095 ID3D10VertexShader *vs;
2096 ID3D10PixelShader *ps;
2097 ID3D10Device *device;
2098 D3D10_VIEWPORT vp;
2099 ID3D10Buffer *vb;
2100 ULONG refcount;
2101 DWORD color;
2102 HWND window;
2103 HRESULT hr;
2105 static const DWORD vs_code[] =
2107 #if 0
2108 struct vs_out
2110 float4 position : SV_POSITION;
2111 float4 color : COLOR;
2114 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
2116 struct vs_out o;
2118 o.position = position;
2119 o.color = color;
2121 return o;
2123 #endif
2124 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
2125 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2126 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2127 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
2128 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2129 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
2130 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
2131 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
2132 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
2133 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
2135 static const DWORD ps_code[] =
2137 #if 0
2138 struct vs_out
2140 float4 position : SV_POSITION;
2141 float4 color : COLOR;
2144 float4 main(struct vs_out i) : SV_TARGET
2146 return i.color;
2148 #endif
2149 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
2150 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
2151 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
2152 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
2153 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2154 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2155 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2156 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2158 static const struct
2160 struct vec3 position;
2161 DWORD diffuse;
2163 quads[] =
2165 /* quad1 */
2166 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
2167 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
2168 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
2169 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
2170 /* quad2 */
2171 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2172 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2173 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
2174 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
2176 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2178 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2179 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
2181 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2182 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2184 if (!(device = create_device()))
2186 skip("Failed to create device, skipping tests.\n");
2187 return;
2189 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2190 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2191 swapchain = create_swapchain(device, window, TRUE);
2192 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2193 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2195 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2196 vs_code, sizeof(vs_code), &input_layout);
2197 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2199 buffer_desc.ByteWidth = sizeof(quads);
2200 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2201 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2202 buffer_desc.CPUAccessFlags = 0;
2203 buffer_desc.MiscFlags = 0;
2205 buffer_data.pSysMem = quads;
2206 buffer_data.SysMemPitch = 0;
2207 buffer_data.SysMemSlicePitch = 0;
2209 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
2210 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2211 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2212 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2213 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2214 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2216 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2217 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2219 memset(&blend_desc, 0, sizeof(blend_desc));
2220 blend_desc.BlendEnable[0] = TRUE;
2221 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
2222 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
2223 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
2224 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
2225 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
2226 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
2227 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
2229 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
2230 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2232 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
2233 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
2234 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
2235 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
2237 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
2238 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2240 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2241 ID3D10Device_IASetInputLayout(device, input_layout);
2242 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2243 stride = sizeof(*quads);
2244 offset = 0;
2245 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2246 ID3D10Device_VSSetShader(device, vs);
2247 ID3D10Device_PSSetShader(device, ps);
2249 vp.TopLeftX = 0;
2250 vp.TopLeftY = 0;
2251 vp.Width = 640;
2252 vp.Height = 480;
2253 vp.MinDepth = 0.0f;
2254 vp.MaxDepth = 1.0f;
2255 ID3D10Device_RSSetViewports(device, 1, &vp);
2257 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2259 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2260 ID3D10Device_Draw(device, 4, 0);
2261 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2262 ID3D10Device_Draw(device, 4, 4);
2264 color = get_texture_color(backbuffer, 320, 360);
2265 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
2266 color = get_texture_color(backbuffer, 320, 120);
2267 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
2269 texture_desc.Width = 128;
2270 texture_desc.Height = 128;
2271 texture_desc.MipLevels = 1;
2272 texture_desc.ArraySize = 1;
2273 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
2274 texture_desc.SampleDesc.Count = 1;
2275 texture_desc.SampleDesc.Quality = 0;
2276 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2277 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
2278 texture_desc.CPUAccessFlags = 0;
2279 texture_desc.MiscFlags = 0;
2281 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
2282 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
2284 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
2285 goto done;
2288 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
2289 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2291 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
2293 vp.TopLeftX = 0;
2294 vp.TopLeftY = 0;
2295 vp.Width = 128;
2296 vp.Height = 128;
2297 vp.MinDepth = 0.0f;
2298 vp.MaxDepth = 1.0f;
2299 ID3D10Device_RSSetViewports(device, 1, &vp);
2301 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
2303 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2304 ID3D10Device_Draw(device, 4, 0);
2305 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2306 ID3D10Device_Draw(device, 4, 4);
2308 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
2309 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
2310 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
2311 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
2313 ID3D10RenderTargetView_Release(offscreen_rtv);
2314 ID3D10Texture2D_Release(offscreen);
2315 done:
2316 ID3D10BlendState_Release(dst_blend);
2317 ID3D10BlendState_Release(src_blend);
2318 ID3D10PixelShader_Release(ps);
2319 ID3D10VertexShader_Release(vs);
2320 ID3D10Buffer_Release(vb);
2321 ID3D10InputLayout_Release(input_layout);
2322 ID3D10RenderTargetView_Release(backbuffer_rtv);
2323 ID3D10Texture2D_Release(backbuffer);
2324 IDXGISwapChain_Release(swapchain);
2325 refcount = ID3D10Device_Release(device);
2326 ok(!refcount, "Device has %u references left.\n", refcount);
2327 DestroyWindow(window);
2330 static void test_texture(void)
2332 ID3D10RenderTargetView *backbuffer_rtv;
2333 D3D10_SUBRESOURCE_DATA resource_data;
2334 D3D10_TEXTURE2D_DESC texture_desc;
2335 ID3D10SamplerState *sampler_state;
2336 ID3D10ShaderResourceView *ps_srv;
2337 D3D10_SAMPLER_DESC sampler_desc;
2338 ID3D10InputLayout *input_layout;
2339 D3D10_BUFFER_DESC buffer_desc;
2340 ID3D10Texture2D *backbuffer;
2341 unsigned int stride, offset;
2342 IDXGISwapChain *swapchain;
2343 ID3D10Texture2D *texture;
2344 ID3D10VertexShader *vs;
2345 ID3D10PixelShader *ps;
2346 ID3D10Device *device;
2347 D3D10_VIEWPORT vp;
2348 unsigned int i, j;
2349 ID3D10Buffer *vb;
2350 ULONG refcount;
2351 DWORD color;
2352 HWND window;
2353 HRESULT hr;
2355 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2357 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2359 static const DWORD vs_code[] =
2361 #if 0
2362 float4 main(float4 position : POSITION) : SV_POSITION
2364 return position;
2366 #endif
2367 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2368 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2369 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2370 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2371 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2372 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2373 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2375 static const DWORD ps_code[] =
2377 #if 0
2378 Texture2D t;
2379 SamplerState s;
2381 float4 main(float4 position : SV_POSITION) : SV_Target
2383 float2 p;
2385 p.x = position.x / 640.0f;
2386 p.y = position.y / 480.0f;
2387 return t.Sample(s, p);
2389 #endif
2390 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
2391 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2392 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
2393 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
2394 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
2395 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
2396 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
2397 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
2398 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
2399 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
2401 static const struct
2403 float x, y;
2405 quad[] =
2407 {-1.0f, -1.0f},
2408 {-1.0f, 1.0f},
2409 { 1.0f, -1.0f},
2410 { 1.0f, 1.0f},
2412 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2413 static const DWORD bitmap_data[] =
2415 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
2416 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
2417 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
2418 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
2421 if (!(device = create_device()))
2423 skip("Failed to create device, skipping tests.\n");
2424 return;
2426 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2427 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2428 swapchain = create_swapchain(device, window, TRUE);
2429 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2430 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2432 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2433 vs_code, sizeof(vs_code), &input_layout);
2434 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2436 buffer_desc.ByteWidth = sizeof(quad);
2437 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2438 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2439 buffer_desc.CPUAccessFlags = 0;
2440 buffer_desc.MiscFlags = 0;
2442 resource_data.pSysMem = quad;
2443 resource_data.SysMemPitch = 0;
2444 resource_data.SysMemSlicePitch = 0;
2446 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
2447 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2449 texture_desc.Width = 4;
2450 texture_desc.Height = 4;
2451 texture_desc.MipLevels = 1;
2452 texture_desc.ArraySize = 1;
2453 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2454 texture_desc.SampleDesc.Count = 1;
2455 texture_desc.SampleDesc.Quality = 0;
2456 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2457 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2458 texture_desc.CPUAccessFlags = 0;
2459 texture_desc.MiscFlags = 0;
2461 resource_data.pSysMem = bitmap_data;
2462 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
2464 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
2465 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2467 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
2468 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
2470 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
2471 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
2472 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
2473 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
2474 sampler_desc.MipLODBias = 0.0f;
2475 sampler_desc.MaxAnisotropy = 0;
2476 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2477 sampler_desc.BorderColor[0] = 0.0f;
2478 sampler_desc.BorderColor[1] = 0.0f;
2479 sampler_desc.BorderColor[2] = 0.0f;
2480 sampler_desc.BorderColor[3] = 0.0f;
2481 sampler_desc.MinLOD = 0.0f;
2482 sampler_desc.MaxLOD = 0.0f;
2484 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
2485 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2487 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2488 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2489 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2490 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2492 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2493 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2495 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2496 ID3D10Device_IASetInputLayout(device, input_layout);
2497 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2498 stride = sizeof(*quad);
2499 offset = 0;
2500 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
2501 ID3D10Device_VSSetShader(device, vs);
2502 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
2503 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
2504 ID3D10Device_PSSetShader(device, ps);
2506 vp.TopLeftX = 0;
2507 vp.TopLeftY = 0;
2508 vp.Width = 640;
2509 vp.Height = 480;
2510 vp.MinDepth = 0.0f;
2511 vp.MaxDepth = 1.0f;
2512 ID3D10Device_RSSetViewports(device, 1, &vp);
2514 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2516 ID3D10Device_Draw(device, 4, 0);
2518 for (i = 0; i < 4; ++i)
2520 for (j = 0; j < 4; ++j)
2522 color = get_texture_color(backbuffer, 80 + j * 160, 60 + i * 120);
2523 ok(compare_color(color, bitmap_data[j + i * 4], 1),
2524 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
2525 color, j, i, bitmap_data[j + i * 4]);
2529 ID3D10PixelShader_Release(ps);
2530 ID3D10VertexShader_Release(vs);
2531 ID3D10SamplerState_Release(sampler_state);
2532 ID3D10ShaderResourceView_Release(ps_srv);
2533 ID3D10Texture2D_Release(texture);
2534 ID3D10Buffer_Release(vb);
2535 ID3D10InputLayout_Release(input_layout);
2536 ID3D10RenderTargetView_Release(backbuffer_rtv);
2537 ID3D10Texture2D_Release(backbuffer);
2538 IDXGISwapChain_Release(swapchain);
2539 refcount = ID3D10Device_Release(device);
2540 ok(!refcount, "Device has %u references left.\n", refcount);
2541 DestroyWindow(window);
2544 static void test_private_data(void)
2546 D3D10_TEXTURE2D_DESC texture_desc;
2547 ULONG refcount, expected_refcount;
2548 ID3D10Device *test_object;
2549 ID3D10Texture2D *texture;
2550 IDXGIDevice *dxgi_device;
2551 IDXGISurface *surface;
2552 ID3D10Device *device;
2553 IUnknown *ptr;
2554 HRESULT hr;
2555 UINT size;
2557 static const GUID test_guid =
2558 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2559 static const GUID test_guid2 =
2560 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2561 static const DWORD data[] = {1, 2, 3, 4};
2563 if (!(device = create_device()))
2565 skip("Failed to create device, skipping tests.\n");
2566 return;
2569 test_object = create_device();
2571 texture_desc.Width = 512;
2572 texture_desc.Height = 512;
2573 texture_desc.MipLevels = 1;
2574 texture_desc.ArraySize = 1;
2575 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2576 texture_desc.SampleDesc.Count = 1;
2577 texture_desc.SampleDesc.Quality = 0;
2578 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2579 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2580 texture_desc.CPUAccessFlags = 0;
2581 texture_desc.MiscFlags = 0;
2583 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2584 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2585 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2586 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
2588 /* SetPrivateData() with a pointer of NULL has the purpose of
2589 * FreePrivateData() in previous D3D versions. A successful clear returns
2590 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
2591 * considered a clear but as setting an interface pointer that happens to
2592 * be NULL. */
2593 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
2594 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2595 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2596 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2597 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2598 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2599 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2600 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2602 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2603 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2604 size = sizeof(ptr) * 2;
2605 ptr = (IUnknown *)0xdeadbeef;
2606 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2607 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2608 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2609 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2611 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2612 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2613 size = sizeof(ptr) * 2;
2614 ptr = (IUnknown *)0xdeadbeef;
2615 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2616 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2617 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2618 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2619 IDXGIDevice_Release(dxgi_device);
2621 refcount = get_refcount((IUnknown *)test_object);
2622 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2623 (IUnknown *)test_object);
2624 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2625 expected_refcount = refcount + 1;
2626 refcount = get_refcount((IUnknown *)test_object);
2627 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2628 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2629 (IUnknown *)test_object);
2630 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2631 refcount = get_refcount((IUnknown *)test_object);
2632 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2634 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
2635 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2636 --expected_refcount;
2637 refcount = get_refcount((IUnknown *)test_object);
2638 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2640 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2641 (IUnknown *)test_object);
2642 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2643 size = sizeof(data);
2644 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
2645 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2646 refcount = get_refcount((IUnknown *)test_object);
2647 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2648 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2649 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2650 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
2651 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2653 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
2654 (IUnknown *)test_object);
2655 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2656 ++expected_refcount;
2657 size = 2 * sizeof(ptr);
2658 ptr = NULL;
2659 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2660 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2661 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2662 ++expected_refcount;
2663 refcount = get_refcount((IUnknown *)test_object);
2664 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2665 IUnknown_Release(ptr);
2666 --expected_refcount;
2668 ptr = (IUnknown *)0xdeadbeef;
2669 size = 1;
2670 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2671 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2672 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2673 size = 2 * sizeof(ptr);
2674 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
2675 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2676 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2677 refcount = get_refcount((IUnknown *)test_object);
2678 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2680 size = 1;
2681 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
2682 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2683 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2684 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2685 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2686 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2687 size = 0xdeadbabe;
2688 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2689 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2690 ok(size == 0, "Got unexpected size %u.\n", size);
2691 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2692 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2693 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2694 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2696 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
2697 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2698 ptr = NULL;
2699 size = sizeof(ptr);
2700 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
2701 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2702 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2703 IUnknown_Release(ptr);
2705 IDXGISurface_Release(surface);
2706 ID3D10Texture2D_Release(texture);
2707 refcount = ID3D10Device_Release(device);
2708 ok(!refcount, "Device has %u references left.\n", refcount);
2709 refcount = ID3D10Device_Release(test_object);
2710 ok(!refcount, "Test object has %u references left.\n", refcount);
2713 static void test_il_append_aligned(void)
2715 ID3D10RenderTargetView *backbuffer_rtv;
2716 D3D10_SUBRESOURCE_DATA resource_data;
2717 ID3D10InputLayout *input_layout;
2718 D3D10_BUFFER_DESC buffer_desc;
2719 ID3D10Texture2D *backbuffer;
2720 unsigned int stride, offset;
2721 IDXGISwapChain *swapchain;
2722 ID3D10VertexShader *vs;
2723 ID3D10PixelShader *ps;
2724 ID3D10Device *device;
2725 ID3D10Buffer *vb[3];
2726 D3D10_VIEWPORT vp;
2727 ULONG refcount;
2728 DWORD color;
2729 HWND window;
2730 HRESULT hr;
2732 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2734 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
2735 D3D10_INPUT_PER_INSTANCE_DATA, 2},
2736 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
2737 D3D10_INPUT_PER_INSTANCE_DATA, 1},
2738 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
2739 D3D10_INPUT_PER_VERTEX_DATA, 0},
2740 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
2741 D3D10_INPUT_PER_INSTANCE_DATA, 1},
2742 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
2743 D3D10_INPUT_PER_INSTANCE_DATA, 2},
2745 static const DWORD vs_code[] =
2747 #if 0
2748 struct vs_in
2750 float4 position : POSITION;
2751 float2 color_xy : COLOR0;
2752 float2 color_zw : COLOR1;
2753 unsigned int instance_id : SV_INSTANCEID;
2756 struct vs_out
2758 float4 position : SV_POSITION;
2759 float2 color_xy : COLOR0;
2760 float2 color_zw : COLOR1;
2763 struct vs_out main(struct vs_in i)
2765 struct vs_out o;
2767 o.position = i.position;
2768 o.position.x += i.instance_id * 0.5;
2769 o.color_xy = i.color_xy;
2770 o.color_zw = i.color_zw;
2772 return o;
2774 #endif
2775 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
2776 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
2777 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
2778 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
2779 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
2780 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
2781 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
2782 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
2783 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
2784 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
2785 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
2786 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
2787 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
2788 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
2789 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
2790 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
2791 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
2793 static const DWORD ps_code[] =
2795 #if 0
2796 struct vs_out
2798 float4 position : SV_POSITION;
2799 float2 color_xy : COLOR0;
2800 float2 color_zw : COLOR1;
2803 float4 main(struct vs_out i) : SV_TARGET
2805 return float4(i.color_xy.xy, i.color_zw.xy);
2807 #endif
2808 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
2809 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
2810 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
2811 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
2812 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2813 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
2814 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
2815 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
2816 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
2818 static const struct
2820 struct vec4 position;
2822 stream0[] =
2824 {{-1.0f, -1.0f, 0.0f, 1.0f}},
2825 {{-1.0f, 1.0f, 0.0f, 1.0f}},
2826 {{-0.5f, -1.0f, 0.0f, 1.0f}},
2827 {{-0.5f, 1.0f, 0.0f, 1.0f}},
2829 static const struct
2831 struct vec2 color2;
2832 struct vec2 color1;
2834 stream1[] =
2836 {{0.5f, 0.5f}, {0.0f, 1.0f}},
2837 {{0.5f, 0.5f}, {1.0f, 1.0f}},
2839 static const struct
2841 struct vec2 color3;
2842 struct vec2 color0;
2844 stream2[] =
2846 {{0.5f, 0.5f}, {1.0f, 0.0f}},
2847 {{0.5f, 0.5f}, {0.0f, 1.0f}},
2848 {{0.5f, 0.5f}, {0.0f, 0.0f}},
2849 {{0.5f, 0.5f}, {1.0f, 0.0f}},
2851 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
2853 if (!(device = create_device()))
2855 skip("Failed to create device, skipping tests.\n");
2856 return;
2858 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2859 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2860 swapchain = create_swapchain(device, window, TRUE);
2861 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
2862 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
2864 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
2865 vs_code, sizeof(vs_code), &input_layout);
2866 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
2868 buffer_desc.ByteWidth = sizeof(stream0);
2869 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2870 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
2871 buffer_desc.CPUAccessFlags = 0;
2872 buffer_desc.MiscFlags = 0;
2874 resource_data.pSysMem = stream0;
2875 resource_data.SysMemPitch = 0;
2876 resource_data.SysMemSlicePitch = 0;
2878 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
2879 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2881 buffer_desc.ByteWidth = sizeof(stream1);
2882 resource_data.pSysMem = stream1;
2884 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
2885 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2887 buffer_desc.ByteWidth = sizeof(stream2);
2888 resource_data.pSysMem = stream2;
2890 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
2891 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2893 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
2894 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2895 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2898 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
2899 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
2901 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
2902 ID3D10Device_IASetInputLayout(device, input_layout);
2903 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
2904 offset = 0;
2905 stride = sizeof(*stream0);
2906 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
2907 stride = sizeof(*stream1);
2908 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
2909 stride = sizeof(*stream2);
2910 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
2911 ID3D10Device_VSSetShader(device, vs);
2912 ID3D10Device_PSSetShader(device, ps);
2914 vp.TopLeftX = 0;
2915 vp.TopLeftY = 0;
2916 vp.Width = 640;
2917 vp.Height = 480;
2918 vp.MinDepth = 0.0f;
2919 vp.MaxDepth = 1.0f;
2920 ID3D10Device_RSSetViewports(device, 1, &vp);
2922 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
2924 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
2926 color = get_texture_color(backbuffer, 80, 240);
2927 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
2928 color = get_texture_color(backbuffer, 240, 240);
2929 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
2930 color = get_texture_color(backbuffer, 400, 240);
2931 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
2932 color = get_texture_color(backbuffer, 560, 240);
2933 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
2935 ID3D10PixelShader_Release(ps);
2936 ID3D10VertexShader_Release(vs);
2937 ID3D10Buffer_Release(vb[2]);
2938 ID3D10Buffer_Release(vb[1]);
2939 ID3D10Buffer_Release(vb[0]);
2940 ID3D10InputLayout_Release(input_layout);
2941 ID3D10RenderTargetView_Release(backbuffer_rtv);
2942 ID3D10Texture2D_Release(backbuffer);
2943 IDXGISwapChain_Release(swapchain);
2944 refcount = ID3D10Device_Release(device);
2945 ok(!refcount, "Device has %u references left.\n", refcount);
2946 DestroyWindow(window);
2949 static void test_fragment_coords(void)
2951 ID3D10RenderTargetView *backbuffer_rtv;
2952 D3D10_SUBRESOURCE_DATA resource_data;
2953 ID3D10InputLayout *input_layout;
2954 ID3D10PixelShader *ps, *ps_frac;
2955 D3D10_BUFFER_DESC buffer_desc;
2956 ID3D10Texture2D *backbuffer;
2957 unsigned int stride, offset;
2958 IDXGISwapChain *swapchain;
2959 ID3D10Buffer *vb, *ps_cb;
2960 ID3D10VertexShader *vs;
2961 ID3D10Device *device;
2962 D3D10_VIEWPORT vp;
2963 ULONG refcount;
2964 DWORD color;
2965 HWND window;
2966 HRESULT hr;
2968 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
2970 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
2972 static const DWORD vs_code[] =
2974 #if 0
2975 float4 main(float4 position : POSITION) : SV_POSITION
2977 return position;
2979 #endif
2980 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
2981 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2982 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2983 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2984 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
2985 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
2986 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2988 static const DWORD ps_code[] =
2990 #if 0
2991 float2 cutoff;
2993 float4 main(float4 position : SV_POSITION) : SV_TARGET
2995 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
2997 if (position.x > cutoff.x)
2998 ret.y = 1.0;
2999 if (position.y > cutoff.y)
3000 ret.z = 1.0;
3002 return ret;
3004 #endif
3005 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
3006 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3007 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3008 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3009 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
3010 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
3011 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
3012 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
3013 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
3014 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
3015 0x0100003e,
3017 static const DWORD ps_frac_code[] =
3019 #if 0
3020 float4 main(float4 position : SV_POSITION) : SV_TARGET
3022 return float4(frac(position.xy), 0.0, 1.0);
3024 #endif
3025 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
3026 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3027 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3028 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3029 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
3030 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3031 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
3032 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
3034 static const struct
3036 struct vec2 position;
3038 quad[] =
3040 {{-1.0f, -1.0f}},
3041 {{-1.0f, 1.0f}},
3042 {{ 1.0f, -1.0f}},
3043 {{ 1.0f, 1.0f}},
3045 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3046 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
3048 if (!(device = create_device()))
3050 skip("Failed to create device, skipping tests.\n");
3051 return;
3053 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3054 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3055 swapchain = create_swapchain(device, window, TRUE);
3056 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
3057 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
3059 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3060 vs_code, sizeof(vs_code), &input_layout);
3061 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3063 buffer_desc.ByteWidth = sizeof(quad);
3064 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3065 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
3066 buffer_desc.CPUAccessFlags = 0;
3067 buffer_desc.MiscFlags = 0;
3069 resource_data.pSysMem = quad;
3070 resource_data.SysMemPitch = 0;
3071 resource_data.SysMemSlicePitch = 0;
3073 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3074 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3076 buffer_desc.ByteWidth = sizeof(cutoff);
3077 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
3079 resource_data.pSysMem = &cutoff;
3081 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3082 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3084 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
3085 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3086 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3087 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3088 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
3089 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3091 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
3092 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3094 ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL);
3095 ID3D10Device_IASetInputLayout(device, input_layout);
3096 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3097 stride = sizeof(*quad);
3098 offset = 0;
3099 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
3100 ID3D10Device_VSSetShader(device, vs);
3101 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
3102 ID3D10Device_PSSetShader(device, ps);
3104 vp.TopLeftX = 0;
3105 vp.TopLeftY = 0;
3106 vp.Width = 640;
3107 vp.Height = 480;
3108 vp.MinDepth = 0.0f;
3109 vp.MaxDepth = 1.0f;
3110 ID3D10Device_RSSetViewports(device, 1, &vp);
3112 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3114 ID3D10Device_Draw(device, 4, 0);
3116 color = get_texture_color(backbuffer, 319, 239);
3117 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3118 color = get_texture_color(backbuffer, 320, 239);
3119 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3120 color = get_texture_color(backbuffer, 319, 240);
3121 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3122 color = get_texture_color(backbuffer, 320, 240);
3123 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3125 ID3D10Buffer_Release(ps_cb);
3126 cutoff.x = 16.0f;
3127 cutoff.y = 16.0f;
3128 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
3129 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3130 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
3132 ID3D10Device_Draw(device, 4, 0);
3134 color = get_texture_color(backbuffer, 14, 14);
3135 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
3136 color = get_texture_color(backbuffer, 18, 14);
3137 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3138 color = get_texture_color(backbuffer, 14, 18);
3139 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
3140 color = get_texture_color(backbuffer, 18, 18);
3141 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
3143 ID3D10Device_PSSetShader(device, ps_frac);
3144 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
3146 ID3D10Device_Draw(device, 4, 0);
3148 color = get_texture_color(backbuffer, 14, 14);
3149 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
3151 ID3D10Buffer_Release(ps_cb);
3152 ID3D10PixelShader_Release(ps_frac);
3153 ID3D10PixelShader_Release(ps);
3154 ID3D10VertexShader_Release(vs);
3155 ID3D10Buffer_Release(vb);
3156 ID3D10InputLayout_Release(input_layout);
3157 ID3D10RenderTargetView_Release(backbuffer_rtv);
3158 ID3D10Texture2D_Release(backbuffer);
3159 IDXGISwapChain_Release(swapchain);
3160 refcount = ID3D10Device_Release(device);
3161 ok(!refcount, "Device has %u references left.\n", refcount);
3162 DestroyWindow(window);
3165 START_TEST(device)
3167 test_create_texture2d();
3168 test_create_texture3d();
3169 test_create_depthstencil_view();
3170 test_create_rendertarget_view();
3171 test_create_shader_resource_view();
3172 test_create_shader();
3173 test_create_sampler_state();
3174 test_create_blend_state();
3175 test_create_depthstencil_state();
3176 test_create_rasterizer_state();
3177 test_create_predicate();
3178 test_device_removed_reason();
3179 test_scissor();
3180 test_clear_state();
3181 test_blend();
3182 test_texture();
3183 test_private_data();
3184 test_il_append_aligned();
3185 test_fragment_coords();