d3d11/tests: Test creating SM4 shaders on feature level 9.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobc42286a91f4e2a74324c83ca4c21351bb18ef788
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
21 #include "initguid.h"
22 #include "d3d11.h"
23 #include "wine/test.h"
25 static const D3D_FEATURE_LEVEL d3d11_feature_levels[] =
27 D3D_FEATURE_LEVEL_11_1,
28 D3D_FEATURE_LEVEL_11_0,
29 D3D_FEATURE_LEVEL_10_1,
30 D3D_FEATURE_LEVEL_10_0,
31 D3D_FEATURE_LEVEL_9_3,
32 D3D_FEATURE_LEVEL_9_2,
33 D3D_FEATURE_LEVEL_9_1
36 struct vec2
38 float x, y;
41 struct vec3
43 float x, y, z;
46 struct vec4
48 float x, y, z, w;
51 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
53 box->left = left;
54 box->top = top;
55 box->front = front;
56 box->right = right;
57 box->bottom = bottom;
58 box->back = back;
61 static ULONG get_refcount(IUnknown *iface)
63 IUnknown_AddRef(iface);
64 return IUnknown_Release(iface);
67 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
69 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
70 return FALSE;
71 c1 >>= 8; c2 >>= 8;
72 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
73 return FALSE;
74 c1 >>= 8; c2 >>= 8;
75 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
76 return FALSE;
77 c1 >>= 8; c2 >>= 8;
78 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
79 return FALSE;
80 return TRUE;
83 struct texture_readback
85 ID3D11Resource *texture;
86 D3D11_MAPPED_SUBRESOURCE map_desc;
87 ID3D11DeviceContext *immediate_context;
88 unsigned int width, height;
91 static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readback *rb)
93 D3D11_TEXTURE2D_DESC texture_desc;
94 ID3D11Device *device;
95 HRESULT hr;
97 memset(rb, 0, sizeof(*rb));
99 ID3D11Texture2D_GetDevice(texture, &device);
101 ID3D11Texture2D_GetDesc(texture, &texture_desc);
102 texture_desc.Usage = D3D11_USAGE_STAGING;
103 texture_desc.BindFlags = 0;
104 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
105 texture_desc.MiscFlags = 0;
106 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->texture)))
108 trace("Failed to create texture, hr %#x.\n", hr);
109 ID3D11Device_Release(device);
110 return;
113 rb->width = texture_desc.Width;
114 rb->height = texture_desc.Height;
116 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
118 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
119 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->texture, 0, D3D11_MAP_READ, 0, &rb->map_desc)))
121 trace("Failed to map texture, hr %#x.\n", hr);
122 ID3D11Resource_Release(rb->texture);
123 rb->texture = NULL;
124 ID3D11DeviceContext_Release(rb->immediate_context);
125 rb->immediate_context = NULL;
128 ID3D11Device_Release(device);
131 static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, unsigned int y)
133 return rb->texture
134 ? ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x] : 0xdeadbeef;
137 static void release_texture_readback(struct texture_readback *rb)
139 if (!rb->texture)
140 return;
142 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->texture, 0);
143 ID3D11Resource_Release(rb->texture);
144 ID3D11DeviceContext_Release(rb->immediate_context);
147 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
149 struct texture_readback rb;
150 DWORD color;
152 get_texture_readback(texture, &rb);
153 color = get_readback_color(&rb, x, y);
154 release_texture_readback(&rb);
156 return color;
159 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
160 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
161 DWORD expected_color, BYTE max_diff)
163 struct texture_readback rb;
164 unsigned int x = 0, y = 0;
165 BOOL all_match = TRUE;
166 DWORD color = 0;
168 get_texture_readback(texture, &rb);
169 for (y = 0; y < rb.height; ++y)
171 for (x = 0; x < rb.width; ++x)
173 color = get_readback_color(&rb, x, y);
174 if (!compare_color(color, expected_color, max_diff))
176 all_match = FALSE;
177 break;
180 if (!all_match)
181 break;
183 release_texture_readback(&rb);
184 ok_(__FILE__, line)(all_match,
185 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
188 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
190 static const D3D_FEATURE_LEVEL default_feature_level[] =
192 D3D_FEATURE_LEVEL_11_0,
193 D3D_FEATURE_LEVEL_10_0,
195 unsigned int feature_level_count;
196 ID3D11Device *device;
198 if (feature_level)
200 feature_level_count = 1;
202 else
204 feature_level = default_feature_level;
205 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
208 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, feature_level, feature_level_count,
209 D3D11_SDK_VERSION, &device, NULL, NULL)))
210 return device;
211 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, feature_level, feature_level_count,
212 D3D11_SDK_VERSION, &device, NULL, NULL)))
213 return device;
214 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, feature_level, feature_level_count,
215 D3D11_SDK_VERSION, &device, NULL, NULL)))
216 return device;
218 return NULL;
221 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, BOOL windowed)
223 IDXGISwapChain *swapchain;
224 DXGI_SWAP_CHAIN_DESC desc;
225 IDXGIDevice *dxgi_device;
226 IDXGIAdapter *adapter;
227 IDXGIFactory *factory;
228 HRESULT hr;
230 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
231 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
232 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
233 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
234 IDXGIDevice_Release(dxgi_device);
235 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
236 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
237 IDXGIAdapter_Release(adapter);
239 desc.BufferDesc.Width = 640;
240 desc.BufferDesc.Height = 480;
241 desc.BufferDesc.RefreshRate.Numerator = 60;
242 desc.BufferDesc.RefreshRate.Denominator = 1;
243 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
244 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
245 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
246 desc.SampleDesc.Count = 1;
247 desc.SampleDesc.Quality = 0;
248 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
249 desc.BufferCount = 1;
250 desc.OutputWindow = window;
251 desc.Windowed = windowed;
252 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
253 desc.Flags = 0;
255 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
256 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
257 IDXGIFactory_Release(factory);
259 return swapchain;
262 struct d3d11_test_context
264 ID3D11Device *device;
265 HWND window;
266 IDXGISwapChain *swapchain;
267 ID3D11Texture2D *backbuffer;
268 ID3D11RenderTargetView *backbuffer_rtv;
269 ID3D11DeviceContext *immediate_context;
271 ID3D11InputLayout *input_layout;
272 ID3D11VertexShader *vs;
273 ID3D11Buffer *vb;
276 #define init_test_context(c) init_test_context_(__LINE__, c)
277 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context)
279 D3D11_VIEWPORT vp;
280 HRESULT hr;
282 memset(context, 0, sizeof(*context));
284 if (!(context->device = create_device(NULL)))
286 skip_(__FILE__, line)("Failed to create device.\n");
287 return FALSE;
289 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
290 0, 0, 640, 480, NULL, NULL, NULL, NULL);
291 context->swapchain = create_swapchain(context->device, context->window, TRUE);
292 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
293 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
295 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
296 NULL, &context->backbuffer_rtv);
297 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
299 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
301 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
303 vp.TopLeftX = 0.0f;
304 vp.TopLeftY = 0.0f;
305 vp.Width = 640.0f;
306 vp.Height = 480.0f;
307 vp.MinDepth = 0.0f;
308 vp.MaxDepth = 1.0f;
309 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
311 return TRUE;
314 #define release_test_context(c) release_test_context_(__LINE__, c)
315 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
317 ULONG ref;
319 if (context->input_layout)
320 ID3D11InputLayout_Release(context->input_layout);
321 if (context->vs)
322 ID3D11VertexShader_Release(context->vs);
323 if (context->vb)
324 ID3D11Buffer_Release(context->vb);
326 ID3D11DeviceContext_Release(context->immediate_context);
327 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
328 ID3D11Texture2D_Release(context->backbuffer);
329 IDXGISwapChain_Release(context->swapchain);
330 DestroyWindow(context->window);
332 ref = ID3D11Device_Release(context->device);
333 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
336 #define draw_quad(c) draw_quad_(__LINE__, c)
337 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
339 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
341 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
343 static const DWORD default_vs_code[] =
345 #if 0
346 float4 main(float4 position : POSITION) : SV_POSITION
348 return position;
350 #endif
351 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
352 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
353 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
354 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
355 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
356 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
357 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
359 static const struct
361 struct vec2 position;
363 quad[] =
365 {{-1.0f, -1.0f}},
366 {{-1.0f, 1.0f}},
367 {{ 1.0f, -1.0f}},
368 {{ 1.0f, 1.0f}},
371 ID3D11Device *device = context->device;
372 D3D11_SUBRESOURCE_DATA resource_data;
373 D3D11_BUFFER_DESC buffer_desc;
374 unsigned int stride, offset;
375 HRESULT hr;
377 if (!context->input_layout)
379 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
380 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
381 default_vs_code, sizeof(default_vs_code), &context->input_layout);
382 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
384 buffer_desc.ByteWidth = sizeof(quad);
385 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
386 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
387 buffer_desc.CPUAccessFlags = 0;
388 buffer_desc.MiscFlags = 0;
389 buffer_desc.StructureByteStride = 0;
391 resource_data.pSysMem = quad;
392 resource_data.SysMemPitch = 0;
393 resource_data.SysMemSlicePitch = 0;
395 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &context->vb);
396 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
398 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
399 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
402 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
403 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
404 stride = sizeof(*quad);
405 offset = 0;
406 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
407 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
409 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
412 static void test_create_device(void)
414 static const D3D_FEATURE_LEVEL default_feature_levels[] =
416 D3D_FEATURE_LEVEL_11_0,
417 D3D_FEATURE_LEVEL_10_1,
418 D3D_FEATURE_LEVEL_10_0,
419 D3D_FEATURE_LEVEL_9_3,
420 D3D_FEATURE_LEVEL_9_2,
421 D3D_FEATURE_LEVEL_9_1,
423 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
424 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
425 ID3D11DeviceContext *immediate_context;
426 IDXGISwapChain *swapchain;
427 ID3D11Device *device;
428 ULONG refcount;
429 HWND window;
430 HRESULT hr;
432 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device,
433 NULL, NULL);
434 if (FAILED(hr))
436 skip("Failed to create HAL device.\n");
437 return;
440 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
441 ID3D11Device_Release(device);
443 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
444 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
446 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
447 &feature_level, NULL);
448 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
449 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
450 feature_level, supported_feature_level);
452 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
453 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
454 &feature_level, NULL);
455 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
456 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
457 feature_level, supported_feature_level);
459 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
460 &immediate_context);
461 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
463 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
464 refcount = get_refcount((IUnknown *)immediate_context);
465 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
467 ID3D11DeviceContext_GetDevice(immediate_context, &device);
468 refcount = ID3D11Device_Release(device);
469 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
471 refcount = ID3D11DeviceContext_Release(immediate_context);
472 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
474 device = (ID3D11Device *)0xdeadbeef;
475 feature_level = 0xdeadbeef;
476 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
477 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
478 &device, &feature_level, &immediate_context);
479 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
480 ok(!device, "Got unexpected device pointer %p.\n", device);
481 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
482 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
484 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
486 swapchain_desc.BufferDesc.Width = 800;
487 swapchain_desc.BufferDesc.Height = 600;
488 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
489 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
490 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
491 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
492 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
493 swapchain_desc.SampleDesc.Count = 1;
494 swapchain_desc.SampleDesc.Quality = 0;
495 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
496 swapchain_desc.BufferCount = 1;
497 swapchain_desc.OutputWindow = window;
498 swapchain_desc.Windowed = TRUE;
499 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
500 swapchain_desc.Flags = 0;
502 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
503 &swapchain_desc, NULL, NULL, NULL, NULL);
504 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
506 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
507 &swapchain_desc, NULL, NULL, &feature_level, NULL);
508 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
509 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
510 feature_level, supported_feature_level);
512 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
513 &swapchain_desc, &swapchain, &device, NULL, NULL);
514 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
516 memset(&obtained_desc, 0, sizeof(obtained_desc));
517 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
518 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
519 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
520 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
521 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
522 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
523 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
524 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
525 obtained_desc.BufferDesc.RefreshRate.Numerator);
526 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
527 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
528 obtained_desc.BufferDesc.RefreshRate.Denominator);
529 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
530 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
531 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
532 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
533 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
534 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
535 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
536 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
537 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
538 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
539 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
540 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
541 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
542 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
543 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
544 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
545 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
546 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
547 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
548 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
549 ok(obtained_desc.Flags == swapchain_desc.Flags,
550 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
552 refcount = IDXGISwapChain_Release(swapchain);
553 ok(!refcount, "Swapchain has %u references left.\n", refcount);
555 feature_level = ID3D11Device_GetFeatureLevel(device);
556 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
557 feature_level, supported_feature_level);
559 refcount = ID3D11Device_Release(device);
560 ok(!refcount, "Device has %u references left.\n", refcount);
562 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
563 NULL, NULL, &device, NULL, NULL);
564 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
565 ID3D11Device_Release(device);
567 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
568 NULL, NULL, NULL, NULL, NULL);
569 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
571 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
572 NULL, NULL, NULL, &feature_level, NULL);
573 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
574 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
575 feature_level, supported_feature_level);
577 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
578 &swapchain_desc, NULL, NULL, NULL, NULL);
579 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
581 swapchain_desc.OutputWindow = NULL;
582 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
583 &swapchain_desc, NULL, &device, NULL, NULL);
584 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
585 ID3D11Device_Release(device);
587 swapchain = (IDXGISwapChain *)0xdeadbeef;
588 device = (ID3D11Device *)0xdeadbeef;
589 feature_level = 0xdeadbeef;
590 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
591 swapchain_desc.OutputWindow = NULL;
592 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
593 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
594 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
595 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
596 ok(!device, "Got unexpected device pointer %p.\n", device);
597 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
598 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
600 swapchain = (IDXGISwapChain *)0xdeadbeef;
601 device = (ID3D11Device *)0xdeadbeef;
602 feature_level = 0xdeadbeef;
603 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
604 swapchain_desc.OutputWindow = window;
605 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
606 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
607 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
608 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
609 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
610 ok(!device, "Got unexpected device pointer %p.\n", device);
611 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
612 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
614 DestroyWindow(window);
617 static void test_device_interfaces(void)
619 IDXGIAdapter *dxgi_adapter;
620 IDXGIDevice *dxgi_device;
621 ID3D11Device *device;
622 IUnknown *iface;
623 ULONG refcount;
624 unsigned int i;
625 HRESULT hr;
627 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
629 if (!(device = create_device(&d3d11_feature_levels[i])))
631 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels[i]);
632 continue;
635 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
636 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
637 IUnknown_Release(iface);
639 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
640 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
641 IUnknown_Release(iface);
643 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
644 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
645 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
646 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
647 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
648 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
649 IUnknown_Release(iface);
650 IDXGIAdapter_Release(dxgi_adapter);
651 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
652 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
653 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
654 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
655 IUnknown_Release(iface);
656 IDXGIAdapter_Release(dxgi_adapter);
657 IDXGIDevice_Release(dxgi_device);
659 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
660 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
661 IUnknown_Release(iface);
663 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
664 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
665 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
666 if (SUCCEEDED(hr)) IUnknown_Release(iface);
668 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
669 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
670 if (SUCCEEDED(hr)) IUnknown_Release(iface);
672 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
673 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
674 if (SUCCEEDED(hr)) IUnknown_Release(iface);
676 refcount = ID3D11Device_Release(device);
677 ok(!refcount, "Device has %u references left.\n", refcount);
681 static void test_get_immediate_context(void)
683 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
684 ULONG expected_refcount, refcount;
685 ID3D11Device *device;
687 if (!(device = create_device(NULL)))
689 skip("Failed to create device.\n");
690 return;
693 expected_refcount = get_refcount((IUnknown *)device) + 1;
694 ID3D11Device_GetImmediateContext(device, &immediate_context);
695 refcount = get_refcount((IUnknown *)device);
696 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
697 previous_immediate_context = immediate_context;
699 ID3D11Device_GetImmediateContext(device, &immediate_context);
700 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
701 refcount = get_refcount((IUnknown *)device);
702 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
704 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
705 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
706 refcount = ID3D11DeviceContext_Release(immediate_context);
707 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
709 ID3D11Device_GetImmediateContext(device, &immediate_context);
710 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
711 refcount = ID3D11DeviceContext_Release(immediate_context);
712 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
714 refcount = ID3D11Device_Release(device);
715 ok(!refcount, "Device has %u references left.\n", refcount);
718 static void test_create_texture2d(void)
720 ULONG refcount, expected_refcount;
721 D3D11_SUBRESOURCE_DATA data = {0};
722 ID3D11Device *device, *tmp;
723 D3D11_TEXTURE2D_DESC desc;
724 ID3D11Texture2D *texture;
725 UINT quality_level_count;
726 IDXGISurface *surface;
727 HRESULT hr;
729 if (!(device = create_device(NULL)))
731 skip("Failed to create device, skipping tests.\n");
732 return;
735 desc.Width = 512;
736 desc.Height = 512;
737 desc.MipLevels = 1;
738 desc.ArraySize = 1;
739 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
740 desc.SampleDesc.Count = 1;
741 desc.SampleDesc.Quality = 0;
742 desc.Usage = D3D11_USAGE_DEFAULT;
743 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
744 desc.CPUAccessFlags = 0;
745 desc.MiscFlags = 0;
747 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
748 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
750 expected_refcount = get_refcount((IUnknown *)device) + 1;
751 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
752 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
753 refcount = get_refcount((IUnknown *)device);
754 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
755 tmp = NULL;
756 expected_refcount = refcount + 1;
757 ID3D11Texture2D_GetDevice(texture, &tmp);
758 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
759 refcount = get_refcount((IUnknown *)device);
760 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
761 ID3D11Device_Release(tmp);
763 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
764 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
765 IDXGISurface_Release(surface);
766 ID3D11Texture2D_Release(texture);
768 desc.MipLevels = 0;
769 expected_refcount = get_refcount((IUnknown *)device) + 1;
770 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
771 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
772 refcount = get_refcount((IUnknown *)device);
773 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
774 tmp = NULL;
775 expected_refcount = refcount + 1;
776 ID3D11Texture2D_GetDevice(texture, &tmp);
777 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
778 refcount = get_refcount((IUnknown *)device);
779 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
780 ID3D11Device_Release(tmp);
782 ID3D11Texture2D_GetDesc(texture, &desc);
783 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
784 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
785 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
786 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
787 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
788 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
789 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
790 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
791 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
792 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
793 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
795 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
796 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
797 ID3D11Texture2D_Release(texture);
799 desc.MipLevels = 1;
800 desc.ArraySize = 2;
801 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
802 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
804 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
805 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
806 ID3D11Texture2D_Release(texture);
808 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
809 desc.ArraySize = 1;
810 desc.SampleDesc.Count = 2;
811 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
812 if (quality_level_count)
814 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
815 ID3D11Texture2D_Release(texture);
816 desc.SampleDesc.Quality = quality_level_count;
817 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
819 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
821 /* We assume 15 samples multisampling is never supported in practice. */
822 desc.SampleDesc.Count = 15;
823 desc.SampleDesc.Quality = 0;
824 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
825 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
827 refcount = ID3D11Device_Release(device);
828 ok(!refcount, "Device has %u references left.\n", refcount);
831 static void test_texture2d_interfaces(void)
833 ID3D10Texture2D *d3d10_texture;
834 D3D11_TEXTURE2D_DESC desc;
835 ID3D11Texture2D *texture;
836 IDXGISurface *surface;
837 ID3D11Device *device;
838 unsigned int i;
839 ULONG refcount;
840 HRESULT hr;
842 static const struct test
844 BOOL implements_d3d10_interfaces;
845 UINT bind_flags;
846 UINT misc_flags;
847 UINT expected_bind_flags;
848 UINT expected_misc_flags;
850 desc_conversion_tests[] =
853 TRUE,
854 D3D11_BIND_SHADER_RESOURCE, 0,
855 D3D10_BIND_SHADER_RESOURCE, 0
858 TRUE,
859 D3D11_BIND_UNORDERED_ACCESS, 0,
860 D3D11_BIND_UNORDERED_ACCESS, 0
863 FALSE,
864 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
865 0, 0
868 TRUE,
869 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
870 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
873 TRUE,
874 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
875 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
879 if (!(device = create_device(NULL)))
881 skip("Failed to create ID3D11Device, skipping tests.\n");
882 return;
885 desc.Width = 512;
886 desc.Height = 512;
887 desc.MipLevels = 0;
888 desc.ArraySize = 1;
889 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
890 desc.SampleDesc.Count = 1;
891 desc.SampleDesc.Quality = 0;
892 desc.Usage = D3D11_USAGE_DEFAULT;
893 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
894 desc.CPUAccessFlags = 0;
895 desc.MiscFlags = 0;
897 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
898 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
900 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
901 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
903 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
904 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
905 "Texture should implement ID3D10Texture2D.\n");
906 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
907 ID3D11Texture2D_Release(texture);
909 if (FAILED(hr))
911 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
912 ID3D11Device_Release(device);
913 return;
916 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
918 const struct test *current = &desc_conversion_tests[i];
919 D3D10_TEXTURE2D_DESC d3d10_desc;
920 ID3D10Device *d3d10_device;
922 desc.Width = 512;
923 desc.Height = 512;
924 desc.MipLevels = 1;
925 desc.ArraySize = 1;
926 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
927 desc.SampleDesc.Count = 1;
928 desc.SampleDesc.Quality = 0;
929 desc.Usage = D3D11_USAGE_DEFAULT;
930 desc.BindFlags = current->bind_flags;
931 desc.CPUAccessFlags = 0;
932 desc.MiscFlags = current->misc_flags;
934 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
935 /* Shared resources are not supported by REF and WARP devices. */
936 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
937 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
938 if (FAILED(hr))
940 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
941 continue;
944 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
945 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
946 IDXGISurface_Release(surface);
948 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
949 ID3D11Texture2D_Release(texture);
951 if (current->implements_d3d10_interfaces)
953 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
955 else
957 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
958 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
959 continue;
962 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
964 ok(d3d10_desc.Width == desc.Width,
965 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
966 ok(d3d10_desc.Height == desc.Height,
967 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
968 ok(d3d10_desc.MipLevels == desc.MipLevels,
969 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
970 ok(d3d10_desc.ArraySize == desc.ArraySize,
971 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
972 ok(d3d10_desc.Format == desc.Format,
973 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
974 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
975 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
976 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
977 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
978 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
979 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
980 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
981 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
982 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
983 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
984 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
985 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
987 d3d10_device = (ID3D10Device *)0xdeadbeef;
988 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
989 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
990 if (d3d10_device) ID3D10Device_Release(d3d10_device);
992 ID3D10Texture2D_Release(d3d10_texture);
995 refcount = ID3D11Device_Release(device);
996 ok(!refcount, "Device has %u references left.\n", refcount);
999 static void test_create_texture3d(void)
1001 ULONG refcount, expected_refcount;
1002 D3D11_SUBRESOURCE_DATA data = {0};
1003 ID3D11Device *device, *tmp;
1004 D3D11_TEXTURE3D_DESC desc;
1005 ID3D11Texture3D *texture;
1006 IDXGISurface *surface;
1007 HRESULT hr;
1009 if (!(device = create_device(NULL)))
1011 skip("Failed to create ID3D11Device, skipping tests.\n");
1012 return;
1015 desc.Width = 64;
1016 desc.Height = 64;
1017 desc.Depth = 64;
1018 desc.MipLevels = 1;
1019 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1020 desc.Usage = D3D11_USAGE_DEFAULT;
1021 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1022 desc.CPUAccessFlags = 0;
1023 desc.MiscFlags = 0;
1025 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
1026 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1028 expected_refcount = get_refcount((IUnknown *)device) + 1;
1029 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1030 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1031 refcount = get_refcount((IUnknown *)device);
1032 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1033 tmp = NULL;
1034 expected_refcount = refcount + 1;
1035 ID3D11Texture3D_GetDevice(texture, &tmp);
1036 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1037 refcount = get_refcount((IUnknown *)device);
1038 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1039 ID3D11Device_Release(tmp);
1041 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1042 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1043 ID3D11Texture3D_Release(texture);
1045 desc.MipLevels = 0;
1046 expected_refcount = get_refcount((IUnknown *)device) + 1;
1047 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1048 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1049 refcount = get_refcount((IUnknown *)device);
1050 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1051 tmp = NULL;
1052 expected_refcount = refcount + 1;
1053 ID3D11Texture3D_GetDevice(texture, &tmp);
1054 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1055 refcount = get_refcount((IUnknown *)device);
1056 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1057 ID3D11Device_Release(tmp);
1059 ID3D11Texture3D_GetDesc(texture, &desc);
1060 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1061 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1062 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1063 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1064 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1065 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1066 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1067 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1068 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1070 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1071 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1072 ID3D11Texture3D_Release(texture);
1074 refcount = ID3D11Device_Release(device);
1075 ok(!refcount, "Device has %u references left.\n", refcount);
1078 static void test_texture3d_interfaces(void)
1080 ID3D10Texture3D *d3d10_texture;
1081 D3D11_TEXTURE3D_DESC desc;
1082 ID3D11Texture3D *texture;
1083 IDXGISurface *surface;
1084 ID3D11Device *device;
1085 unsigned int i;
1086 ULONG refcount;
1087 HRESULT hr;
1089 static const struct test
1091 BOOL implements_d3d10_interfaces;
1092 UINT bind_flags;
1093 UINT misc_flags;
1094 UINT expected_bind_flags;
1095 UINT expected_misc_flags;
1097 desc_conversion_tests[] =
1100 TRUE,
1101 D3D11_BIND_SHADER_RESOURCE, 0,
1102 D3D10_BIND_SHADER_RESOURCE, 0
1105 TRUE,
1106 D3D11_BIND_UNORDERED_ACCESS, 0,
1107 D3D11_BIND_UNORDERED_ACCESS, 0
1110 FALSE,
1111 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1112 0, 0
1115 TRUE,
1116 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1117 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1121 if (!(device = create_device(NULL)))
1123 skip("Failed to create ID3D11Device.\n");
1124 return;
1127 desc.Width = 64;
1128 desc.Height = 64;
1129 desc.Depth = 64;
1130 desc.MipLevels = 0;
1131 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1132 desc.Usage = D3D11_USAGE_DEFAULT;
1133 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1134 desc.CPUAccessFlags = 0;
1135 desc.MiscFlags = 0;
1137 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1138 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1140 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1141 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1143 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1144 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1145 "Texture should implement ID3D10Texture3D.\n");
1146 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1147 ID3D11Texture3D_Release(texture);
1149 if (FAILED(hr))
1151 win_skip("3D textures do not implement ID3D10Texture3D.\n");
1152 ID3D11Device_Release(device);
1153 return;
1156 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1158 const struct test *current = &desc_conversion_tests[i];
1159 D3D10_TEXTURE3D_DESC d3d10_desc;
1160 ID3D10Device *d3d10_device;
1162 desc.Width = 64;
1163 desc.Height = 64;
1164 desc.Depth = 64;
1165 desc.MipLevels = 1;
1166 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1167 desc.Usage = D3D11_USAGE_DEFAULT;
1168 desc.BindFlags = current->bind_flags;
1169 desc.CPUAccessFlags = 0;
1170 desc.MiscFlags = current->misc_flags;
1172 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1173 /* Shared resources are not supported by REF and WARP devices. */
1174 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1175 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
1176 if (FAILED(hr))
1178 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
1179 continue;
1182 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1183 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1185 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1186 ID3D11Texture3D_Release(texture);
1188 if (current->implements_d3d10_interfaces)
1190 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
1192 else
1194 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
1195 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1196 continue;
1199 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
1201 ok(d3d10_desc.Width == desc.Width,
1202 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1203 ok(d3d10_desc.Height == desc.Height,
1204 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1205 ok(d3d10_desc.Depth == desc.Depth,
1206 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
1207 ok(d3d10_desc.MipLevels == desc.MipLevels,
1208 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1209 ok(d3d10_desc.Format == desc.Format,
1210 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1211 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1212 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1213 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1214 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1215 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1216 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1217 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1218 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1220 d3d10_device = (ID3D10Device *)0xdeadbeef;
1221 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
1222 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1223 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1225 ID3D10Texture3D_Release(d3d10_texture);
1228 refcount = ID3D11Device_Release(device);
1229 ok(!refcount, "Device has %u references left.\n", refcount);
1232 static void test_buffer_interfaces(void)
1234 ID3D10Buffer *d3d10_buffer;
1235 D3D11_BUFFER_DESC desc;
1236 ID3D11Buffer *buffer;
1237 ID3D11Device *device;
1238 unsigned int i;
1239 ULONG refcount;
1240 HRESULT hr;
1242 static const struct test
1244 BOOL implements_d3d10_interfaces;
1245 UINT bind_flags;
1246 UINT misc_flags;
1247 UINT structure_stride;
1248 UINT expected_bind_flags;
1249 UINT expected_misc_flags;
1251 desc_conversion_tests[] =
1254 TRUE,
1255 D3D11_BIND_VERTEX_BUFFER, 0, 0,
1256 D3D10_BIND_VERTEX_BUFFER, 0
1259 TRUE,
1260 D3D11_BIND_INDEX_BUFFER, 0, 0,
1261 D3D10_BIND_INDEX_BUFFER, 0
1264 TRUE,
1265 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
1266 D3D10_BIND_CONSTANT_BUFFER, 0
1269 TRUE,
1270 D3D11_BIND_SHADER_RESOURCE, 0, 0,
1271 D3D10_BIND_SHADER_RESOURCE, 0
1274 TRUE,
1275 D3D11_BIND_STREAM_OUTPUT, 0, 0,
1276 D3D10_BIND_STREAM_OUTPUT, 0
1279 TRUE,
1280 D3D11_BIND_RENDER_TARGET, 0, 0,
1281 D3D10_BIND_RENDER_TARGET, 0
1284 TRUE,
1285 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
1286 D3D11_BIND_UNORDERED_ACCESS, 0
1289 TRUE,
1290 0, D3D11_RESOURCE_MISC_SHARED, 0,
1291 0, D3D10_RESOURCE_MISC_SHARED
1294 TRUE,
1295 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
1296 0, 0
1299 TRUE,
1300 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
1301 D3D10_BIND_SHADER_RESOURCE, 0
1304 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
1305 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
1306 0, 0
1309 TRUE,
1310 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
1311 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1315 if (!(device = create_device(NULL)))
1317 skip("Failed to create ID3D11Device.\n");
1318 return;
1321 desc.ByteWidth = 1024;
1322 desc.Usage = D3D11_USAGE_DEFAULT;
1323 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1324 desc.CPUAccessFlags = 0;
1325 desc.MiscFlags = 0;
1326 desc.StructureByteStride = 0;
1328 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1329 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1331 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1332 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1333 "Buffer should implement ID3D10Buffer.\n");
1334 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1335 ID3D11Buffer_Release(buffer);
1337 if (FAILED(hr))
1339 win_skip("Buffers do not implement ID3D10Buffer.\n");
1340 ID3D11Device_Release(device);
1341 return;
1344 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1346 const struct test *current = &desc_conversion_tests[i];
1347 D3D10_BUFFER_DESC d3d10_desc;
1348 ID3D10Device *d3d10_device;
1350 desc.ByteWidth = 1024;
1351 desc.Usage = D3D11_USAGE_DEFAULT;
1352 desc.BindFlags = current->bind_flags;
1353 desc.CPUAccessFlags = 0;
1354 desc.MiscFlags = current->misc_flags;
1355 desc.StructureByteStride = current->structure_stride;
1357 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1358 /* Shared resources are not supported by REF and WARP devices. */
1359 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1360 if (FAILED(hr))
1362 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1363 continue;
1366 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1367 ID3D11Buffer_Release(buffer);
1369 if (current->implements_d3d10_interfaces)
1371 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
1373 else
1375 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
1376 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1377 continue;
1380 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
1382 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
1383 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
1384 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1385 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1386 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1387 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1388 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1389 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1390 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1391 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1393 d3d10_device = (ID3D10Device *)0xdeadbeef;
1394 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
1395 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1396 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1398 ID3D10Buffer_Release(d3d10_buffer);
1401 refcount = ID3D11Device_Release(device);
1402 ok(!refcount, "Device has %u references left.\n", refcount);
1405 static void test_create_depthstencil_view(void)
1407 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1408 D3D11_TEXTURE2D_DESC texture_desc;
1409 ULONG refcount, expected_refcount;
1410 ID3D11DepthStencilView *dsview;
1411 ID3D11Device *device, *tmp;
1412 ID3D11Texture2D *texture;
1413 HRESULT hr;
1415 if (!(device = create_device(NULL)))
1417 skip("Failed to create device.\n");
1418 return;
1421 texture_desc.Width = 512;
1422 texture_desc.Height = 512;
1423 texture_desc.MipLevels = 1;
1424 texture_desc.ArraySize = 1;
1425 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1426 texture_desc.SampleDesc.Count = 1;
1427 texture_desc.SampleDesc.Quality = 0;
1428 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1429 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1430 texture_desc.CPUAccessFlags = 0;
1431 texture_desc.MiscFlags = 0;
1433 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1434 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1436 expected_refcount = get_refcount((IUnknown *)device) + 1;
1437 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1438 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1439 refcount = get_refcount((IUnknown *)device);
1440 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1441 tmp = NULL;
1442 expected_refcount = refcount + 1;
1443 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
1444 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1445 refcount = get_refcount((IUnknown *)device);
1446 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1447 ID3D11Device_Release(tmp);
1449 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1450 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1451 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1452 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1453 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1454 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1456 ID3D11DepthStencilView_Release(dsview);
1458 dsv_desc.Format = DXGI_FORMAT_UNKNOWN;
1459 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1460 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1462 memset(&dsv_desc, 0, sizeof(dsv_desc));
1463 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1464 todo_wine ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1465 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1466 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1467 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1468 ok(!U(dsv_desc).Texture2D.MipSlice, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1470 ID3D11DepthStencilView_Release(dsview);
1472 ID3D11Texture2D_Release(texture);
1474 refcount = ID3D11Device_Release(device);
1475 ok(!refcount, "Device has %u references left.\n", refcount);
1478 static void test_depthstencil_view_interfaces(void)
1480 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
1481 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1482 ID3D10DepthStencilView *d3d10_dsview;
1483 D3D11_TEXTURE2D_DESC texture_desc;
1484 ID3D11DepthStencilView *dsview;
1485 ID3D11Texture2D *texture;
1486 ID3D11Device *device;
1487 ULONG refcount;
1488 HRESULT hr;
1490 if (!(device = create_device(NULL)))
1492 skip("Failed to create device.\n");
1493 return;
1496 texture_desc.Width = 512;
1497 texture_desc.Height = 512;
1498 texture_desc.MipLevels = 1;
1499 texture_desc.ArraySize = 1;
1500 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1501 texture_desc.SampleDesc.Count = 1;
1502 texture_desc.SampleDesc.Quality = 0;
1503 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1504 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1505 texture_desc.CPUAccessFlags = 0;
1506 texture_desc.MiscFlags = 0;
1508 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1509 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1511 dsv_desc.Format = texture_desc.Format;
1512 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
1513 dsv_desc.Flags = 0;
1514 U(dsv_desc).Texture2D.MipSlice = 0;
1516 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1517 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1519 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
1520 ID3D11DepthStencilView_Release(dsview);
1521 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1522 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1524 if (FAILED(hr))
1526 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1527 goto done;
1530 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
1531 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
1532 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
1533 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
1534 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
1535 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
1537 ID3D10DepthStencilView_Release(d3d10_dsview);
1539 done:
1540 ID3D11Texture2D_Release(texture);
1542 refcount = ID3D11Device_Release(device);
1543 ok(!refcount, "Device has %u references left.\n", refcount);
1546 static void test_create_rendertarget_view(void)
1548 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
1549 D3D11_SUBRESOURCE_DATA data = {0};
1550 D3D11_TEXTURE2D_DESC texture_desc;
1551 ULONG refcount, expected_refcount;
1552 D3D11_BUFFER_DESC buffer_desc;
1553 ID3D11RenderTargetView *rtview;
1554 ID3D11Device *device, *tmp;
1555 ID3D11Texture2D *texture;
1556 ID3D11Buffer *buffer;
1557 IUnknown *iface;
1558 HRESULT hr;
1560 if (!(device = create_device(NULL)))
1562 skip("Failed to create device.\n");
1563 return;
1566 buffer_desc.ByteWidth = 1024;
1567 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1568 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1569 buffer_desc.CPUAccessFlags = 0;
1570 buffer_desc.MiscFlags = 0;
1571 buffer_desc.StructureByteStride = 0;
1573 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
1574 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1576 expected_refcount = get_refcount((IUnknown *)device) + 1;
1577 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1578 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1579 refcount = get_refcount((IUnknown *)device);
1580 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1581 tmp = NULL;
1582 expected_refcount = refcount + 1;
1583 ID3D11Buffer_GetDevice(buffer, &tmp);
1584 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1585 refcount = get_refcount((IUnknown *)device);
1586 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1587 ID3D11Device_Release(tmp);
1589 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1590 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
1591 U(rtv_desc).Buffer.ElementOffset = 0;
1592 U(rtv_desc).Buffer.ElementWidth = 64;
1594 expected_refcount = get_refcount((IUnknown *)device) + 1;
1595 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
1596 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1597 refcount = get_refcount((IUnknown *)device);
1598 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1599 tmp = NULL;
1600 expected_refcount = refcount + 1;
1601 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
1602 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1603 refcount = get_refcount((IUnknown *)device);
1604 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1605 ID3D11Device_Release(tmp);
1607 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1608 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1609 "Render target view should implement ID3D10RenderTargetView.\n");
1610 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1612 ID3D11RenderTargetView_Release(rtview);
1613 ID3D11Buffer_Release(buffer);
1615 texture_desc.Width = 512;
1616 texture_desc.Height = 512;
1617 texture_desc.MipLevels = 1;
1618 texture_desc.ArraySize = 1;
1619 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1620 texture_desc.SampleDesc.Count = 1;
1621 texture_desc.SampleDesc.Quality = 0;
1622 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1623 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1624 texture_desc.CPUAccessFlags = 0;
1625 texture_desc.MiscFlags = 0;
1627 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1628 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1630 /* For texture resources it's allowed to specify NULL as desc */
1631 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1632 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1634 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1635 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1636 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1637 rtv_desc.ViewDimension);
1638 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1640 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1641 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1642 "Render target view should implement ID3D10RenderTargetView.\n");
1643 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1645 ID3D11RenderTargetView_Release(rtview);
1647 rtv_desc.Format = DXGI_FORMAT_UNKNOWN;
1648 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtview);
1649 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1651 memset(&rtv_desc, 0, sizeof(rtv_desc));
1652 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1653 todo_wine ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1654 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1655 rtv_desc.ViewDimension);
1656 ok(!U(rtv_desc).Texture2D.MipSlice, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1658 ID3D11RenderTargetView_Release(rtview);
1660 ID3D11Texture2D_Release(texture);
1662 refcount = ID3D11Device_Release(device);
1663 ok(!refcount, "Device has %u references left.\n", refcount);
1666 static void test_create_shader_resource_view(void)
1668 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
1669 D3D11_TEXTURE2D_DESC texture_desc;
1670 ULONG refcount, expected_refcount;
1671 ID3D11ShaderResourceView *srview;
1672 D3D11_BUFFER_DESC buffer_desc;
1673 ID3D11Device *device, *tmp;
1674 ID3D11Texture2D *texture;
1675 ID3D11Buffer *buffer;
1676 IUnknown *iface;
1677 HRESULT hr;
1679 if (!(device = create_device(NULL)))
1681 skip("Failed to create device.\n");
1682 return;
1685 buffer_desc.ByteWidth = 1024;
1686 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1687 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1688 buffer_desc.CPUAccessFlags = 0;
1689 buffer_desc.MiscFlags = 0;
1690 buffer_desc.StructureByteStride = 0;
1692 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1693 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1695 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
1696 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1698 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1699 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
1700 U(srv_desc).Buffer.ElementOffset = 0;
1701 U(srv_desc).Buffer.ElementWidth = 64;
1703 expected_refcount = get_refcount((IUnknown *)device) + 1;
1704 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
1705 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1706 refcount = get_refcount((IUnknown *)device);
1707 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1708 tmp = NULL;
1709 expected_refcount = refcount + 1;
1710 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
1711 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1712 refcount = get_refcount((IUnknown *)device);
1713 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1714 ID3D11Device_Release(tmp);
1716 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1717 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1718 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1719 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1720 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1721 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1722 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1723 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1725 ID3D11ShaderResourceView_Release(srview);
1726 ID3D11Buffer_Release(buffer);
1728 texture_desc.Width = 512;
1729 texture_desc.Height = 512;
1730 texture_desc.MipLevels = 0;
1731 texture_desc.ArraySize = 1;
1732 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1733 texture_desc.SampleDesc.Count = 1;
1734 texture_desc.SampleDesc.Quality = 0;
1735 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1736 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1737 texture_desc.CPUAccessFlags = 0;
1738 texture_desc.MiscFlags = 0;
1740 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1741 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1743 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
1744 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1746 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1747 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1748 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1749 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1750 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1751 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1752 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1753 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1755 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1756 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1757 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1758 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1759 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1760 U(srv_desc).Texture2D.MostDetailedMip);
1761 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1763 ID3D11ShaderResourceView_Release(srview);
1765 srv_desc.Format = DXGI_FORMAT_UNKNOWN;
1766 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srview);
1767 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1769 memset(&srv_desc, 0, sizeof(srv_desc));
1770 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1771 todo_wine ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1772 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1773 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1774 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1775 U(srv_desc).Texture2D.MostDetailedMip);
1776 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1778 ID3D11ShaderResourceView_Release(srview);
1780 ID3D11Texture2D_Release(texture);
1782 refcount = ID3D11Device_Release(device);
1783 ok(!refcount, "Device has %u references left.\n", refcount);
1786 static void test_create_shader(void)
1788 #if 0
1789 float4 light;
1790 float4x4 mat;
1792 struct input
1794 float4 position : POSITION;
1795 float3 normal : NORMAL;
1798 struct output
1800 float4 position : POSITION;
1801 float4 diffuse : COLOR;
1804 output main(const input v)
1806 output o;
1808 o.position = mul(v.position, mat);
1809 o.diffuse = dot((float3)light, v.normal);
1811 return o;
1813 #endif
1814 static const DWORD vs_4_0[] =
1816 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1817 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1818 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1819 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1820 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1821 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1822 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1823 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1824 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1825 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1826 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1827 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1828 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1829 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1830 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1831 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1834 static const DWORD vs_2_0[] =
1836 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1837 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1838 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1839 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1840 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1841 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1842 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1843 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
1844 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
1845 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
1846 0x90e40001, 0x0000ffff,
1849 static const DWORD vs_3_0[] =
1851 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
1852 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1853 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1854 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1855 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1856 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1857 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1858 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
1859 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
1860 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
1861 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
1862 0x0000ffff,
1865 #if 0
1866 float4 main(const float4 color : COLOR) : SV_TARGET
1868 float4 o;
1870 o = color;
1872 return o;
1874 #endif
1875 static const DWORD ps_4_0[] =
1877 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
1878 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
1879 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
1880 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
1881 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
1882 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1883 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
1884 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1885 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
1886 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
1887 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
1888 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
1889 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1890 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1891 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1892 0x00000000, 0x00000000,
1894 static const DWORD ps_4_0_level_9_0[] =
1896 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
1897 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
1898 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
1899 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
1900 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
1901 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1902 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
1903 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
1904 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
1905 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
1906 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1907 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1908 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
1909 0xabab0054,
1911 static const DWORD ps_4_0_level_9_1[] =
1913 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
1914 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
1915 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
1916 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
1917 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
1918 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
1919 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
1920 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1921 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
1922 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
1923 0x45475241, 0xabab0054,
1925 static const DWORD ps_4_0_level_9_3[] =
1927 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
1928 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
1929 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
1930 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
1931 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
1932 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
1933 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
1934 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1935 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
1936 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
1937 0x45475241, 0xabab0054,
1940 #if 0
1941 struct gs_out
1943 float4 pos : SV_POSITION;
1946 [maxvertexcount(4)]
1947 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1949 float offset = 0.1 * vin[0].w;
1950 gs_out v;
1952 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1953 vout.Append(v);
1954 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1955 vout.Append(v);
1956 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1957 vout.Append(v);
1958 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1959 vout.Append(v);
1961 #endif
1962 static const DWORD gs_4_0[] =
1964 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1965 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1966 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1967 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1968 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1969 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1970 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1971 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1972 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1973 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1974 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1975 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1976 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1977 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1978 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1979 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1980 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1981 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1984 ULONG refcount, expected_refcount;
1985 ID3D11Device *device, *tmp;
1986 ID3D11GeometryShader *gs;
1987 ID3D11VertexShader *vs;
1988 ID3D11PixelShader *ps;
1989 IUnknown *iface;
1990 unsigned int i;
1991 HRESULT hr;
1993 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
1995 D3D_FEATURE_LEVEL feature_level = d3d11_feature_levels[i];
1996 BOOL todo = feature_level <= D3D_FEATURE_LEVEL_9_3;
1998 if (!(device = create_device(&feature_level)))
2000 skip("Failed to create device for feature level %#x.\n", feature_level);
2001 continue;
2004 /* level_9 shaders */
2005 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
2006 todo_wine_if(todo)
2007 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2008 if (SUCCEEDED(hr))
2009 ID3D11PixelShader_Release(ps);
2011 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
2012 todo_wine_if(todo)
2013 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2014 if (SUCCEEDED(hr))
2015 ID3D11PixelShader_Release(ps);
2017 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
2018 todo_wine_if(todo)
2019 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2020 if (SUCCEEDED(hr))
2021 ID3D11PixelShader_Release(ps);
2023 /* vertex shader */
2024 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
2025 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2027 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
2028 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2030 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
2031 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
2032 hr, feature_level);
2034 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2035 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
2036 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2037 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2038 else
2039 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2041 refcount = get_refcount((IUnknown *)device);
2042 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2043 refcount, expected_refcount);
2044 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2046 tmp = NULL;
2047 expected_refcount = refcount + 1;
2048 ID3D11VertexShader_GetDevice(vs, &tmp);
2049 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2050 refcount = get_refcount((IUnknown *)device);
2051 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2052 refcount, expected_refcount);
2053 ID3D11Device_Release(tmp);
2055 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
2056 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2057 "Vertex shader should implement ID3D10VertexShader.\n");
2058 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2060 refcount = ID3D11VertexShader_Release(vs);
2061 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2064 /* pixel shader */
2065 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2066 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
2067 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2068 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2069 else
2070 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2072 refcount = get_refcount((IUnknown *)device);
2073 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2074 refcount, expected_refcount);
2075 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2077 tmp = NULL;
2078 expected_refcount = refcount + 1;
2079 ID3D11PixelShader_GetDevice(ps, &tmp);
2080 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2081 refcount = get_refcount((IUnknown *)device);
2082 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2083 refcount, expected_refcount);
2084 ID3D11Device_Release(tmp);
2086 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
2087 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2088 "Pixel shader should implement ID3D10PixelShader.\n");
2089 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2091 refcount = ID3D11PixelShader_Release(ps);
2092 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
2095 /* geometry shader */
2096 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2097 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
2098 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2099 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2100 else
2101 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2103 refcount = get_refcount((IUnknown *)device);
2104 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2105 refcount, expected_refcount);
2106 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2108 tmp = NULL;
2109 expected_refcount = refcount + 1;
2110 ID3D11GeometryShader_GetDevice(gs, &tmp);
2111 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2112 refcount = get_refcount((IUnknown *)device);
2113 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2114 refcount, expected_refcount);
2115 ID3D11Device_Release(tmp);
2117 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
2118 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2119 "Geometry shader should implement ID3D10GeometryShader.\n");
2120 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2122 refcount = ID3D11GeometryShader_Release(gs);
2123 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
2126 refcount = ID3D11Device_Release(device);
2127 ok(!refcount, "Device has %u references left.\n", refcount);
2131 static void test_create_sampler_state(void)
2133 static const struct test
2135 D3D11_FILTER filter;
2136 D3D10_FILTER expected_filter;
2138 desc_conversion_tests[] =
2140 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
2141 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
2142 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
2143 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
2144 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
2145 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
2146 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
2147 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
2148 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
2149 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
2150 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
2152 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
2153 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
2155 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
2156 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
2158 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
2159 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
2161 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
2162 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
2163 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
2166 ID3D11SamplerState *sampler_state1, *sampler_state2;
2167 ID3D10SamplerState *d3d10_sampler_state;
2168 ULONG refcount, expected_refcount;
2169 ID3D11Device *device, *tmp;
2170 D3D11_SAMPLER_DESC desc;
2171 unsigned int i;
2172 HRESULT hr;
2174 if (!(device = create_device(NULL)))
2176 skip("Failed to create device.\n");
2177 return;
2180 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
2181 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2183 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
2184 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2185 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2186 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
2187 desc.MipLODBias = 0.0f;
2188 desc.MaxAnisotropy = 16;
2189 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2190 desc.BorderColor[0] = 0.0f;
2191 desc.BorderColor[1] = 1.0f;
2192 desc.BorderColor[2] = 0.0f;
2193 desc.BorderColor[3] = 1.0f;
2194 desc.MinLOD = 0.0f;
2195 desc.MaxLOD = 16.0f;
2197 expected_refcount = get_refcount((IUnknown *)device) + 1;
2198 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2199 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2200 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
2201 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2202 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
2203 refcount = get_refcount((IUnknown *)device);
2204 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2205 tmp = NULL;
2206 expected_refcount = refcount + 1;
2207 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
2208 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2209 refcount = get_refcount((IUnknown *)device);
2210 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2211 ID3D11Device_Release(tmp);
2213 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
2214 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
2215 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
2216 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
2217 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
2218 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
2219 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
2220 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
2221 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
2222 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
2223 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
2224 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
2225 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
2227 refcount = ID3D11SamplerState_Release(sampler_state2);
2228 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2229 refcount = ID3D11SamplerState_Release(sampler_state1);
2230 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2232 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2234 const struct test *current = &desc_conversion_tests[i];
2235 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
2237 desc.Filter = current->filter;
2238 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2239 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2240 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
2241 desc.MipLODBias = 0.0f;
2242 desc.MaxAnisotropy = 16;
2243 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2244 desc.BorderColor[0] = 0.0f;
2245 desc.BorderColor[1] = 1.0f;
2246 desc.BorderColor[2] = 0.0f;
2247 desc.BorderColor[3] = 1.0f;
2248 desc.MinLOD = 0.0f;
2249 desc.MaxLOD = 16.0f;
2251 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2252 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
2254 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
2255 (void **)&d3d10_sampler_state);
2256 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2257 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
2258 if (FAILED(hr))
2260 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
2261 ID3D11SamplerState_Release(sampler_state1);
2262 break;
2265 memcpy(&expected_desc, &desc, sizeof(expected_desc));
2266 expected_desc.Filter = current->expected_filter;
2267 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
2268 expected_desc.MaxAnisotropy = 0;
2269 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
2270 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2272 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
2273 ok(d3d10_desc.Filter == expected_desc.Filter,
2274 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
2275 ok(d3d10_desc.AddressU == expected_desc.AddressU,
2276 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
2277 ok(d3d10_desc.AddressV == expected_desc.AddressV,
2278 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
2279 ok(d3d10_desc.AddressW == expected_desc.AddressW,
2280 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
2281 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
2282 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
2283 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
2284 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
2285 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
2286 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
2287 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
2288 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
2289 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
2290 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
2291 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
2292 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
2293 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
2294 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
2295 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
2296 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
2297 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
2299 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
2300 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2301 refcount = ID3D11SamplerState_Release(sampler_state1);
2302 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2305 refcount = ID3D11Device_Release(device);
2306 ok(!refcount, "Device has %u references left.\n", refcount);
2309 static void test_create_blend_state(void)
2311 static const D3D11_BLEND_DESC desc_conversion_tests[] =
2314 FALSE, FALSE,
2317 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2318 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
2323 FALSE, TRUE,
2326 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2327 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2330 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2331 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
2334 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2335 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2338 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2339 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
2342 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2343 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2346 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2347 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2350 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2351 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2354 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2355 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2360 FALSE, TRUE,
2363 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2364 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2367 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
2368 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2371 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
2372 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2375 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2376 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2379 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
2380 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2383 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
2384 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2387 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2388 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2391 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2392 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2398 ID3D11BlendState *blend_state1, *blend_state2;
2399 D3D11_BLEND_DESC desc, obtained_desc;
2400 ID3D10BlendState *d3d10_blend_state;
2401 D3D10_BLEND_DESC d3d10_blend_desc;
2402 ULONG refcount, expected_refcount;
2403 ID3D11Device *device, *tmp;
2404 unsigned int i, j;
2405 IUnknown *iface;
2406 HRESULT hr;
2408 if (!(device = create_device(NULL)))
2410 skip("Failed to create device.\n");
2411 return;
2414 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
2415 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2417 memset(&desc, 0, sizeof(desc));
2418 desc.AlphaToCoverageEnable = FALSE;
2419 desc.IndependentBlendEnable = FALSE;
2420 desc.RenderTarget[0].BlendEnable = FALSE;
2421 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
2422 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
2423 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2424 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
2425 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2426 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2427 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2429 expected_refcount = get_refcount((IUnknown *)device) + 1;
2430 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
2431 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2432 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
2433 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2434 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
2435 refcount = get_refcount((IUnknown *)device);
2436 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2437 tmp = NULL;
2438 expected_refcount = refcount + 1;
2439 ID3D11BlendState_GetDevice(blend_state1, &tmp);
2440 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2441 refcount = get_refcount((IUnknown *)device);
2442 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2443 ID3D11Device_Release(tmp);
2445 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
2446 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
2447 obtained_desc.AlphaToCoverageEnable);
2448 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
2449 obtained_desc.IndependentBlendEnable);
2450 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2452 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
2453 "Got unexpected blend enable %#x for render target %u.\n",
2454 obtained_desc.RenderTarget[i].BlendEnable, i);
2455 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
2456 "Got unexpected src blend %u for render target %u.\n",
2457 obtained_desc.RenderTarget[i].SrcBlend, i);
2458 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
2459 "Got unexpected dest blend %u for render target %u.\n",
2460 obtained_desc.RenderTarget[i].DestBlend, i);
2461 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
2462 "Got unexpected blend op %u for render target %u.\n",
2463 obtained_desc.RenderTarget[i].BlendOp, i);
2464 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
2465 "Got unexpected src blend alpha %u for render target %u.\n",
2466 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
2467 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
2468 "Got unexpected dest blend alpha %u for render target %u.\n",
2469 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
2470 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
2471 "Got unexpected blend op alpha %u for render target %u.\n",
2472 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
2473 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
2474 "Got unexpected render target write mask %#x for render target %u.\n",
2475 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
2478 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
2479 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2480 "Blend state should implement ID3D10BlendState.\n");
2481 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2482 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
2483 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2484 "Blend state should implement ID3D10BlendState1.\n");
2485 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2487 refcount = ID3D11BlendState_Release(blend_state1);
2488 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2489 refcount = ID3D11BlendState_Release(blend_state2);
2490 ok(!refcount, "Blend state has %u references left.\n", refcount);
2492 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2494 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
2496 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
2497 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2499 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
2500 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2501 "Blend state should implement ID3D10BlendState.\n");
2502 if (FAILED(hr))
2504 win_skip("Blend state does not implement ID3D10BlendState.\n");
2505 ID3D11BlendState_Release(blend_state1);
2506 break;
2509 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
2510 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
2511 "Got unexpected alpha to coverage enable %#x for test %u.\n",
2512 d3d10_blend_desc.AlphaToCoverageEnable, i);
2513 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
2514 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
2515 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
2516 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
2517 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
2518 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
2519 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
2520 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
2521 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
2522 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
2523 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
2524 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
2525 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
2527 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
2528 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
2529 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2530 d3d10_blend_desc.BlendEnable[j], i, j);
2531 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
2532 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2533 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
2536 ID3D10BlendState_Release(d3d10_blend_state);
2538 refcount = ID3D11BlendState_Release(blend_state1);
2539 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2542 refcount = ID3D11Device_Release(device);
2543 ok(!refcount, "Device has %u references left.\n", refcount);
2546 static void test_create_depthstencil_state(void)
2548 ID3D11DepthStencilState *ds_state1, *ds_state2;
2549 ID3D10DepthStencilState *d3d10_ds_state;
2550 ULONG refcount, expected_refcount;
2551 D3D11_DEPTH_STENCIL_DESC ds_desc;
2552 ID3D11Device *device, *tmp;
2553 HRESULT hr;
2555 if (!(device = create_device(NULL)))
2557 skip("Failed to create device.\n");
2558 return;
2561 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
2562 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2564 ds_desc.DepthEnable = TRUE;
2565 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2566 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
2567 ds_desc.StencilEnable = FALSE;
2568 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2569 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2570 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2571 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2572 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2573 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2574 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2575 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2576 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2577 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2579 expected_refcount = get_refcount((IUnknown *)device) + 1;
2580 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
2581 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2582 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
2583 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2584 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
2585 refcount = get_refcount((IUnknown *)device);
2586 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2587 tmp = NULL;
2588 expected_refcount = refcount + 1;
2589 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
2590 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2591 refcount = get_refcount((IUnknown *)device);
2592 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2593 ID3D11Device_Release(tmp);
2595 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
2596 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2597 "Depth stencil state should implement ID3D10DepthStencilState.\n");
2598 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
2600 refcount = ID3D11DepthStencilState_Release(ds_state2);
2601 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2602 refcount = ID3D11DepthStencilState_Release(ds_state1);
2603 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2605 refcount = ID3D11Device_Release(device);
2606 ok(!refcount, "Device has %u references left.\n", refcount);
2609 static void test_create_rasterizer_state(void)
2611 ID3D11RasterizerState *rast_state1, *rast_state2;
2612 ID3D10RasterizerState *d3d10_rast_state;
2613 ULONG refcount, expected_refcount;
2614 D3D10_RASTERIZER_DESC d3d10_desc;
2615 D3D11_RASTERIZER_DESC desc;
2616 ID3D11Device *device, *tmp;
2617 HRESULT hr;
2619 if (!(device = create_device(NULL)))
2621 skip("Failed to create device.\n");
2622 return;
2625 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
2626 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2628 desc.FillMode = D3D11_FILL_SOLID;
2629 desc.CullMode = D3D11_CULL_BACK;
2630 desc.FrontCounterClockwise = FALSE;
2631 desc.DepthBias = 0;
2632 desc.DepthBiasClamp = 0.0f;
2633 desc.SlopeScaledDepthBias = 0.0f;
2634 desc.DepthClipEnable = TRUE;
2635 desc.ScissorEnable = FALSE;
2636 desc.MultisampleEnable = FALSE;
2637 desc.AntialiasedLineEnable = FALSE;
2639 expected_refcount = get_refcount((IUnknown *)device) + 1;
2640 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
2641 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2642 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
2643 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2644 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
2645 refcount = get_refcount((IUnknown *)device);
2646 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2647 tmp = NULL;
2648 expected_refcount = refcount + 1;
2649 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
2650 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2651 refcount = get_refcount((IUnknown *)device);
2652 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2653 ID3D11Device_Release(tmp);
2655 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
2656 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2657 "Rasterizer state should implement ID3D10RasterizerState.\n");
2658 if (SUCCEEDED(hr))
2660 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
2661 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
2662 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
2663 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
2664 d3d10_desc.FrontCounterClockwise);
2665 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
2666 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
2667 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
2668 d3d10_desc.SlopeScaledDepthBias);
2669 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
2670 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
2671 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
2672 d3d10_desc.MultisampleEnable);
2673 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
2674 d3d10_desc.AntialiasedLineEnable);
2676 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
2677 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
2680 refcount = ID3D11RasterizerState_Release(rast_state2);
2681 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2682 refcount = ID3D11RasterizerState_Release(rast_state1);
2683 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2685 refcount = ID3D11Device_Release(device);
2686 ok(!refcount, "Device has %u references left.\n", refcount);
2689 static void test_create_predicate(void)
2691 static const D3D11_QUERY other_queries[] =
2693 D3D11_QUERY_EVENT,
2694 D3D11_QUERY_OCCLUSION,
2695 D3D11_QUERY_TIMESTAMP,
2696 D3D11_QUERY_TIMESTAMP_DISJOINT,
2697 D3D11_QUERY_PIPELINE_STATISTICS,
2698 D3D11_QUERY_SO_STATISTICS,
2699 D3D11_QUERY_SO_STATISTICS_STREAM0,
2700 D3D11_QUERY_SO_STATISTICS_STREAM1,
2701 D3D11_QUERY_SO_STATISTICS_STREAM2,
2702 D3D11_QUERY_SO_STATISTICS_STREAM3,
2705 ULONG refcount, expected_refcount;
2706 D3D11_QUERY_DESC query_desc;
2707 ID3D11Predicate *predicate;
2708 ID3D11Device *device, *tmp;
2709 IUnknown *iface;
2710 unsigned int i;
2711 HRESULT hr;
2713 if (!(device = create_device(NULL)))
2715 skip("Failed to create device.\n");
2716 return;
2719 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
2720 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2722 query_desc.MiscFlags = 0;
2724 for (i = 0; i < sizeof(other_queries) / sizeof(*other_queries); ++i)
2726 query_desc.Query = other_queries[i];
2727 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2728 ok(hr == E_INVALIDARG, "Got unexpected hr %#x for query type %u.\n", hr, other_queries[i]);
2731 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
2732 expected_refcount = get_refcount((IUnknown *)device) + 1;
2733 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2734 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2735 refcount = get_refcount((IUnknown *)device);
2736 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2737 tmp = NULL;
2738 expected_refcount = refcount + 1;
2739 ID3D11Predicate_GetDevice(predicate, &tmp);
2740 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2741 refcount = get_refcount((IUnknown *)device);
2742 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2743 ID3D11Device_Release(tmp);
2744 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
2745 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2746 "Predicate should implement ID3D10Predicate.\n");
2747 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2748 ID3D11Predicate_Release(predicate);
2750 query_desc.Query = D3D11_QUERY_SO_OVERFLOW_PREDICATE;
2751 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2752 todo_wine ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2753 if (SUCCEEDED(hr))
2754 ID3D11Predicate_Release(predicate);
2756 refcount = ID3D11Device_Release(device);
2757 ok(!refcount, "Device has %u references left.\n", refcount);
2760 static void test_device_removed_reason(void)
2762 ID3D11Device *device;
2763 ULONG refcount;
2764 HRESULT hr;
2766 if (!(device = create_device(NULL)))
2768 skip("Failed to create device.\n");
2769 return;
2772 hr = ID3D11Device_GetDeviceRemovedReason(device);
2773 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2774 hr = ID3D11Device_GetDeviceRemovedReason(device);
2775 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2777 refcount = ID3D11Device_Release(device);
2778 ok(!refcount, "Device has %u references left.\n", refcount);
2781 static void test_private_data(void)
2783 ULONG refcount, expected_refcount;
2784 D3D11_TEXTURE2D_DESC texture_desc;
2785 ID3D10Texture2D *d3d10_texture;
2786 ID3D11Device *test_object;
2787 ID3D11Texture2D *texture;
2788 IDXGIDevice *dxgi_device;
2789 IDXGISurface *surface;
2790 ID3D11Device *device;
2791 IUnknown *ptr;
2792 HRESULT hr;
2793 UINT size;
2795 static const GUID test_guid =
2796 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2797 static const GUID test_guid2 =
2798 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2799 static const DWORD data[] = {1, 2, 3, 4};
2801 if (!(device = create_device(NULL)))
2803 skip("Failed to create device.\n");
2804 return;
2807 test_object = create_device(NULL);
2809 texture_desc.Width = 512;
2810 texture_desc.Height = 512;
2811 texture_desc.MipLevels = 1;
2812 texture_desc.ArraySize = 1;
2813 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2814 texture_desc.SampleDesc.Count = 1;
2815 texture_desc.SampleDesc.Quality = 0;
2816 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2817 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2818 texture_desc.CPUAccessFlags = 0;
2819 texture_desc.MiscFlags = 0;
2821 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2822 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2823 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2824 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
2826 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
2827 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2828 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2829 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2830 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2831 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2832 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2833 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2835 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2836 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2837 size = sizeof(ptr) * 2;
2838 ptr = (IUnknown *)0xdeadbeef;
2839 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2840 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2841 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2842 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2844 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2845 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2846 size = sizeof(ptr) * 2;
2847 ptr = (IUnknown *)0xdeadbeef;
2848 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2849 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2850 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2851 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2852 IDXGIDevice_Release(dxgi_device);
2854 refcount = get_refcount((IUnknown *)test_object);
2855 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2856 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2857 expected_refcount = refcount + 1;
2858 refcount = get_refcount((IUnknown *)test_object);
2859 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2860 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2861 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2862 refcount = get_refcount((IUnknown *)test_object);
2863 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2865 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2866 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2867 --expected_refcount;
2868 refcount = get_refcount((IUnknown *)test_object);
2869 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2871 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2872 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2873 size = sizeof(data);
2874 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
2875 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2876 refcount = get_refcount((IUnknown *)test_object);
2877 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2878 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2879 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2880 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2881 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2883 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2884 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2885 ++expected_refcount;
2886 size = 2 * sizeof(ptr);
2887 ptr = NULL;
2888 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2889 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2890 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2891 ++expected_refcount;
2892 refcount = get_refcount((IUnknown *)test_object);
2893 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2894 IUnknown_Release(ptr);
2895 --expected_refcount;
2897 ptr = (IUnknown *)0xdeadbeef;
2898 size = 1;
2899 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2900 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2901 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2902 size = 2 * sizeof(ptr);
2903 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2904 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2905 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2906 refcount = get_refcount((IUnknown *)test_object);
2907 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2909 size = 1;
2910 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2911 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2912 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2913 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2914 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2915 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2916 size = 0xdeadbabe;
2917 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2918 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2919 ok(size == 0, "Got unexpected size %u.\n", size);
2920 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2921 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2922 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2923 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2925 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
2926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2927 ptr = NULL;
2928 size = sizeof(ptr);
2929 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
2930 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2931 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2932 IUnknown_Release(ptr);
2934 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2935 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2936 "Texture should implement ID3D10Texture2D.\n");
2937 if (SUCCEEDED(hr))
2939 ptr = NULL;
2940 size = sizeof(ptr);
2941 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
2942 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2943 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2944 IUnknown_Release(ptr);
2945 ID3D10Texture2D_Release(d3d10_texture);
2948 IDXGISurface_Release(surface);
2949 ID3D11Texture2D_Release(texture);
2950 refcount = ID3D11Device_Release(device);
2951 ok(!refcount, "Device has %u references left.\n", refcount);
2952 refcount = ID3D11Device_Release(test_object);
2953 ok(!refcount, "Test object has %u references left.\n", refcount);
2956 static void test_blend(void)
2958 ID3D11BlendState *src_blend, *dst_blend;
2959 struct d3d11_test_context test_context;
2960 ID3D11RenderTargetView *offscreen_rtv;
2961 D3D11_SUBRESOURCE_DATA buffer_data;
2962 D3D11_TEXTURE2D_DESC texture_desc;
2963 ID3D11InputLayout *input_layout;
2964 D3D11_BUFFER_DESC buffer_desc;
2965 ID3D11DeviceContext *context;
2966 D3D11_BLEND_DESC blend_desc;
2967 unsigned int stride, offset;
2968 ID3D11Texture2D *offscreen;
2969 ID3D11VertexShader *vs;
2970 ID3D11PixelShader *ps;
2971 ID3D11Device *device;
2972 D3D11_VIEWPORT vp;
2973 ID3D11Buffer *vb;
2974 DWORD color;
2975 HRESULT hr;
2977 static const DWORD vs_code[] =
2979 #if 0
2980 struct vs_out
2982 float4 position : SV_POSITION;
2983 float4 color : COLOR;
2986 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
2988 struct vs_out o;
2990 o.position = position;
2991 o.color = color;
2993 return o;
2995 #endif
2996 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
2997 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2998 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2999 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
3000 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3001 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
3002 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
3003 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
3004 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
3005 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
3007 static const DWORD ps_code[] =
3009 #if 0
3010 struct vs_out
3012 float4 position : SV_POSITION;
3013 float4 color : COLOR;
3016 float4 main(struct vs_out i) : SV_TARGET
3018 return i.color;
3020 #endif
3021 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
3022 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
3023 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
3024 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
3025 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3026 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3027 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3028 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3030 static const struct
3032 struct vec3 position;
3033 DWORD diffuse;
3035 quads[] =
3037 /* quad1 */
3038 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
3039 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
3040 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
3041 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
3042 /* quad2 */
3043 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3044 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3045 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3046 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3048 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3050 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3051 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
3053 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
3054 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3056 if (!init_test_context(&test_context))
3057 return;
3059 device = test_context.device;
3060 context = test_context.immediate_context;
3062 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3063 vs_code, sizeof(vs_code), &input_layout);
3064 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3066 buffer_desc.ByteWidth = sizeof(quads);
3067 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3068 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3069 buffer_desc.CPUAccessFlags = 0;
3070 buffer_desc.MiscFlags = 0;
3071 buffer_desc.StructureByteStride = 0;
3073 buffer_data.pSysMem = quads;
3074 buffer_data.SysMemPitch = 0;
3075 buffer_data.SysMemSlicePitch = 0;
3077 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
3078 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3079 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3080 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3081 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3082 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3084 memset(&blend_desc, 0, sizeof(blend_desc));
3085 blend_desc.RenderTarget[0].BlendEnable = TRUE;
3086 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
3087 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
3088 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
3089 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
3090 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
3091 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
3092 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
3094 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
3095 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3097 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
3098 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
3099 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
3100 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
3102 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
3103 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3105 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3106 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3107 stride = sizeof(*quads);
3108 offset = 0;
3109 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3110 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3111 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3113 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
3115 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3116 ID3D11DeviceContext_Draw(context, 4, 0);
3117 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3118 ID3D11DeviceContext_Draw(context, 4, 4);
3120 color = get_texture_color(test_context.backbuffer, 320, 360);
3121 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
3122 color = get_texture_color(test_context.backbuffer, 320, 120);
3123 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
3125 texture_desc.Width = 128;
3126 texture_desc.Height = 128;
3127 texture_desc.MipLevels = 1;
3128 texture_desc.ArraySize = 1;
3129 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
3130 texture_desc.SampleDesc.Count = 1;
3131 texture_desc.SampleDesc.Quality = 0;
3132 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3133 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
3134 texture_desc.CPUAccessFlags = 0;
3135 texture_desc.MiscFlags = 0;
3137 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
3138 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
3140 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
3141 goto done;
3144 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
3145 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3147 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
3149 vp.TopLeftX = 0.0f;
3150 vp.TopLeftY = 0.0f;
3151 vp.Width = 128.0f;
3152 vp.Height = 128.0f;
3153 vp.MinDepth = 0.0f;
3154 vp.MaxDepth = 1.0f;
3155 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3157 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
3159 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3160 ID3D11DeviceContext_Draw(context, 4, 0);
3161 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3162 ID3D11DeviceContext_Draw(context, 4, 4);
3164 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
3165 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
3166 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
3167 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
3169 ID3D11RenderTargetView_Release(offscreen_rtv);
3170 ID3D11Texture2D_Release(offscreen);
3171 done:
3172 ID3D11BlendState_Release(dst_blend);
3173 ID3D11BlendState_Release(src_blend);
3174 ID3D11PixelShader_Release(ps);
3175 ID3D11VertexShader_Release(vs);
3176 ID3D11Buffer_Release(vb);
3177 ID3D11InputLayout_Release(input_layout);
3178 release_test_context(&test_context);
3181 static void test_texture(void)
3183 struct shader
3185 const DWORD *code;
3186 size_t size;
3188 struct texture
3190 UINT width;
3191 UINT height;
3192 UINT miplevel_count;
3193 DXGI_FORMAT format;
3194 D3D11_SUBRESOURCE_DATA data[3];
3197 struct d3d11_test_context test_context;
3198 const struct texture *current_texture;
3199 D3D11_TEXTURE2D_DESC texture_desc;
3200 D3D11_SAMPLER_DESC sampler_desc;
3201 const struct shader *current_ps;
3202 ID3D11ShaderResourceView *srv;
3203 D3D11_BUFFER_DESC buffer_desc;
3204 ID3D11DeviceContext *context;
3205 ID3D11SamplerState *sampler;
3206 struct texture_readback rb;
3207 ID3D11Texture2D *texture;
3208 ID3D11PixelShader *ps;
3209 ID3D11Device *device;
3210 unsigned int i, x, y;
3211 struct vec4 miplevel;
3212 ID3D11Buffer *cb;
3213 DWORD color;
3214 HRESULT hr;
3216 static const DWORD ps_ld_code[] =
3218 #if 0
3219 Texture2D t;
3221 float miplevel;
3223 float4 main(float4 position : SV_POSITION) : SV_TARGET
3225 float3 p;
3226 t.GetDimensions(miplevel, p.x, p.y, p.z);
3227 p.z = miplevel;
3228 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
3229 return t.Load(int3(p));
3231 #endif
3232 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
3233 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3234 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3235 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3236 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
3237 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
3238 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3239 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
3240 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
3241 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
3242 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
3243 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
3244 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
3245 0x00107e46, 0x00000000, 0x0100003e,
3247 static const DWORD ps_ld_sint8_code[] =
3249 #if 0
3250 Texture2D<int4> t;
3252 float4 main(float4 position : SV_POSITION) : SV_TARGET
3254 float3 p, s;
3255 int4 c;
3257 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3258 t.GetDimensions(0, s.x, s.y, s.z);
3259 p *= s;
3261 c = t.Load(int3(p));
3262 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
3264 #endif
3265 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
3266 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3267 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3268 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3269 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
3270 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
3271 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3272 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3273 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3274 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3275 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3276 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3277 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3278 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
3279 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
3280 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3281 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
3282 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
3284 static const DWORD ps_ld_uint8_code[] =
3286 #if 0
3287 Texture2D<uint4> t;
3289 float4 main(float4 position : SV_POSITION) : SV_TARGET
3291 float3 p, s;
3293 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3294 t.GetDimensions(0, s.x, s.y, s.z);
3295 p *= s;
3297 return t.Load(int3(p)) / (float4)255;
3299 #endif
3300 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
3301 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3302 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3303 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3304 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
3305 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
3306 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3307 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3308 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3309 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3310 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3311 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3312 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3313 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
3314 0x3b808081, 0x0100003e,
3316 static const DWORD ps_sample_code[] =
3318 #if 0
3319 Texture2D t;
3320 SamplerState s;
3322 float4 main(float4 position : SV_POSITION) : SV_Target
3324 float2 p;
3326 p.x = position.x / 640.0f;
3327 p.y = position.y / 480.0f;
3328 return t.Sample(s, p);
3330 #endif
3331 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3332 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3333 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3334 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3335 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3336 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3337 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3338 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3339 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3340 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3342 static const DWORD ps_sample_b_code[] =
3344 #if 0
3345 Texture2D t;
3346 SamplerState s;
3348 float bias;
3350 float4 main(float4 position : SV_POSITION) : SV_Target
3352 float2 p;
3354 p.x = position.x / 640.0f;
3355 p.y = position.y / 480.0f;
3356 return t.SampleBias(s, p, bias);
3358 #endif
3359 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
3360 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3361 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3362 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3363 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3364 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3365 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3366 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3367 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
3368 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3369 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3371 static const DWORD ps_sample_l_code[] =
3373 #if 0
3374 Texture2D t;
3375 SamplerState s;
3377 float level;
3379 float4 main(float4 position : SV_POSITION) : SV_Target
3381 float2 p;
3383 p.x = position.x / 640.0f;
3384 p.y = position.y / 480.0f;
3385 return t.SampleLevel(s, p, level);
3387 #endif
3388 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
3389 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3390 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3391 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3392 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3393 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3394 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3395 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3396 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
3397 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3398 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3400 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
3401 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
3402 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
3403 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
3404 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
3405 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
3406 static const DWORD rgba_level_0[] =
3408 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3409 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3410 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3411 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3413 static const DWORD rgba_level_1[] =
3415 0xffffffff, 0xff0000ff,
3416 0xff000000, 0xff00ff00,
3418 static const DWORD rgba_level_2[] =
3420 0xffff0000,
3422 static const DWORD srgb_data[] =
3424 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
3425 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
3426 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
3427 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
3429 static const BYTE bc1_data[] =
3431 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3432 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3433 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3434 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3436 static const BYTE bc2_data[] =
3438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3439 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3443 static const BYTE bc3_data[] =
3445 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3446 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3447 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3448 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3450 static const BYTE bc4_data[] =
3452 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
3453 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
3454 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3455 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
3457 static const BYTE bc5_data[] =
3459 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
3460 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
3461 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3462 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
3464 static const struct texture rgba_texture =
3466 4, 4, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
3468 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
3469 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
3470 {rgba_level_2, sizeof(*rgba_level_2), 0},
3473 static const struct texture srgb_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
3474 {{srgb_data, 4 * sizeof(*srgb_data)}}};
3475 static const struct texture bc1_texture = {8, 8, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
3476 static const struct texture bc2_texture = {8, 8, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
3477 static const struct texture bc3_texture = {8, 8, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
3478 static const struct texture bc4_texture = {8, 8, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
3479 static const struct texture bc5_texture = {8, 8, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
3480 static const struct texture bc1_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
3481 static const struct texture bc2_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
3482 static const struct texture bc3_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
3483 static const struct texture sint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_SINT,
3484 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3485 static const struct texture uint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UINT,
3486 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3487 static const DWORD level_1_colors[] =
3489 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3490 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3491 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3492 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3494 static const DWORD lerp_1_2_colors[] =
3496 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3497 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3498 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3499 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3501 static const DWORD level_2_colors[] =
3503 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3504 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3505 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3506 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3508 static const DWORD srgb_colors[] =
3510 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
3511 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
3512 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
3513 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
3515 static const DWORD bc_colors[] =
3517 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3518 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3519 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3520 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3522 static const DWORD bc4_colors[] =
3524 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
3525 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
3526 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
3527 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
3529 static const DWORD bc5_colors[] =
3531 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
3532 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
3533 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
3534 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
3536 static const DWORD sint8_colors[] =
3538 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
3539 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
3540 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
3541 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
3543 static const DWORD zero_colors[4 * 4] = {0};
3544 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3546 static const struct test
3548 const struct shader *ps;
3549 const struct texture *texture;
3550 D3D11_FILTER filter;
3551 float lod_bias;
3552 float min_lod;
3553 float max_lod;
3554 float miplevel;
3555 const DWORD *expected_colors;
3557 tests[] =
3559 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3560 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
3561 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
3562 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
3563 {&ps_ld, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
3564 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3565 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3566 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3567 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3568 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3569 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3570 {&ps_ld, &bc1_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3571 {&ps_ld, &bc2_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3572 {&ps_ld, &bc3_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3573 {&ps_ld, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
3574 {&ps_ld, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
3575 {&ps_ld_sint8, &sint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
3576 {&ps_ld_uint8, &uint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3577 {&ps_sample, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3578 {&ps_sample, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3579 {&ps_sample, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3580 {&ps_sample, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
3581 {&ps_sample, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
3582 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3583 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3584 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3585 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3586 {&ps_sample, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
3587 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3588 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3589 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.0f, level_1_colors},
3590 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.4f, level_1_colors},
3591 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.5f, level_2_colors},
3592 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 9.0f, level_2_colors},
3593 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
3594 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
3595 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
3596 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
3597 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, rgba_level_0},
3598 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3599 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.4f, rgba_level_0},
3600 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.5f, level_1_colors},
3601 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_1_colors},
3602 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.4f, level_1_colors},
3603 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3604 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 2.0f, level_2_colors},
3605 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 3.0f, level_2_colors},
3606 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 4.0f, level_2_colors},
3607 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, lerp_1_2_colors},
3608 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -2.0f, rgba_level_0},
3609 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_1_colors},
3610 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_2_colors},
3611 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_2_colors},
3612 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3613 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3614 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3615 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3616 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3617 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3618 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3619 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3620 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3621 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3622 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3625 if (!init_test_context(&test_context))
3626 return;
3628 device = test_context.device;
3629 context = test_context.immediate_context;
3631 buffer_desc.ByteWidth = sizeof(miplevel);
3632 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3633 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3634 buffer_desc.CPUAccessFlags = 0;
3635 buffer_desc.MiscFlags = 0;
3636 buffer_desc.StructureByteStride = 0;
3638 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
3639 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3641 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
3643 texture_desc.Width = 4;
3644 texture_desc.Height = 4;
3645 texture_desc.MipLevels = 3;
3646 texture_desc.ArraySize = 1;
3647 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3648 texture_desc.SampleDesc.Count = 1;
3649 texture_desc.SampleDesc.Quality = 0;
3650 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3651 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3652 texture_desc.CPUAccessFlags = 0;
3653 texture_desc.MiscFlags = 0;
3655 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
3656 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
3657 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
3658 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
3659 sampler_desc.MipLODBias = 0.0f;
3660 sampler_desc.MaxAnisotropy = 0;
3661 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3662 sampler_desc.BorderColor[0] = 0.0f;
3663 sampler_desc.BorderColor[1] = 0.0f;
3664 sampler_desc.BorderColor[2] = 0.0f;
3665 sampler_desc.BorderColor[3] = 0.0f;
3666 sampler_desc.MinLOD = 0.0f;
3667 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
3669 ps = NULL;
3670 srv = NULL;
3671 sampler = NULL;
3672 texture = NULL;
3673 current_ps = NULL;
3674 current_texture = NULL;
3675 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3677 const struct test *test = &tests[i];
3679 if (current_ps != test->ps)
3681 if (ps)
3682 ID3D11PixelShader_Release(ps);
3684 current_ps = test->ps;
3686 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
3687 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
3689 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3692 if (current_texture != test->texture)
3694 if (texture)
3695 ID3D11Texture2D_Release(texture);
3696 if (srv)
3697 ID3D11ShaderResourceView_Release(srv);
3699 current_texture = test->texture;
3701 texture_desc.Width = current_texture->width;
3702 texture_desc.Height = current_texture->height;
3703 texture_desc.MipLevels = current_texture->miplevel_count;
3704 texture_desc.Format = current_texture->format;
3706 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
3707 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3709 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
3710 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
3712 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
3715 if (!sampler || (sampler_desc.Filter != test->filter
3716 || sampler_desc.MipLODBias != test->lod_bias
3717 || sampler_desc.MinLOD != test->min_lod
3718 || sampler_desc.MaxLOD != test->max_lod))
3720 if (sampler)
3721 ID3D11SamplerState_Release(sampler);
3723 sampler_desc.Filter = test->filter;
3724 sampler_desc.MipLODBias = test->lod_bias;
3725 sampler_desc.MinLOD = test->min_lod;
3726 sampler_desc.MaxLOD = test->max_lod;
3728 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
3729 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3731 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
3734 miplevel.x = test->miplevel;
3735 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &miplevel, 0, 0);
3737 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
3739 draw_quad(&test_context);
3741 get_texture_readback(test_context.backbuffer, &rb);
3742 for (x = 0; x < 4; ++x)
3744 for (y = 0; y < 4; ++y)
3746 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
3747 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
3748 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
3751 release_texture_readback(&rb);
3753 ID3D11ShaderResourceView_Release(srv);
3754 ID3D11SamplerState_Release(sampler);
3755 ID3D11Texture2D_Release(texture);
3756 ID3D11PixelShader_Release(ps);
3758 ID3D11Buffer_Release(cb);
3759 release_test_context(&test_context);
3762 static void test_multiple_render_targets(void)
3764 D3D11_SUBRESOURCE_DATA resource_data;
3765 D3D11_TEXTURE2D_DESC texture_desc;
3766 ID3D11InputLayout *input_layout;
3767 unsigned int stride, offset, i;
3768 ID3D11RenderTargetView *rtv[4];
3769 D3D11_BUFFER_DESC buffer_desc;
3770 ID3D11DeviceContext *context;
3771 ID3D11Texture2D *rt[4];
3772 ID3D11VertexShader *vs;
3773 ID3D11PixelShader *ps;
3774 ID3D11Device *device;
3775 D3D11_VIEWPORT vp;
3776 ID3D11Buffer *vb;
3777 ULONG refcount;
3778 HRESULT hr;
3780 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3782 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3784 static const DWORD vs_code[] =
3786 #if 0
3787 float4 main(float4 position : POSITION) : SV_POSITION
3789 return position;
3791 #endif
3792 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
3793 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3794 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3795 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3796 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
3797 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
3798 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3800 static const DWORD ps_code[] =
3802 #if 0
3803 struct output
3805 float4 t1 : SV_TARGET0;
3806 float4 t2 : SV_Target1;
3807 float4 t3 : SV_TARGET2;
3808 float4 t4 : SV_Target3;
3811 output main(float4 position : SV_POSITION)
3813 struct output o;
3814 o.t1 = (float4)1.0f;
3815 o.t2 = (float4)0.5f;
3816 o.t3 = (float4)0.2f;
3817 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
3818 return o;
3820 #endif
3821 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
3822 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3823 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
3824 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
3825 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
3826 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
3827 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
3828 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
3829 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
3830 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
3831 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
3832 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
3833 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
3834 0x3f800000, 0x0100003e,
3836 static const struct
3838 struct vec2 position;
3840 quad[] =
3842 {{-1.0f, -1.0f}},
3843 {{-1.0f, 1.0f}},
3844 {{ 1.0f, -1.0f}},
3845 {{ 1.0f, 1.0f}},
3847 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
3849 if (!(device = create_device(NULL)))
3851 skip("Failed to create device.\n");
3852 return;
3855 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_9_3)
3857 skip("Feature level 9_3 or higher is required.\n");
3858 ID3D11Device_Release(device);
3859 return;
3862 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3863 vs_code, sizeof(vs_code), &input_layout);
3864 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3866 buffer_desc.ByteWidth = sizeof(quad);
3867 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3868 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3869 buffer_desc.CPUAccessFlags = 0;
3870 buffer_desc.MiscFlags = 0;
3871 buffer_desc.StructureByteStride = 0;
3873 resource_data.pSysMem = quad;
3874 resource_data.SysMemPitch = 0;
3875 resource_data.SysMemSlicePitch = 0;
3877 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
3878 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3880 texture_desc.Width = 640;
3881 texture_desc.Height = 480;
3882 texture_desc.MipLevels = 1;
3883 texture_desc.ArraySize = 1;
3884 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3885 texture_desc.SampleDesc.Count = 1;
3886 texture_desc.SampleDesc.Quality = 0;
3887 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3888 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3889 texture_desc.CPUAccessFlags = 0;
3890 texture_desc.MiscFlags = 0;
3892 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
3894 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
3895 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
3897 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
3898 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
3901 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3902 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3903 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3904 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3906 ID3D11Device_GetImmediateContext(device, &context);
3908 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
3909 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3910 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3911 stride = sizeof(*quad);
3912 offset = 0;
3913 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3914 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3915 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3917 vp.TopLeftX = 0.0f;
3918 vp.TopLeftY = 0.0f;
3919 vp.Width = 640.0f;
3920 vp.Height = 480.0f;
3921 vp.MinDepth = 0.0f;
3922 vp.MaxDepth = 1.0f;
3923 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3925 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
3926 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
3928 ID3D11DeviceContext_Draw(context, 4, 0);
3930 check_texture_color(rt[0], 0xffffffff, 2);
3931 check_texture_color(rt[1], 0x7f7f7f7f, 2);
3932 check_texture_color(rt[2], 0x33333333, 2);
3933 check_texture_color(rt[3], 0xff7f3300, 2);
3935 ID3D11Buffer_Release(vb);
3936 ID3D11PixelShader_Release(ps);
3937 ID3D11VertexShader_Release(vs);
3938 ID3D11InputLayout_Release(input_layout);
3939 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
3940 ID3D11RenderTargetView_Release(rtv[i]);
3941 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
3942 ID3D11Texture2D_Release(rt[i]);
3943 ID3D11DeviceContext_Release(context);
3944 refcount = ID3D11Device_Release(device);
3945 ok(!refcount, "Device has %u references left.\n", refcount);
3948 static void test_scissor(void)
3950 struct d3d11_test_context test_context;
3951 ID3D11DeviceContext *immediate_context;
3952 D3D11_RASTERIZER_DESC rs_desc;
3953 ID3D11RasterizerState *rs;
3954 D3D11_RECT scissor_rect;
3955 ID3D11PixelShader *ps;
3956 ID3D11Device *device;
3957 DWORD color;
3958 HRESULT hr;
3960 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
3961 static const DWORD ps_code[] =
3963 #if 0
3964 float4 main(float4 position : SV_POSITION) : SV_Target
3966 return float4(0.0, 1.0, 0.0, 1.0);
3968 #endif
3969 0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
3970 0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
3971 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
3972 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
3973 0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3974 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
3975 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3976 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
3977 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
3978 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
3979 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
3980 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3981 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3982 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3985 if (!init_test_context(&test_context))
3986 return;
3988 device = test_context.device;
3989 immediate_context = test_context.immediate_context;
3991 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3992 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3994 rs_desc.FillMode = D3D11_FILL_SOLID;
3995 rs_desc.CullMode = D3D11_CULL_BACK;
3996 rs_desc.FrontCounterClockwise = FALSE;
3997 rs_desc.DepthBias = 0;
3998 rs_desc.DepthBiasClamp = 0.0f;
3999 rs_desc.SlopeScaledDepthBias = 0.0f;
4000 rs_desc.DepthClipEnable = TRUE;
4001 rs_desc.ScissorEnable = TRUE;
4002 rs_desc.MultisampleEnable = FALSE;
4003 rs_desc.AntialiasedLineEnable = FALSE;
4004 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
4005 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4007 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
4009 scissor_rect.left = 160;
4010 scissor_rect.top = 120;
4011 scissor_rect.right = 480;
4012 scissor_rect.bottom = 360;
4013 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
4015 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4016 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4018 draw_quad(&test_context);
4019 color = get_texture_color(test_context.backbuffer, 320, 60);
4020 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4021 color = get_texture_color(test_context.backbuffer, 80, 240);
4022 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4023 color = get_texture_color(test_context.backbuffer, 320, 240);
4024 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4025 color = get_texture_color(test_context.backbuffer, 560, 240);
4026 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4027 color = get_texture_color(test_context.backbuffer, 320, 420);
4028 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4030 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4031 ID3D11DeviceContext_RSSetState(immediate_context, rs);
4032 draw_quad(&test_context);
4033 color = get_texture_color(test_context.backbuffer, 320, 60);
4034 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4035 color = get_texture_color(test_context.backbuffer, 80, 240);
4036 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4037 color = get_texture_color(test_context.backbuffer, 320, 240);
4038 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4039 color = get_texture_color(test_context.backbuffer, 560, 240);
4040 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4041 color = get_texture_color(test_context.backbuffer, 320, 420);
4042 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4044 ID3D11RasterizerState_Release(rs);
4045 ID3D11PixelShader_Release(ps);
4046 release_test_context(&test_context);
4049 static void test_il_append_aligned(void)
4051 struct d3d11_test_context test_context;
4052 D3D11_SUBRESOURCE_DATA resource_data;
4053 ID3D11InputLayout *input_layout;
4054 D3D11_BUFFER_DESC buffer_desc;
4055 ID3D11DeviceContext *context;
4056 unsigned int stride, offset;
4057 ID3D11VertexShader *vs;
4058 ID3D11PixelShader *ps;
4059 ID3D11Device *device;
4060 ID3D11Buffer *vb[3];
4061 DWORD color;
4062 HRESULT hr;
4064 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4066 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4067 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4068 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4069 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4070 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
4071 D3D11_INPUT_PER_VERTEX_DATA, 0},
4072 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4073 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4074 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4075 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4077 static const DWORD vs_code[] =
4079 #if 0
4080 struct vs_in
4082 float4 position : POSITION;
4083 float2 color_xy : COLOR0;
4084 float2 color_zw : COLOR1;
4085 unsigned int instance_id : SV_INSTANCEID;
4088 struct vs_out
4090 float4 position : SV_POSITION;
4091 float2 color_xy : COLOR0;
4092 float2 color_zw : COLOR1;
4095 struct vs_out main(struct vs_in i)
4097 struct vs_out o;
4099 o.position = i.position;
4100 o.position.x += i.instance_id * 0.5;
4101 o.color_xy = i.color_xy;
4102 o.color_zw = i.color_zw;
4104 return o;
4106 #endif
4107 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
4108 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
4109 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
4110 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
4111 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
4112 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
4113 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4114 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
4115 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
4116 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
4117 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
4118 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
4119 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
4120 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
4121 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
4122 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
4123 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
4125 static const DWORD ps_code[] =
4127 #if 0
4128 struct vs_out
4130 float4 position : SV_POSITION;
4131 float2 color_xy : COLOR0;
4132 float2 color_zw : COLOR1;
4135 float4 main(struct vs_out i) : SV_TARGET
4137 return float4(i.color_xy.xy, i.color_zw.xy);
4139 #endif
4140 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
4141 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
4142 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
4143 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
4144 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
4145 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
4146 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
4147 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4148 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
4150 static const struct
4152 struct vec4 position;
4154 stream0[] =
4156 {{-1.0f, -1.0f, 0.0f, 1.0f}},
4157 {{-1.0f, 1.0f, 0.0f, 1.0f}},
4158 {{-0.5f, -1.0f, 0.0f, 1.0f}},
4159 {{-0.5f, 1.0f, 0.0f, 1.0f}},
4161 static const struct
4163 struct vec2 color2;
4164 struct vec2 color1;
4166 stream1[] =
4168 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4169 {{0.5f, 0.5f}, {1.0f, 1.0f}},
4171 static const struct
4173 struct vec2 color3;
4174 struct vec2 color0;
4176 stream2[] =
4178 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4179 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4180 {{0.5f, 0.5f}, {0.0f, 0.0f}},
4181 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4183 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4185 if (!init_test_context(&test_context))
4186 return;
4188 device = test_context.device;
4189 context = test_context.immediate_context;
4191 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4192 vs_code, sizeof(vs_code), &input_layout);
4193 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4195 buffer_desc.ByteWidth = sizeof(stream0);
4196 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4197 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4198 buffer_desc.CPUAccessFlags = 0;
4199 buffer_desc.MiscFlags = 0;
4200 buffer_desc.StructureByteStride = 0;
4202 resource_data.pSysMem = stream0;
4203 resource_data.SysMemPitch = 0;
4204 resource_data.SysMemSlicePitch = 0;
4206 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
4207 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4209 buffer_desc.ByteWidth = sizeof(stream1);
4210 resource_data.pSysMem = stream1;
4212 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
4213 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4215 buffer_desc.ByteWidth = sizeof(stream2);
4216 resource_data.pSysMem = stream2;
4218 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
4219 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4221 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4222 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4223 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4224 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4226 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4227 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4228 offset = 0;
4229 stride = sizeof(*stream0);
4230 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
4231 stride = sizeof(*stream1);
4232 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
4233 stride = sizeof(*stream2);
4234 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
4235 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4236 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4238 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4240 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
4242 color = get_texture_color(test_context.backbuffer, 80, 240);
4243 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4244 color = get_texture_color(test_context.backbuffer, 240, 240);
4245 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4246 color = get_texture_color(test_context.backbuffer, 400, 240);
4247 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4248 color = get_texture_color(test_context.backbuffer, 560, 240);
4249 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
4251 ID3D11PixelShader_Release(ps);
4252 ID3D11VertexShader_Release(vs);
4253 ID3D11Buffer_Release(vb[2]);
4254 ID3D11Buffer_Release(vb[1]);
4255 ID3D11Buffer_Release(vb[0]);
4256 ID3D11InputLayout_Release(input_layout);
4257 release_test_context(&test_context);
4260 static void test_fragment_coords(void)
4262 struct d3d11_test_context test_context;
4263 D3D11_SUBRESOURCE_DATA resource_data;
4264 ID3D11PixelShader *ps, *ps_frac;
4265 D3D11_BUFFER_DESC buffer_desc;
4266 ID3D11DeviceContext *context;
4267 ID3D11Device *device;
4268 ID3D11Buffer *ps_cb;
4269 DWORD color;
4270 HRESULT hr;
4272 static const DWORD ps_code[] =
4274 #if 0
4275 float2 cutoff;
4277 float4 main(float4 position : SV_POSITION) : SV_TARGET
4279 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
4281 if (position.x > cutoff.x)
4282 ret.y = 1.0;
4283 if (position.y > cutoff.y)
4284 ret.z = 1.0;
4286 return ret;
4288 #endif
4289 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
4290 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4291 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4292 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4293 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
4294 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
4295 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
4296 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
4297 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
4298 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
4299 0x0100003e,
4301 static const DWORD ps_frac_code[] =
4303 #if 0
4304 float4 main(float4 position : SV_POSITION) : SV_TARGET
4306 return float4(frac(position.xy), 0.0, 1.0);
4308 #endif
4309 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
4310 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4311 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4312 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4313 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
4314 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4315 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
4316 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
4318 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4319 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
4321 if (!init_test_context(&test_context))
4322 return;
4324 device = test_context.device;
4325 context = test_context.immediate_context;
4327 buffer_desc.ByteWidth = sizeof(cutoff);
4328 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4329 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4330 buffer_desc.CPUAccessFlags = 0;
4331 buffer_desc.MiscFlags = 0;
4332 buffer_desc.StructureByteStride = 0;
4334 resource_data.pSysMem = &cutoff;
4335 resource_data.SysMemPitch = 0;
4336 resource_data.SysMemSlicePitch = 0;
4338 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4339 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4341 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4342 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4343 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
4344 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4346 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4347 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4349 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4351 draw_quad(&test_context);
4353 color = get_texture_color(test_context.backbuffer, 319, 239);
4354 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4355 color = get_texture_color(test_context.backbuffer, 320, 239);
4356 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4357 color = get_texture_color(test_context.backbuffer, 319, 240);
4358 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4359 color = get_texture_color(test_context.backbuffer, 320, 240);
4360 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4362 ID3D11Buffer_Release(ps_cb);
4363 cutoff.x = 16.0f;
4364 cutoff.y = 16.0f;
4365 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4366 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4367 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4369 draw_quad(&test_context);
4371 color = get_texture_color(test_context.backbuffer, 14, 14);
4372 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4373 color = get_texture_color(test_context.backbuffer, 18, 14);
4374 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4375 color = get_texture_color(test_context.backbuffer, 14, 18);
4376 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4377 color = get_texture_color(test_context.backbuffer, 18, 18);
4378 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4380 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
4381 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4383 ID3D11DeviceContext_Draw(context, 4, 0);
4385 color = get_texture_color(test_context.backbuffer, 14, 14);
4386 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
4388 ID3D11Buffer_Release(ps_cb);
4389 ID3D11PixelShader_Release(ps_frac);
4390 ID3D11PixelShader_Release(ps);
4391 release_test_context(&test_context);
4394 static void test_update_subresource(void)
4396 struct d3d11_test_context test_context;
4397 D3D11_TEXTURE2D_DESC texture_desc;
4398 ID3D11SamplerState *sampler_state;
4399 ID3D11ShaderResourceView *ps_srv;
4400 D3D11_SAMPLER_DESC sampler_desc;
4401 ID3D11DeviceContext *context;
4402 struct texture_readback rb;
4403 ID3D11Texture2D *texture;
4404 ID3D11PixelShader *ps;
4405 ID3D11Device *device;
4406 unsigned int i, j;
4407 D3D11_BOX box;
4408 DWORD color;
4409 HRESULT hr;
4411 static const DWORD ps_code[] =
4413 #if 0
4414 Texture2D t;
4415 SamplerState s;
4417 float4 main(float4 position : SV_POSITION) : SV_Target
4419 float2 p;
4421 p.x = position.x / 640.0f;
4422 p.y = position.y / 480.0f;
4423 return t.Sample(s, p);
4425 #endif
4426 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4427 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4428 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4429 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4430 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4431 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4432 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4433 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4434 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4435 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4437 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4438 static const DWORD bitmap_data[] =
4440 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4441 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4442 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4443 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4445 static const DWORD expected_colors[] =
4447 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
4448 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4449 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
4450 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
4453 if (!init_test_context(&test_context))
4454 return;
4456 device = test_context.device;
4457 context = test_context.immediate_context;
4459 texture_desc.Width = 4;
4460 texture_desc.Height = 4;
4461 texture_desc.MipLevels = 1;
4462 texture_desc.ArraySize = 1;
4463 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4464 texture_desc.SampleDesc.Count = 1;
4465 texture_desc.SampleDesc.Quality = 0;
4466 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4467 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4468 texture_desc.CPUAccessFlags = 0;
4469 texture_desc.MiscFlags = 0;
4471 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4472 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4474 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
4475 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4477 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4478 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4479 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4480 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4481 sampler_desc.MipLODBias = 0.0f;
4482 sampler_desc.MaxAnisotropy = 0;
4483 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4484 sampler_desc.BorderColor[0] = 0.0f;
4485 sampler_desc.BorderColor[1] = 0.0f;
4486 sampler_desc.BorderColor[2] = 0.0f;
4487 sampler_desc.BorderColor[3] = 0.0f;
4488 sampler_desc.MinLOD = 0.0f;
4489 sampler_desc.MaxLOD = 0.0f;
4491 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4492 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4494 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4495 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4497 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
4498 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
4499 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4501 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4502 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
4504 draw_quad(&test_context);
4505 check_texture_color(test_context.backbuffer, 0x00000000, 0);
4507 set_box(&box, 1, 1, 0, 3, 3, 1);
4508 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4509 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4510 set_box(&box, 0, 3, 0, 3, 4, 1);
4511 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4512 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
4513 set_box(&box, 0, 0, 0, 4, 1, 1);
4514 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4515 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
4516 set_box(&box, 0, 1, 0, 1, 3, 1);
4517 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4518 &bitmap_data[2], sizeof(*bitmap_data), 0);
4519 set_box(&box, 4, 4, 0, 3, 1, 1);
4520 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4521 bitmap_data, sizeof(*bitmap_data), 0);
4522 set_box(&box, 0, 0, 0, 4, 4, 0);
4523 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4524 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4525 draw_quad(&test_context);
4526 get_texture_readback(test_context.backbuffer, &rb);
4527 for (i = 0; i < 4; ++i)
4529 for (j = 0; j < 4; ++j)
4531 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4532 ok(compare_color(color, expected_colors[j + i * 4], 1),
4533 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4534 color, j, i, expected_colors[j + i * 4]);
4537 release_texture_readback(&rb);
4539 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
4540 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4541 draw_quad(&test_context);
4542 get_texture_readback(test_context.backbuffer, &rb);
4543 for (i = 0; i < 4; ++i)
4545 for (j = 0; j < 4; ++j)
4547 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4548 ok(compare_color(color, bitmap_data[j + i * 4], 1),
4549 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4550 color, j, i, bitmap_data[j + i * 4]);
4553 release_texture_readback(&rb);
4555 ID3D11PixelShader_Release(ps);
4556 ID3D11SamplerState_Release(sampler_state);
4557 ID3D11ShaderResourceView_Release(ps_srv);
4558 ID3D11Texture2D_Release(texture);
4559 release_test_context(&test_context);
4562 static void test_copy_subresource_region(void)
4564 ID3D11Texture2D *dst_texture, *src_texture;
4565 struct d3d11_test_context test_context;
4566 D3D11_SUBRESOURCE_DATA resource_data;
4567 D3D11_TEXTURE2D_DESC texture_desc;
4568 ID3D11SamplerState *sampler_state;
4569 ID3D11ShaderResourceView *ps_srv;
4570 D3D11_SAMPLER_DESC sampler_desc;
4571 ID3D11DeviceContext *context;
4572 struct texture_readback rb;
4573 ID3D11PixelShader *ps;
4574 ID3D11Device *device;
4575 unsigned int i, j;
4576 D3D11_BOX box;
4577 DWORD color;
4578 HRESULT hr;
4580 static const DWORD ps_code[] =
4582 #if 0
4583 Texture2D t;
4584 SamplerState s;
4586 float4 main(float4 position : SV_POSITION) : SV_Target
4588 float2 p;
4590 p.x = position.x / 640.0f;
4591 p.y = position.y / 480.0f;
4592 return t.Sample(s, p);
4594 #endif
4595 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4596 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4597 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4598 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4599 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4600 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4601 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4602 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4603 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4604 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4606 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4607 static const DWORD bitmap_data[] =
4609 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4610 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4611 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4612 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4614 static const DWORD expected_colors[] =
4616 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4617 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4618 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
4619 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
4622 if (!init_test_context(&test_context))
4623 return;
4625 device = test_context.device;
4626 context = test_context.immediate_context;
4628 texture_desc.Width = 4;
4629 texture_desc.Height = 4;
4630 texture_desc.MipLevels = 1;
4631 texture_desc.ArraySize = 1;
4632 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4633 texture_desc.SampleDesc.Count = 1;
4634 texture_desc.SampleDesc.Quality = 0;
4635 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4636 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4637 texture_desc.CPUAccessFlags = 0;
4638 texture_desc.MiscFlags = 0;
4640 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
4641 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4643 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
4645 resource_data.pSysMem = bitmap_data;
4646 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
4647 resource_data.SysMemSlicePitch = 0;
4649 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
4650 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4652 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
4653 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4655 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4656 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4657 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4658 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4659 sampler_desc.MipLODBias = 0.0f;
4660 sampler_desc.MaxAnisotropy = 0;
4661 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4662 sampler_desc.BorderColor[0] = 0.0f;
4663 sampler_desc.BorderColor[1] = 0.0f;
4664 sampler_desc.BorderColor[2] = 0.0f;
4665 sampler_desc.BorderColor[3] = 0.0f;
4666 sampler_desc.MinLOD = 0.0f;
4667 sampler_desc.MaxLOD = 0.0f;
4669 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4670 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4672 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4673 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4675 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
4676 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
4677 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4679 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4681 set_box(&box, 0, 0, 0, 2, 2, 1);
4682 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4683 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
4684 set_box(&box, 1, 2, 0, 4, 3, 1);
4685 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4686 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
4687 set_box(&box, 0, 3, 0, 4, 4, 1);
4688 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4689 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
4690 set_box(&box, 3, 0, 0, 4, 2, 1);
4691 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4692 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
4693 set_box(&box, 3, 1, 0, 4, 2, 1);
4694 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4695 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
4696 set_box(&box, 0, 0, 0, 4, 4, 0);
4697 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4698 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
4699 draw_quad(&test_context);
4700 get_texture_readback(test_context.backbuffer, &rb);
4701 for (i = 0; i < 4; ++i)
4703 for (j = 0; j < 4; ++j)
4705 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4706 ok(compare_color(color, expected_colors[j + i * 4], 1),
4707 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4708 color, j, i, expected_colors[j + i * 4]);
4711 release_texture_readback(&rb);
4713 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4714 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
4715 draw_quad(&test_context);
4716 get_texture_readback(test_context.backbuffer, &rb);
4717 for (i = 0; i < 4; ++i)
4719 for (j = 0; j < 4; ++j)
4721 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4722 ok(compare_color(color, bitmap_data[j + i * 4], 1),
4723 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4724 color, j, i, bitmap_data[j + i * 4]);
4727 release_texture_readback(&rb);
4729 ID3D11PixelShader_Release(ps);
4730 ID3D11SamplerState_Release(sampler_state);
4731 ID3D11ShaderResourceView_Release(ps_srv);
4732 ID3D11Texture2D_Release(dst_texture);
4733 ID3D11Texture2D_Release(src_texture);
4734 release_test_context(&test_context);
4737 static void test_resource_map(void)
4739 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
4740 D3D11_TEXTURE3D_DESC texture3d_desc;
4741 D3D11_TEXTURE2D_DESC texture2d_desc;
4742 D3D11_BUFFER_DESC buffer_desc;
4743 ID3D11DeviceContext *context;
4744 ID3D11Texture3D *texture3d;
4745 ID3D11Texture2D *texture2d;
4746 ID3D11Buffer *buffer;
4747 ID3D11Device *device;
4748 ULONG refcount;
4749 HRESULT hr;
4750 DWORD data;
4752 if (!(device = create_device(NULL)))
4754 skip("Failed to create device.\n");
4755 return;
4758 ID3D11Device_GetImmediateContext(device, &context);
4760 buffer_desc.ByteWidth = 1024;
4761 buffer_desc.Usage = D3D11_USAGE_STAGING;
4762 buffer_desc.BindFlags = 0;
4763 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4764 buffer_desc.MiscFlags = 0;
4765 buffer_desc.StructureByteStride = 0;
4767 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4768 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4770 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4771 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4773 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4774 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4775 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
4776 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4777 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
4778 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4779 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
4781 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4782 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4783 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
4784 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4785 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
4786 data = *((DWORD *)mapped_subresource.pData);
4787 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4788 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
4790 refcount = ID3D11Buffer_Release(buffer);
4791 ok(!refcount, "Buffer has %u references left.\n", refcount);
4793 texture2d_desc.Width = 512;
4794 texture2d_desc.Height = 512;
4795 texture2d_desc.MipLevels = 1;
4796 texture2d_desc.ArraySize = 1;
4797 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4798 texture2d_desc.SampleDesc.Count = 1;
4799 texture2d_desc.SampleDesc.Quality = 0;
4800 texture2d_desc.Usage = D3D11_USAGE_STAGING;
4801 texture2d_desc.BindFlags = 0;
4802 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4803 texture2d_desc.MiscFlags = 0;
4805 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4806 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4808 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4809 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4811 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4812 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4813 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4814 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4815 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4816 mapped_subresource.DepthPitch);
4817 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4818 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
4820 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4821 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4822 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4823 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4824 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
4825 mapped_subresource.DepthPitch);
4826 data = *((DWORD *)mapped_subresource.pData);
4827 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4828 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
4830 refcount = ID3D11Texture2D_Release(texture2d);
4831 ok(!refcount, "2D texture has %u references left.\n", refcount);
4833 texture3d_desc.Width = 64;
4834 texture3d_desc.Height = 64;
4835 texture3d_desc.Depth = 64;
4836 texture3d_desc.MipLevels = 1;
4837 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4838 texture3d_desc.Usage = D3D11_USAGE_STAGING;
4839 texture3d_desc.BindFlags = 0;
4840 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
4841 texture3d_desc.MiscFlags = 0;
4843 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4844 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
4846 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
4847 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4849 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4850 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
4851 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4852 if (FAILED(hr)) goto done;
4853 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4854 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4855 mapped_subresource.DepthPitch);
4856 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
4857 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
4859 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
4860 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
4861 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
4862 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
4863 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
4864 mapped_subresource.DepthPitch);
4865 data = *((DWORD *)mapped_subresource.pData);
4866 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
4867 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
4869 done:
4870 refcount = ID3D11Texture3D_Release(texture3d);
4871 ok(!refcount, "3D texture has %u references left.\n", refcount);
4873 ID3D11DeviceContext_Release(context);
4875 refcount = ID3D11Device_Release(device);
4876 ok(!refcount, "Device has %u references left.\n", refcount);
4879 static void test_multisample_init(void)
4881 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4882 struct d3d11_test_context test_context;
4883 ID3D11DeviceContext *context;
4884 D3D11_TEXTURE2D_DESC desc;
4885 ID3D11Texture2D *multi;
4886 ID3D11Device *device;
4887 UINT count = 0;
4888 HRESULT hr;
4890 if (!init_test_context(&test_context))
4891 return;
4893 device = test_context.device;
4894 context = test_context.immediate_context;
4896 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
4897 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
4898 if (!count)
4900 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
4901 goto done;
4904 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4906 desc.Width = 640;
4907 desc.Height = 480;
4908 desc.MipLevels = 1;
4909 desc.ArraySize = 1;
4910 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4911 desc.SampleDesc.Count = 2;
4912 desc.SampleDesc.Quality = 0;
4913 desc.Usage = D3D11_USAGE_DEFAULT;
4914 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4915 desc.CPUAccessFlags = 0;
4916 desc.MiscFlags = 0;
4917 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &multi);
4918 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4920 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
4921 (ID3D11Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
4923 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 0);
4925 ID3D11Texture2D_Release(multi);
4926 done:
4927 release_test_context(&test_context);
4930 static void test_check_multisample_quality_levels(void)
4932 ID3D11Device *device;
4933 UINT quality_levels;
4934 ULONG refcount;
4935 HRESULT hr;
4937 if (!(device = create_device(NULL)))
4939 skip("Failed to create device.\n");
4940 return;
4943 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
4944 if (!quality_levels)
4946 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
4947 goto done;
4950 quality_levels = 0xdeadbeef;
4951 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
4952 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4953 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4954 quality_levels = 0xdeadbeef;
4955 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
4956 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4957 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
4959 quality_levels = 0xdeadbeef;
4960 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
4961 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4962 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
4963 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4964 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4966 quality_levels = 0xdeadbeef;
4967 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
4968 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4969 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
4970 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4971 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
4973 quality_levels = 0xdeadbeef;
4974 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
4975 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4976 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
4977 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4978 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4980 /* We assume 15 samples multisampling is never supported in practice. */
4981 quality_levels = 0xdeadbeef;
4982 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
4983 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4984 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4985 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
4986 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4987 quality_levels = 0xdeadbeef;
4988 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
4989 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4990 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4991 quality_levels = 0xdeadbeef;
4992 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
4993 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4994 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
4996 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
4997 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4998 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5000 done:
5001 refcount = ID3D11Device_Release(device);
5002 ok(!refcount, "Device has %u references left.\n", refcount);
5005 static void test_create_typeless_resource(void)
5007 D3D11_TEXTURE2D_DESC texture2d_desc;
5008 D3D11_TEXTURE3D_DESC texture3d_desc;
5009 ID3D11Resource *resource;
5010 ID3D11Device *device;
5011 ULONG refcount;
5012 unsigned int i;
5013 HRESULT hr;
5015 static const struct
5017 DXGI_FORMAT format;
5018 D3D11_BIND_FLAG bind_flags;
5019 D3D11_RESOURCE_DIMENSION type;
5020 BOOL succeeds;
5021 BOOL todo;
5023 tests[] =
5025 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5026 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5027 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5028 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5029 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE3D, TRUE, FALSE},
5030 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5031 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_DEPTH_STENCIL, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5032 {DXGI_FORMAT_R32G32B32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5033 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5034 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE3D, TRUE, FALSE},
5035 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5036 {DXGI_FORMAT_R32G32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5037 {DXGI_FORMAT_R32G8X24_TYPELESS, D3D11_BIND_DEPTH_STENCIL, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, TRUE},
5038 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5039 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE3D, TRUE, FALSE},
5040 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5041 {DXGI_FORMAT_R32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5042 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5043 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5044 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_DIMENSION_TEXTURE2D, FALSE, TRUE},
5045 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5046 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_DEPTH_STENCIL, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5047 {DXGI_FORMAT_R8G8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5048 {DXGI_FORMAT_R16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5049 {DXGI_FORMAT_R8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_DIMENSION_TEXTURE2D, TRUE, FALSE},
5052 if (!(device = create_device(NULL)))
5054 skip("Failed to create device.\n");
5055 return;
5058 texture2d_desc.Width = 512;
5059 texture2d_desc.Height = 512;
5060 texture2d_desc.MipLevels = 1;
5061 texture2d_desc.ArraySize = 1;
5062 texture2d_desc.SampleDesc.Count = 1;
5063 texture2d_desc.SampleDesc.Quality = 0;
5064 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
5065 texture2d_desc.CPUAccessFlags = 0;
5066 texture2d_desc.MiscFlags = 0;
5068 texture3d_desc.Width = 64;
5069 texture3d_desc.Height = 64;
5070 texture3d_desc.Depth = 64;
5071 texture3d_desc.MipLevels = 1;
5072 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
5073 texture3d_desc.CPUAccessFlags = 0;
5074 texture3d_desc.MiscFlags = 0;
5076 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5078 if (tests[i].type == D3D11_RESOURCE_DIMENSION_TEXTURE2D)
5080 texture2d_desc.Format = tests[i].format;
5081 texture2d_desc.BindFlags = tests[i].bind_flags;
5082 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
5084 else if (tests[i].type == D3D11_RESOURCE_DIMENSION_TEXTURE3D)
5086 texture3d_desc.Format = tests[i].format;
5087 texture3d_desc.BindFlags = tests[i].bind_flags;
5088 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&resource);
5090 else
5092 trace("Test %u: Unknown resource type %#x.\n", i, tests[i].type);
5093 continue;
5096 todo_wine_if(tests[i].todo)
5097 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
5099 if (SUCCEEDED(hr))
5100 ID3D11Resource_Release(resource);
5103 refcount = ID3D11Device_Release(device);
5104 ok(!refcount, "Device has %u references left.\n", refcount);
5107 START_TEST(d3d11)
5109 test_create_device();
5110 test_device_interfaces();
5111 test_get_immediate_context();
5112 test_create_texture2d();
5113 test_texture2d_interfaces();
5114 test_create_texture3d();
5115 test_texture3d_interfaces();
5116 test_buffer_interfaces();
5117 test_create_depthstencil_view();
5118 test_depthstencil_view_interfaces();
5119 test_create_rendertarget_view();
5120 test_create_shader_resource_view();
5121 test_create_shader();
5122 test_create_sampler_state();
5123 test_create_blend_state();
5124 test_create_depthstencil_state();
5125 test_create_rasterizer_state();
5126 test_create_predicate();
5127 test_device_removed_reason();
5128 test_private_data();
5129 test_blend();
5130 test_texture();
5131 test_multiple_render_targets();
5132 test_scissor();
5133 test_il_append_aligned();
5134 test_fragment_coords();
5135 test_update_subresource();
5136 test_copy_subresource_region();
5137 test_resource_map();
5138 test_multisample_init();
5139 test_check_multisample_quality_levels();
5140 test_create_typeless_resource();