d3d11/tests: Also trace feature level when HAL device cannot be created.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobff2d56d293cef4ca1cb58a2b11049f60e793994a
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"
24 #include <limits.h>
26 static const D3D_FEATURE_LEVEL d3d11_feature_levels[] =
28 D3D_FEATURE_LEVEL_11_1,
29 D3D_FEATURE_LEVEL_11_0,
30 D3D_FEATURE_LEVEL_10_1,
31 D3D_FEATURE_LEVEL_10_0,
32 D3D_FEATURE_LEVEL_9_3,
33 D3D_FEATURE_LEVEL_9_2,
34 D3D_FEATURE_LEVEL_9_1
37 struct vec2
39 float x, y;
42 struct vec3
44 float x, y, z;
47 struct vec4
49 float x, y, z, w;
52 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
54 box->left = left;
55 box->top = top;
56 box->front = front;
57 box->right = right;
58 box->bottom = bottom;
59 box->back = back;
62 static ULONG get_refcount(IUnknown *iface)
64 IUnknown_AddRef(iface);
65 return IUnknown_Release(iface);
68 static BOOL compare_float(float f, float g, unsigned int ulps)
70 int x = *(int *)&f;
71 int y = *(int *)&g;
73 if (x < 0)
74 x = INT_MIN - x;
75 if (y < 0)
76 y = INT_MIN - y;
78 if (abs(x - y) > ulps)
79 return FALSE;
81 return TRUE;
84 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
86 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
87 return FALSE;
88 c1 >>= 8; c2 >>= 8;
89 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
90 return FALSE;
91 c1 >>= 8; c2 >>= 8;
92 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
93 return FALSE;
94 c1 >>= 8; c2 >>= 8;
95 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
96 return FALSE;
97 return TRUE;
100 struct texture_readback
102 ID3D11Resource *texture;
103 D3D11_MAPPED_SUBRESOURCE map_desc;
104 ID3D11DeviceContext *immediate_context;
105 unsigned int width, height;
108 static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readback *rb)
110 D3D11_TEXTURE2D_DESC texture_desc;
111 ID3D11Device *device;
112 HRESULT hr;
114 memset(rb, 0, sizeof(*rb));
116 ID3D11Texture2D_GetDevice(texture, &device);
118 ID3D11Texture2D_GetDesc(texture, &texture_desc);
119 texture_desc.Usage = D3D11_USAGE_STAGING;
120 texture_desc.BindFlags = 0;
121 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
122 texture_desc.MiscFlags = 0;
123 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->texture)))
125 trace("Failed to create texture, hr %#x.\n", hr);
126 ID3D11Device_Release(device);
127 return;
130 rb->width = texture_desc.Width;
131 rb->height = texture_desc.Height;
133 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
135 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
136 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->texture, 0, D3D11_MAP_READ, 0, &rb->map_desc)))
138 trace("Failed to map texture, hr %#x.\n", hr);
139 ID3D11Resource_Release(rb->texture);
140 rb->texture = NULL;
141 ID3D11DeviceContext_Release(rb->immediate_context);
142 rb->immediate_context = NULL;
145 ID3D11Device_Release(device);
148 static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, unsigned int y)
150 return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
153 static float get_readback_float(struct texture_readback *rb, unsigned int x, unsigned int y)
155 return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
158 static void release_texture_readback(struct texture_readback *rb)
160 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->texture, 0);
161 ID3D11Resource_Release(rb->texture);
162 ID3D11DeviceContext_Release(rb->immediate_context);
165 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
167 struct texture_readback rb;
168 DWORD color;
170 get_texture_readback(texture, &rb);
171 color = get_readback_color(&rb, x, y);
172 release_texture_readback(&rb);
174 return color;
177 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
178 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
179 DWORD expected_color, BYTE max_diff)
181 struct texture_readback rb;
182 unsigned int x = 0, y = 0;
183 BOOL all_match = TRUE;
184 DWORD color = 0;
186 get_texture_readback(texture, &rb);
187 for (y = 0; y < rb.height; ++y)
189 for (x = 0; x < rb.width; ++x)
191 color = get_readback_color(&rb, x, y);
192 if (!compare_color(color, expected_color, max_diff))
194 all_match = FALSE;
195 break;
198 if (!all_match)
199 break;
201 release_texture_readback(&rb);
202 ok_(__FILE__, line)(all_match,
203 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
206 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
207 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
208 float expected_value, BYTE max_diff)
210 struct texture_readback rb;
211 unsigned int x = 0, y = 0;
212 BOOL all_match = TRUE;
213 float value = 0.0f;
215 get_texture_readback(texture, &rb);
216 for (y = 0; y < rb.height; ++y)
218 for (x = 0; x < rb.width; ++x)
220 value = get_readback_float(&rb, x, y);
221 if (!compare_float(value, expected_value, max_diff))
223 all_match = FALSE;
224 break;
227 if (!all_match)
228 break;
230 release_texture_readback(&rb);
231 ok_(__FILE__, line)(all_match,
232 "Got unexpected value %.8e at (%u, %u).\n", value, x, y);
235 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
237 static const D3D_FEATURE_LEVEL default_feature_level[] =
239 D3D_FEATURE_LEVEL_11_0,
240 D3D_FEATURE_LEVEL_10_0,
242 unsigned int feature_level_count;
243 ID3D11Device *device;
245 if (feature_level)
247 feature_level_count = 1;
249 else
251 feature_level = default_feature_level;
252 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
255 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, feature_level, feature_level_count,
256 D3D11_SDK_VERSION, &device, NULL, NULL)))
257 return device;
258 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, feature_level, feature_level_count,
259 D3D11_SDK_VERSION, &device, NULL, NULL)))
260 return device;
261 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, feature_level, feature_level_count,
262 D3D11_SDK_VERSION, &device, NULL, NULL)))
263 return device;
265 return NULL;
268 static BOOL is_warp_device(ID3D11Device *device)
270 DXGI_ADAPTER_DESC adapter_desc;
271 IDXGIDevice *dxgi_device;
272 IDXGIAdapter *adapter;
273 HRESULT hr;
275 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
276 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
277 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
278 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
279 IDXGIDevice_Release(dxgi_device);
280 hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
281 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
282 IDXGIAdapter_Release(adapter);
284 return !adapter_desc.SubSysId && !adapter_desc.Revision
285 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
286 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
289 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, BOOL windowed)
291 IDXGISwapChain *swapchain;
292 DXGI_SWAP_CHAIN_DESC desc;
293 IDXGIDevice *dxgi_device;
294 IDXGIAdapter *adapter;
295 IDXGIFactory *factory;
296 HRESULT hr;
298 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
299 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
300 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
301 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
302 IDXGIDevice_Release(dxgi_device);
303 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
304 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
305 IDXGIAdapter_Release(adapter);
307 desc.BufferDesc.Width = 640;
308 desc.BufferDesc.Height = 480;
309 desc.BufferDesc.RefreshRate.Numerator = 60;
310 desc.BufferDesc.RefreshRate.Denominator = 1;
311 desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
312 desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
313 desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
314 desc.SampleDesc.Count = 1;
315 desc.SampleDesc.Quality = 0;
316 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
317 desc.BufferCount = 1;
318 desc.OutputWindow = window;
319 desc.Windowed = windowed;
320 desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
321 desc.Flags = 0;
323 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain);
324 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
325 IDXGIFactory_Release(factory);
327 return swapchain;
330 struct d3d11_test_context
332 ID3D11Device *device;
333 HWND window;
334 IDXGISwapChain *swapchain;
335 ID3D11Texture2D *backbuffer;
336 ID3D11RenderTargetView *backbuffer_rtv;
337 ID3D11DeviceContext *immediate_context;
339 ID3D11InputLayout *input_layout;
340 ID3D11VertexShader *vs;
341 ID3D11Buffer *vb;
344 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
345 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
346 const D3D_FEATURE_LEVEL *feature_level)
348 D3D11_VIEWPORT vp;
349 HRESULT hr;
351 memset(context, 0, sizeof(*context));
353 if (!(context->device = create_device(feature_level)))
355 skip_(__FILE__, line)("Failed to create device.\n");
356 return FALSE;
358 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
359 0, 0, 640, 480, NULL, NULL, NULL, NULL);
360 context->swapchain = create_swapchain(context->device, context->window, TRUE);
361 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
362 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
364 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
365 NULL, &context->backbuffer_rtv);
366 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
368 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
370 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
372 vp.TopLeftX = 0.0f;
373 vp.TopLeftY = 0.0f;
374 vp.Width = 640.0f;
375 vp.Height = 480.0f;
376 vp.MinDepth = 0.0f;
377 vp.MaxDepth = 1.0f;
378 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
380 return TRUE;
383 #define release_test_context(c) release_test_context_(__LINE__, c)
384 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
386 ULONG ref;
388 if (context->input_layout)
389 ID3D11InputLayout_Release(context->input_layout);
390 if (context->vs)
391 ID3D11VertexShader_Release(context->vs);
392 if (context->vb)
393 ID3D11Buffer_Release(context->vb);
395 ID3D11DeviceContext_Release(context->immediate_context);
396 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
397 ID3D11Texture2D_Release(context->backbuffer);
398 IDXGISwapChain_Release(context->swapchain);
399 DestroyWindow(context->window);
401 ref = ID3D11Device_Release(context->device);
402 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
405 #define draw_quad(c) draw_quad_(__LINE__, c)
406 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
408 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
410 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
412 static const DWORD default_vs_code[] =
414 #if 0
415 float4 main(float4 position : POSITION) : SV_POSITION
417 return position;
419 #endif
420 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
421 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
422 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
423 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
424 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
425 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
426 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
428 static const struct
430 struct vec2 position;
432 quad[] =
434 {{-1.0f, -1.0f}},
435 {{-1.0f, 1.0f}},
436 {{ 1.0f, -1.0f}},
437 {{ 1.0f, 1.0f}},
440 ID3D11Device *device = context->device;
441 D3D11_SUBRESOURCE_DATA resource_data;
442 D3D11_BUFFER_DESC buffer_desc;
443 unsigned int stride, offset;
444 HRESULT hr;
446 if (!context->input_layout)
448 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
449 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
450 default_vs_code, sizeof(default_vs_code), &context->input_layout);
451 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
453 buffer_desc.ByteWidth = sizeof(quad);
454 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
455 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
456 buffer_desc.CPUAccessFlags = 0;
457 buffer_desc.MiscFlags = 0;
458 buffer_desc.StructureByteStride = 0;
460 resource_data.pSysMem = quad;
461 resource_data.SysMemPitch = 0;
462 resource_data.SysMemSlicePitch = 0;
464 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &context->vb);
465 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
467 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
468 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
471 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
472 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
473 stride = sizeof(*quad);
474 offset = 0;
475 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
476 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
478 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
481 static void test_create_device(void)
483 static const D3D_FEATURE_LEVEL default_feature_levels[] =
485 D3D_FEATURE_LEVEL_11_0,
486 D3D_FEATURE_LEVEL_10_1,
487 D3D_FEATURE_LEVEL_10_0,
488 D3D_FEATURE_LEVEL_9_3,
489 D3D_FEATURE_LEVEL_9_2,
490 D3D_FEATURE_LEVEL_9_1,
492 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
493 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
494 ID3D11DeviceContext *immediate_context;
495 IDXGISwapChain *swapchain;
496 ID3D11Device *device;
497 ULONG refcount;
498 HWND window;
499 HRESULT hr;
501 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
502 &device, NULL, NULL)))
504 skip("Failed to create HAL device.\n");
505 if ((device = create_device(NULL)))
507 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
508 ID3D11Device_Release(device);
510 return;
513 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
514 trace("Feature level %#x.\n", supported_feature_level);
515 ID3D11Device_Release(device);
517 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
518 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
520 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
521 &feature_level, NULL);
522 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
523 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
524 feature_level, supported_feature_level);
526 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
527 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
528 &feature_level, NULL);
529 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
530 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
531 feature_level, supported_feature_level);
533 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
534 &immediate_context);
535 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
537 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
538 refcount = get_refcount((IUnknown *)immediate_context);
539 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
541 ID3D11DeviceContext_GetDevice(immediate_context, &device);
542 refcount = ID3D11Device_Release(device);
543 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
545 refcount = ID3D11DeviceContext_Release(immediate_context);
546 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
548 device = (ID3D11Device *)0xdeadbeef;
549 feature_level = 0xdeadbeef;
550 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
551 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
552 &device, &feature_level, &immediate_context);
553 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
554 ok(!device, "Got unexpected device pointer %p.\n", device);
555 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
556 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
558 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
560 swapchain_desc.BufferDesc.Width = 800;
561 swapchain_desc.BufferDesc.Height = 600;
562 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
563 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
564 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
565 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
566 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
567 swapchain_desc.SampleDesc.Count = 1;
568 swapchain_desc.SampleDesc.Quality = 0;
569 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
570 swapchain_desc.BufferCount = 1;
571 swapchain_desc.OutputWindow = window;
572 swapchain_desc.Windowed = TRUE;
573 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
574 swapchain_desc.Flags = 0;
576 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
577 &swapchain_desc, NULL, NULL, NULL, NULL);
578 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
580 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
581 &swapchain_desc, NULL, NULL, &feature_level, NULL);
582 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
583 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
584 feature_level, supported_feature_level);
586 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
587 &swapchain_desc, &swapchain, &device, NULL, NULL);
588 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
590 memset(&obtained_desc, 0, sizeof(obtained_desc));
591 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
592 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
593 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
594 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
595 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
596 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
597 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
598 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
599 obtained_desc.BufferDesc.RefreshRate.Numerator);
600 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
601 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
602 obtained_desc.BufferDesc.RefreshRate.Denominator);
603 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
604 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
605 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
606 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
607 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
608 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
609 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
610 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
611 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
612 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
613 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
614 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
615 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
616 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
617 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
618 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
619 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
620 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
621 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
622 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
623 ok(obtained_desc.Flags == swapchain_desc.Flags,
624 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
626 refcount = IDXGISwapChain_Release(swapchain);
627 ok(!refcount, "Swapchain has %u references left.\n", refcount);
629 feature_level = ID3D11Device_GetFeatureLevel(device);
630 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
631 feature_level, supported_feature_level);
633 refcount = ID3D11Device_Release(device);
634 ok(!refcount, "Device has %u references left.\n", refcount);
636 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
637 NULL, NULL, &device, NULL, NULL);
638 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
639 ID3D11Device_Release(device);
641 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
642 NULL, NULL, NULL, NULL, NULL);
643 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
645 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
646 NULL, NULL, NULL, &feature_level, NULL);
647 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
648 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
649 feature_level, supported_feature_level);
651 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
652 &swapchain_desc, NULL, NULL, NULL, NULL);
653 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
655 swapchain_desc.OutputWindow = NULL;
656 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
657 &swapchain_desc, NULL, &device, NULL, NULL);
658 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
659 ID3D11Device_Release(device);
661 swapchain = (IDXGISwapChain *)0xdeadbeef;
662 device = (ID3D11Device *)0xdeadbeef;
663 feature_level = 0xdeadbeef;
664 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
665 swapchain_desc.OutputWindow = NULL;
666 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
667 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
668 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
669 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
670 ok(!device, "Got unexpected device pointer %p.\n", device);
671 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
672 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
674 swapchain = (IDXGISwapChain *)0xdeadbeef;
675 device = (ID3D11Device *)0xdeadbeef;
676 feature_level = 0xdeadbeef;
677 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
678 swapchain_desc.OutputWindow = window;
679 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
680 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
681 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
682 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
683 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
684 ok(!device, "Got unexpected device pointer %p.\n", device);
685 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
686 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
688 DestroyWindow(window);
691 static void test_device_interfaces(void)
693 IDXGIAdapter *dxgi_adapter;
694 IDXGIDevice *dxgi_device;
695 ID3D11Device *device;
696 IUnknown *iface;
697 ULONG refcount;
698 unsigned int i;
699 HRESULT hr;
701 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
703 if (!(device = create_device(&d3d11_feature_levels[i])))
705 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels[i]);
706 continue;
709 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
710 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
711 IUnknown_Release(iface);
713 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
714 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
715 IUnknown_Release(iface);
717 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
718 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
719 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
720 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
721 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
722 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
723 IUnknown_Release(iface);
724 IDXGIAdapter_Release(dxgi_adapter);
725 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
726 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
727 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
728 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
729 IUnknown_Release(iface);
730 IDXGIAdapter_Release(dxgi_adapter);
731 IDXGIDevice_Release(dxgi_device);
733 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
734 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
735 IUnknown_Release(iface);
737 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
738 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
739 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
740 if (SUCCEEDED(hr)) IUnknown_Release(iface);
742 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
743 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
744 if (SUCCEEDED(hr)) IUnknown_Release(iface);
746 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
747 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
748 if (SUCCEEDED(hr)) IUnknown_Release(iface);
750 refcount = ID3D11Device_Release(device);
751 ok(!refcount, "Device has %u references left.\n", refcount);
755 static void test_get_immediate_context(void)
757 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
758 ULONG expected_refcount, refcount;
759 ID3D11Device *device;
761 if (!(device = create_device(NULL)))
763 skip("Failed to create device.\n");
764 return;
767 expected_refcount = get_refcount((IUnknown *)device) + 1;
768 ID3D11Device_GetImmediateContext(device, &immediate_context);
769 refcount = get_refcount((IUnknown *)device);
770 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
771 previous_immediate_context = immediate_context;
773 ID3D11Device_GetImmediateContext(device, &immediate_context);
774 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
775 refcount = get_refcount((IUnknown *)device);
776 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
778 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
779 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
780 refcount = ID3D11DeviceContext_Release(immediate_context);
781 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
783 ID3D11Device_GetImmediateContext(device, &immediate_context);
784 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
785 refcount = ID3D11DeviceContext_Release(immediate_context);
786 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
788 refcount = ID3D11Device_Release(device);
789 ok(!refcount, "Device has %u references left.\n", refcount);
792 static void test_create_texture2d(void)
794 ULONG refcount, expected_refcount;
795 D3D11_SUBRESOURCE_DATA data = {0};
796 ID3D11Device *device, *tmp;
797 D3D11_TEXTURE2D_DESC desc;
798 ID3D11Texture2D *texture;
799 UINT quality_level_count;
800 IDXGISurface *surface;
801 unsigned int i;
802 HRESULT hr;
804 static const struct
806 DXGI_FORMAT format;
807 D3D11_BIND_FLAG bind_flags;
808 BOOL succeeds;
809 BOOL todo;
811 tests[] =
813 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
814 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
815 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
816 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
817 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_RENDER_TARGET, TRUE, FALSE},
818 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
819 {DXGI_FORMAT_R32G32B32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
820 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
821 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_RENDER_TARGET, TRUE, FALSE},
822 {DXGI_FORMAT_R32G32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
823 {DXGI_FORMAT_R32G8X24_TYPELESS, D3D11_BIND_DEPTH_STENCIL, TRUE, TRUE},
824 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
825 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_RENDER_TARGET, TRUE, FALSE},
826 {DXGI_FORMAT_R32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
827 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
828 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
829 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
830 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
831 {DXGI_FORMAT_R24G8_TYPELESS, D3D11_BIND_DEPTH_STENCIL, TRUE, FALSE},
832 {DXGI_FORMAT_R8G8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
833 {DXGI_FORMAT_R16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
834 {DXGI_FORMAT_R8_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
835 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
836 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
837 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
840 if (!(device = create_device(NULL)))
842 skip("Failed to create device, skipping tests.\n");
843 return;
846 desc.Width = 512;
847 desc.Height = 512;
848 desc.MipLevels = 1;
849 desc.ArraySize = 1;
850 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
851 desc.SampleDesc.Count = 1;
852 desc.SampleDesc.Quality = 0;
853 desc.Usage = D3D11_USAGE_DEFAULT;
854 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
855 desc.CPUAccessFlags = 0;
856 desc.MiscFlags = 0;
858 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
859 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
861 expected_refcount = get_refcount((IUnknown *)device) + 1;
862 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
863 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
864 refcount = get_refcount((IUnknown *)device);
865 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
866 tmp = NULL;
867 expected_refcount = refcount + 1;
868 ID3D11Texture2D_GetDevice(texture, &tmp);
869 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
870 refcount = get_refcount((IUnknown *)device);
871 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
872 ID3D11Device_Release(tmp);
874 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
875 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
876 IDXGISurface_Release(surface);
877 ID3D11Texture2D_Release(texture);
879 desc.MipLevels = 0;
880 expected_refcount = get_refcount((IUnknown *)device) + 1;
881 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
882 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
883 refcount = get_refcount((IUnknown *)device);
884 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
885 tmp = NULL;
886 expected_refcount = refcount + 1;
887 ID3D11Texture2D_GetDevice(texture, &tmp);
888 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
889 refcount = get_refcount((IUnknown *)device);
890 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
891 ID3D11Device_Release(tmp);
893 ID3D11Texture2D_GetDesc(texture, &desc);
894 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
895 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
896 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
897 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
898 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
899 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
900 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
901 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
902 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
903 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
904 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
906 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
907 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
908 ID3D11Texture2D_Release(texture);
910 desc.MipLevels = 1;
911 desc.ArraySize = 2;
912 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
913 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
915 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
916 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
917 ID3D11Texture2D_Release(texture);
919 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
920 desc.ArraySize = 1;
921 desc.SampleDesc.Count = 2;
922 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
923 if (quality_level_count)
925 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
926 ID3D11Texture2D_Release(texture);
927 desc.SampleDesc.Quality = quality_level_count;
928 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
930 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
932 /* We assume 15 samples multisampling is never supported in practice. */
933 desc.SampleDesc.Count = 15;
934 desc.SampleDesc.Quality = 0;
935 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
936 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
938 desc.SampleDesc.Count = 1;
939 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
941 desc.Format = tests[i].format;
942 desc.BindFlags = tests[i].bind_flags;
943 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
945 todo_wine_if(tests[i].todo)
946 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
948 if (SUCCEEDED(hr))
949 ID3D11Texture2D_Release(texture);
952 refcount = ID3D11Device_Release(device);
953 ok(!refcount, "Device has %u references left.\n", refcount);
956 static void test_texture2d_interfaces(void)
958 ID3D10Texture2D *d3d10_texture;
959 D3D11_TEXTURE2D_DESC desc;
960 ID3D11Texture2D *texture;
961 IDXGISurface *surface;
962 ID3D11Device *device;
963 unsigned int i;
964 ULONG refcount;
965 HRESULT hr;
967 static const struct test
969 BOOL implements_d3d10_interfaces;
970 UINT bind_flags;
971 UINT misc_flags;
972 UINT expected_bind_flags;
973 UINT expected_misc_flags;
975 desc_conversion_tests[] =
978 TRUE,
979 D3D11_BIND_SHADER_RESOURCE, 0,
980 D3D10_BIND_SHADER_RESOURCE, 0
983 TRUE,
984 D3D11_BIND_UNORDERED_ACCESS, 0,
985 D3D11_BIND_UNORDERED_ACCESS, 0
988 FALSE,
989 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
990 0, 0
993 TRUE,
994 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
995 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
998 TRUE,
999 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1000 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1004 if (!(device = create_device(NULL)))
1006 skip("Failed to create ID3D11Device, skipping tests.\n");
1007 return;
1010 desc.Width = 512;
1011 desc.Height = 512;
1012 desc.MipLevels = 0;
1013 desc.ArraySize = 1;
1014 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1015 desc.SampleDesc.Count = 1;
1016 desc.SampleDesc.Quality = 0;
1017 desc.Usage = D3D11_USAGE_DEFAULT;
1018 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1019 desc.CPUAccessFlags = 0;
1020 desc.MiscFlags = 0;
1022 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1023 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1025 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1026 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1028 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1029 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1030 "Texture should implement ID3D10Texture2D.\n");
1031 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1032 ID3D11Texture2D_Release(texture);
1034 if (FAILED(hr))
1036 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1037 ID3D11Device_Release(device);
1038 return;
1041 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1043 const struct test *current = &desc_conversion_tests[i];
1044 D3D10_TEXTURE2D_DESC d3d10_desc;
1045 ID3D10Device *d3d10_device;
1047 desc.Width = 512;
1048 desc.Height = 512;
1049 desc.MipLevels = 1;
1050 desc.ArraySize = 1;
1051 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1052 desc.SampleDesc.Count = 1;
1053 desc.SampleDesc.Quality = 0;
1054 desc.Usage = D3D11_USAGE_DEFAULT;
1055 desc.BindFlags = current->bind_flags;
1056 desc.CPUAccessFlags = 0;
1057 desc.MiscFlags = current->misc_flags;
1059 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1060 /* Shared resources are not supported by REF and WARP devices. */
1061 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1062 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1063 if (FAILED(hr))
1065 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1066 continue;
1069 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1070 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1071 IDXGISurface_Release(surface);
1073 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1074 ID3D11Texture2D_Release(texture);
1076 if (current->implements_d3d10_interfaces)
1078 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
1080 else
1082 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
1083 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1084 continue;
1087 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
1089 ok(d3d10_desc.Width == desc.Width,
1090 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1091 ok(d3d10_desc.Height == desc.Height,
1092 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1093 ok(d3d10_desc.MipLevels == desc.MipLevels,
1094 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1095 ok(d3d10_desc.ArraySize == desc.ArraySize,
1096 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
1097 ok(d3d10_desc.Format == desc.Format,
1098 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1099 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
1100 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
1101 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1102 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
1103 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1104 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1105 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1106 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1107 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1108 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1109 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1110 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1112 d3d10_device = (ID3D10Device *)0xdeadbeef;
1113 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
1114 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1115 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1117 ID3D10Texture2D_Release(d3d10_texture);
1120 refcount = ID3D11Device_Release(device);
1121 ok(!refcount, "Device has %u references left.\n", refcount);
1124 static void test_create_texture3d(void)
1126 ULONG refcount, expected_refcount;
1127 D3D11_SUBRESOURCE_DATA data = {0};
1128 ID3D11Device *device, *tmp;
1129 D3D11_TEXTURE3D_DESC desc;
1130 ID3D11Texture3D *texture;
1131 IDXGISurface *surface;
1132 unsigned int i;
1133 HRESULT hr;
1135 static const struct
1137 DXGI_FORMAT format;
1138 D3D11_BIND_FLAG bind_flags;
1139 BOOL succeeds;
1140 BOOL todo;
1142 tests[] =
1144 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
1145 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
1146 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1147 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1148 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1149 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1150 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
1151 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1152 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1155 if (!(device = create_device(NULL)))
1157 skip("Failed to create ID3D11Device, skipping tests.\n");
1158 return;
1161 desc.Width = 64;
1162 desc.Height = 64;
1163 desc.Depth = 64;
1164 desc.MipLevels = 1;
1165 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1166 desc.Usage = D3D11_USAGE_DEFAULT;
1167 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1168 desc.CPUAccessFlags = 0;
1169 desc.MiscFlags = 0;
1171 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
1172 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1174 expected_refcount = get_refcount((IUnknown *)device) + 1;
1175 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1176 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1177 refcount = get_refcount((IUnknown *)device);
1178 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1179 tmp = NULL;
1180 expected_refcount = refcount + 1;
1181 ID3D11Texture3D_GetDevice(texture, &tmp);
1182 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1183 refcount = get_refcount((IUnknown *)device);
1184 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1185 ID3D11Device_Release(tmp);
1187 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1188 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1189 ID3D11Texture3D_Release(texture);
1191 desc.MipLevels = 0;
1192 expected_refcount = get_refcount((IUnknown *)device) + 1;
1193 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1194 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1195 refcount = get_refcount((IUnknown *)device);
1196 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1197 tmp = NULL;
1198 expected_refcount = refcount + 1;
1199 ID3D11Texture3D_GetDevice(texture, &tmp);
1200 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1201 refcount = get_refcount((IUnknown *)device);
1202 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1203 ID3D11Device_Release(tmp);
1205 ID3D11Texture3D_GetDesc(texture, &desc);
1206 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1207 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1208 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1209 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1210 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1211 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1212 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1213 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1214 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1216 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1217 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1218 ID3D11Texture3D_Release(texture);
1220 desc.MipLevels = 1;
1221 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1223 desc.Format = tests[i].format;
1224 desc.BindFlags = tests[i].bind_flags;
1225 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
1227 todo_wine_if(tests[i].todo)
1228 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1230 if (SUCCEEDED(hr))
1231 ID3D11Texture3D_Release(texture);
1234 refcount = ID3D11Device_Release(device);
1235 ok(!refcount, "Device has %u references left.\n", refcount);
1238 static void test_texture3d_interfaces(void)
1240 ID3D10Texture3D *d3d10_texture;
1241 D3D11_TEXTURE3D_DESC desc;
1242 ID3D11Texture3D *texture;
1243 IDXGISurface *surface;
1244 ID3D11Device *device;
1245 unsigned int i;
1246 ULONG refcount;
1247 HRESULT hr;
1249 static const struct test
1251 BOOL implements_d3d10_interfaces;
1252 UINT bind_flags;
1253 UINT misc_flags;
1254 UINT expected_bind_flags;
1255 UINT expected_misc_flags;
1257 desc_conversion_tests[] =
1260 TRUE,
1261 D3D11_BIND_SHADER_RESOURCE, 0,
1262 D3D10_BIND_SHADER_RESOURCE, 0
1265 TRUE,
1266 D3D11_BIND_UNORDERED_ACCESS, 0,
1267 D3D11_BIND_UNORDERED_ACCESS, 0
1270 FALSE,
1271 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1272 0, 0
1275 TRUE,
1276 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1277 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1281 if (!(device = create_device(NULL)))
1283 skip("Failed to create ID3D11Device.\n");
1284 return;
1287 desc.Width = 64;
1288 desc.Height = 64;
1289 desc.Depth = 64;
1290 desc.MipLevels = 0;
1291 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1292 desc.Usage = D3D11_USAGE_DEFAULT;
1293 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1294 desc.CPUAccessFlags = 0;
1295 desc.MiscFlags = 0;
1297 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1298 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1300 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1301 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1303 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1304 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1305 "Texture should implement ID3D10Texture3D.\n");
1306 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1307 ID3D11Texture3D_Release(texture);
1309 if (FAILED(hr))
1311 win_skip("3D textures do not implement ID3D10Texture3D.\n");
1312 ID3D11Device_Release(device);
1313 return;
1316 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1318 const struct test *current = &desc_conversion_tests[i];
1319 D3D10_TEXTURE3D_DESC d3d10_desc;
1320 ID3D10Device *d3d10_device;
1322 desc.Width = 64;
1323 desc.Height = 64;
1324 desc.Depth = 64;
1325 desc.MipLevels = 1;
1326 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1327 desc.Usage = D3D11_USAGE_DEFAULT;
1328 desc.BindFlags = current->bind_flags;
1329 desc.CPUAccessFlags = 0;
1330 desc.MiscFlags = current->misc_flags;
1332 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1333 /* Shared resources are not supported by REF and WARP devices. */
1334 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1335 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
1336 if (FAILED(hr))
1338 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
1339 continue;
1342 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1343 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1345 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1346 ID3D11Texture3D_Release(texture);
1348 if (current->implements_d3d10_interfaces)
1350 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
1352 else
1354 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
1355 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1356 continue;
1359 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
1361 ok(d3d10_desc.Width == desc.Width,
1362 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1363 ok(d3d10_desc.Height == desc.Height,
1364 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1365 ok(d3d10_desc.Depth == desc.Depth,
1366 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
1367 ok(d3d10_desc.MipLevels == desc.MipLevels,
1368 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1369 ok(d3d10_desc.Format == desc.Format,
1370 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1371 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1372 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1373 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1374 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1375 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1376 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1377 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1378 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1380 d3d10_device = (ID3D10Device *)0xdeadbeef;
1381 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
1382 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1383 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1385 ID3D10Texture3D_Release(d3d10_texture);
1388 refcount = ID3D11Device_Release(device);
1389 ok(!refcount, "Device has %u references left.\n", refcount);
1392 static void test_buffer_interfaces(void)
1394 ID3D10Buffer *d3d10_buffer;
1395 D3D11_BUFFER_DESC desc;
1396 ID3D11Buffer *buffer;
1397 ID3D11Device *device;
1398 unsigned int i;
1399 ULONG refcount;
1400 HRESULT hr;
1402 static const struct test
1404 BOOL implements_d3d10_interfaces;
1405 UINT bind_flags;
1406 UINT misc_flags;
1407 UINT structure_stride;
1408 UINT expected_bind_flags;
1409 UINT expected_misc_flags;
1411 desc_conversion_tests[] =
1414 TRUE,
1415 D3D11_BIND_VERTEX_BUFFER, 0, 0,
1416 D3D10_BIND_VERTEX_BUFFER, 0
1419 TRUE,
1420 D3D11_BIND_INDEX_BUFFER, 0, 0,
1421 D3D10_BIND_INDEX_BUFFER, 0
1424 TRUE,
1425 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
1426 D3D10_BIND_CONSTANT_BUFFER, 0
1429 TRUE,
1430 D3D11_BIND_SHADER_RESOURCE, 0, 0,
1431 D3D10_BIND_SHADER_RESOURCE, 0
1434 TRUE,
1435 D3D11_BIND_STREAM_OUTPUT, 0, 0,
1436 D3D10_BIND_STREAM_OUTPUT, 0
1439 TRUE,
1440 D3D11_BIND_RENDER_TARGET, 0, 0,
1441 D3D10_BIND_RENDER_TARGET, 0
1444 TRUE,
1445 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
1446 D3D11_BIND_UNORDERED_ACCESS, 0
1449 TRUE,
1450 0, D3D11_RESOURCE_MISC_SHARED, 0,
1451 0, D3D10_RESOURCE_MISC_SHARED
1454 TRUE,
1455 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
1456 0, 0
1459 TRUE,
1460 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
1461 D3D10_BIND_SHADER_RESOURCE, 0
1464 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
1465 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
1466 0, 0
1469 TRUE,
1470 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
1471 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1475 if (!(device = create_device(NULL)))
1477 skip("Failed to create ID3D11Device.\n");
1478 return;
1481 desc.ByteWidth = 1024;
1482 desc.Usage = D3D11_USAGE_DEFAULT;
1483 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1484 desc.CPUAccessFlags = 0;
1485 desc.MiscFlags = 0;
1486 desc.StructureByteStride = 0;
1488 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1489 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1491 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1492 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1493 "Buffer should implement ID3D10Buffer.\n");
1494 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1495 ID3D11Buffer_Release(buffer);
1497 if (FAILED(hr))
1499 win_skip("Buffers do not implement ID3D10Buffer.\n");
1500 ID3D11Device_Release(device);
1501 return;
1504 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1506 const struct test *current = &desc_conversion_tests[i];
1507 D3D10_BUFFER_DESC d3d10_desc;
1508 ID3D10Device *d3d10_device;
1510 desc.ByteWidth = 1024;
1511 desc.Usage = D3D11_USAGE_DEFAULT;
1512 desc.BindFlags = current->bind_flags;
1513 desc.CPUAccessFlags = 0;
1514 desc.MiscFlags = current->misc_flags;
1515 desc.StructureByteStride = current->structure_stride;
1517 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1518 /* Shared resources are not supported by REF and WARP devices. */
1519 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1520 if (FAILED(hr))
1522 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1523 continue;
1526 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1527 ID3D11Buffer_Release(buffer);
1529 if (current->implements_d3d10_interfaces)
1531 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
1533 else
1535 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
1536 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1537 continue;
1540 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
1542 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
1543 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
1544 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1545 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1546 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1547 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1548 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1549 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1550 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1551 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1553 d3d10_device = (ID3D10Device *)0xdeadbeef;
1554 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
1555 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1556 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1558 ID3D10Buffer_Release(d3d10_buffer);
1561 refcount = ID3D11Device_Release(device);
1562 ok(!refcount, "Device has %u references left.\n", refcount);
1565 static void test_create_depthstencil_view(void)
1567 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1568 D3D11_TEXTURE2D_DESC texture_desc;
1569 ULONG refcount, expected_refcount;
1570 ID3D11DepthStencilView *dsview;
1571 ID3D11Device *device, *tmp;
1572 ID3D11Texture2D *texture;
1573 HRESULT hr;
1575 if (!(device = create_device(NULL)))
1577 skip("Failed to create device.\n");
1578 return;
1581 texture_desc.Width = 512;
1582 texture_desc.Height = 512;
1583 texture_desc.MipLevels = 1;
1584 texture_desc.ArraySize = 1;
1585 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1586 texture_desc.SampleDesc.Count = 1;
1587 texture_desc.SampleDesc.Quality = 0;
1588 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1589 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1590 texture_desc.CPUAccessFlags = 0;
1591 texture_desc.MiscFlags = 0;
1593 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1594 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1596 expected_refcount = get_refcount((IUnknown *)device) + 1;
1597 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1598 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1599 refcount = get_refcount((IUnknown *)device);
1600 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1601 tmp = NULL;
1602 expected_refcount = refcount + 1;
1603 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
1604 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1605 refcount = get_refcount((IUnknown *)device);
1606 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1607 ID3D11Device_Release(tmp);
1609 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1610 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1611 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1612 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1613 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1614 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1616 ID3D11DepthStencilView_Release(dsview);
1618 dsv_desc.Format = DXGI_FORMAT_UNKNOWN;
1619 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1620 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1622 memset(&dsv_desc, 0, sizeof(dsv_desc));
1623 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1624 todo_wine ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1625 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1626 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1627 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1628 ok(!U(dsv_desc).Texture2D.MipSlice, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1630 ID3D11DepthStencilView_Release(dsview);
1632 ID3D11Texture2D_Release(texture);
1634 refcount = ID3D11Device_Release(device);
1635 ok(!refcount, "Device has %u references left.\n", refcount);
1638 static void test_depthstencil_view_interfaces(void)
1640 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
1641 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1642 ID3D10DepthStencilView *d3d10_dsview;
1643 D3D11_TEXTURE2D_DESC texture_desc;
1644 ID3D11DepthStencilView *dsview;
1645 ID3D11Texture2D *texture;
1646 ID3D11Device *device;
1647 ULONG refcount;
1648 HRESULT hr;
1650 if (!(device = create_device(NULL)))
1652 skip("Failed to create device.\n");
1653 return;
1656 texture_desc.Width = 512;
1657 texture_desc.Height = 512;
1658 texture_desc.MipLevels = 1;
1659 texture_desc.ArraySize = 1;
1660 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1661 texture_desc.SampleDesc.Count = 1;
1662 texture_desc.SampleDesc.Quality = 0;
1663 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1664 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1665 texture_desc.CPUAccessFlags = 0;
1666 texture_desc.MiscFlags = 0;
1668 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1669 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1671 dsv_desc.Format = texture_desc.Format;
1672 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
1673 dsv_desc.Flags = 0;
1674 U(dsv_desc).Texture2D.MipSlice = 0;
1676 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1677 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1679 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
1680 ID3D11DepthStencilView_Release(dsview);
1681 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1682 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1684 if (FAILED(hr))
1686 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1687 goto done;
1690 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
1691 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
1692 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
1693 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
1694 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
1695 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
1697 ID3D10DepthStencilView_Release(d3d10_dsview);
1699 done:
1700 ID3D11Texture2D_Release(texture);
1702 refcount = ID3D11Device_Release(device);
1703 ok(!refcount, "Device has %u references left.\n", refcount);
1706 static void test_create_rendertarget_view(void)
1708 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
1709 D3D11_SUBRESOURCE_DATA data = {0};
1710 D3D11_TEXTURE2D_DESC texture_desc;
1711 ULONG refcount, expected_refcount;
1712 D3D11_BUFFER_DESC buffer_desc;
1713 ID3D11RenderTargetView *rtview;
1714 ID3D11Device *device, *tmp;
1715 ID3D11Texture2D *texture;
1716 ID3D11Buffer *buffer;
1717 IUnknown *iface;
1718 HRESULT hr;
1720 if (!(device = create_device(NULL)))
1722 skip("Failed to create device.\n");
1723 return;
1726 buffer_desc.ByteWidth = 1024;
1727 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1728 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1729 buffer_desc.CPUAccessFlags = 0;
1730 buffer_desc.MiscFlags = 0;
1731 buffer_desc.StructureByteStride = 0;
1733 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
1734 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1736 expected_refcount = get_refcount((IUnknown *)device) + 1;
1737 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1738 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1739 refcount = get_refcount((IUnknown *)device);
1740 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1741 tmp = NULL;
1742 expected_refcount = refcount + 1;
1743 ID3D11Buffer_GetDevice(buffer, &tmp);
1744 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1745 refcount = get_refcount((IUnknown *)device);
1746 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1747 ID3D11Device_Release(tmp);
1749 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1750 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
1751 U(rtv_desc).Buffer.ElementOffset = 0;
1752 U(rtv_desc).Buffer.ElementWidth = 64;
1754 expected_refcount = get_refcount((IUnknown *)device) + 1;
1755 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
1756 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1757 refcount = get_refcount((IUnknown *)device);
1758 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1759 tmp = NULL;
1760 expected_refcount = refcount + 1;
1761 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
1762 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1763 refcount = get_refcount((IUnknown *)device);
1764 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1765 ID3D11Device_Release(tmp);
1767 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1768 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1769 "Render target view should implement ID3D10RenderTargetView.\n");
1770 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1772 ID3D11RenderTargetView_Release(rtview);
1773 ID3D11Buffer_Release(buffer);
1775 texture_desc.Width = 512;
1776 texture_desc.Height = 512;
1777 texture_desc.MipLevels = 1;
1778 texture_desc.ArraySize = 1;
1779 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1780 texture_desc.SampleDesc.Count = 1;
1781 texture_desc.SampleDesc.Quality = 0;
1782 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1783 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1784 texture_desc.CPUAccessFlags = 0;
1785 texture_desc.MiscFlags = 0;
1787 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1788 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1790 /* For texture resources it's allowed to specify NULL as desc */
1791 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1792 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1794 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1795 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1796 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1797 rtv_desc.ViewDimension);
1798 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1800 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1801 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1802 "Render target view should implement ID3D10RenderTargetView.\n");
1803 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1805 ID3D11RenderTargetView_Release(rtview);
1807 rtv_desc.Format = DXGI_FORMAT_UNKNOWN;
1808 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtview);
1809 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1811 memset(&rtv_desc, 0, sizeof(rtv_desc));
1812 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1813 todo_wine ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1814 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1815 rtv_desc.ViewDimension);
1816 ok(!U(rtv_desc).Texture2D.MipSlice, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1818 ID3D11RenderTargetView_Release(rtview);
1820 ID3D11Texture2D_Release(texture);
1822 refcount = ID3D11Device_Release(device);
1823 ok(!refcount, "Device has %u references left.\n", refcount);
1826 static void test_create_shader_resource_view(void)
1828 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
1829 D3D11_TEXTURE2D_DESC texture_desc;
1830 ULONG refcount, expected_refcount;
1831 ID3D11ShaderResourceView *srview;
1832 D3D11_BUFFER_DESC buffer_desc;
1833 ID3D11Device *device, *tmp;
1834 ID3D11Texture2D *texture;
1835 ID3D11Buffer *buffer;
1836 IUnknown *iface;
1837 HRESULT hr;
1839 if (!(device = create_device(NULL)))
1841 skip("Failed to create device.\n");
1842 return;
1845 buffer_desc.ByteWidth = 1024;
1846 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1847 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1848 buffer_desc.CPUAccessFlags = 0;
1849 buffer_desc.MiscFlags = 0;
1850 buffer_desc.StructureByteStride = 0;
1852 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1853 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1855 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
1856 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1858 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1859 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
1860 U(srv_desc).Buffer.ElementOffset = 0;
1861 U(srv_desc).Buffer.ElementWidth = 64;
1863 expected_refcount = get_refcount((IUnknown *)device) + 1;
1864 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
1865 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1866 refcount = get_refcount((IUnknown *)device);
1867 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1868 tmp = NULL;
1869 expected_refcount = refcount + 1;
1870 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
1871 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1872 refcount = get_refcount((IUnknown *)device);
1873 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1874 ID3D11Device_Release(tmp);
1876 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1877 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1878 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1879 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1880 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1881 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1882 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1883 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1885 ID3D11ShaderResourceView_Release(srview);
1886 ID3D11Buffer_Release(buffer);
1888 texture_desc.Width = 512;
1889 texture_desc.Height = 512;
1890 texture_desc.MipLevels = 0;
1891 texture_desc.ArraySize = 1;
1892 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1893 texture_desc.SampleDesc.Count = 1;
1894 texture_desc.SampleDesc.Quality = 0;
1895 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1896 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1897 texture_desc.CPUAccessFlags = 0;
1898 texture_desc.MiscFlags = 0;
1900 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1901 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1903 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
1904 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1906 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1907 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1908 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1909 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1910 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1911 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1912 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1913 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1915 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1916 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1917 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1918 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1919 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1920 U(srv_desc).Texture2D.MostDetailedMip);
1921 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1923 ID3D11ShaderResourceView_Release(srview);
1925 srv_desc.Format = DXGI_FORMAT_UNKNOWN;
1926 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srview);
1927 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1929 memset(&srv_desc, 0, sizeof(srv_desc));
1930 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1931 todo_wine ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1932 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1933 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1934 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1935 U(srv_desc).Texture2D.MostDetailedMip);
1936 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1938 ID3D11ShaderResourceView_Release(srview);
1940 ID3D11Texture2D_Release(texture);
1942 refcount = ID3D11Device_Release(device);
1943 ok(!refcount, "Device has %u references left.\n", refcount);
1946 static void test_create_shader(void)
1948 #if 0
1949 float4 light;
1950 float4x4 mat;
1952 struct input
1954 float4 position : POSITION;
1955 float3 normal : NORMAL;
1958 struct output
1960 float4 position : POSITION;
1961 float4 diffuse : COLOR;
1964 output main(const input v)
1966 output o;
1968 o.position = mul(v.position, mat);
1969 o.diffuse = dot((float3)light, v.normal);
1971 return o;
1973 #endif
1974 static const DWORD vs_4_0[] =
1976 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1977 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1978 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1979 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1980 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1981 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1982 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1983 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1984 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1985 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1986 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1987 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1988 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1989 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1990 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1991 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1994 static const DWORD vs_2_0[] =
1996 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1997 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1998 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1999 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2000 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2001 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2002 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2003 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
2004 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
2005 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
2006 0x90e40001, 0x0000ffff,
2009 static const DWORD vs_3_0[] =
2011 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
2012 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2013 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2014 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2015 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2016 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2017 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2018 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
2019 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
2020 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
2021 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
2022 0x0000ffff,
2025 #if 0
2026 float4 main(const float4 color : COLOR) : SV_TARGET
2028 float4 o;
2030 o = color;
2032 return o;
2034 #endif
2035 static const DWORD ps_4_0[] =
2037 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
2038 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
2039 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
2040 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
2041 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
2042 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
2043 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2044 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2045 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2046 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
2047 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
2048 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
2049 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2050 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
2051 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2052 0x00000000, 0x00000000,
2054 static const DWORD ps_4_0_level_9_0[] =
2056 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
2057 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
2058 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
2059 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
2060 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
2061 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
2062 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
2063 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
2064 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
2065 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
2066 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
2067 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2068 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
2069 0xabab0054,
2071 static const DWORD ps_4_0_level_9_1[] =
2073 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
2074 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
2075 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
2076 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
2077 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
2078 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2079 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
2080 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2081 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
2082 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2083 0x45475241, 0xabab0054,
2085 static const DWORD ps_4_0_level_9_3[] =
2087 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
2088 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
2089 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
2090 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
2091 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
2092 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2093 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
2094 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2095 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
2096 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2097 0x45475241, 0xabab0054,
2100 #if 0
2101 struct gs_out
2103 float4 pos : SV_POSITION;
2106 [maxvertexcount(4)]
2107 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
2109 float offset = 0.1 * vin[0].w;
2110 gs_out v;
2112 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
2113 vout.Append(v);
2114 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
2115 vout.Append(v);
2116 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
2117 vout.Append(v);
2118 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
2119 vout.Append(v);
2121 #endif
2122 static const DWORD gs_4_0[] =
2124 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
2125 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2126 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2127 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2128 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
2129 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
2130 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
2131 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2132 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
2133 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2134 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
2135 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
2136 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
2137 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
2138 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
2139 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2140 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
2141 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2144 ULONG refcount, expected_refcount;
2145 ID3D11Device *device, *tmp;
2146 ID3D11GeometryShader *gs;
2147 ID3D11VertexShader *vs;
2148 ID3D11PixelShader *ps;
2149 IUnknown *iface;
2150 unsigned int i;
2151 HRESULT hr;
2153 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
2155 D3D_FEATURE_LEVEL feature_level = d3d11_feature_levels[i];
2156 BOOL todo = feature_level <= D3D_FEATURE_LEVEL_9_3;
2158 if (!(device = create_device(&feature_level)))
2160 skip("Failed to create device for feature level %#x.\n", feature_level);
2161 continue;
2164 /* level_9 shaders */
2165 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
2166 todo_wine_if(todo)
2167 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2168 if (SUCCEEDED(hr))
2169 ID3D11PixelShader_Release(ps);
2171 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
2172 todo_wine_if(todo)
2173 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2174 if (SUCCEEDED(hr))
2175 ID3D11PixelShader_Release(ps);
2177 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
2178 todo_wine_if(todo)
2179 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2180 if (SUCCEEDED(hr))
2181 ID3D11PixelShader_Release(ps);
2183 /* vertex shader */
2184 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
2185 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2187 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
2188 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2190 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
2191 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
2192 hr, feature_level);
2194 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2195 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
2196 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2197 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2198 else
2199 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2201 refcount = get_refcount((IUnknown *)device);
2202 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2203 refcount, expected_refcount);
2204 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2206 tmp = NULL;
2207 expected_refcount = refcount + 1;
2208 ID3D11VertexShader_GetDevice(vs, &tmp);
2209 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2210 refcount = get_refcount((IUnknown *)device);
2211 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2212 refcount, expected_refcount);
2213 ID3D11Device_Release(tmp);
2215 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
2216 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2217 "Vertex shader should implement ID3D10VertexShader.\n");
2218 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2220 refcount = ID3D11VertexShader_Release(vs);
2221 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2224 /* pixel shader */
2225 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2226 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
2227 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2228 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2229 else
2230 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2232 refcount = get_refcount((IUnknown *)device);
2233 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2234 refcount, expected_refcount);
2235 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2237 tmp = NULL;
2238 expected_refcount = refcount + 1;
2239 ID3D11PixelShader_GetDevice(ps, &tmp);
2240 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2241 refcount = get_refcount((IUnknown *)device);
2242 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2243 refcount, expected_refcount);
2244 ID3D11Device_Release(tmp);
2246 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
2247 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2248 "Pixel shader should implement ID3D10PixelShader.\n");
2249 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2251 refcount = ID3D11PixelShader_Release(ps);
2252 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
2255 /* geometry shader */
2256 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2257 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
2258 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2259 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2260 else
2261 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2263 refcount = get_refcount((IUnknown *)device);
2264 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2265 refcount, expected_refcount);
2266 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2268 tmp = NULL;
2269 expected_refcount = refcount + 1;
2270 ID3D11GeometryShader_GetDevice(gs, &tmp);
2271 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2272 refcount = get_refcount((IUnknown *)device);
2273 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2274 refcount, expected_refcount);
2275 ID3D11Device_Release(tmp);
2277 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
2278 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2279 "Geometry shader should implement ID3D10GeometryShader.\n");
2280 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2282 refcount = ID3D11GeometryShader_Release(gs);
2283 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
2286 refcount = ID3D11Device_Release(device);
2287 ok(!refcount, "Device has %u references left.\n", refcount);
2291 static void test_create_sampler_state(void)
2293 static const struct test
2295 D3D11_FILTER filter;
2296 D3D10_FILTER expected_filter;
2298 desc_conversion_tests[] =
2300 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
2301 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
2302 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
2303 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
2304 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
2305 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
2306 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
2307 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
2308 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
2309 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
2310 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
2312 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
2313 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
2315 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
2316 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
2318 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
2319 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
2321 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
2322 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
2323 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
2326 ID3D11SamplerState *sampler_state1, *sampler_state2;
2327 ID3D10SamplerState *d3d10_sampler_state;
2328 ULONG refcount, expected_refcount;
2329 ID3D11Device *device, *tmp;
2330 D3D11_SAMPLER_DESC desc;
2331 unsigned int i;
2332 HRESULT hr;
2334 if (!(device = create_device(NULL)))
2336 skip("Failed to create device.\n");
2337 return;
2340 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
2341 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2343 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
2344 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2345 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2346 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
2347 desc.MipLODBias = 0.0f;
2348 desc.MaxAnisotropy = 16;
2349 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2350 desc.BorderColor[0] = 0.0f;
2351 desc.BorderColor[1] = 1.0f;
2352 desc.BorderColor[2] = 0.0f;
2353 desc.BorderColor[3] = 1.0f;
2354 desc.MinLOD = 0.0f;
2355 desc.MaxLOD = 16.0f;
2357 expected_refcount = get_refcount((IUnknown *)device) + 1;
2358 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2359 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2360 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
2361 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2362 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
2363 refcount = get_refcount((IUnknown *)device);
2364 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2365 tmp = NULL;
2366 expected_refcount = refcount + 1;
2367 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
2368 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2369 refcount = get_refcount((IUnknown *)device);
2370 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2371 ID3D11Device_Release(tmp);
2373 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
2374 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
2375 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
2376 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
2377 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
2378 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
2379 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
2380 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
2381 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
2382 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
2383 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
2384 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
2385 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
2387 refcount = ID3D11SamplerState_Release(sampler_state2);
2388 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2389 refcount = ID3D11SamplerState_Release(sampler_state1);
2390 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2392 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2394 const struct test *current = &desc_conversion_tests[i];
2395 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
2397 desc.Filter = current->filter;
2398 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2399 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2400 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
2401 desc.MipLODBias = 0.0f;
2402 desc.MaxAnisotropy = 16;
2403 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2404 desc.BorderColor[0] = 0.0f;
2405 desc.BorderColor[1] = 1.0f;
2406 desc.BorderColor[2] = 0.0f;
2407 desc.BorderColor[3] = 1.0f;
2408 desc.MinLOD = 0.0f;
2409 desc.MaxLOD = 16.0f;
2411 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2412 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
2414 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
2415 (void **)&d3d10_sampler_state);
2416 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2417 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
2418 if (FAILED(hr))
2420 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
2421 ID3D11SamplerState_Release(sampler_state1);
2422 break;
2425 memcpy(&expected_desc, &desc, sizeof(expected_desc));
2426 expected_desc.Filter = current->expected_filter;
2427 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
2428 expected_desc.MaxAnisotropy = 0;
2429 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
2430 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2432 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
2433 ok(d3d10_desc.Filter == expected_desc.Filter,
2434 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
2435 ok(d3d10_desc.AddressU == expected_desc.AddressU,
2436 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
2437 ok(d3d10_desc.AddressV == expected_desc.AddressV,
2438 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
2439 ok(d3d10_desc.AddressW == expected_desc.AddressW,
2440 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
2441 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
2442 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
2443 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
2444 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
2445 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
2446 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
2447 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
2448 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
2449 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
2450 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
2451 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
2452 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
2453 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
2454 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
2455 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
2456 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
2457 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
2459 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
2460 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2461 refcount = ID3D11SamplerState_Release(sampler_state1);
2462 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2465 refcount = ID3D11Device_Release(device);
2466 ok(!refcount, "Device has %u references left.\n", refcount);
2469 static void test_create_blend_state(void)
2471 static const D3D11_BLEND_DESC desc_conversion_tests[] =
2474 FALSE, FALSE,
2477 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2478 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
2483 FALSE, TRUE,
2486 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2487 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2490 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2491 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
2494 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2495 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2498 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2499 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
2502 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2503 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2506 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2507 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2510 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2511 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2514 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2515 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2520 FALSE, TRUE,
2523 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2524 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2527 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
2528 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2531 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
2532 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2535 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2536 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2539 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
2540 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2543 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
2544 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2547 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2548 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2551 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2552 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2558 ID3D11BlendState *blend_state1, *blend_state2;
2559 D3D11_BLEND_DESC desc, obtained_desc;
2560 ID3D10BlendState *d3d10_blend_state;
2561 D3D10_BLEND_DESC d3d10_blend_desc;
2562 ULONG refcount, expected_refcount;
2563 ID3D11Device *device, *tmp;
2564 unsigned int i, j;
2565 IUnknown *iface;
2566 HRESULT hr;
2568 if (!(device = create_device(NULL)))
2570 skip("Failed to create device.\n");
2571 return;
2574 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
2575 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2577 memset(&desc, 0, sizeof(desc));
2578 desc.AlphaToCoverageEnable = FALSE;
2579 desc.IndependentBlendEnable = FALSE;
2580 desc.RenderTarget[0].BlendEnable = FALSE;
2581 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
2582 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
2583 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2584 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
2585 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2586 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2587 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2589 expected_refcount = get_refcount((IUnknown *)device) + 1;
2590 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
2591 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2592 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
2593 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2594 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
2595 refcount = get_refcount((IUnknown *)device);
2596 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2597 tmp = NULL;
2598 expected_refcount = refcount + 1;
2599 ID3D11BlendState_GetDevice(blend_state1, &tmp);
2600 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2601 refcount = get_refcount((IUnknown *)device);
2602 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2603 ID3D11Device_Release(tmp);
2605 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
2606 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
2607 obtained_desc.AlphaToCoverageEnable);
2608 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
2609 obtained_desc.IndependentBlendEnable);
2610 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2612 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
2613 "Got unexpected blend enable %#x for render target %u.\n",
2614 obtained_desc.RenderTarget[i].BlendEnable, i);
2615 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
2616 "Got unexpected src blend %u for render target %u.\n",
2617 obtained_desc.RenderTarget[i].SrcBlend, i);
2618 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
2619 "Got unexpected dest blend %u for render target %u.\n",
2620 obtained_desc.RenderTarget[i].DestBlend, i);
2621 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
2622 "Got unexpected blend op %u for render target %u.\n",
2623 obtained_desc.RenderTarget[i].BlendOp, i);
2624 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
2625 "Got unexpected src blend alpha %u for render target %u.\n",
2626 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
2627 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
2628 "Got unexpected dest blend alpha %u for render target %u.\n",
2629 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
2630 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
2631 "Got unexpected blend op alpha %u for render target %u.\n",
2632 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
2633 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
2634 "Got unexpected render target write mask %#x for render target %u.\n",
2635 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
2638 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
2639 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2640 "Blend state should implement ID3D10BlendState.\n");
2641 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2642 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
2643 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2644 "Blend state should implement ID3D10BlendState1.\n");
2645 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2647 refcount = ID3D11BlendState_Release(blend_state1);
2648 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2649 refcount = ID3D11BlendState_Release(blend_state2);
2650 ok(!refcount, "Blend state has %u references left.\n", refcount);
2652 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2654 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
2656 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
2657 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2659 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
2660 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2661 "Blend state should implement ID3D10BlendState.\n");
2662 if (FAILED(hr))
2664 win_skip("Blend state does not implement ID3D10BlendState.\n");
2665 ID3D11BlendState_Release(blend_state1);
2666 break;
2669 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
2670 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
2671 "Got unexpected alpha to coverage enable %#x for test %u.\n",
2672 d3d10_blend_desc.AlphaToCoverageEnable, i);
2673 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
2674 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
2675 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
2676 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
2677 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
2678 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
2679 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
2680 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
2681 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
2682 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
2683 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
2684 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
2685 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
2687 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
2688 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
2689 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2690 d3d10_blend_desc.BlendEnable[j], i, j);
2691 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
2692 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2693 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
2696 ID3D10BlendState_Release(d3d10_blend_state);
2698 refcount = ID3D11BlendState_Release(blend_state1);
2699 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2702 refcount = ID3D11Device_Release(device);
2703 ok(!refcount, "Device has %u references left.\n", refcount);
2706 static void test_create_depthstencil_state(void)
2708 ID3D11DepthStencilState *ds_state1, *ds_state2;
2709 ID3D10DepthStencilState *d3d10_ds_state;
2710 ULONG refcount, expected_refcount;
2711 D3D11_DEPTH_STENCIL_DESC ds_desc;
2712 ID3D11Device *device, *tmp;
2713 HRESULT hr;
2715 if (!(device = create_device(NULL)))
2717 skip("Failed to create device.\n");
2718 return;
2721 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
2722 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2724 ds_desc.DepthEnable = TRUE;
2725 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2726 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
2727 ds_desc.StencilEnable = FALSE;
2728 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2729 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2730 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2731 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2732 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2733 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2734 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2735 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2736 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2737 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2739 expected_refcount = get_refcount((IUnknown *)device) + 1;
2740 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
2741 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2742 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
2743 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2744 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
2745 refcount = get_refcount((IUnknown *)device);
2746 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2747 tmp = NULL;
2748 expected_refcount = refcount + 1;
2749 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
2750 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2751 refcount = get_refcount((IUnknown *)device);
2752 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2753 ID3D11Device_Release(tmp);
2755 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
2756 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2757 "Depth stencil state should implement ID3D10DepthStencilState.\n");
2758 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
2760 refcount = ID3D11DepthStencilState_Release(ds_state2);
2761 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2762 refcount = ID3D11DepthStencilState_Release(ds_state1);
2763 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2765 ds_desc.DepthEnable = FALSE;
2766 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
2767 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
2768 ds_desc.StencilEnable = FALSE;
2769 ds_desc.StencilReadMask = 0;
2770 ds_desc.StencilWriteMask = 0;
2771 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
2772 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
2773 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
2774 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
2775 ds_desc.BackFace = ds_desc.FrontFace;
2777 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
2778 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2780 memset(&ds_desc, 0, sizeof(ds_desc));
2781 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
2782 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
2783 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
2784 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
2785 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
2786 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
2787 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
2788 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
2789 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
2790 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
2791 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
2792 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
2793 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
2794 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
2795 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
2796 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
2797 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
2798 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
2799 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
2800 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
2801 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
2802 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
2803 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
2804 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
2805 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
2806 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
2808 ID3D11DepthStencilState_Release(ds_state1);
2810 refcount = ID3D11Device_Release(device);
2811 ok(!refcount, "Device has %u references left.\n", refcount);
2814 static void test_create_rasterizer_state(void)
2816 ID3D11RasterizerState *rast_state1, *rast_state2;
2817 ID3D10RasterizerState *d3d10_rast_state;
2818 ULONG refcount, expected_refcount;
2819 D3D10_RASTERIZER_DESC d3d10_desc;
2820 D3D11_RASTERIZER_DESC desc;
2821 ID3D11Device *device, *tmp;
2822 HRESULT hr;
2824 if (!(device = create_device(NULL)))
2826 skip("Failed to create device.\n");
2827 return;
2830 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
2831 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2833 desc.FillMode = D3D11_FILL_SOLID;
2834 desc.CullMode = D3D11_CULL_BACK;
2835 desc.FrontCounterClockwise = FALSE;
2836 desc.DepthBias = 0;
2837 desc.DepthBiasClamp = 0.0f;
2838 desc.SlopeScaledDepthBias = 0.0f;
2839 desc.DepthClipEnable = TRUE;
2840 desc.ScissorEnable = FALSE;
2841 desc.MultisampleEnable = FALSE;
2842 desc.AntialiasedLineEnable = FALSE;
2844 expected_refcount = get_refcount((IUnknown *)device) + 1;
2845 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
2846 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2847 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
2848 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2849 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
2850 refcount = get_refcount((IUnknown *)device);
2851 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2852 tmp = NULL;
2853 expected_refcount = refcount + 1;
2854 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
2855 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2856 refcount = get_refcount((IUnknown *)device);
2857 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2858 ID3D11Device_Release(tmp);
2860 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
2861 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2862 "Rasterizer state should implement ID3D10RasterizerState.\n");
2863 if (SUCCEEDED(hr))
2865 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
2866 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
2867 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
2868 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
2869 d3d10_desc.FrontCounterClockwise);
2870 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
2871 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
2872 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
2873 d3d10_desc.SlopeScaledDepthBias);
2874 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
2875 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
2876 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
2877 d3d10_desc.MultisampleEnable);
2878 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
2879 d3d10_desc.AntialiasedLineEnable);
2881 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
2882 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
2885 refcount = ID3D11RasterizerState_Release(rast_state2);
2886 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2887 refcount = ID3D11RasterizerState_Release(rast_state1);
2888 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2890 refcount = ID3D11Device_Release(device);
2891 ok(!refcount, "Device has %u references left.\n", refcount);
2894 static void test_create_query(void)
2896 static const struct
2898 D3D11_QUERY query;
2899 D3D_FEATURE_LEVEL required_feature_level;
2900 BOOL is_predicate;
2901 BOOL can_use_create_predicate;
2902 BOOL todo;
2904 tests[] =
2906 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
2907 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
2908 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
2909 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
2910 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
2911 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
2912 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
2913 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
2914 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
2915 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
2916 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
2917 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
2918 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
2919 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
2920 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
2921 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
2924 ULONG refcount, expected_refcount;
2925 D3D_FEATURE_LEVEL feature_level;
2926 D3D11_QUERY_DESC query_desc;
2927 ID3D11Predicate *predicate;
2928 ID3D11Device *device, *tmp;
2929 HRESULT hr, expected_hr;
2930 ID3D11Query *query;
2931 IUnknown *iface;
2932 unsigned int i;
2934 if (!(device = create_device(NULL)))
2936 skip("Failed to create device.\n");
2937 return;
2939 feature_level = ID3D11Device_GetFeatureLevel(device);
2941 hr = ID3D11Device_CreateQuery(device, NULL, &query);
2942 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2943 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
2944 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2946 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2948 if (tests[i].required_feature_level > feature_level)
2950 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
2951 continue;
2954 query_desc.Query = tests[i].query;
2955 query_desc.MiscFlags = 0;
2957 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
2958 todo_wine_if(tests[i].todo)
2959 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
2961 query_desc.Query = tests[i].query;
2962 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
2963 todo_wine_if(tests[i].todo)
2964 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
2965 if (FAILED(hr))
2966 continue;
2968 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
2969 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
2970 ID3D11Query_Release(query);
2971 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
2972 if (SUCCEEDED(hr))
2973 ID3D11Predicate_Release(predicate);
2975 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
2976 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
2977 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
2979 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
2980 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2981 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
2982 if (SUCCEEDED(hr))
2983 ID3D11Predicate_Release(predicate);
2986 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
2987 expected_refcount = get_refcount((IUnknown *)device) + 1;
2988 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
2989 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
2990 refcount = get_refcount((IUnknown *)device);
2991 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2992 tmp = NULL;
2993 expected_refcount = refcount + 1;
2994 ID3D11Predicate_GetDevice(predicate, &tmp);
2995 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2996 refcount = get_refcount((IUnknown *)device);
2997 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2998 ID3D11Device_Release(tmp);
2999 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
3000 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3001 "Predicate should implement ID3D10Predicate.\n");
3002 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3003 ID3D11Predicate_Release(predicate);
3005 refcount = ID3D11Device_Release(device);
3006 ok(!refcount, "Device has %u references left.\n", refcount);
3009 static void test_device_removed_reason(void)
3011 ID3D11Device *device;
3012 ULONG refcount;
3013 HRESULT hr;
3015 if (!(device = create_device(NULL)))
3017 skip("Failed to create device.\n");
3018 return;
3021 hr = ID3D11Device_GetDeviceRemovedReason(device);
3022 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3023 hr = ID3D11Device_GetDeviceRemovedReason(device);
3024 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3026 refcount = ID3D11Device_Release(device);
3027 ok(!refcount, "Device has %u references left.\n", refcount);
3030 static void test_private_data(void)
3032 ULONG refcount, expected_refcount;
3033 D3D11_TEXTURE2D_DESC texture_desc;
3034 ID3D10Texture2D *d3d10_texture;
3035 ID3D11Device *test_object;
3036 ID3D11Texture2D *texture;
3037 IDXGIDevice *dxgi_device;
3038 IDXGISurface *surface;
3039 ID3D11Device *device;
3040 IUnknown *ptr;
3041 HRESULT hr;
3042 UINT size;
3044 static const GUID test_guid =
3045 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
3046 static const GUID test_guid2 =
3047 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
3048 static const DWORD data[] = {1, 2, 3, 4};
3050 if (!(device = create_device(NULL)))
3052 skip("Failed to create device.\n");
3053 return;
3056 test_object = create_device(NULL);
3058 texture_desc.Width = 512;
3059 texture_desc.Height = 512;
3060 texture_desc.MipLevels = 1;
3061 texture_desc.ArraySize = 1;
3062 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3063 texture_desc.SampleDesc.Count = 1;
3064 texture_desc.SampleDesc.Quality = 0;
3065 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3066 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3067 texture_desc.CPUAccessFlags = 0;
3068 texture_desc.MiscFlags = 0;
3070 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3071 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3072 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
3073 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
3075 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
3076 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3077 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3078 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3079 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3080 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3081 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3082 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3084 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3086 size = sizeof(ptr) * 2;
3087 ptr = (IUnknown *)0xdeadbeef;
3088 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3089 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3090 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3091 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3093 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
3094 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
3095 size = sizeof(ptr) * 2;
3096 ptr = (IUnknown *)0xdeadbeef;
3097 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
3098 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3099 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3100 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3101 IDXGIDevice_Release(dxgi_device);
3103 refcount = get_refcount((IUnknown *)test_object);
3104 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3105 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3106 expected_refcount = refcount + 1;
3107 refcount = get_refcount((IUnknown *)test_object);
3108 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3109 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3110 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3111 refcount = get_refcount((IUnknown *)test_object);
3112 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3114 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3115 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3116 --expected_refcount;
3117 refcount = get_refcount((IUnknown *)test_object);
3118 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3120 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3121 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3122 size = sizeof(data);
3123 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
3124 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3125 refcount = get_refcount((IUnknown *)test_object);
3126 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3127 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
3128 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3129 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
3130 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3132 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3133 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3134 ++expected_refcount;
3135 size = 2 * sizeof(ptr);
3136 ptr = NULL;
3137 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3138 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3139 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
3140 ++expected_refcount;
3141 refcount = get_refcount((IUnknown *)test_object);
3142 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3143 IUnknown_Release(ptr);
3144 --expected_refcount;
3146 ptr = (IUnknown *)0xdeadbeef;
3147 size = 1;
3148 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
3149 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3150 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3151 size = 2 * sizeof(ptr);
3152 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
3153 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3154 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3155 refcount = get_refcount((IUnknown *)test_object);
3156 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3158 size = 1;
3159 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3160 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
3161 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3162 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3163 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
3164 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3165 size = 0xdeadbabe;
3166 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
3167 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
3168 ok(size == 0, "Got unexpected size %u.\n", size);
3169 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3170 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
3171 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3172 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3174 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
3175 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3176 ptr = NULL;
3177 size = sizeof(ptr);
3178 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
3179 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3180 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
3181 IUnknown_Release(ptr);
3183 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
3184 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3185 "Texture should implement ID3D10Texture2D.\n");
3186 if (SUCCEEDED(hr))
3188 ptr = NULL;
3189 size = sizeof(ptr);
3190 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
3191 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3192 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
3193 IUnknown_Release(ptr);
3194 ID3D10Texture2D_Release(d3d10_texture);
3197 IDXGISurface_Release(surface);
3198 ID3D11Texture2D_Release(texture);
3199 refcount = ID3D11Device_Release(device);
3200 ok(!refcount, "Device has %u references left.\n", refcount);
3201 refcount = ID3D11Device_Release(test_object);
3202 ok(!refcount, "Test object has %u references left.\n", refcount);
3205 static void test_blend(void)
3207 ID3D11BlendState *src_blend, *dst_blend;
3208 struct d3d11_test_context test_context;
3209 ID3D11RenderTargetView *offscreen_rtv;
3210 D3D11_SUBRESOURCE_DATA buffer_data;
3211 D3D11_TEXTURE2D_DESC texture_desc;
3212 ID3D11InputLayout *input_layout;
3213 D3D11_BUFFER_DESC buffer_desc;
3214 ID3D11DeviceContext *context;
3215 D3D11_BLEND_DESC blend_desc;
3216 unsigned int stride, offset;
3217 ID3D11Texture2D *offscreen;
3218 ID3D11VertexShader *vs;
3219 ID3D11PixelShader *ps;
3220 ID3D11Device *device;
3221 D3D11_VIEWPORT vp;
3222 ID3D11Buffer *vb;
3223 DWORD color;
3224 HRESULT hr;
3226 static const DWORD vs_code[] =
3228 #if 0
3229 struct vs_out
3231 float4 position : SV_POSITION;
3232 float4 color : COLOR;
3235 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
3237 struct vs_out o;
3239 o.position = position;
3240 o.color = color;
3242 return o;
3244 #endif
3245 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
3246 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3247 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3248 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
3249 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3250 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
3251 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
3252 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
3253 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
3254 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
3256 static const DWORD ps_code[] =
3258 #if 0
3259 struct vs_out
3261 float4 position : SV_POSITION;
3262 float4 color : COLOR;
3265 float4 main(struct vs_out i) : SV_TARGET
3267 return i.color;
3269 #endif
3270 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
3271 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
3272 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
3273 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
3274 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3275 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3276 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3277 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3279 static const struct
3281 struct vec3 position;
3282 DWORD diffuse;
3284 quads[] =
3286 /* quad1 */
3287 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
3288 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
3289 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
3290 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
3291 /* quad2 */
3292 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3293 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3294 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3295 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3297 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3299 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3300 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
3302 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
3303 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3305 if (!init_test_context(&test_context, NULL))
3306 return;
3308 device = test_context.device;
3309 context = test_context.immediate_context;
3311 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3312 vs_code, sizeof(vs_code), &input_layout);
3313 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3315 buffer_desc.ByteWidth = sizeof(quads);
3316 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3317 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3318 buffer_desc.CPUAccessFlags = 0;
3319 buffer_desc.MiscFlags = 0;
3320 buffer_desc.StructureByteStride = 0;
3322 buffer_data.pSysMem = quads;
3323 buffer_data.SysMemPitch = 0;
3324 buffer_data.SysMemSlicePitch = 0;
3326 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
3327 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3328 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3329 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3330 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3331 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3333 memset(&blend_desc, 0, sizeof(blend_desc));
3334 blend_desc.RenderTarget[0].BlendEnable = TRUE;
3335 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
3336 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
3337 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
3338 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
3339 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
3340 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
3341 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
3343 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
3344 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3346 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
3347 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
3348 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
3349 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
3351 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
3352 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3354 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3355 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3356 stride = sizeof(*quads);
3357 offset = 0;
3358 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3359 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3360 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3362 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
3364 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3365 ID3D11DeviceContext_Draw(context, 4, 0);
3366 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3367 ID3D11DeviceContext_Draw(context, 4, 4);
3369 color = get_texture_color(test_context.backbuffer, 320, 360);
3370 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
3371 color = get_texture_color(test_context.backbuffer, 320, 120);
3372 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
3374 texture_desc.Width = 128;
3375 texture_desc.Height = 128;
3376 texture_desc.MipLevels = 1;
3377 texture_desc.ArraySize = 1;
3378 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
3379 texture_desc.SampleDesc.Count = 1;
3380 texture_desc.SampleDesc.Quality = 0;
3381 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3382 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
3383 texture_desc.CPUAccessFlags = 0;
3384 texture_desc.MiscFlags = 0;
3386 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
3387 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
3389 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
3390 goto done;
3393 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
3394 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3396 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
3398 vp.TopLeftX = 0.0f;
3399 vp.TopLeftY = 0.0f;
3400 vp.Width = 128.0f;
3401 vp.Height = 128.0f;
3402 vp.MinDepth = 0.0f;
3403 vp.MaxDepth = 1.0f;
3404 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3406 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
3408 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3409 ID3D11DeviceContext_Draw(context, 4, 0);
3410 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3411 ID3D11DeviceContext_Draw(context, 4, 4);
3413 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
3414 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
3415 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
3416 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
3418 ID3D11RenderTargetView_Release(offscreen_rtv);
3419 ID3D11Texture2D_Release(offscreen);
3420 done:
3421 ID3D11BlendState_Release(dst_blend);
3422 ID3D11BlendState_Release(src_blend);
3423 ID3D11PixelShader_Release(ps);
3424 ID3D11VertexShader_Release(vs);
3425 ID3D11Buffer_Release(vb);
3426 ID3D11InputLayout_Release(input_layout);
3427 release_test_context(&test_context);
3430 static void test_texture(void)
3432 struct shader
3434 const DWORD *code;
3435 size_t size;
3437 struct texture
3439 UINT width;
3440 UINT height;
3441 UINT miplevel_count;
3442 DXGI_FORMAT format;
3443 D3D11_SUBRESOURCE_DATA data[3];
3446 struct d3d11_test_context test_context;
3447 const struct texture *current_texture;
3448 D3D11_TEXTURE2D_DESC texture_desc;
3449 D3D11_SAMPLER_DESC sampler_desc;
3450 const struct shader *current_ps;
3451 ID3D11ShaderResourceView *srv;
3452 D3D11_BUFFER_DESC buffer_desc;
3453 ID3D11DeviceContext *context;
3454 ID3D11SamplerState *sampler;
3455 struct texture_readback rb;
3456 ID3D11Texture2D *texture;
3457 ID3D11PixelShader *ps;
3458 ID3D11Device *device;
3459 unsigned int i, x, y;
3460 struct vec4 miplevel;
3461 ID3D11Buffer *cb;
3462 DWORD color;
3463 HRESULT hr;
3465 static const DWORD ps_ld_code[] =
3467 #if 0
3468 Texture2D t;
3470 float miplevel;
3472 float4 main(float4 position : SV_POSITION) : SV_TARGET
3474 float3 p;
3475 t.GetDimensions(miplevel, p.x, p.y, p.z);
3476 p.z = miplevel;
3477 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
3478 return t.Load(int3(p));
3480 #endif
3481 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
3482 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3483 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3484 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3485 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
3486 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
3487 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3488 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
3489 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
3490 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
3491 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
3492 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
3493 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
3494 0x00107e46, 0x00000000, 0x0100003e,
3496 static const DWORD ps_ld_sint8_code[] =
3498 #if 0
3499 Texture2D<int4> t;
3501 float4 main(float4 position : SV_POSITION) : SV_TARGET
3503 float3 p, s;
3504 int4 c;
3506 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3507 t.GetDimensions(0, s.x, s.y, s.z);
3508 p *= s;
3510 c = t.Load(int3(p));
3511 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
3513 #endif
3514 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
3515 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3516 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3517 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3518 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
3519 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
3520 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3521 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3522 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3523 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3524 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3525 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3526 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3527 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
3528 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
3529 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3530 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
3531 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
3533 static const DWORD ps_ld_uint8_code[] =
3535 #if 0
3536 Texture2D<uint4> t;
3538 float4 main(float4 position : SV_POSITION) : SV_TARGET
3540 float3 p, s;
3542 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3543 t.GetDimensions(0, s.x, s.y, s.z);
3544 p *= s;
3546 return t.Load(int3(p)) / (float4)255;
3548 #endif
3549 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
3550 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3551 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3552 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3553 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
3554 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
3555 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3556 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3557 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3558 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3559 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3560 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3561 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3562 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
3563 0x3b808081, 0x0100003e,
3565 static const DWORD ps_sample_code[] =
3567 #if 0
3568 Texture2D t;
3569 SamplerState s;
3571 float4 main(float4 position : SV_POSITION) : SV_Target
3573 float2 p;
3575 p.x = position.x / 640.0f;
3576 p.y = position.y / 480.0f;
3577 return t.Sample(s, p);
3579 #endif
3580 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3581 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3582 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3583 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3584 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3585 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3586 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3587 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3588 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3589 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3591 static const DWORD ps_sample_b_code[] =
3593 #if 0
3594 Texture2D t;
3595 SamplerState s;
3597 float bias;
3599 float4 main(float4 position : SV_POSITION) : SV_Target
3601 float2 p;
3603 p.x = position.x / 640.0f;
3604 p.y = position.y / 480.0f;
3605 return t.SampleBias(s, p, bias);
3607 #endif
3608 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
3609 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3610 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3611 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3612 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3613 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3614 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3615 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3616 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
3617 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3618 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3620 static const DWORD ps_sample_l_code[] =
3622 #if 0
3623 Texture2D t;
3624 SamplerState s;
3626 float level;
3628 float4 main(float4 position : SV_POSITION) : SV_Target
3630 float2 p;
3632 p.x = position.x / 640.0f;
3633 p.y = position.y / 480.0f;
3634 return t.SampleLevel(s, p, level);
3636 #endif
3637 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
3638 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3639 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3640 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3641 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3642 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3643 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3644 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3645 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
3646 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3647 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3649 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
3650 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
3651 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
3652 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
3653 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
3654 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
3655 static const DWORD rgba_level_0[] =
3657 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3658 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3659 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3660 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3662 static const DWORD rgba_level_1[] =
3664 0xffffffff, 0xff0000ff,
3665 0xff000000, 0xff00ff00,
3667 static const DWORD rgba_level_2[] =
3669 0xffff0000,
3671 static const DWORD srgb_data[] =
3673 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
3674 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
3675 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
3676 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
3678 static const BYTE a8_data[] =
3680 0x00, 0x10, 0x20, 0x30,
3681 0x40, 0x50, 0x60, 0x70,
3682 0x80, 0x90, 0xa0, 0xb0,
3683 0xc0, 0xd0, 0xe0, 0xf0,
3685 static const BYTE bc1_data[] =
3687 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3688 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3689 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3690 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3692 static const BYTE bc2_data[] =
3694 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3695 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3696 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3697 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3699 static const BYTE bc3_data[] =
3701 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3702 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3703 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3704 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3706 static const BYTE bc4_data[] =
3708 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
3709 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
3710 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3711 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
3713 static const BYTE bc5_data[] =
3715 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
3716 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
3717 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3718 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
3720 static const struct texture rgba_texture =
3722 4, 4, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
3724 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
3725 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
3726 {rgba_level_2, sizeof(*rgba_level_2), 0},
3729 static const struct texture srgb_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
3730 {{srgb_data, 4 * sizeof(*srgb_data)}}};
3731 static const struct texture a8_texture = {4, 4, 1, DXGI_FORMAT_A8_UNORM,
3732 {{a8_data, 4 * sizeof(*a8_data)}}};
3733 static const struct texture bc1_texture = {8, 8, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
3734 static const struct texture bc2_texture = {8, 8, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
3735 static const struct texture bc3_texture = {8, 8, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
3736 static const struct texture bc4_texture = {8, 8, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
3737 static const struct texture bc5_texture = {8, 8, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
3738 static const struct texture bc1_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
3739 static const struct texture bc2_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
3740 static const struct texture bc3_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
3741 static const struct texture sint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_SINT,
3742 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3743 static const struct texture uint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UINT,
3744 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
3745 static const DWORD level_1_colors[] =
3747 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3748 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
3749 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3750 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
3752 static const DWORD lerp_1_2_colors[] =
3754 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3755 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
3756 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3757 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
3759 static const DWORD level_2_colors[] =
3761 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3762 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3763 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3764 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
3766 static const DWORD srgb_colors[] =
3768 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
3769 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
3770 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
3771 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
3773 static const DWORD a8_colors[] =
3775 0x00000000, 0x10000000, 0x20000000, 0x30000000,
3776 0x40000000, 0x50000000, 0x60000000, 0x70000000,
3777 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
3778 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
3780 static const DWORD bc_colors[] =
3782 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3783 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
3784 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3785 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
3787 static const DWORD bc4_colors[] =
3789 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
3790 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
3791 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
3792 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
3794 static const DWORD bc5_colors[] =
3796 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
3797 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
3798 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
3799 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
3801 static const DWORD sint8_colors[] =
3803 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
3804 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
3805 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
3806 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
3808 static const DWORD zero_colors[4 * 4] = {0};
3809 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3811 static const struct test
3813 const struct shader *ps;
3814 const struct texture *texture;
3815 D3D11_FILTER filter;
3816 float lod_bias;
3817 float min_lod;
3818 float max_lod;
3819 float miplevel;
3820 const DWORD *expected_colors;
3822 tests[] =
3824 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3825 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
3826 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
3827 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
3828 {&ps_ld, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
3829 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3830 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3831 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3832 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3833 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3834 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
3835 {&ps_ld, &bc1_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3836 {&ps_ld, &bc2_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3837 {&ps_ld, &bc3_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3838 {&ps_ld, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
3839 {&ps_ld, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
3840 {&ps_ld_sint8, &sint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
3841 {&ps_ld_uint8, &uint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3842 {&ps_sample, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3843 {&ps_sample, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3844 {&ps_sample, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
3845 {&ps_sample, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
3846 {&ps_sample, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
3847 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
3848 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3849 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3850 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3851 {&ps_sample, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
3852 {&ps_sample, &a8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
3853 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3854 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
3855 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.0f, level_1_colors},
3856 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.4f, level_1_colors},
3857 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.5f, level_2_colors},
3858 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 9.0f, level_2_colors},
3859 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
3860 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
3861 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
3862 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
3863 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, rgba_level_0},
3864 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
3865 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.4f, rgba_level_0},
3866 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.5f, level_1_colors},
3867 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_1_colors},
3868 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.4f, level_1_colors},
3869 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3870 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 2.0f, level_2_colors},
3871 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 3.0f, level_2_colors},
3872 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 4.0f, level_2_colors},
3873 {&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},
3874 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -2.0f, rgba_level_0},
3875 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_1_colors},
3876 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_2_colors},
3877 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_2_colors},
3878 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
3879 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3880 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3881 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3882 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3883 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3884 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
3885 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
3886 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
3887 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
3888 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
3891 if (!init_test_context(&test_context, NULL))
3892 return;
3894 device = test_context.device;
3895 context = test_context.immediate_context;
3897 buffer_desc.ByteWidth = sizeof(miplevel);
3898 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3899 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3900 buffer_desc.CPUAccessFlags = 0;
3901 buffer_desc.MiscFlags = 0;
3902 buffer_desc.StructureByteStride = 0;
3904 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
3905 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
3907 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
3909 texture_desc.Width = 4;
3910 texture_desc.Height = 4;
3911 texture_desc.MipLevels = 3;
3912 texture_desc.ArraySize = 1;
3913 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3914 texture_desc.SampleDesc.Count = 1;
3915 texture_desc.SampleDesc.Quality = 0;
3916 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3917 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3918 texture_desc.CPUAccessFlags = 0;
3919 texture_desc.MiscFlags = 0;
3921 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
3922 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
3923 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
3924 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
3925 sampler_desc.MipLODBias = 0.0f;
3926 sampler_desc.MaxAnisotropy = 0;
3927 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3928 sampler_desc.BorderColor[0] = 0.0f;
3929 sampler_desc.BorderColor[1] = 0.0f;
3930 sampler_desc.BorderColor[2] = 0.0f;
3931 sampler_desc.BorderColor[3] = 0.0f;
3932 sampler_desc.MinLOD = 0.0f;
3933 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
3935 ps = NULL;
3936 srv = NULL;
3937 sampler = NULL;
3938 texture = NULL;
3939 current_ps = NULL;
3940 current_texture = NULL;
3941 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3943 const struct test *test = &tests[i];
3945 if (current_ps != test->ps)
3947 if (ps)
3948 ID3D11PixelShader_Release(ps);
3950 current_ps = test->ps;
3952 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
3953 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
3955 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3958 if (current_texture != test->texture)
3960 if (texture)
3961 ID3D11Texture2D_Release(texture);
3962 if (srv)
3963 ID3D11ShaderResourceView_Release(srv);
3965 current_texture = test->texture;
3967 texture_desc.Width = current_texture->width;
3968 texture_desc.Height = current_texture->height;
3969 texture_desc.MipLevels = current_texture->miplevel_count;
3970 texture_desc.Format = current_texture->format;
3972 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
3973 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3975 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
3976 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
3978 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
3981 if (!sampler || (sampler_desc.Filter != test->filter
3982 || sampler_desc.MipLODBias != test->lod_bias
3983 || sampler_desc.MinLOD != test->min_lod
3984 || sampler_desc.MaxLOD != test->max_lod))
3986 if (sampler)
3987 ID3D11SamplerState_Release(sampler);
3989 sampler_desc.Filter = test->filter;
3990 sampler_desc.MipLODBias = test->lod_bias;
3991 sampler_desc.MinLOD = test->min_lod;
3992 sampler_desc.MaxLOD = test->max_lod;
3994 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
3995 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3997 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
4000 miplevel.x = test->miplevel;
4001 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &miplevel, 0, 0);
4003 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4005 draw_quad(&test_context);
4007 get_texture_readback(test_context.backbuffer, &rb);
4008 for (y = 0; y < 4; ++y)
4010 for (x = 0; x < 4; ++x)
4012 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
4013 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
4014 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
4017 release_texture_readback(&rb);
4019 ID3D11ShaderResourceView_Release(srv);
4020 ID3D11SamplerState_Release(sampler);
4021 ID3D11Texture2D_Release(texture);
4022 ID3D11PixelShader_Release(ps);
4024 ID3D11Buffer_Release(cb);
4025 release_test_context(&test_context);
4028 static void test_multiple_render_targets(void)
4030 D3D11_SUBRESOURCE_DATA resource_data;
4031 D3D11_TEXTURE2D_DESC texture_desc;
4032 ID3D11InputLayout *input_layout;
4033 unsigned int stride, offset, i;
4034 ID3D11RenderTargetView *rtv[4];
4035 D3D11_BUFFER_DESC buffer_desc;
4036 ID3D11DeviceContext *context;
4037 ID3D11Texture2D *rt[4];
4038 ID3D11VertexShader *vs;
4039 ID3D11PixelShader *ps;
4040 ID3D11Device *device;
4041 D3D11_VIEWPORT vp;
4042 ID3D11Buffer *vb;
4043 ULONG refcount;
4044 HRESULT hr;
4046 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4048 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
4050 static const DWORD vs_code[] =
4052 #if 0
4053 float4 main(float4 position : POSITION) : SV_POSITION
4055 return position;
4057 #endif
4058 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4059 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4060 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4061 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4062 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4063 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4064 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4066 static const DWORD ps_code[] =
4068 #if 0
4069 struct output
4071 float4 t1 : SV_TARGET0;
4072 float4 t2 : SV_Target1;
4073 float4 t3 : SV_TARGET2;
4074 float4 t4 : SV_Target3;
4077 output main(float4 position : SV_POSITION)
4079 struct output o;
4080 o.t1 = (float4)1.0f;
4081 o.t2 = (float4)0.5f;
4082 o.t3 = (float4)0.2f;
4083 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
4084 return o;
4086 #endif
4087 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
4088 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4089 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4090 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
4091 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
4092 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
4093 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
4094 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
4095 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
4096 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
4097 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
4098 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
4099 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
4100 0x3f800000, 0x0100003e,
4102 static const struct
4104 struct vec2 position;
4106 quad[] =
4108 {{-1.0f, -1.0f}},
4109 {{-1.0f, 1.0f}},
4110 {{ 1.0f, -1.0f}},
4111 {{ 1.0f, 1.0f}},
4113 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4115 if (!(device = create_device(NULL)))
4117 skip("Failed to create device.\n");
4118 return;
4121 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4122 vs_code, sizeof(vs_code), &input_layout);
4123 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4125 buffer_desc.ByteWidth = sizeof(quad);
4126 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4127 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4128 buffer_desc.CPUAccessFlags = 0;
4129 buffer_desc.MiscFlags = 0;
4130 buffer_desc.StructureByteStride = 0;
4132 resource_data.pSysMem = quad;
4133 resource_data.SysMemPitch = 0;
4134 resource_data.SysMemSlicePitch = 0;
4136 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4137 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4139 texture_desc.Width = 640;
4140 texture_desc.Height = 480;
4141 texture_desc.MipLevels = 1;
4142 texture_desc.ArraySize = 1;
4143 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4144 texture_desc.SampleDesc.Count = 1;
4145 texture_desc.SampleDesc.Quality = 0;
4146 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4147 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4148 texture_desc.CPUAccessFlags = 0;
4149 texture_desc.MiscFlags = 0;
4151 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
4153 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
4154 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
4156 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
4157 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
4160 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4161 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4162 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4163 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4165 ID3D11Device_GetImmediateContext(device, &context);
4167 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
4168 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4169 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4170 stride = sizeof(*quad);
4171 offset = 0;
4172 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
4173 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4174 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4176 vp.TopLeftX = 0.0f;
4177 vp.TopLeftY = 0.0f;
4178 vp.Width = 640.0f;
4179 vp.Height = 480.0f;
4180 vp.MinDepth = 0.0f;
4181 vp.MaxDepth = 1.0f;
4182 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4184 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
4185 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
4187 ID3D11DeviceContext_Draw(context, 4, 0);
4189 check_texture_color(rt[0], 0xffffffff, 2);
4190 check_texture_color(rt[1], 0x7f7f7f7f, 2);
4191 check_texture_color(rt[2], 0x33333333, 2);
4192 check_texture_color(rt[3], 0xff7f3300, 2);
4194 ID3D11Buffer_Release(vb);
4195 ID3D11PixelShader_Release(ps);
4196 ID3D11VertexShader_Release(vs);
4197 ID3D11InputLayout_Release(input_layout);
4198 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
4199 ID3D11RenderTargetView_Release(rtv[i]);
4200 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
4201 ID3D11Texture2D_Release(rt[i]);
4202 ID3D11DeviceContext_Release(context);
4203 refcount = ID3D11Device_Release(device);
4204 ok(!refcount, "Device has %u references left.\n", refcount);
4207 static void test_scissor(void)
4209 struct d3d11_test_context test_context;
4210 ID3D11DeviceContext *immediate_context;
4211 D3D11_RASTERIZER_DESC rs_desc;
4212 ID3D11RasterizerState *rs;
4213 D3D11_RECT scissor_rect;
4214 ID3D11PixelShader *ps;
4215 ID3D11Device *device;
4216 DWORD color;
4217 HRESULT hr;
4219 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4220 static const DWORD ps_code[] =
4222 #if 0
4223 float4 main(float4 position : SV_POSITION) : SV_Target
4225 return float4(0.0, 1.0, 0.0, 1.0);
4227 #endif
4228 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
4229 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4230 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4231 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4232 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
4233 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
4234 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
4237 if (!init_test_context(&test_context, NULL))
4238 return;
4240 device = test_context.device;
4241 immediate_context = test_context.immediate_context;
4243 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4244 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4246 rs_desc.FillMode = D3D11_FILL_SOLID;
4247 rs_desc.CullMode = D3D11_CULL_BACK;
4248 rs_desc.FrontCounterClockwise = FALSE;
4249 rs_desc.DepthBias = 0;
4250 rs_desc.DepthBiasClamp = 0.0f;
4251 rs_desc.SlopeScaledDepthBias = 0.0f;
4252 rs_desc.DepthClipEnable = TRUE;
4253 rs_desc.ScissorEnable = TRUE;
4254 rs_desc.MultisampleEnable = FALSE;
4255 rs_desc.AntialiasedLineEnable = FALSE;
4256 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
4257 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4259 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
4261 scissor_rect.left = 160;
4262 scissor_rect.top = 120;
4263 scissor_rect.right = 480;
4264 scissor_rect.bottom = 360;
4265 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
4267 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4268 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4270 draw_quad(&test_context);
4271 color = get_texture_color(test_context.backbuffer, 320, 60);
4272 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4273 color = get_texture_color(test_context.backbuffer, 80, 240);
4274 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4275 color = get_texture_color(test_context.backbuffer, 320, 240);
4276 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4277 color = get_texture_color(test_context.backbuffer, 560, 240);
4278 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4279 color = get_texture_color(test_context.backbuffer, 320, 420);
4280 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4282 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4283 ID3D11DeviceContext_RSSetState(immediate_context, rs);
4284 draw_quad(&test_context);
4285 color = get_texture_color(test_context.backbuffer, 320, 60);
4286 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4287 color = get_texture_color(test_context.backbuffer, 80, 240);
4288 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4289 color = get_texture_color(test_context.backbuffer, 320, 240);
4290 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4291 color = get_texture_color(test_context.backbuffer, 560, 240);
4292 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4293 color = get_texture_color(test_context.backbuffer, 320, 420);
4294 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4296 ID3D11RasterizerState_Release(rs);
4297 ID3D11PixelShader_Release(ps);
4298 release_test_context(&test_context);
4301 static void test_il_append_aligned(void)
4303 struct d3d11_test_context test_context;
4304 D3D11_SUBRESOURCE_DATA resource_data;
4305 ID3D11InputLayout *input_layout;
4306 D3D11_BUFFER_DESC buffer_desc;
4307 ID3D11DeviceContext *context;
4308 unsigned int stride, offset;
4309 ID3D11VertexShader *vs;
4310 ID3D11PixelShader *ps;
4311 ID3D11Device *device;
4312 ID3D11Buffer *vb[3];
4313 DWORD color;
4314 HRESULT hr;
4316 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4318 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4319 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4320 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4321 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4322 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
4323 D3D11_INPUT_PER_VERTEX_DATA, 0},
4324 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4325 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4326 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4327 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4329 static const DWORD vs_code[] =
4331 #if 0
4332 struct vs_in
4334 float4 position : POSITION;
4335 float2 color_xy : COLOR0;
4336 float2 color_zw : COLOR1;
4337 unsigned int instance_id : SV_INSTANCEID;
4340 struct vs_out
4342 float4 position : SV_POSITION;
4343 float2 color_xy : COLOR0;
4344 float2 color_zw : COLOR1;
4347 struct vs_out main(struct vs_in i)
4349 struct vs_out o;
4351 o.position = i.position;
4352 o.position.x += i.instance_id * 0.5;
4353 o.color_xy = i.color_xy;
4354 o.color_zw = i.color_zw;
4356 return o;
4358 #endif
4359 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
4360 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
4361 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
4362 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
4363 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
4364 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
4365 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4366 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
4367 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
4368 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
4369 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
4370 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
4371 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
4372 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
4373 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
4374 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
4375 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
4377 static const DWORD ps_code[] =
4379 #if 0
4380 struct vs_out
4382 float4 position : SV_POSITION;
4383 float2 color_xy : COLOR0;
4384 float2 color_zw : COLOR1;
4387 float4 main(struct vs_out i) : SV_TARGET
4389 return float4(i.color_xy.xy, i.color_zw.xy);
4391 #endif
4392 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
4393 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
4394 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
4395 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
4396 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
4397 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
4398 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
4399 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4400 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
4402 static const struct
4404 struct vec4 position;
4406 stream0[] =
4408 {{-1.0f, -1.0f, 0.0f, 1.0f}},
4409 {{-1.0f, 1.0f, 0.0f, 1.0f}},
4410 {{-0.5f, -1.0f, 0.0f, 1.0f}},
4411 {{-0.5f, 1.0f, 0.0f, 1.0f}},
4413 static const struct
4415 struct vec2 color2;
4416 struct vec2 color1;
4418 stream1[] =
4420 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4421 {{0.5f, 0.5f}, {1.0f, 1.0f}},
4423 static const struct
4425 struct vec2 color3;
4426 struct vec2 color0;
4428 stream2[] =
4430 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4431 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4432 {{0.5f, 0.5f}, {0.0f, 0.0f}},
4433 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4435 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4437 if (!init_test_context(&test_context, NULL))
4438 return;
4440 device = test_context.device;
4441 context = test_context.immediate_context;
4443 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4444 vs_code, sizeof(vs_code), &input_layout);
4445 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4447 buffer_desc.ByteWidth = sizeof(stream0);
4448 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4449 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4450 buffer_desc.CPUAccessFlags = 0;
4451 buffer_desc.MiscFlags = 0;
4452 buffer_desc.StructureByteStride = 0;
4454 resource_data.pSysMem = stream0;
4455 resource_data.SysMemPitch = 0;
4456 resource_data.SysMemSlicePitch = 0;
4458 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
4459 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4461 buffer_desc.ByteWidth = sizeof(stream1);
4462 resource_data.pSysMem = stream1;
4464 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
4465 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4467 buffer_desc.ByteWidth = sizeof(stream2);
4468 resource_data.pSysMem = stream2;
4470 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
4471 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4473 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4474 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4475 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4476 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4478 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4479 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4480 offset = 0;
4481 stride = sizeof(*stream0);
4482 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
4483 stride = sizeof(*stream1);
4484 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
4485 stride = sizeof(*stream2);
4486 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
4487 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4488 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4490 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4492 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
4494 color = get_texture_color(test_context.backbuffer, 80, 240);
4495 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4496 color = get_texture_color(test_context.backbuffer, 240, 240);
4497 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4498 color = get_texture_color(test_context.backbuffer, 400, 240);
4499 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4500 color = get_texture_color(test_context.backbuffer, 560, 240);
4501 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
4503 ID3D11PixelShader_Release(ps);
4504 ID3D11VertexShader_Release(vs);
4505 ID3D11Buffer_Release(vb[2]);
4506 ID3D11Buffer_Release(vb[1]);
4507 ID3D11Buffer_Release(vb[0]);
4508 ID3D11InputLayout_Release(input_layout);
4509 release_test_context(&test_context);
4512 static void test_fragment_coords(void)
4514 struct d3d11_test_context test_context;
4515 D3D11_SUBRESOURCE_DATA resource_data;
4516 ID3D11PixelShader *ps, *ps_frac;
4517 D3D11_BUFFER_DESC buffer_desc;
4518 ID3D11DeviceContext *context;
4519 ID3D11Device *device;
4520 ID3D11Buffer *ps_cb;
4521 DWORD color;
4522 HRESULT hr;
4524 static const DWORD ps_code[] =
4526 #if 0
4527 float2 cutoff;
4529 float4 main(float4 position : SV_POSITION) : SV_TARGET
4531 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
4533 if (position.x > cutoff.x)
4534 ret.y = 1.0;
4535 if (position.y > cutoff.y)
4536 ret.z = 1.0;
4538 return ret;
4540 #endif
4541 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
4542 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4543 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4544 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4545 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
4546 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
4547 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
4548 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
4549 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
4550 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
4551 0x0100003e,
4553 static const DWORD ps_frac_code[] =
4555 #if 0
4556 float4 main(float4 position : SV_POSITION) : SV_TARGET
4558 return float4(frac(position.xy), 0.0, 1.0);
4560 #endif
4561 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
4562 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4563 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4564 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4565 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
4566 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4567 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
4568 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
4570 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4571 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
4573 if (!init_test_context(&test_context, NULL))
4574 return;
4576 device = test_context.device;
4577 context = test_context.immediate_context;
4579 buffer_desc.ByteWidth = sizeof(cutoff);
4580 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4581 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4582 buffer_desc.CPUAccessFlags = 0;
4583 buffer_desc.MiscFlags = 0;
4584 buffer_desc.StructureByteStride = 0;
4586 resource_data.pSysMem = &cutoff;
4587 resource_data.SysMemPitch = 0;
4588 resource_data.SysMemSlicePitch = 0;
4590 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4591 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4593 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4594 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4595 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
4596 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4598 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4599 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4601 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4603 draw_quad(&test_context);
4605 color = get_texture_color(test_context.backbuffer, 319, 239);
4606 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4607 color = get_texture_color(test_context.backbuffer, 320, 239);
4608 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4609 color = get_texture_color(test_context.backbuffer, 319, 240);
4610 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4611 color = get_texture_color(test_context.backbuffer, 320, 240);
4612 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4614 ID3D11Buffer_Release(ps_cb);
4615 cutoff.x = 16.0f;
4616 cutoff.y = 16.0f;
4617 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4618 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4619 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4621 draw_quad(&test_context);
4623 color = get_texture_color(test_context.backbuffer, 14, 14);
4624 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4625 color = get_texture_color(test_context.backbuffer, 18, 14);
4626 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4627 color = get_texture_color(test_context.backbuffer, 14, 18);
4628 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4629 color = get_texture_color(test_context.backbuffer, 18, 18);
4630 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4632 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
4633 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4635 ID3D11DeviceContext_Draw(context, 4, 0);
4637 color = get_texture_color(test_context.backbuffer, 14, 14);
4638 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
4640 ID3D11Buffer_Release(ps_cb);
4641 ID3D11PixelShader_Release(ps_frac);
4642 ID3D11PixelShader_Release(ps);
4643 release_test_context(&test_context);
4646 static void test_update_subresource(void)
4648 struct d3d11_test_context test_context;
4649 D3D11_TEXTURE2D_DESC texture_desc;
4650 ID3D11SamplerState *sampler_state;
4651 ID3D11ShaderResourceView *ps_srv;
4652 D3D11_SAMPLER_DESC sampler_desc;
4653 ID3D11DeviceContext *context;
4654 struct texture_readback rb;
4655 ID3D11Texture2D *texture;
4656 ID3D11PixelShader *ps;
4657 ID3D11Device *device;
4658 unsigned int i, j;
4659 D3D11_BOX box;
4660 DWORD color;
4661 HRESULT hr;
4663 static const DWORD ps_code[] =
4665 #if 0
4666 Texture2D t;
4667 SamplerState s;
4669 float4 main(float4 position : SV_POSITION) : SV_Target
4671 float2 p;
4673 p.x = position.x / 640.0f;
4674 p.y = position.y / 480.0f;
4675 return t.Sample(s, p);
4677 #endif
4678 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4679 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4680 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4681 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4682 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4683 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4684 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4685 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4686 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4687 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4689 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4690 static const DWORD bitmap_data[] =
4692 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4693 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4694 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4695 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4697 static const DWORD expected_colors[] =
4699 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
4700 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4701 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
4702 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
4705 if (!init_test_context(&test_context, NULL))
4706 return;
4708 device = test_context.device;
4709 context = test_context.immediate_context;
4711 texture_desc.Width = 4;
4712 texture_desc.Height = 4;
4713 texture_desc.MipLevels = 1;
4714 texture_desc.ArraySize = 1;
4715 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4716 texture_desc.SampleDesc.Count = 1;
4717 texture_desc.SampleDesc.Quality = 0;
4718 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4719 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4720 texture_desc.CPUAccessFlags = 0;
4721 texture_desc.MiscFlags = 0;
4723 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4724 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4726 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
4727 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4729 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4730 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4731 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4732 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4733 sampler_desc.MipLODBias = 0.0f;
4734 sampler_desc.MaxAnisotropy = 0;
4735 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4736 sampler_desc.BorderColor[0] = 0.0f;
4737 sampler_desc.BorderColor[1] = 0.0f;
4738 sampler_desc.BorderColor[2] = 0.0f;
4739 sampler_desc.BorderColor[3] = 0.0f;
4740 sampler_desc.MinLOD = 0.0f;
4741 sampler_desc.MaxLOD = 0.0f;
4743 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4744 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4746 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4747 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4749 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
4750 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
4751 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4753 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4754 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
4756 draw_quad(&test_context);
4757 check_texture_color(test_context.backbuffer, 0x00000000, 0);
4759 set_box(&box, 1, 1, 0, 3, 3, 1);
4760 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4761 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4762 set_box(&box, 0, 3, 0, 3, 4, 1);
4763 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4764 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
4765 set_box(&box, 0, 0, 0, 4, 1, 1);
4766 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4767 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
4768 set_box(&box, 0, 1, 0, 1, 3, 1);
4769 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4770 &bitmap_data[2], sizeof(*bitmap_data), 0);
4771 set_box(&box, 4, 4, 0, 3, 1, 1);
4772 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4773 bitmap_data, sizeof(*bitmap_data), 0);
4774 set_box(&box, 0, 0, 0, 4, 4, 0);
4775 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
4776 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4777 draw_quad(&test_context);
4778 get_texture_readback(test_context.backbuffer, &rb);
4779 for (i = 0; i < 4; ++i)
4781 for (j = 0; j < 4; ++j)
4783 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4784 ok(compare_color(color, expected_colors[j + i * 4], 1),
4785 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4786 color, j, i, expected_colors[j + i * 4]);
4789 release_texture_readback(&rb);
4791 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
4792 bitmap_data, 4 * sizeof(*bitmap_data), 0);
4793 draw_quad(&test_context);
4794 get_texture_readback(test_context.backbuffer, &rb);
4795 for (i = 0; i < 4; ++i)
4797 for (j = 0; j < 4; ++j)
4799 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4800 ok(compare_color(color, bitmap_data[j + i * 4], 1),
4801 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4802 color, j, i, bitmap_data[j + i * 4]);
4805 release_texture_readback(&rb);
4807 ID3D11PixelShader_Release(ps);
4808 ID3D11SamplerState_Release(sampler_state);
4809 ID3D11ShaderResourceView_Release(ps_srv);
4810 ID3D11Texture2D_Release(texture);
4811 release_test_context(&test_context);
4814 static void test_copy_subresource_region(void)
4816 ID3D11Texture2D *dst_texture, *src_texture;
4817 struct d3d11_test_context test_context;
4818 ID3D11Buffer *dst_buffer, *src_buffer;
4819 D3D11_SUBRESOURCE_DATA resource_data;
4820 D3D11_TEXTURE2D_DESC texture_desc;
4821 ID3D11SamplerState *sampler_state;
4822 ID3D11ShaderResourceView *ps_srv;
4823 D3D11_SAMPLER_DESC sampler_desc;
4824 D3D11_BUFFER_DESC buffer_desc;
4825 ID3D11DeviceContext *context;
4826 struct vec4 float_colors[16];
4827 struct texture_readback rb;
4828 ID3D11PixelShader *ps;
4829 ID3D11Device *device;
4830 unsigned int i, j;
4831 D3D11_BOX box;
4832 DWORD color;
4833 HRESULT hr;
4835 static const DWORD ps_code[] =
4837 #if 0
4838 Texture2D t;
4839 SamplerState s;
4841 float4 main(float4 position : SV_POSITION) : SV_Target
4843 float2 p;
4845 p.x = position.x / 640.0f;
4846 p.y = position.y / 480.0f;
4847 return t.Sample(s, p);
4849 #endif
4850 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4851 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4852 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4853 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4854 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4855 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4856 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4857 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4858 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4859 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4861 static const DWORD ps_buffer_code[] =
4863 #if 0
4864 float4 buffer[16];
4866 float4 main(float4 position : SV_POSITION) : SV_TARGET
4868 float2 p = (float2)4;
4869 p *= float2(position.x / 640.0f, position.y / 480.0f);
4870 return buffer[(int)p.y * 4 + (int)p.x];
4872 #endif
4873 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
4874 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4875 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4876 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4877 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
4878 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
4879 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
4880 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
4881 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
4882 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
4883 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
4884 0x0010000a, 0x00000000, 0x0100003e,
4886 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4887 static const DWORD bitmap_data[] =
4889 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4890 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4891 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4892 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4894 static const DWORD expected_colors[] =
4896 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4897 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
4898 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
4899 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
4902 if (!init_test_context(&test_context, NULL))
4903 return;
4905 device = test_context.device;
4906 context = test_context.immediate_context;
4908 texture_desc.Width = 4;
4909 texture_desc.Height = 4;
4910 texture_desc.MipLevels = 1;
4911 texture_desc.ArraySize = 1;
4912 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4913 texture_desc.SampleDesc.Count = 1;
4914 texture_desc.SampleDesc.Quality = 0;
4915 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4916 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4917 texture_desc.CPUAccessFlags = 0;
4918 texture_desc.MiscFlags = 0;
4920 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
4921 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4923 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
4925 resource_data.pSysMem = bitmap_data;
4926 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
4927 resource_data.SysMemSlicePitch = 0;
4929 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
4930 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
4932 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
4933 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4935 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4936 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4937 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4938 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4939 sampler_desc.MipLODBias = 0.0f;
4940 sampler_desc.MaxAnisotropy = 0;
4941 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4942 sampler_desc.BorderColor[0] = 0.0f;
4943 sampler_desc.BorderColor[1] = 0.0f;
4944 sampler_desc.BorderColor[2] = 0.0f;
4945 sampler_desc.BorderColor[3] = 0.0f;
4946 sampler_desc.MinLOD = 0.0f;
4947 sampler_desc.MaxLOD = 0.0f;
4949 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
4950 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4952 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4953 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4955 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
4956 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
4957 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4959 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4961 set_box(&box, 0, 0, 0, 2, 2, 1);
4962 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4963 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
4964 set_box(&box, 1, 2, 0, 4, 3, 1);
4965 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4966 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
4967 set_box(&box, 0, 3, 0, 4, 4, 1);
4968 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4969 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
4970 set_box(&box, 3, 0, 0, 4, 2, 1);
4971 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4972 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
4973 set_box(&box, 3, 1, 0, 4, 2, 1);
4974 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4975 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
4976 set_box(&box, 0, 0, 0, 4, 4, 0);
4977 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4978 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
4979 draw_quad(&test_context);
4980 get_texture_readback(test_context.backbuffer, &rb);
4981 for (i = 0; i < 4; ++i)
4983 for (j = 0; j < 4; ++j)
4985 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
4986 ok(compare_color(color, expected_colors[j + i * 4], 1),
4987 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
4988 color, j, i, expected_colors[j + i * 4]);
4991 release_texture_readback(&rb);
4993 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
4994 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
4995 draw_quad(&test_context);
4996 get_texture_readback(test_context.backbuffer, &rb);
4997 for (i = 0; i < 4; ++i)
4999 for (j = 0; j < 4; ++j)
5001 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5002 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5003 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5004 color, j, i, bitmap_data[j + i * 4]);
5007 release_texture_readback(&rb);
5009 ID3D11PixelShader_Release(ps);
5010 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
5011 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5013 ID3D11ShaderResourceView_Release(ps_srv);
5014 ps_srv = NULL;
5016 ID3D11SamplerState_Release(sampler_state);
5017 sampler_state = NULL;
5019 ID3D11Texture2D_Release(dst_texture);
5020 ID3D11Texture2D_Release(src_texture);
5022 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
5023 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
5024 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5026 buffer_desc.ByteWidth = sizeof(float_colors);
5027 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
5028 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
5029 buffer_desc.CPUAccessFlags = 0;
5030 buffer_desc.MiscFlags = 0;
5031 buffer_desc.StructureByteStride = 0;
5033 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
5034 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5036 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
5038 buffer_desc.ByteWidth = 256 * sizeof(*float_colors);
5039 buffer_desc.BindFlags = 0;
5041 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &src_buffer);
5042 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5044 for (i = 0; i < 4; ++i)
5046 for (j = 0; j < 4; ++j)
5048 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
5049 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
5050 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
5051 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
5054 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
5055 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
5057 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
5058 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5059 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5060 draw_quad(&test_context);
5061 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5063 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
5064 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5065 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5066 draw_quad(&test_context);
5067 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5069 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
5070 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5071 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5072 draw_quad(&test_context);
5073 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5075 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
5076 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5077 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5078 draw_quad(&test_context);
5079 get_texture_readback(test_context.backbuffer, &rb);
5080 for (i = 0; i < 4; ++i)
5082 for (j = 0; j < 4; ++j)
5084 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5085 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5086 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5087 color, j, i, bitmap_data[j + i * 4]);
5090 release_texture_readback(&rb);
5092 ID3D11Buffer_Release(dst_buffer);
5093 ID3D11Buffer_Release(src_buffer);
5094 ID3D11PixelShader_Release(ps);
5095 release_test_context(&test_context);
5098 static void test_resource_map(void)
5100 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
5101 D3D11_TEXTURE3D_DESC texture3d_desc;
5102 D3D11_TEXTURE2D_DESC texture2d_desc;
5103 D3D11_BUFFER_DESC buffer_desc;
5104 ID3D11DeviceContext *context;
5105 ID3D11Texture3D *texture3d;
5106 ID3D11Texture2D *texture2d;
5107 ID3D11Buffer *buffer;
5108 ID3D11Device *device;
5109 ULONG refcount;
5110 HRESULT hr;
5111 DWORD data;
5113 if (!(device = create_device(NULL)))
5115 skip("Failed to create device.\n");
5116 return;
5119 ID3D11Device_GetImmediateContext(device, &context);
5121 buffer_desc.ByteWidth = 1024;
5122 buffer_desc.Usage = D3D11_USAGE_STAGING;
5123 buffer_desc.BindFlags = 0;
5124 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5125 buffer_desc.MiscFlags = 0;
5126 buffer_desc.StructureByteStride = 0;
5128 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
5129 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
5131 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5132 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5134 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5135 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5136 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
5137 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5138 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
5139 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5140 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
5142 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5143 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5144 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
5145 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5146 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
5147 data = *((DWORD *)mapped_subresource.pData);
5148 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5149 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
5151 refcount = ID3D11Buffer_Release(buffer);
5152 ok(!refcount, "Buffer has %u references left.\n", refcount);
5154 texture2d_desc.Width = 512;
5155 texture2d_desc.Height = 512;
5156 texture2d_desc.MipLevels = 1;
5157 texture2d_desc.ArraySize = 1;
5158 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5159 texture2d_desc.SampleDesc.Count = 1;
5160 texture2d_desc.SampleDesc.Quality = 0;
5161 texture2d_desc.Usage = D3D11_USAGE_STAGING;
5162 texture2d_desc.BindFlags = 0;
5163 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5164 texture2d_desc.MiscFlags = 0;
5166 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
5167 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
5169 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5170 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5172 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5173 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5174 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5175 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5176 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
5177 mapped_subresource.DepthPitch);
5178 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5179 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
5181 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5182 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5183 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5184 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5185 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
5186 mapped_subresource.DepthPitch);
5187 data = *((DWORD *)mapped_subresource.pData);
5188 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5189 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
5191 refcount = ID3D11Texture2D_Release(texture2d);
5192 ok(!refcount, "2D texture has %u references left.\n", refcount);
5194 texture3d_desc.Width = 64;
5195 texture3d_desc.Height = 64;
5196 texture3d_desc.Depth = 64;
5197 texture3d_desc.MipLevels = 1;
5198 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5199 texture3d_desc.Usage = D3D11_USAGE_STAGING;
5200 texture3d_desc.BindFlags = 0;
5201 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5202 texture3d_desc.MiscFlags = 0;
5204 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
5205 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
5207 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5208 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5210 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5211 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5212 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5213 if (FAILED(hr)) goto done;
5214 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5215 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
5216 mapped_subresource.DepthPitch);
5217 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5218 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
5220 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5221 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5222 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5223 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5224 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
5225 mapped_subresource.DepthPitch);
5226 data = *((DWORD *)mapped_subresource.pData);
5227 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5228 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
5230 done:
5231 refcount = ID3D11Texture3D_Release(texture3d);
5232 ok(!refcount, "3D texture has %u references left.\n", refcount);
5234 ID3D11DeviceContext_Release(context);
5236 refcount = ID3D11Device_Release(device);
5237 ok(!refcount, "Device has %u references left.\n", refcount);
5240 static void test_multisample_init(void)
5242 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5243 struct d3d11_test_context test_context;
5244 ID3D11DeviceContext *context;
5245 D3D11_TEXTURE2D_DESC desc;
5246 ID3D11Texture2D *multi;
5247 ID3D11Device *device;
5248 UINT count = 0;
5249 HRESULT hr;
5251 if (!init_test_context(&test_context, NULL))
5252 return;
5254 device = test_context.device;
5255 context = test_context.immediate_context;
5257 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
5258 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
5259 if (!count)
5261 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
5262 goto done;
5265 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5267 desc.Width = 640;
5268 desc.Height = 480;
5269 desc.MipLevels = 1;
5270 desc.ArraySize = 1;
5271 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5272 desc.SampleDesc.Count = 2;
5273 desc.SampleDesc.Quality = 0;
5274 desc.Usage = D3D11_USAGE_DEFAULT;
5275 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5276 desc.CPUAccessFlags = 0;
5277 desc.MiscFlags = 0;
5278 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &multi);
5279 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5281 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
5282 (ID3D11Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
5284 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 0);
5286 ID3D11Texture2D_Release(multi);
5287 done:
5288 release_test_context(&test_context);
5291 static void test_check_multisample_quality_levels(void)
5293 ID3D11Device *device;
5294 UINT quality_levels;
5295 ULONG refcount;
5296 HRESULT hr;
5298 if (!(device = create_device(NULL)))
5300 skip("Failed to create device.\n");
5301 return;
5304 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5305 if (!quality_levels)
5307 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
5308 goto done;
5311 quality_levels = 0xdeadbeef;
5312 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
5313 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5314 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5315 quality_levels = 0xdeadbeef;
5316 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
5317 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5318 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
5320 quality_levels = 0xdeadbeef;
5321 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
5322 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5323 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
5324 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5325 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5327 quality_levels = 0xdeadbeef;
5328 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
5329 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5330 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
5331 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5332 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
5334 quality_levels = 0xdeadbeef;
5335 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
5336 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5337 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5338 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5339 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5341 /* We assume 15 samples multisampling is never supported in practice. */
5342 quality_levels = 0xdeadbeef;
5343 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
5344 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5345 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5346 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
5347 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5348 quality_levels = 0xdeadbeef;
5349 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
5350 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5351 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5352 quality_levels = 0xdeadbeef;
5353 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
5354 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5355 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5357 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
5358 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5359 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5361 done:
5362 refcount = ID3D11Device_Release(device);
5363 ok(!refcount, "Device has %u references left.\n", refcount);
5366 static void test_clear_render_target_view(void)
5368 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
5369 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
5371 ID3D11Texture2D *texture, *srgb_texture;
5372 struct d3d11_test_context test_context;
5373 ID3D11RenderTargetView *rtv, *srgb_rtv;
5374 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
5375 D3D11_TEXTURE2D_DESC texture_desc;
5376 ID3D11DeviceContext *context;
5377 ID3D11Device *device;
5378 HRESULT hr;
5380 if (!init_test_context(&test_context, NULL))
5381 return;
5383 device = test_context.device;
5384 context = test_context.immediate_context;
5386 texture_desc.Width = 640;
5387 texture_desc.Height = 480;
5388 texture_desc.MipLevels = 1;
5389 texture_desc.ArraySize = 1;
5390 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5391 texture_desc.SampleDesc.Count = 1;
5392 texture_desc.SampleDesc.Quality = 0;
5393 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5394 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5395 texture_desc.CPUAccessFlags = 0;
5396 texture_desc.MiscFlags = 0;
5397 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5398 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
5400 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
5401 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
5402 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
5404 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5405 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5407 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
5408 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5410 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
5411 check_texture_color(test_context.backbuffer, expected_color, 1);
5413 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
5414 check_texture_color(texture, expected_color, 1);
5416 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
5417 check_texture_color(srgb_texture, expected_srgb_color, 1);
5419 ID3D11RenderTargetView_Release(srgb_rtv);
5420 ID3D11RenderTargetView_Release(rtv);
5421 ID3D11Texture2D_Release(srgb_texture);
5422 ID3D11Texture2D_Release(texture);
5424 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
5425 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5426 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
5428 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
5429 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
5430 U(rtv_desc).Texture2D.MipSlice = 0;
5431 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
5432 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5434 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5435 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
5436 U(rtv_desc).Texture2D.MipSlice = 0;
5437 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
5438 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5440 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
5441 check_texture_color(texture, expected_color, 1);
5443 if (!is_warp_device(device))
5445 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
5446 todo_wine check_texture_color(texture, expected_srgb_color, 1);
5448 else
5450 win_skip("Skipping broken test on WARP.\n");
5454 ID3D11RenderTargetView_Release(srgb_rtv);
5455 ID3D11RenderTargetView_Release(rtv);
5456 ID3D11Texture2D_Release(texture);
5457 release_test_context(&test_context);
5460 static void test_clear_depth_stencil_view(void)
5462 D3D11_TEXTURE2D_DESC texture_desc;
5463 ID3D11Texture2D *depth_texture;
5464 ID3D11DeviceContext *context;
5465 ID3D11DepthStencilView *dsv;
5466 ID3D11Device *device;
5467 ULONG refcount;
5468 HRESULT hr;
5470 if (!(device = create_device(NULL)))
5472 skip("Failed to create device.\n");
5473 return;
5476 ID3D11Device_GetImmediateContext(device, &context);
5478 texture_desc.Width = 640;
5479 texture_desc.Height = 480;
5480 texture_desc.MipLevels = 1;
5481 texture_desc.ArraySize = 1;
5482 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
5483 texture_desc.SampleDesc.Count = 1;
5484 texture_desc.SampleDesc.Quality = 0;
5485 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5486 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
5487 texture_desc.CPUAccessFlags = 0;
5488 texture_desc.MiscFlags = 0;
5489 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
5490 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
5492 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
5493 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
5495 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
5496 check_texture_float(depth_texture, 1.0f, 0);
5498 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
5499 check_texture_float(depth_texture, 0.25f, 0);
5501 ID3D11Texture2D_Release(depth_texture);
5502 ID3D11DepthStencilView_Release(dsv);
5504 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5505 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
5506 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
5508 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
5509 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
5511 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
5512 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
5514 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
5515 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
5517 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
5518 check_texture_color(depth_texture, 0xffffffff, 0);
5520 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
5521 check_texture_color(depth_texture, 0x00000000, 0);
5523 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
5524 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
5526 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
5527 check_texture_color(depth_texture, 0xffffffff, 0);
5529 ID3D11Texture2D_Release(depth_texture);
5530 ID3D11DepthStencilView_Release(dsv);
5532 ID3D11DeviceContext_Release(context);
5534 refcount = ID3D11Device_Release(device);
5535 ok(!refcount, "Device has %u references left.\n", refcount);
5538 static void test_draw_depth_only(void)
5540 ID3D11DepthStencilState *depth_stencil_state;
5541 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
5542 struct d3d11_test_context test_context;
5543 ID3D11PixelShader *ps_color, *ps_depth;
5544 D3D11_TEXTURE2D_DESC texture_desc;
5545 D3D11_BUFFER_DESC buffer_desc;
5546 ID3D11DeviceContext *context;
5547 ID3D11DepthStencilView *dsv;
5548 struct texture_readback rb;
5549 ID3D11Texture2D *texture;
5550 ID3D11Device *device;
5551 unsigned int i, j;
5552 D3D11_VIEWPORT vp;
5553 struct vec4 depth;
5554 ID3D11Buffer *cb;
5555 HRESULT hr;
5557 static const DWORD ps_color_code[] =
5559 #if 0
5560 float4 main(float4 position : SV_POSITION) : SV_Target
5562 return float4(0.0, 1.0, 0.0, 1.0);
5564 #endif
5565 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
5566 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5567 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
5568 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5569 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
5570 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
5571 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
5573 static const DWORD ps_depth_code[] =
5575 #if 0
5576 float depth;
5578 float main() : SV_Depth
5580 return depth;
5582 #endif
5583 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
5584 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
5585 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
5586 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
5587 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
5588 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5591 if (!init_test_context(&test_context, NULL))
5592 return;
5594 device = test_context.device;
5595 context = test_context.immediate_context;
5597 buffer_desc.ByteWidth = sizeof(depth);
5598 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
5599 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
5600 buffer_desc.CPUAccessFlags = 0;
5601 buffer_desc.MiscFlags = 0;
5602 buffer_desc.StructureByteStride = 0;
5604 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
5605 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
5607 texture_desc.Width = 640;
5608 texture_desc.Height = 480;
5609 texture_desc.MipLevels = 1;
5610 texture_desc.ArraySize = 1;
5611 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
5612 texture_desc.SampleDesc.Count = 1;
5613 texture_desc.SampleDesc.Quality = 0;
5614 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5615 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
5616 texture_desc.CPUAccessFlags = 0;
5617 texture_desc.MiscFlags = 0;
5619 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5620 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5622 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
5623 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
5625 depth_stencil_desc.DepthEnable = TRUE;
5626 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5627 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
5628 depth_stencil_desc.StencilEnable = FALSE;
5630 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
5631 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
5633 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
5634 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5635 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
5636 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5638 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
5639 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
5640 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
5641 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
5643 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
5644 check_texture_float(texture, 1.0f, 1);
5645 draw_quad(&test_context);
5646 check_texture_float(texture, 0.0f, 1);
5648 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
5650 depth.x = 0.7f;
5651 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
5652 draw_quad(&test_context);
5653 check_texture_float(texture, 0.0f, 1);
5654 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
5655 check_texture_float(texture, 1.0f, 1);
5656 draw_quad(&test_context);
5657 check_texture_float(texture, 0.7f, 1);
5658 depth.x = 0.8f;
5659 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
5660 draw_quad(&test_context);
5661 check_texture_float(texture, 0.7f, 1);
5662 depth.x = 0.5f;
5663 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
5664 draw_quad(&test_context);
5665 check_texture_float(texture, 0.5f, 1);
5667 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
5668 depth.x = 0.1f;
5669 for (i = 0; i < 4; ++i)
5671 for (j = 0; j < 4; ++j)
5673 depth.x = 1.0f / 16.0f * (j + 4 * i);
5674 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
5676 vp.TopLeftX = 160.0f * j;
5677 vp.TopLeftY = 120.0f * i;
5678 vp.Width = 160.0f;
5679 vp.Height = 120.0f;
5680 vp.MinDepth = 0.0f;
5681 vp.MaxDepth = 1.0f;
5682 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5684 draw_quad(&test_context);
5687 get_texture_readback(texture, &rb);
5688 for (i = 0; i < 4; ++i)
5690 for (j = 0; j < 4; ++j)
5692 float obtained_depth, expected_depth;
5694 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
5695 expected_depth = 1.0f / 16.0f * (j + 4 * i);
5696 ok(compare_float(obtained_depth, expected_depth, 1),
5697 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
5698 obtained_depth, j, i, expected_depth);
5701 release_texture_readback(&rb);
5703 ID3D11Buffer_Release(cb);
5704 ID3D11PixelShader_Release(ps_color);
5705 ID3D11PixelShader_Release(ps_depth);
5706 ID3D11DepthStencilView_Release(dsv);
5707 ID3D11DepthStencilState_Release(depth_stencil_state);
5708 ID3D11Texture2D_Release(texture);
5709 release_test_context(&test_context);
5712 static void test_cb_relative_addressing(void)
5714 struct d3d11_test_context test_context;
5715 D3D11_SUBRESOURCE_DATA resource_data;
5716 ID3D11Buffer *colors_cb, *index_cb;
5717 unsigned int i, index[4] = {0};
5718 D3D11_BUFFER_DESC buffer_desc;
5719 ID3D11DeviceContext *context;
5720 ID3D11PixelShader *ps;
5721 ID3D11Device *device;
5722 DWORD color;
5723 HRESULT hr;
5725 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5727 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5729 static const DWORD vs_code[] =
5731 #if 0
5732 int color_index;
5734 cbuffer colors
5736 float4 colors[8];
5739 struct vs_in
5741 float4 position : POSITION;
5744 struct vs_out
5746 float4 position : SV_POSITION;
5747 float4 color : COLOR;
5750 vs_out main(const vs_in v)
5752 vs_out o;
5754 o.position = v.position;
5755 o.color = colors[color_index];
5757 return o;
5759 #endif
5760 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
5761 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5762 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5763 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
5764 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
5765 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
5766 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
5767 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
5768 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
5769 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
5770 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
5771 0x0100003e,
5773 static const DWORD ps_code[] =
5775 #if 0
5776 struct ps_in
5778 float4 position : SV_POSITION;
5779 float4 color : COLOR;
5782 float4 main(const ps_in v) : SV_TARGET
5784 return v.color;
5786 #endif
5787 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
5788 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5789 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5790 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5791 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5792 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
5793 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5794 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5796 static const struct
5798 struct vec2 position;
5800 quad[] =
5802 {{-1.0f, -1.0f}},
5803 {{-1.0f, 1.0f}},
5804 {{ 1.0f, -1.0f}},
5805 {{ 1.0f, 1.0f}},
5807 static const struct
5809 float color[4];
5811 colors[10] =
5813 {{0.0f, 0.0f, 0.0f, 1.0f}},
5814 {{0.0f, 0.0f, 1.0f, 0.0f}},
5815 {{0.0f, 0.0f, 1.0f, 1.0f}},
5816 {{0.0f, 1.0f, 0.0f, 0.0f}},
5817 {{0.0f, 1.0f, 0.0f, 1.0f}},
5818 {{0.0f, 1.0f, 1.0f, 0.0f}},
5819 {{0.0f, 1.0f, 1.0f, 1.0f}},
5820 {{1.0f, 0.0f, 0.0f, 0.0f}},
5821 {{1.0f, 0.0f, 0.0f, 1.0f}},
5822 {{1.0f, 0.0f, 1.0f, 0.0f}},
5824 static const struct
5826 unsigned int index;
5827 DWORD expected;
5829 test_data[] =
5831 {0, 0xff000000},
5832 {1, 0x00ff0000},
5833 {2, 0xffff0000},
5834 {3, 0x0000ff00},
5835 {4, 0xff00ff00},
5836 {5, 0x00ffff00},
5837 {6, 0xffffff00},
5838 {7, 0x000000ff},
5840 {8, 0xff0000ff},
5841 {9, 0x00ff00ff},
5843 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
5844 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
5846 if (!init_test_context(&test_context, &feature_level))
5847 return;
5849 device = test_context.device;
5850 context = test_context.immediate_context;
5852 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5853 vs_code, sizeof(vs_code), &test_context.input_layout);
5854 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5856 buffer_desc.ByteWidth = sizeof(quad);
5857 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
5858 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
5859 buffer_desc.CPUAccessFlags = 0;
5860 buffer_desc.MiscFlags = 0;
5861 buffer_desc.StructureByteStride = 0;
5863 resource_data.pSysMem = quad;
5864 resource_data.SysMemPitch = 0;
5865 resource_data.SysMemSlicePitch = 0;
5867 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &test_context.vb);
5868 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
5870 buffer_desc.ByteWidth = sizeof(colors);
5871 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
5872 resource_data.pSysMem = &colors;
5873 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &colors_cb);
5874 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
5876 buffer_desc.ByteWidth = sizeof(index);
5877 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &index_cb);
5878 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
5880 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
5881 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5882 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5883 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5885 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
5886 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
5887 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5889 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5891 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
5893 index[0] = test_data[i].index;
5894 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
5896 draw_quad(&test_context);
5898 color = get_texture_color(test_context.backbuffer, 319, 239);
5899 ok(compare_color(color, test_data[i].expected, 1),
5900 "Got unexpected color 0x%08x for index %u.\n", color, test_data[i].index);
5903 ID3D11Buffer_Release(index_cb);
5904 ID3D11Buffer_Release(colors_cb);
5905 ID3D11PixelShader_Release(ps);
5907 release_test_context(&test_context);
5910 START_TEST(d3d11)
5912 test_create_device();
5913 test_device_interfaces();
5914 test_get_immediate_context();
5915 test_create_texture2d();
5916 test_texture2d_interfaces();
5917 test_create_texture3d();
5918 test_texture3d_interfaces();
5919 test_buffer_interfaces();
5920 test_create_depthstencil_view();
5921 test_depthstencil_view_interfaces();
5922 test_create_rendertarget_view();
5923 test_create_shader_resource_view();
5924 test_create_shader();
5925 test_create_sampler_state();
5926 test_create_blend_state();
5927 test_create_depthstencil_state();
5928 test_create_rasterizer_state();
5929 test_create_query();
5930 test_device_removed_reason();
5931 test_private_data();
5932 test_blend();
5933 test_texture();
5934 test_multiple_render_targets();
5935 test_scissor();
5936 test_il_append_aligned();
5937 test_fragment_coords();
5938 test_update_subresource();
5939 test_copy_subresource_region();
5940 test_resource_map();
5941 test_multisample_init();
5942 test_check_multisample_quality_levels();
5943 test_clear_render_target_view();
5944 test_clear_depth_stencil_view();
5945 test_draw_depth_only();
5946 test_cb_relative_addressing();