d3d11/tests: Check all sub-resources in check_texture_* functions.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob95afdacf15adefb656a7f00148ed464e1ecaa332
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 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
28 static const D3D_FEATURE_LEVEL d3d11_feature_levels[] =
30 D3D_FEATURE_LEVEL_11_1,
31 D3D_FEATURE_LEVEL_11_0,
32 D3D_FEATURE_LEVEL_10_1,
33 D3D_FEATURE_LEVEL_10_0,
34 D3D_FEATURE_LEVEL_9_3,
35 D3D_FEATURE_LEVEL_9_2,
36 D3D_FEATURE_LEVEL_9_1
39 struct vec2
41 float x, y;
44 struct vec3
46 float x, y, z;
49 struct vec4
51 float x, y, z, w;
54 struct device_desc
56 const D3D_FEATURE_LEVEL *feature_level;
57 UINT flags;
60 struct swapchain_desc
62 BOOL windowed;
63 UINT buffer_count;
64 DXGI_SWAP_EFFECT swap_effect;
65 DWORD flags;
68 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
70 box->left = left;
71 box->top = top;
72 box->front = front;
73 box->right = right;
74 box->bottom = bottom;
75 box->back = back;
78 static ULONG get_refcount(IUnknown *iface)
80 IUnknown_AddRef(iface);
81 return IUnknown_Release(iface);
84 static BOOL compare_float(float f, float g, unsigned int ulps)
86 int x = *(int *)&f;
87 int y = *(int *)&g;
89 if (x < 0)
90 x = INT_MIN - x;
91 if (y < 0)
92 y = INT_MIN - y;
94 if (abs(x - y) > ulps)
95 return FALSE;
97 return TRUE;
100 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
102 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
103 return FALSE;
104 c1 >>= 8; c2 >>= 8;
105 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
106 return FALSE;
107 c1 >>= 8; c2 >>= 8;
108 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
109 return FALSE;
110 c1 >>= 8; c2 >>= 8;
111 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
112 return FALSE;
113 return TRUE;
116 struct texture_readback
118 ID3D11Resource *texture;
119 D3D11_MAPPED_SUBRESOURCE map_desc;
120 ID3D11DeviceContext *immediate_context;
121 unsigned int width, height, sub_resource_idx;
124 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
125 struct texture_readback *rb)
127 D3D11_TEXTURE2D_DESC texture_desc;
128 unsigned int miplevel;
129 ID3D11Device *device;
130 HRESULT hr;
132 memset(rb, 0, sizeof(*rb));
134 ID3D11Texture2D_GetDevice(texture, &device);
136 ID3D11Texture2D_GetDesc(texture, &texture_desc);
137 texture_desc.Usage = D3D11_USAGE_STAGING;
138 texture_desc.BindFlags = 0;
139 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
140 texture_desc.MiscFlags = 0;
141 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->texture)))
143 trace("Failed to create texture, hr %#x.\n", hr);
144 ID3D11Device_Release(device);
145 return;
148 miplevel = sub_resource_idx % texture_desc.MipLevels;
149 rb->width = max(1, texture_desc.Width >> miplevel);
150 rb->height = max(1, texture_desc.Height >> miplevel);
151 rb->sub_resource_idx = sub_resource_idx;
153 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
155 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
156 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->texture, sub_resource_idx,
157 D3D11_MAP_READ, 0, &rb->map_desc)))
159 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
160 ID3D11Resource_Release(rb->texture);
161 rb->texture = NULL;
162 ID3D11DeviceContext_Release(rb->immediate_context);
163 rb->immediate_context = NULL;
166 ID3D11Device_Release(device);
169 static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, unsigned int y)
171 return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
174 static float get_readback_float(struct texture_readback *rb, unsigned int x, unsigned int y)
176 return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
179 static void release_texture_readback(struct texture_readback *rb)
181 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->texture, rb->sub_resource_idx);
182 ID3D11Resource_Release(rb->texture);
183 ID3D11DeviceContext_Release(rb->immediate_context);
186 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
188 struct texture_readback rb;
189 DWORD color;
191 get_texture_readback(texture, 0, &rb);
192 color = get_readback_color(&rb, x, y);
193 release_texture_readback(&rb);
195 return color;
198 #define check_texture_sub_resource_color(t, s, c, d) check_texture_sub_resource_color_(__LINE__, t, s, c, d)
199 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
200 unsigned int sub_resource_idx, DWORD expected_color, BYTE max_diff)
202 struct texture_readback rb;
203 unsigned int x = 0, y = 0;
204 BOOL all_match = TRUE;
205 DWORD color = 0;
207 get_texture_readback(texture, sub_resource_idx, &rb);
208 for (y = 0; y < rb.height; ++y)
210 for (x = 0; x < rb.width; ++x)
212 color = get_readback_color(&rb, x, y);
213 if (!compare_color(color, expected_color, max_diff))
215 all_match = FALSE;
216 break;
219 if (!all_match)
220 break;
222 release_texture_readback(&rb);
223 ok_(__FILE__, line)(all_match,
224 "Got unexpected color 0x%08x at (%u, %u), sub-resource %u.\n",
225 color, x, y, sub_resource_idx);
228 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
229 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
230 DWORD expected_color, BYTE max_diff)
232 unsigned int sub_resource_idx, sub_resource_count;
233 D3D11_TEXTURE2D_DESC texture_desc;
235 ID3D11Texture2D_GetDesc(texture, &texture_desc);
236 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
237 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
238 check_texture_sub_resource_color_(line, texture, sub_resource_idx, expected_color, max_diff);
241 #define check_texture_sub_resource_float(t, s, c, d) check_texture_sub_resource_flot_(__LINE__, t, s, c, d)
242 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
243 unsigned int sub_resource_idx, float expected_value, BYTE max_diff)
245 struct texture_readback rb;
246 unsigned int x = 0, y = 0;
247 BOOL all_match = TRUE;
248 float value = 0.0f;
250 get_texture_readback(texture, sub_resource_idx, &rb);
251 for (y = 0; y < rb.height; ++y)
253 for (x = 0; x < rb.width; ++x)
255 value = get_readback_float(&rb, x, y);
256 if (!compare_float(value, expected_value, max_diff))
258 all_match = FALSE;
259 break;
262 if (!all_match)
263 break;
265 release_texture_readback(&rb);
266 ok_(__FILE__, line)(all_match,
267 "Got unexpected value %.8e at (%u, %u), sub-resource %u.\n",
268 value, x, y, sub_resource_idx);
271 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
272 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
273 float expected_value, BYTE max_diff)
275 unsigned int sub_resource_idx, sub_resource_count;
276 D3D11_TEXTURE2D_DESC texture_desc;
278 ID3D11Texture2D_GetDesc(texture, &texture_desc);
279 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
280 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
281 check_texture_sub_resource_float_(line, texture, sub_resource_idx, expected_value, max_diff);
284 static ID3D11Device *create_device(const struct device_desc *desc)
286 static const D3D_FEATURE_LEVEL default_feature_level[] =
288 D3D_FEATURE_LEVEL_11_0,
289 D3D_FEATURE_LEVEL_10_0,
291 const D3D_FEATURE_LEVEL *feature_level;
292 UINT flags = desc ? desc->flags : 0;
293 unsigned int feature_level_count;
294 ID3D11Device *device;
296 if (desc && desc->feature_level)
298 feature_level = desc->feature_level;
299 feature_level_count = 1;
301 else
303 feature_level = default_feature_level;
304 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
307 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
308 D3D11_SDK_VERSION, &device, NULL, NULL)))
309 return device;
310 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
311 D3D11_SDK_VERSION, &device, NULL, NULL)))
312 return device;
313 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
314 D3D11_SDK_VERSION, &device, NULL, NULL)))
315 return device;
317 return NULL;
320 static BOOL is_warp_device(ID3D11Device *device)
322 DXGI_ADAPTER_DESC adapter_desc;
323 IDXGIDevice *dxgi_device;
324 IDXGIAdapter *adapter;
325 HRESULT hr;
327 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
328 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
329 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
330 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
331 IDXGIDevice_Release(dxgi_device);
332 hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
333 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
334 IDXGIAdapter_Release(adapter);
336 return !adapter_desc.SubSysId && !adapter_desc.Revision
337 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
338 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
341 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
343 DXGI_SWAP_CHAIN_DESC dxgi_desc;
344 IDXGISwapChain *swapchain;
345 IDXGIDevice *dxgi_device;
346 IDXGIAdapter *adapter;
347 IDXGIFactory *factory;
348 HRESULT hr;
350 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
351 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
352 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
353 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
354 IDXGIDevice_Release(dxgi_device);
355 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
356 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
357 IDXGIAdapter_Release(adapter);
359 dxgi_desc.BufferDesc.Width = 640;
360 dxgi_desc.BufferDesc.Height = 480;
361 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
362 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
363 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
364 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
365 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
366 dxgi_desc.SampleDesc.Count = 1;
367 dxgi_desc.SampleDesc.Quality = 0;
368 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
369 dxgi_desc.BufferCount = 1;
370 dxgi_desc.OutputWindow = window;
371 dxgi_desc.Windowed = TRUE;
372 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
373 dxgi_desc.Flags = 0;
375 if (swapchain_desc)
377 dxgi_desc.Windowed = swapchain_desc->windowed;
378 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
379 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
381 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
382 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
385 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
386 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
387 IDXGIFactory_Release(factory);
389 return swapchain;
392 struct d3d11_test_context
394 ID3D11Device *device;
395 HWND window;
396 IDXGISwapChain *swapchain;
397 ID3D11Texture2D *backbuffer;
398 ID3D11RenderTargetView *backbuffer_rtv;
399 ID3D11DeviceContext *immediate_context;
401 ID3D11InputLayout *input_layout;
402 ID3D11VertexShader *vs;
403 ID3D11Buffer *vb;
406 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
407 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
408 const D3D_FEATURE_LEVEL *feature_level)
410 struct device_desc device_desc;
411 D3D11_VIEWPORT vp;
412 HRESULT hr;
414 memset(context, 0, sizeof(*context));
416 device_desc.feature_level = feature_level;
417 device_desc.flags = 0;
418 if (!(context->device = create_device(&device_desc)))
420 skip_(__FILE__, line)("Failed to create device.\n");
421 return FALSE;
423 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
424 0, 0, 640, 480, NULL, NULL, NULL, NULL);
425 context->swapchain = create_swapchain(context->device, context->window, NULL);
426 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
427 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
429 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
430 NULL, &context->backbuffer_rtv);
431 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
433 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
435 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
437 vp.TopLeftX = 0.0f;
438 vp.TopLeftY = 0.0f;
439 vp.Width = 640.0f;
440 vp.Height = 480.0f;
441 vp.MinDepth = 0.0f;
442 vp.MaxDepth = 1.0f;
443 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
445 return TRUE;
448 #define release_test_context(c) release_test_context_(__LINE__, c)
449 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
451 ULONG ref;
453 if (context->input_layout)
454 ID3D11InputLayout_Release(context->input_layout);
455 if (context->vs)
456 ID3D11VertexShader_Release(context->vs);
457 if (context->vb)
458 ID3D11Buffer_Release(context->vb);
460 ID3D11DeviceContext_Release(context->immediate_context);
461 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
462 ID3D11Texture2D_Release(context->backbuffer);
463 IDXGISwapChain_Release(context->swapchain);
464 DestroyWindow(context->window);
466 ref = ID3D11Device_Release(context->device);
467 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
470 #define draw_quad(c) draw_quad_(__LINE__, c)
471 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
473 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
475 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
477 static const DWORD default_vs_code[] =
479 #if 0
480 float4 main(float4 position : POSITION) : SV_POSITION
482 return position;
484 #endif
485 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
486 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
487 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
488 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
489 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
490 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
491 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
493 static const struct
495 struct vec2 position;
497 quad[] =
499 {{-1.0f, -1.0f}},
500 {{-1.0f, 1.0f}},
501 {{ 1.0f, -1.0f}},
502 {{ 1.0f, 1.0f}},
505 ID3D11Device *device = context->device;
506 D3D11_SUBRESOURCE_DATA resource_data;
507 D3D11_BUFFER_DESC buffer_desc;
508 unsigned int stride, offset;
509 HRESULT hr;
511 if (!context->input_layout)
513 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
514 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
515 default_vs_code, sizeof(default_vs_code), &context->input_layout);
516 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
518 buffer_desc.ByteWidth = sizeof(quad);
519 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
520 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
521 buffer_desc.CPUAccessFlags = 0;
522 buffer_desc.MiscFlags = 0;
523 buffer_desc.StructureByteStride = 0;
525 resource_data.pSysMem = quad;
526 resource_data.SysMemPitch = 0;
527 resource_data.SysMemSlicePitch = 0;
529 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &context->vb);
530 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
532 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
533 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
536 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
537 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
538 stride = sizeof(*quad);
539 offset = 0;
540 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
541 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
543 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
546 static void test_create_device(void)
548 static const D3D_FEATURE_LEVEL default_feature_levels[] =
550 D3D_FEATURE_LEVEL_11_0,
551 D3D_FEATURE_LEVEL_10_1,
552 D3D_FEATURE_LEVEL_10_0,
553 D3D_FEATURE_LEVEL_9_3,
554 D3D_FEATURE_LEVEL_9_2,
555 D3D_FEATURE_LEVEL_9_1,
557 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
558 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
559 ID3D11DeviceContext *immediate_context;
560 IDXGISwapChain *swapchain;
561 ID3D11Device *device;
562 ULONG refcount;
563 HWND window;
564 HRESULT hr;
566 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
567 &device, NULL, NULL)))
569 skip("Failed to create HAL device.\n");
570 if ((device = create_device(NULL)))
572 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
573 ID3D11Device_Release(device);
575 return;
578 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
579 trace("Feature level %#x.\n", supported_feature_level);
580 ID3D11Device_Release(device);
582 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
583 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
585 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
586 &feature_level, NULL);
587 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
588 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
589 feature_level, supported_feature_level);
591 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
592 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
593 &feature_level, NULL);
594 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
595 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
596 feature_level, supported_feature_level);
598 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
599 &immediate_context);
600 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
602 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
603 refcount = get_refcount((IUnknown *)immediate_context);
604 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
606 ID3D11DeviceContext_GetDevice(immediate_context, &device);
607 refcount = ID3D11Device_Release(device);
608 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
610 refcount = ID3D11DeviceContext_Release(immediate_context);
611 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
613 device = (ID3D11Device *)0xdeadbeef;
614 feature_level = 0xdeadbeef;
615 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
616 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
617 &device, &feature_level, &immediate_context);
618 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
619 ok(!device, "Got unexpected device pointer %p.\n", device);
620 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
621 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
623 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
625 swapchain_desc.BufferDesc.Width = 800;
626 swapchain_desc.BufferDesc.Height = 600;
627 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
628 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
629 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
630 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
631 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
632 swapchain_desc.SampleDesc.Count = 1;
633 swapchain_desc.SampleDesc.Quality = 0;
634 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
635 swapchain_desc.BufferCount = 1;
636 swapchain_desc.OutputWindow = window;
637 swapchain_desc.Windowed = TRUE;
638 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
639 swapchain_desc.Flags = 0;
641 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
642 &swapchain_desc, NULL, NULL, NULL, NULL);
643 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
645 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
646 &swapchain_desc, NULL, NULL, &feature_level, NULL);
647 ok(hr == S_FALSE, "Got unexpected hr %#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, &swapchain, &device, NULL, NULL);
653 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
655 memset(&obtained_desc, 0, sizeof(obtained_desc));
656 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
657 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
658 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
659 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
660 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
661 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
662 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
663 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
664 obtained_desc.BufferDesc.RefreshRate.Numerator);
665 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
666 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
667 obtained_desc.BufferDesc.RefreshRate.Denominator);
668 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
669 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
670 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
671 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
672 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
673 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
674 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
675 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
676 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
677 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
678 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
679 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
680 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
681 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
682 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
683 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
684 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
685 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
686 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
687 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
688 ok(obtained_desc.Flags == swapchain_desc.Flags,
689 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
691 refcount = IDXGISwapChain_Release(swapchain);
692 ok(!refcount, "Swapchain has %u references left.\n", refcount);
694 feature_level = ID3D11Device_GetFeatureLevel(device);
695 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
696 feature_level, supported_feature_level);
698 refcount = ID3D11Device_Release(device);
699 ok(!refcount, "Device has %u references left.\n", refcount);
701 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
702 NULL, NULL, &device, NULL, NULL);
703 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
704 ID3D11Device_Release(device);
706 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
707 NULL, NULL, NULL, NULL, NULL);
708 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
710 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
711 NULL, NULL, NULL, &feature_level, NULL);
712 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
713 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
714 feature_level, supported_feature_level);
716 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
717 NULL, NULL, NULL, NULL, &immediate_context);
718 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
719 ID3D11DeviceContext_Release(immediate_context);
721 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
722 &swapchain_desc, NULL, NULL, NULL, NULL);
723 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
725 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
726 &swapchain_desc, &swapchain, NULL, NULL, NULL);
727 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
728 IDXGISwapChain_Release(swapchain);
730 swapchain_desc.OutputWindow = NULL;
731 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
732 &swapchain_desc, NULL, NULL, NULL, NULL);
733 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
734 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
735 &swapchain_desc, NULL, &device, NULL, NULL);
736 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
737 ID3D11Device_Release(device);
739 swapchain = (IDXGISwapChain *)0xdeadbeef;
740 device = (ID3D11Device *)0xdeadbeef;
741 feature_level = 0xdeadbeef;
742 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
743 swapchain_desc.OutputWindow = NULL;
744 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
745 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
746 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
747 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
748 ok(!device, "Got unexpected device pointer %p.\n", device);
749 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
750 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
752 swapchain = (IDXGISwapChain *)0xdeadbeef;
753 device = (ID3D11Device *)0xdeadbeef;
754 feature_level = 0xdeadbeef;
755 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
756 swapchain_desc.OutputWindow = window;
757 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
758 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
759 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
760 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
761 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
762 ok(!device, "Got unexpected device pointer %p.\n", device);
763 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
764 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
766 DestroyWindow(window);
769 static void test_device_interfaces(void)
771 IDXGIAdapter *dxgi_adapter;
772 IDXGIDevice *dxgi_device;
773 ID3D11Device *device;
774 IUnknown *iface;
775 ULONG refcount;
776 unsigned int i;
777 HRESULT hr;
779 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
781 struct device_desc device_desc;
783 device_desc.feature_level = &d3d11_feature_levels[i];
784 device_desc.flags = 0;
785 if (!(device = create_device(&device_desc)))
787 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels[i]);
788 continue;
791 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
792 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
793 IUnknown_Release(iface);
795 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
796 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
797 IUnknown_Release(iface);
799 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
800 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
801 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
802 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
803 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
804 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
805 IUnknown_Release(iface);
806 IDXGIAdapter_Release(dxgi_adapter);
807 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
808 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
809 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
810 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
811 IUnknown_Release(iface);
812 IDXGIAdapter_Release(dxgi_adapter);
813 IDXGIDevice_Release(dxgi_device);
815 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
816 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
817 IUnknown_Release(iface);
819 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
820 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
821 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
822 if (SUCCEEDED(hr)) IUnknown_Release(iface);
824 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
825 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
826 if (SUCCEEDED(hr)) IUnknown_Release(iface);
828 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
829 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
830 if (SUCCEEDED(hr)) IUnknown_Release(iface);
832 refcount = ID3D11Device_Release(device);
833 ok(!refcount, "Device has %u references left.\n", refcount);
837 static void test_get_immediate_context(void)
839 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
840 ULONG expected_refcount, refcount;
841 ID3D11Device *device;
843 if (!(device = create_device(NULL)))
845 skip("Failed to create device.\n");
846 return;
849 expected_refcount = get_refcount((IUnknown *)device) + 1;
850 ID3D11Device_GetImmediateContext(device, &immediate_context);
851 refcount = get_refcount((IUnknown *)device);
852 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
853 previous_immediate_context = immediate_context;
855 ID3D11Device_GetImmediateContext(device, &immediate_context);
856 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
857 refcount = get_refcount((IUnknown *)device);
858 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
860 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
861 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
862 refcount = ID3D11DeviceContext_Release(immediate_context);
863 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
865 ID3D11Device_GetImmediateContext(device, &immediate_context);
866 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
867 refcount = ID3D11DeviceContext_Release(immediate_context);
868 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
870 refcount = ID3D11Device_Release(device);
871 ok(!refcount, "Device has %u references left.\n", refcount);
874 static void test_create_texture2d(void)
876 ULONG refcount, expected_refcount;
877 D3D11_SUBRESOURCE_DATA data = {0};
878 D3D_FEATURE_LEVEL feature_level;
879 ID3D11Device *device, *tmp;
880 D3D11_TEXTURE2D_DESC desc;
881 ID3D11Texture2D *texture;
882 UINT quality_level_count;
883 IDXGISurface *surface;
884 unsigned int i;
885 HRESULT hr;
887 static const struct
889 DXGI_FORMAT format;
890 UINT array_size;
891 D3D11_BIND_FLAG bind_flags;
892 UINT misc_flags;
893 BOOL succeeds;
894 BOOL todo;
896 tests[] =
898 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
899 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
900 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
901 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
902 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
903 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
904 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
905 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
906 FALSE, TRUE},
907 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
908 FALSE, TRUE},
909 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
910 FALSE, TRUE},
911 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
912 TRUE, FALSE},
913 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
914 TRUE, FALSE},
915 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
916 TRUE, FALSE},
917 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
918 TRUE, FALSE},
919 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
920 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
921 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
922 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
923 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
924 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
925 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
926 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
927 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
928 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, TRUE},
929 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
930 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
931 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
932 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
933 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
934 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
935 TRUE, FALSE},
936 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
937 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
938 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
939 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
940 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
941 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
942 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
943 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
944 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
945 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
946 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
949 if (!(device = create_device(NULL)))
951 skip("Failed to create device.\n");
952 return;
955 feature_level = ID3D11Device_GetFeatureLevel(device);
957 desc.Width = 512;
958 desc.Height = 512;
959 desc.MipLevels = 1;
960 desc.ArraySize = 1;
961 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
962 desc.SampleDesc.Count = 1;
963 desc.SampleDesc.Quality = 0;
964 desc.Usage = D3D11_USAGE_DEFAULT;
965 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
966 desc.CPUAccessFlags = 0;
967 desc.MiscFlags = 0;
969 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
970 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
972 expected_refcount = get_refcount((IUnknown *)device) + 1;
973 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
974 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
975 refcount = get_refcount((IUnknown *)device);
976 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
977 tmp = NULL;
978 expected_refcount = refcount + 1;
979 ID3D11Texture2D_GetDevice(texture, &tmp);
980 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
981 refcount = get_refcount((IUnknown *)device);
982 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
983 ID3D11Device_Release(tmp);
985 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
986 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
987 IDXGISurface_Release(surface);
988 ID3D11Texture2D_Release(texture);
990 desc.MipLevels = 0;
991 expected_refcount = get_refcount((IUnknown *)device) + 1;
992 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
993 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
994 refcount = get_refcount((IUnknown *)device);
995 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
996 tmp = NULL;
997 expected_refcount = refcount + 1;
998 ID3D11Texture2D_GetDevice(texture, &tmp);
999 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1000 refcount = get_refcount((IUnknown *)device);
1001 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1002 ID3D11Device_Release(tmp);
1004 ID3D11Texture2D_GetDesc(texture, &desc);
1005 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1006 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1007 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1008 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1009 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1010 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1011 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1012 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1013 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1014 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1015 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1017 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1018 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1019 ID3D11Texture2D_Release(texture);
1021 desc.MipLevels = 1;
1022 desc.ArraySize = 2;
1023 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1024 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1026 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1027 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1028 ID3D11Texture2D_Release(texture);
1030 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1031 desc.ArraySize = 1;
1032 desc.SampleDesc.Count = 2;
1033 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1034 if (quality_level_count)
1036 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1037 ID3D11Texture2D_Release(texture);
1038 desc.SampleDesc.Quality = quality_level_count;
1039 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1041 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1043 /* We assume 15 samples multisampling is never supported in practice. */
1044 desc.SampleDesc.Count = 15;
1045 desc.SampleDesc.Quality = 0;
1046 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1047 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1049 desc.SampleDesc.Count = 1;
1050 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1052 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1053 BOOL todo = tests[i].todo;
1055 if (feature_level < D3D_FEATURE_LEVEL_10_1
1056 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1057 && tests[i].array_size > 6)
1059 expected_hr = E_INVALIDARG;
1060 todo = TRUE;
1063 desc.ArraySize = tests[i].array_size;
1064 desc.Format = tests[i].format;
1065 desc.BindFlags = tests[i].bind_flags;
1066 desc.MiscFlags = tests[i].misc_flags;
1067 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1069 todo_wine_if(todo)
1070 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
1072 if (SUCCEEDED(hr))
1073 ID3D11Texture2D_Release(texture);
1076 refcount = ID3D11Device_Release(device);
1077 ok(!refcount, "Device has %u references left.\n", refcount);
1080 static void test_texture2d_interfaces(void)
1082 ID3D10Texture2D *d3d10_texture;
1083 D3D11_TEXTURE2D_DESC desc;
1084 ID3D11Texture2D *texture;
1085 IDXGISurface *surface;
1086 ID3D11Device *device;
1087 unsigned int i;
1088 ULONG refcount;
1089 HRESULT hr;
1091 static const struct test
1093 BOOL implements_d3d10_interfaces;
1094 UINT bind_flags;
1095 UINT misc_flags;
1096 UINT expected_bind_flags;
1097 UINT expected_misc_flags;
1099 desc_conversion_tests[] =
1102 TRUE,
1103 D3D11_BIND_SHADER_RESOURCE, 0,
1104 D3D10_BIND_SHADER_RESOURCE, 0
1107 TRUE,
1108 D3D11_BIND_UNORDERED_ACCESS, 0,
1109 D3D11_BIND_UNORDERED_ACCESS, 0
1112 FALSE,
1113 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1114 0, 0
1117 TRUE,
1118 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1119 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1122 TRUE,
1123 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1124 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1128 if (!(device = create_device(NULL)))
1130 skip("Failed to create ID3D11Device, skipping tests.\n");
1131 return;
1134 desc.Width = 512;
1135 desc.Height = 512;
1136 desc.MipLevels = 0;
1137 desc.ArraySize = 1;
1138 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1139 desc.SampleDesc.Count = 1;
1140 desc.SampleDesc.Quality = 0;
1141 desc.Usage = D3D11_USAGE_DEFAULT;
1142 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1143 desc.CPUAccessFlags = 0;
1144 desc.MiscFlags = 0;
1146 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1147 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1149 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1150 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1152 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1153 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1154 "Texture should implement ID3D10Texture2D.\n");
1155 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1156 ID3D11Texture2D_Release(texture);
1158 if (FAILED(hr))
1160 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1161 ID3D11Device_Release(device);
1162 return;
1165 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1167 const struct test *current = &desc_conversion_tests[i];
1168 D3D10_TEXTURE2D_DESC d3d10_desc;
1169 ID3D10Device *d3d10_device;
1171 desc.Width = 512;
1172 desc.Height = 512;
1173 desc.MipLevels = 1;
1174 desc.ArraySize = 1;
1175 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1176 desc.SampleDesc.Count = 1;
1177 desc.SampleDesc.Quality = 0;
1178 desc.Usage = D3D11_USAGE_DEFAULT;
1179 desc.BindFlags = current->bind_flags;
1180 desc.CPUAccessFlags = 0;
1181 desc.MiscFlags = current->misc_flags;
1183 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1184 /* Shared resources are not supported by REF and WARP devices. */
1185 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1186 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1187 if (FAILED(hr))
1189 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1190 continue;
1193 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1194 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1195 IDXGISurface_Release(surface);
1197 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1198 ID3D11Texture2D_Release(texture);
1200 if (current->implements_d3d10_interfaces)
1202 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
1204 else
1206 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
1207 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1208 continue;
1211 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
1213 ok(d3d10_desc.Width == desc.Width,
1214 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1215 ok(d3d10_desc.Height == desc.Height,
1216 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1217 ok(d3d10_desc.MipLevels == desc.MipLevels,
1218 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1219 ok(d3d10_desc.ArraySize == desc.ArraySize,
1220 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
1221 ok(d3d10_desc.Format == desc.Format,
1222 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1223 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
1224 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
1225 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1226 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
1227 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1228 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1229 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1230 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1231 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1232 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1233 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1234 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1236 d3d10_device = (ID3D10Device *)0xdeadbeef;
1237 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
1238 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1239 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1241 ID3D10Texture2D_Release(d3d10_texture);
1244 refcount = ID3D11Device_Release(device);
1245 ok(!refcount, "Device has %u references left.\n", refcount);
1248 static void test_create_texture3d(void)
1250 ULONG refcount, expected_refcount;
1251 D3D11_SUBRESOURCE_DATA data = {0};
1252 ID3D11Device *device, *tmp;
1253 D3D11_TEXTURE3D_DESC desc;
1254 ID3D11Texture3D *texture;
1255 IDXGISurface *surface;
1256 unsigned int i;
1257 HRESULT hr;
1259 static const struct
1261 DXGI_FORMAT format;
1262 D3D11_BIND_FLAG bind_flags;
1263 BOOL succeeds;
1264 BOOL todo;
1266 tests[] =
1268 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
1269 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
1270 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1271 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1272 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1273 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1274 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
1275 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1276 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1279 if (!(device = create_device(NULL)))
1281 skip("Failed to create ID3D11Device, skipping tests.\n");
1282 return;
1285 desc.Width = 64;
1286 desc.Height = 64;
1287 desc.Depth = 64;
1288 desc.MipLevels = 1;
1289 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1290 desc.Usage = D3D11_USAGE_DEFAULT;
1291 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1292 desc.CPUAccessFlags = 0;
1293 desc.MiscFlags = 0;
1295 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
1296 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1298 expected_refcount = get_refcount((IUnknown *)device) + 1;
1299 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1300 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1301 refcount = get_refcount((IUnknown *)device);
1302 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1303 tmp = NULL;
1304 expected_refcount = refcount + 1;
1305 ID3D11Texture3D_GetDevice(texture, &tmp);
1306 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1307 refcount = get_refcount((IUnknown *)device);
1308 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1309 ID3D11Device_Release(tmp);
1311 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1312 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1313 ID3D11Texture3D_Release(texture);
1315 desc.MipLevels = 0;
1316 expected_refcount = get_refcount((IUnknown *)device) + 1;
1317 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1318 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1319 refcount = get_refcount((IUnknown *)device);
1320 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1321 tmp = NULL;
1322 expected_refcount = refcount + 1;
1323 ID3D11Texture3D_GetDevice(texture, &tmp);
1324 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1325 refcount = get_refcount((IUnknown *)device);
1326 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1327 ID3D11Device_Release(tmp);
1329 ID3D11Texture3D_GetDesc(texture, &desc);
1330 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1331 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1332 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1333 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1334 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1335 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1336 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1337 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1338 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1340 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1341 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1342 ID3D11Texture3D_Release(texture);
1344 desc.MipLevels = 1;
1345 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1347 desc.Format = tests[i].format;
1348 desc.BindFlags = tests[i].bind_flags;
1349 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
1351 todo_wine_if(tests[i].todo)
1352 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1354 if (SUCCEEDED(hr))
1355 ID3D11Texture3D_Release(texture);
1358 refcount = ID3D11Device_Release(device);
1359 ok(!refcount, "Device has %u references left.\n", refcount);
1362 static void test_texture3d_interfaces(void)
1364 ID3D10Texture3D *d3d10_texture;
1365 D3D11_TEXTURE3D_DESC desc;
1366 ID3D11Texture3D *texture;
1367 IDXGISurface *surface;
1368 ID3D11Device *device;
1369 unsigned int i;
1370 ULONG refcount;
1371 HRESULT hr;
1373 static const struct test
1375 BOOL implements_d3d10_interfaces;
1376 UINT bind_flags;
1377 UINT misc_flags;
1378 UINT expected_bind_flags;
1379 UINT expected_misc_flags;
1381 desc_conversion_tests[] =
1384 TRUE,
1385 D3D11_BIND_SHADER_RESOURCE, 0,
1386 D3D10_BIND_SHADER_RESOURCE, 0
1389 TRUE,
1390 D3D11_BIND_UNORDERED_ACCESS, 0,
1391 D3D11_BIND_UNORDERED_ACCESS, 0
1394 FALSE,
1395 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1396 0, 0
1399 TRUE,
1400 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1401 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1405 if (!(device = create_device(NULL)))
1407 skip("Failed to create ID3D11Device.\n");
1408 return;
1411 desc.Width = 64;
1412 desc.Height = 64;
1413 desc.Depth = 64;
1414 desc.MipLevels = 0;
1415 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1416 desc.Usage = D3D11_USAGE_DEFAULT;
1417 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1418 desc.CPUAccessFlags = 0;
1419 desc.MiscFlags = 0;
1421 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1422 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1424 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1425 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1427 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1428 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1429 "Texture should implement ID3D10Texture3D.\n");
1430 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1431 ID3D11Texture3D_Release(texture);
1433 if (FAILED(hr))
1435 win_skip("3D textures do not implement ID3D10Texture3D.\n");
1436 ID3D11Device_Release(device);
1437 return;
1440 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1442 const struct test *current = &desc_conversion_tests[i];
1443 D3D10_TEXTURE3D_DESC d3d10_desc;
1444 ID3D10Device *d3d10_device;
1446 desc.Width = 64;
1447 desc.Height = 64;
1448 desc.Depth = 64;
1449 desc.MipLevels = 1;
1450 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1451 desc.Usage = D3D11_USAGE_DEFAULT;
1452 desc.BindFlags = current->bind_flags;
1453 desc.CPUAccessFlags = 0;
1454 desc.MiscFlags = current->misc_flags;
1456 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
1457 /* Shared resources are not supported by REF and WARP devices. */
1458 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1459 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
1460 if (FAILED(hr))
1462 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
1463 continue;
1466 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1467 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1469 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
1470 ID3D11Texture3D_Release(texture);
1472 if (current->implements_d3d10_interfaces)
1474 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
1476 else
1478 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
1479 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
1480 continue;
1483 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
1485 ok(d3d10_desc.Width == desc.Width,
1486 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1487 ok(d3d10_desc.Height == desc.Height,
1488 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1489 ok(d3d10_desc.Depth == desc.Depth,
1490 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
1491 ok(d3d10_desc.MipLevels == desc.MipLevels,
1492 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1493 ok(d3d10_desc.Format == desc.Format,
1494 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1495 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1496 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1497 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1498 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1499 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1500 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1501 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1502 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1504 d3d10_device = (ID3D10Device *)0xdeadbeef;
1505 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
1506 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1507 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1509 ID3D10Texture3D_Release(d3d10_texture);
1512 refcount = ID3D11Device_Release(device);
1513 ok(!refcount, "Device has %u references left.\n", refcount);
1516 static void test_buffer_interfaces(void)
1518 ID3D10Buffer *d3d10_buffer;
1519 D3D11_BUFFER_DESC desc;
1520 ID3D11Buffer *buffer;
1521 ID3D11Device *device;
1522 unsigned int i;
1523 ULONG refcount;
1524 HRESULT hr;
1526 static const struct test
1528 BOOL implements_d3d10_interfaces;
1529 UINT bind_flags;
1530 UINT misc_flags;
1531 UINT structure_stride;
1532 UINT expected_bind_flags;
1533 UINT expected_misc_flags;
1535 desc_conversion_tests[] =
1538 TRUE,
1539 D3D11_BIND_VERTEX_BUFFER, 0, 0,
1540 D3D10_BIND_VERTEX_BUFFER, 0
1543 TRUE,
1544 D3D11_BIND_INDEX_BUFFER, 0, 0,
1545 D3D10_BIND_INDEX_BUFFER, 0
1548 TRUE,
1549 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
1550 D3D10_BIND_CONSTANT_BUFFER, 0
1553 TRUE,
1554 D3D11_BIND_SHADER_RESOURCE, 0, 0,
1555 D3D10_BIND_SHADER_RESOURCE, 0
1558 TRUE,
1559 D3D11_BIND_STREAM_OUTPUT, 0, 0,
1560 D3D10_BIND_STREAM_OUTPUT, 0
1563 TRUE,
1564 D3D11_BIND_RENDER_TARGET, 0, 0,
1565 D3D10_BIND_RENDER_TARGET, 0
1568 TRUE,
1569 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
1570 D3D11_BIND_UNORDERED_ACCESS, 0
1573 TRUE,
1574 0, D3D11_RESOURCE_MISC_SHARED, 0,
1575 0, D3D10_RESOURCE_MISC_SHARED
1578 TRUE,
1579 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
1580 0, 0
1583 TRUE,
1584 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
1585 D3D10_BIND_SHADER_RESOURCE, 0
1588 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
1589 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
1590 0, 0
1593 TRUE,
1594 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
1595 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1599 if (!(device = create_device(NULL)))
1601 skip("Failed to create ID3D11Device.\n");
1602 return;
1605 desc.ByteWidth = 1024;
1606 desc.Usage = D3D11_USAGE_DEFAULT;
1607 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
1608 desc.CPUAccessFlags = 0;
1609 desc.MiscFlags = 0;
1610 desc.StructureByteStride = 0;
1612 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1613 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1615 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1616 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1617 "Buffer should implement ID3D10Buffer.\n");
1618 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1619 ID3D11Buffer_Release(buffer);
1621 if (FAILED(hr))
1623 win_skip("Buffers do not implement ID3D10Buffer.\n");
1624 ID3D11Device_Release(device);
1625 return;
1628 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1630 const struct test *current = &desc_conversion_tests[i];
1631 D3D10_BUFFER_DESC d3d10_desc;
1632 ID3D10Device *d3d10_device;
1634 desc.ByteWidth = 1024;
1635 desc.Usage = D3D11_USAGE_DEFAULT;
1636 desc.BindFlags = current->bind_flags;
1637 desc.CPUAccessFlags = 0;
1638 desc.MiscFlags = current->misc_flags;
1639 desc.StructureByteStride = current->structure_stride;
1641 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
1642 /* Shared resources are not supported by REF and WARP devices. */
1643 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1644 if (FAILED(hr))
1646 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1647 continue;
1650 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
1651 ID3D11Buffer_Release(buffer);
1653 if (current->implements_d3d10_interfaces)
1655 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
1657 else
1659 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
1660 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
1661 continue;
1664 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
1666 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
1667 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
1668 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1669 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1670 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1671 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1672 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1673 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1674 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1675 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1677 d3d10_device = (ID3D10Device *)0xdeadbeef;
1678 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
1679 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1680 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1682 ID3D10Buffer_Release(d3d10_buffer);
1685 refcount = ID3D11Device_Release(device);
1686 ok(!refcount, "Device has %u references left.\n", refcount);
1689 static void test_create_depthstencil_view(void)
1691 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1692 D3D11_TEXTURE2D_DESC texture_desc;
1693 ULONG refcount, expected_refcount;
1694 ID3D11DepthStencilView *dsview;
1695 ID3D11Device *device, *tmp;
1696 ID3D11Texture2D *texture;
1697 HRESULT hr;
1699 if (!(device = create_device(NULL)))
1701 skip("Failed to create device.\n");
1702 return;
1705 texture_desc.Width = 512;
1706 texture_desc.Height = 512;
1707 texture_desc.MipLevels = 1;
1708 texture_desc.ArraySize = 1;
1709 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1710 texture_desc.SampleDesc.Count = 1;
1711 texture_desc.SampleDesc.Quality = 0;
1712 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1713 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1714 texture_desc.CPUAccessFlags = 0;
1715 texture_desc.MiscFlags = 0;
1717 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1718 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1720 expected_refcount = get_refcount((IUnknown *)device) + 1;
1721 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1722 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1723 refcount = get_refcount((IUnknown *)device);
1724 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1725 tmp = NULL;
1726 expected_refcount = refcount + 1;
1727 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
1728 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1729 refcount = get_refcount((IUnknown *)device);
1730 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1731 ID3D11Device_Release(tmp);
1733 memset(&dsv_desc, 0, sizeof(dsv_desc));
1734 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1735 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1736 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1737 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1738 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1739 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1741 ID3D11DepthStencilView_Release(dsview);
1743 dsv_desc.Format = DXGI_FORMAT_UNKNOWN;
1745 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1746 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1748 memset(&dsv_desc, 0, sizeof(dsv_desc));
1749 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1750 todo_wine ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1751 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1752 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1753 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1754 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1756 ID3D11DepthStencilView_Release(dsview);
1757 ID3D11Texture2D_Release(texture);
1759 texture_desc.ArraySize = 4;
1761 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1762 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
1764 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1765 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
1767 memset(&dsv_desc, 0, sizeof(dsv_desc));
1768 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1769 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1770 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY,
1771 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1772 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1773 ok(!U(dsv_desc).Texture2DArray.MipSlice, "Got unexpected mip slice %u.\n",
1774 U(dsv_desc).Texture2DArray.MipSlice);
1775 ok(!U(dsv_desc).Texture2DArray.FirstArraySlice, "Got unexpected first array slice %u.\n",
1776 U(dsv_desc).Texture2DArray.FirstArraySlice);
1777 todo_wine ok(U(dsv_desc).Texture2DArray.ArraySize == texture_desc.ArraySize,
1778 "Got unexpected array size %u.\n", U(dsv_desc).Texture2DArray.ArraySize);
1780 ID3D11DepthStencilView_Release(dsview);
1781 ID3D11Texture2D_Release(texture);
1783 refcount = ID3D11Device_Release(device);
1784 ok(!refcount, "Device has %u references left.\n", refcount);
1787 static void test_depthstencil_view_interfaces(void)
1789 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
1790 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1791 ID3D10DepthStencilView *d3d10_dsview;
1792 D3D11_TEXTURE2D_DESC texture_desc;
1793 ID3D11DepthStencilView *dsview;
1794 ID3D11Texture2D *texture;
1795 ID3D11Device *device;
1796 ULONG refcount;
1797 HRESULT hr;
1799 if (!(device = create_device(NULL)))
1801 skip("Failed to create device.\n");
1802 return;
1805 texture_desc.Width = 512;
1806 texture_desc.Height = 512;
1807 texture_desc.MipLevels = 1;
1808 texture_desc.ArraySize = 1;
1809 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1810 texture_desc.SampleDesc.Count = 1;
1811 texture_desc.SampleDesc.Quality = 0;
1812 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1813 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1814 texture_desc.CPUAccessFlags = 0;
1815 texture_desc.MiscFlags = 0;
1817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1818 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1820 dsv_desc.Format = texture_desc.Format;
1821 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
1822 dsv_desc.Flags = 0;
1823 U(dsv_desc).Texture2D.MipSlice = 0;
1825 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1826 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1828 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
1829 ID3D11DepthStencilView_Release(dsview);
1830 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1831 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1833 if (FAILED(hr))
1835 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1836 goto done;
1839 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
1840 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
1841 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
1842 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
1843 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
1844 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
1846 ID3D10DepthStencilView_Release(d3d10_dsview);
1848 done:
1849 ID3D11Texture2D_Release(texture);
1851 refcount = ID3D11Device_Release(device);
1852 ok(!refcount, "Device has %u references left.\n", refcount);
1855 static void test_create_rendertarget_view(void)
1857 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
1858 D3D11_SUBRESOURCE_DATA data = {0};
1859 D3D11_TEXTURE2D_DESC texture_desc;
1860 ULONG refcount, expected_refcount;
1861 D3D11_BUFFER_DESC buffer_desc;
1862 ID3D11RenderTargetView *rtview;
1863 ID3D11Device *device, *tmp;
1864 ID3D11Texture2D *texture;
1865 ID3D11Buffer *buffer;
1866 IUnknown *iface;
1867 HRESULT hr;
1869 if (!(device = create_device(NULL)))
1871 skip("Failed to create device.\n");
1872 return;
1875 buffer_desc.ByteWidth = 1024;
1876 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1877 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1878 buffer_desc.CPUAccessFlags = 0;
1879 buffer_desc.MiscFlags = 0;
1880 buffer_desc.StructureByteStride = 0;
1882 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
1883 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1885 expected_refcount = get_refcount((IUnknown *)device) + 1;
1886 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1887 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1888 refcount = get_refcount((IUnknown *)device);
1889 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1890 tmp = NULL;
1891 expected_refcount = refcount + 1;
1892 ID3D11Buffer_GetDevice(buffer, &tmp);
1893 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1894 refcount = get_refcount((IUnknown *)device);
1895 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1896 ID3D11Device_Release(tmp);
1898 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1899 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
1900 U(rtv_desc).Buffer.ElementOffset = 0;
1901 U(rtv_desc).Buffer.ElementWidth = 64;
1903 expected_refcount = get_refcount((IUnknown *)device) + 1;
1904 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
1905 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1906 refcount = get_refcount((IUnknown *)device);
1907 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1908 tmp = NULL;
1909 expected_refcount = refcount + 1;
1910 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
1911 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1912 refcount = get_refcount((IUnknown *)device);
1913 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1914 ID3D11Device_Release(tmp);
1916 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1917 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1918 "Render target view should implement ID3D10RenderTargetView.\n");
1919 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1921 ID3D11RenderTargetView_Release(rtview);
1922 ID3D11Buffer_Release(buffer);
1924 texture_desc.Width = 512;
1925 texture_desc.Height = 512;
1926 texture_desc.MipLevels = 1;
1927 texture_desc.ArraySize = 1;
1928 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1929 texture_desc.SampleDesc.Count = 1;
1930 texture_desc.SampleDesc.Quality = 0;
1931 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1932 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1933 texture_desc.CPUAccessFlags = 0;
1934 texture_desc.MiscFlags = 0;
1936 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1937 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1939 /* For texture resources it's allowed to specify NULL as desc */
1940 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1941 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1943 memset(&rtv_desc, 0, sizeof(rtv_desc));
1944 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1945 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1946 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1947 rtv_desc.ViewDimension);
1948 ok(!U(rtv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(rtv_desc).Texture2D.MipSlice);
1950 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1951 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1952 "Render target view should implement ID3D10RenderTargetView.\n");
1953 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1955 ID3D11RenderTargetView_Release(rtview);
1957 rtv_desc.Format = DXGI_FORMAT_UNKNOWN;
1959 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtview);
1960 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1962 memset(&rtv_desc, 0, sizeof(rtv_desc));
1963 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1964 todo_wine ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1965 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1966 rtv_desc.ViewDimension);
1967 ok(!U(rtv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(rtv_desc).Texture2D.MipSlice);
1969 ID3D11RenderTargetView_Release(rtview);
1970 ID3D11Texture2D_Release(texture);
1972 texture_desc.ArraySize = 4;
1974 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1975 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
1977 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1978 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1980 memset(&rtv_desc, 0, sizeof(rtv_desc));
1981 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1982 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1983 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY, "Got unexpected view dimension %#x.\n",
1984 rtv_desc.ViewDimension);
1985 ok(!U(rtv_desc).Texture2DArray.MipSlice, "Got unexpected mip slice %u.\n",
1986 U(rtv_desc).Texture2DArray.MipSlice);
1987 ok(!U(rtv_desc).Texture2DArray.FirstArraySlice, "Got unexpected first array slice %u.\n",
1988 U(rtv_desc).Texture2DArray.FirstArraySlice);
1989 todo_wine ok(U(rtv_desc).Texture2DArray.ArraySize == texture_desc.ArraySize, "Got unexpected array size %u.\n",
1990 U(rtv_desc).Texture2DArray.ArraySize);
1992 ID3D11RenderTargetView_Release(rtview);
1993 ID3D11Texture2D_Release(texture);
1995 refcount = ID3D11Device_Release(device);
1996 ok(!refcount, "Device has %u references left.\n", refcount);
1999 static void test_create_shader_resource_view(void)
2001 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
2002 D3D11_TEXTURE2D_DESC texture_desc;
2003 ULONG refcount, expected_refcount;
2004 ID3D11ShaderResourceView *srview;
2005 D3D11_BUFFER_DESC buffer_desc;
2006 ID3D11Device *device, *tmp;
2007 ID3D11Texture2D *texture;
2008 ID3D11Buffer *buffer;
2009 IUnknown *iface;
2010 HRESULT hr;
2012 if (!(device = create_device(NULL)))
2014 skip("Failed to create device.\n");
2015 return;
2018 buffer_desc.ByteWidth = 1024;
2019 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
2020 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2021 buffer_desc.CPUAccessFlags = 0;
2022 buffer_desc.MiscFlags = 0;
2023 buffer_desc.StructureByteStride = 0;
2025 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2026 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2028 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
2029 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2031 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2032 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
2033 U(srv_desc).Buffer.ElementOffset = 0;
2034 U(srv_desc).Buffer.ElementWidth = 64;
2036 expected_refcount = get_refcount((IUnknown *)device) + 1;
2037 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
2038 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2039 refcount = get_refcount((IUnknown *)device);
2040 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2041 tmp = NULL;
2042 expected_refcount = refcount + 1;
2043 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
2044 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2045 refcount = get_refcount((IUnknown *)device);
2046 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2047 ID3D11Device_Release(tmp);
2049 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
2050 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2051 "Shader resource view should implement ID3D10ShaderResourceView.\n");
2052 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2053 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2054 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2055 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
2056 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2058 ID3D11ShaderResourceView_Release(srview);
2059 ID3D11Buffer_Release(buffer);
2061 texture_desc.Width = 512;
2062 texture_desc.Height = 512;
2063 texture_desc.MipLevels = 0;
2064 texture_desc.ArraySize = 1;
2065 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2066 texture_desc.SampleDesc.Count = 1;
2067 texture_desc.SampleDesc.Quality = 0;
2068 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2069 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2070 texture_desc.CPUAccessFlags = 0;
2071 texture_desc.MiscFlags = 0;
2073 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2074 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2076 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
2077 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2079 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
2080 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2081 "Shader resource view should implement ID3D10ShaderResourceView.\n");
2082 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2083 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2084 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2085 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
2086 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2088 memset(&srv_desc, 0, sizeof(srv_desc));
2089 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
2090 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
2091 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
2092 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
2093 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
2094 U(srv_desc).Texture2D.MostDetailedMip);
2095 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
2097 ID3D11ShaderResourceView_Release(srview);
2099 srv_desc.Format = DXGI_FORMAT_UNKNOWN;
2100 U(srv_desc).Texture2D.MipLevels = -1;
2102 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srview);
2103 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2105 memset(&srv_desc, 0, sizeof(srv_desc));
2106 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
2107 todo_wine ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
2108 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
2109 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
2110 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
2111 U(srv_desc).Texture2D.MostDetailedMip);
2112 todo_wine ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n",
2113 U(srv_desc).Texture2D.MipLevels);
2115 ID3D11ShaderResourceView_Release(srview);
2116 ID3D11Texture2D_Release(texture);
2118 texture_desc.ArraySize = 4;
2120 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2121 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
2123 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
2124 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
2126 memset(&srv_desc, 0, sizeof(srv_desc));
2127 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
2128 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
2129 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY,
2130 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
2131 ok(!U(srv_desc).Texture2DArray.MostDetailedMip, "Got unexpected MostDetailedMip %u.\n",
2132 U(srv_desc).Texture2DArray.MostDetailedMip);
2133 ok(U(srv_desc).Texture2DArray.MipLevels == 10, "Got unexpected MipLevels %u.\n",
2134 U(srv_desc).Texture2DArray.MipLevels);
2135 ok(!U(srv_desc).Texture2DArray.FirstArraySlice, "Got unexpected FirstArraySlice %u.\n",
2136 U(srv_desc).Texture2DArray.FirstArraySlice);
2137 ok(U(srv_desc).Texture2DArray.ArraySize == texture_desc.ArraySize, "Got unexpected ArraySize %u.\n",
2138 U(srv_desc).Texture2DArray.ArraySize);
2140 ID3D11ShaderResourceView_Release(srview);
2141 ID3D11Texture2D_Release(texture);
2143 refcount = ID3D11Device_Release(device);
2144 ok(!refcount, "Device has %u references left.\n", refcount);
2147 static void test_create_shader(void)
2149 #if 0
2150 float4 light;
2151 float4x4 mat;
2153 struct input
2155 float4 position : POSITION;
2156 float3 normal : NORMAL;
2159 struct output
2161 float4 position : POSITION;
2162 float4 diffuse : COLOR;
2165 output main(const input v)
2167 output o;
2169 o.position = mul(v.position, mat);
2170 o.diffuse = dot((float3)light, v.normal);
2172 return o;
2174 #endif
2175 static const DWORD vs_4_1[] =
2177 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
2178 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
2179 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
2180 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
2181 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2182 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
2183 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
2184 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
2185 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
2186 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
2187 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
2188 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
2189 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
2190 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
2191 0x0100003e,
2193 static const DWORD vs_4_0[] =
2195 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
2196 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
2197 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
2198 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
2199 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
2200 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
2201 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
2202 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
2203 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
2204 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
2205 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
2206 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
2207 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
2208 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
2209 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
2210 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
2212 static const DWORD vs_3_0[] =
2214 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
2215 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2216 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2217 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2218 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2219 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2220 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2221 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
2222 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
2223 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
2224 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
2225 0x0000ffff,
2227 static const DWORD vs_2_0[] =
2229 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
2230 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2231 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2232 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2233 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2234 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2235 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2236 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
2237 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
2238 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
2239 0x90e40001, 0x0000ffff,
2242 #if 0
2243 float4 main(const float4 color : COLOR) : SV_TARGET
2245 float4 o;
2247 o = color;
2249 return o;
2251 #endif
2252 static const DWORD ps_4_1[] =
2254 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
2255 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
2256 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
2257 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2258 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
2259 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2260 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
2262 static const DWORD ps_4_0[] =
2264 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
2265 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
2266 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
2267 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
2268 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
2269 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
2270 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2271 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2272 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2273 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
2274 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
2275 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
2276 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2277 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
2278 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2279 0x00000000, 0x00000000,
2281 static const DWORD ps_4_0_level_9_0[] =
2283 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
2284 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
2285 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
2286 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
2287 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
2288 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
2289 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
2290 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
2291 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
2292 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
2293 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
2294 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2295 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
2296 0xabab0054,
2298 static const DWORD ps_4_0_level_9_1[] =
2300 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
2301 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
2302 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
2303 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
2304 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
2305 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2306 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
2307 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2308 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
2309 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2310 0x45475241, 0xabab0054,
2312 static const DWORD ps_4_0_level_9_3[] =
2314 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
2315 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
2316 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
2317 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
2318 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
2319 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
2320 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
2321 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2322 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
2323 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2324 0x45475241, 0xabab0054,
2327 #if 0
2328 struct gs_out
2330 float4 pos : SV_POSITION;
2333 [maxvertexcount(4)]
2334 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
2336 float offset = 0.1 * vin[0].w;
2337 gs_out v;
2339 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
2340 vout.Append(v);
2341 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
2342 vout.Append(v);
2343 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
2344 vout.Append(v);
2345 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
2346 vout.Append(v);
2348 #endif
2349 static const DWORD gs_4_1[] =
2351 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
2352 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2353 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2354 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2355 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
2356 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
2357 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
2358 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
2359 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
2360 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
2361 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
2362 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2363 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
2364 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2365 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
2366 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
2367 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
2368 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2370 static const DWORD gs_4_0[] =
2372 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
2373 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2374 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2375 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2376 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
2377 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
2378 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
2379 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2380 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
2381 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2382 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
2383 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
2384 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
2385 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
2386 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
2387 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2388 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
2389 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2392 ULONG refcount, expected_refcount;
2393 ID3D11Device *device, *tmp;
2394 ID3D11GeometryShader *gs;
2395 ID3D11VertexShader *vs;
2396 ID3D11PixelShader *ps;
2397 IUnknown *iface;
2398 unsigned int i;
2399 HRESULT hr;
2401 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
2403 D3D_FEATURE_LEVEL feature_level = d3d11_feature_levels[i];
2404 BOOL todo = feature_level <= D3D_FEATURE_LEVEL_9_3;
2405 struct device_desc device_desc;
2407 device_desc.feature_level = &feature_level;
2408 device_desc.flags = 0;
2409 if (!(device = create_device(&device_desc)))
2411 skip("Failed to create device for feature level %#x.\n", feature_level);
2412 continue;
2415 /* level_9 shaders */
2416 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
2417 todo_wine_if(todo)
2418 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2419 if (SUCCEEDED(hr))
2420 ID3D11PixelShader_Release(ps);
2422 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
2423 todo_wine_if(todo)
2424 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2425 if (SUCCEEDED(hr))
2426 ID3D11PixelShader_Release(ps);
2428 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
2429 todo_wine_if(todo)
2430 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
2431 if (SUCCEEDED(hr))
2432 ID3D11PixelShader_Release(ps);
2434 /* vertex shader */
2435 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
2436 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2438 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
2439 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2441 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
2442 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
2443 hr, feature_level);
2445 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2446 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
2447 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2448 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2449 else
2450 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2452 refcount = get_refcount((IUnknown *)device);
2453 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2454 refcount, expected_refcount);
2455 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2457 tmp = NULL;
2458 expected_refcount = refcount + 1;
2459 ID3D11VertexShader_GetDevice(vs, &tmp);
2460 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2461 refcount = get_refcount((IUnknown *)device);
2462 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2463 refcount, expected_refcount);
2464 ID3D11Device_Release(tmp);
2466 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
2467 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2468 "Vertex shader should implement ID3D10VertexShader.\n");
2469 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2471 refcount = ID3D11VertexShader_Release(vs);
2472 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2475 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
2476 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
2478 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
2479 hr, feature_level);
2480 refcount = ID3D11VertexShader_Release(vs);
2481 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2483 else
2485 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
2486 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
2487 if (SUCCEEDED(hr))
2488 ID3D11VertexShader_Release(vs);
2491 /* pixel shader */
2492 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2493 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
2494 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2495 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2496 else
2497 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2499 refcount = get_refcount((IUnknown *)device);
2500 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2501 refcount, expected_refcount);
2502 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2504 tmp = NULL;
2505 expected_refcount = refcount + 1;
2506 ID3D11PixelShader_GetDevice(ps, &tmp);
2507 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2508 refcount = get_refcount((IUnknown *)device);
2509 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2510 refcount, expected_refcount);
2511 ID3D11Device_Release(tmp);
2513 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
2514 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2515 "Pixel shader should implement ID3D10PixelShader.\n");
2516 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2518 refcount = ID3D11PixelShader_Release(ps);
2519 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
2522 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
2523 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
2525 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
2526 hr, feature_level);
2527 refcount = ID3D11PixelShader_Release(ps);
2528 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
2530 else
2532 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
2533 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
2534 if (SUCCEEDED(hr))
2535 ID3D11PixelShader_Release(ps);
2538 /* geometry shader */
2539 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
2540 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
2541 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2542 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2543 else
2544 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
2546 refcount = get_refcount((IUnknown *)device);
2547 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
2548 refcount, expected_refcount);
2549 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
2551 tmp = NULL;
2552 expected_refcount = refcount + 1;
2553 ID3D11GeometryShader_GetDevice(gs, &tmp);
2554 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2555 refcount = get_refcount((IUnknown *)device);
2556 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
2557 refcount, expected_refcount);
2558 ID3D11Device_Release(tmp);
2560 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
2561 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2562 "Geometry shader should implement ID3D10GeometryShader.\n");
2563 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2565 refcount = ID3D11GeometryShader_Release(gs);
2566 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
2569 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
2570 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
2572 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
2573 hr, feature_level);
2574 refcount = ID3D11GeometryShader_Release(gs);
2575 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
2577 else
2579 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
2580 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
2581 hr, feature_level);
2582 if (SUCCEEDED(hr))
2583 ID3D11GeometryShader_Release(gs);
2586 refcount = ID3D11Device_Release(device);
2587 ok(!refcount, "Device has %u references left.\n", refcount);
2591 static void test_create_sampler_state(void)
2593 static const struct test
2595 D3D11_FILTER filter;
2596 D3D10_FILTER expected_filter;
2598 desc_conversion_tests[] =
2600 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
2601 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
2602 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
2603 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
2604 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
2605 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
2606 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
2607 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
2608 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
2609 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
2610 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
2612 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
2613 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
2615 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
2616 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
2618 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
2619 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
2621 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
2622 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
2623 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
2626 ID3D11SamplerState *sampler_state1, *sampler_state2;
2627 ID3D10SamplerState *d3d10_sampler_state;
2628 ULONG refcount, expected_refcount;
2629 ID3D11Device *device, *tmp;
2630 D3D11_SAMPLER_DESC desc;
2631 unsigned int i;
2632 HRESULT hr;
2634 if (!(device = create_device(NULL)))
2636 skip("Failed to create device.\n");
2637 return;
2640 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
2641 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2643 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
2644 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2645 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2646 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
2647 desc.MipLODBias = 0.0f;
2648 desc.MaxAnisotropy = 16;
2649 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2650 desc.BorderColor[0] = 0.0f;
2651 desc.BorderColor[1] = 1.0f;
2652 desc.BorderColor[2] = 0.0f;
2653 desc.BorderColor[3] = 1.0f;
2654 desc.MinLOD = 0.0f;
2655 desc.MaxLOD = 16.0f;
2657 expected_refcount = get_refcount((IUnknown *)device) + 1;
2658 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2659 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2660 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
2661 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
2662 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
2663 refcount = get_refcount((IUnknown *)device);
2664 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2665 tmp = NULL;
2666 expected_refcount = refcount + 1;
2667 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
2668 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2669 refcount = get_refcount((IUnknown *)device);
2670 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2671 ID3D11Device_Release(tmp);
2673 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
2674 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
2675 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
2676 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
2677 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
2678 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
2679 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
2680 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
2681 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
2682 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
2683 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
2684 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
2685 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
2687 refcount = ID3D11SamplerState_Release(sampler_state2);
2688 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2689 refcount = ID3D11SamplerState_Release(sampler_state1);
2690 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2692 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2694 const struct test *current = &desc_conversion_tests[i];
2695 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
2697 desc.Filter = current->filter;
2698 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
2699 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
2700 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
2701 desc.MipLODBias = 0.0f;
2702 desc.MaxAnisotropy = 16;
2703 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
2704 desc.BorderColor[0] = 0.0f;
2705 desc.BorderColor[1] = 1.0f;
2706 desc.BorderColor[2] = 0.0f;
2707 desc.BorderColor[3] = 1.0f;
2708 desc.MinLOD = 0.0f;
2709 desc.MaxLOD = 16.0f;
2711 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
2712 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
2714 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
2715 (void **)&d3d10_sampler_state);
2716 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2717 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
2718 if (FAILED(hr))
2720 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
2721 ID3D11SamplerState_Release(sampler_state1);
2722 break;
2725 memcpy(&expected_desc, &desc, sizeof(expected_desc));
2726 expected_desc.Filter = current->expected_filter;
2727 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
2728 expected_desc.MaxAnisotropy = 0;
2729 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
2730 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
2732 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
2733 ok(d3d10_desc.Filter == expected_desc.Filter,
2734 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
2735 ok(d3d10_desc.AddressU == expected_desc.AddressU,
2736 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
2737 ok(d3d10_desc.AddressV == expected_desc.AddressV,
2738 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
2739 ok(d3d10_desc.AddressW == expected_desc.AddressW,
2740 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
2741 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
2742 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
2743 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
2744 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
2745 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
2746 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
2747 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
2748 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
2749 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
2750 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
2751 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
2752 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
2753 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
2754 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
2755 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
2756 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
2757 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
2759 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
2760 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2761 refcount = ID3D11SamplerState_Release(sampler_state1);
2762 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
2765 refcount = ID3D11Device_Release(device);
2766 ok(!refcount, "Device has %u references left.\n", refcount);
2769 static void test_create_blend_state(void)
2771 static const D3D11_BLEND_DESC desc_conversion_tests[] =
2774 FALSE, FALSE,
2777 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2778 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
2783 FALSE, TRUE,
2786 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2787 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2790 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2791 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
2794 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2795 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2798 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2799 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
2802 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2803 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2806 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2807 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2810 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2811 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2814 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2815 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2820 FALSE, TRUE,
2823 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2824 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2827 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
2828 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2831 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
2832 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2835 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2836 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2839 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
2840 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2843 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
2844 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2847 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2848 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2851 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
2852 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
2858 ID3D11BlendState *blend_state1, *blend_state2;
2859 D3D11_BLEND_DESC desc, obtained_desc;
2860 ID3D10BlendState *d3d10_blend_state;
2861 D3D10_BLEND_DESC d3d10_blend_desc;
2862 ULONG refcount, expected_refcount;
2863 ID3D11Device *device, *tmp;
2864 unsigned int i, j;
2865 IUnknown *iface;
2866 HRESULT hr;
2868 if (!(device = create_device(NULL)))
2870 skip("Failed to create device.\n");
2871 return;
2874 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
2875 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2877 memset(&desc, 0, sizeof(desc));
2878 desc.AlphaToCoverageEnable = FALSE;
2879 desc.IndependentBlendEnable = FALSE;
2880 desc.RenderTarget[0].BlendEnable = FALSE;
2881 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
2882 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
2883 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
2884 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
2885 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2886 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
2887 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
2889 expected_refcount = get_refcount((IUnknown *)device) + 1;
2890 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
2891 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2892 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
2893 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2894 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
2895 refcount = get_refcount((IUnknown *)device);
2896 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2897 tmp = NULL;
2898 expected_refcount = refcount + 1;
2899 ID3D11BlendState_GetDevice(blend_state1, &tmp);
2900 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2901 refcount = get_refcount((IUnknown *)device);
2902 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2903 ID3D11Device_Release(tmp);
2905 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
2906 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
2907 obtained_desc.AlphaToCoverageEnable);
2908 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
2909 obtained_desc.IndependentBlendEnable);
2910 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2912 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
2913 "Got unexpected blend enable %#x for render target %u.\n",
2914 obtained_desc.RenderTarget[i].BlendEnable, i);
2915 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
2916 "Got unexpected src blend %u for render target %u.\n",
2917 obtained_desc.RenderTarget[i].SrcBlend, i);
2918 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
2919 "Got unexpected dest blend %u for render target %u.\n",
2920 obtained_desc.RenderTarget[i].DestBlend, i);
2921 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
2922 "Got unexpected blend op %u for render target %u.\n",
2923 obtained_desc.RenderTarget[i].BlendOp, i);
2924 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
2925 "Got unexpected src blend alpha %u for render target %u.\n",
2926 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
2927 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
2928 "Got unexpected dest blend alpha %u for render target %u.\n",
2929 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
2930 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
2931 "Got unexpected blend op alpha %u for render target %u.\n",
2932 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
2933 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
2934 "Got unexpected render target write mask %#x for render target %u.\n",
2935 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
2938 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
2939 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2940 "Blend state should implement ID3D10BlendState.\n");
2941 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2942 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
2943 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2944 "Blend state should implement ID3D10BlendState1.\n");
2945 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2947 refcount = ID3D11BlendState_Release(blend_state1);
2948 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2949 refcount = ID3D11BlendState_Release(blend_state2);
2950 ok(!refcount, "Blend state has %u references left.\n", refcount);
2952 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2954 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
2956 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
2957 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
2959 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
2960 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2961 "Blend state should implement ID3D10BlendState.\n");
2962 if (FAILED(hr))
2964 win_skip("Blend state does not implement ID3D10BlendState.\n");
2965 ID3D11BlendState_Release(blend_state1);
2966 break;
2969 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
2970 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
2971 "Got unexpected alpha to coverage enable %#x for test %u.\n",
2972 d3d10_blend_desc.AlphaToCoverageEnable, i);
2973 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
2974 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
2975 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
2976 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
2977 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
2978 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
2979 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
2980 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
2981 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
2982 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
2983 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
2984 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
2985 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
2987 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
2988 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
2989 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2990 d3d10_blend_desc.BlendEnable[j], i, j);
2991 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
2992 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2993 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
2996 ID3D10BlendState_Release(d3d10_blend_state);
2998 refcount = ID3D11BlendState_Release(blend_state1);
2999 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3002 refcount = ID3D11Device_Release(device);
3003 ok(!refcount, "Device has %u references left.\n", refcount);
3006 static void test_create_depthstencil_state(void)
3008 ID3D11DepthStencilState *ds_state1, *ds_state2;
3009 ID3D10DepthStencilState *d3d10_ds_state;
3010 ULONG refcount, expected_refcount;
3011 D3D11_DEPTH_STENCIL_DESC ds_desc;
3012 ID3D11Device *device, *tmp;
3013 HRESULT hr;
3015 if (!(device = create_device(NULL)))
3017 skip("Failed to create device.\n");
3018 return;
3021 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
3022 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3024 ds_desc.DepthEnable = TRUE;
3025 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
3026 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
3027 ds_desc.StencilEnable = FALSE;
3028 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
3029 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
3030 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3031 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3032 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3033 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3034 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3035 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3036 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3037 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3039 expected_refcount = get_refcount((IUnknown *)device) + 1;
3040 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3041 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3042 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
3043 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3044 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
3045 refcount = get_refcount((IUnknown *)device);
3046 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3047 tmp = NULL;
3048 expected_refcount = refcount + 1;
3049 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
3050 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3051 refcount = get_refcount((IUnknown *)device);
3052 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3053 ID3D11Device_Release(tmp);
3055 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
3056 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3057 "Depth stencil state should implement ID3D10DepthStencilState.\n");
3058 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
3060 refcount = ID3D11DepthStencilState_Release(ds_state2);
3061 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3062 refcount = ID3D11DepthStencilState_Release(ds_state1);
3063 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3065 ds_desc.DepthEnable = FALSE;
3066 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
3067 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
3068 ds_desc.StencilEnable = FALSE;
3069 ds_desc.StencilReadMask = 0;
3070 ds_desc.StencilWriteMask = 0;
3071 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
3072 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
3073 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
3074 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
3075 ds_desc.BackFace = ds_desc.FrontFace;
3077 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3078 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3080 memset(&ds_desc, 0, sizeof(ds_desc));
3081 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
3082 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
3083 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
3084 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
3085 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
3086 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
3087 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
3088 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
3089 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
3090 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
3091 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
3092 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
3093 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
3094 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
3095 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
3096 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
3097 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
3098 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
3099 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
3100 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
3101 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
3102 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
3103 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
3104 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
3105 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
3106 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
3108 ID3D11DepthStencilState_Release(ds_state1);
3110 refcount = ID3D11Device_Release(device);
3111 ok(!refcount, "Device has %u references left.\n", refcount);
3114 static void test_create_rasterizer_state(void)
3116 ID3D11RasterizerState *rast_state1, *rast_state2;
3117 ID3D10RasterizerState *d3d10_rast_state;
3118 ULONG refcount, expected_refcount;
3119 D3D10_RASTERIZER_DESC d3d10_desc;
3120 D3D11_RASTERIZER_DESC desc;
3121 ID3D11Device *device, *tmp;
3122 HRESULT hr;
3124 if (!(device = create_device(NULL)))
3126 skip("Failed to create device.\n");
3127 return;
3130 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
3131 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3133 desc.FillMode = D3D11_FILL_SOLID;
3134 desc.CullMode = D3D11_CULL_BACK;
3135 desc.FrontCounterClockwise = FALSE;
3136 desc.DepthBias = 0;
3137 desc.DepthBiasClamp = 0.0f;
3138 desc.SlopeScaledDepthBias = 0.0f;
3139 desc.DepthClipEnable = TRUE;
3140 desc.ScissorEnable = FALSE;
3141 desc.MultisampleEnable = FALSE;
3142 desc.AntialiasedLineEnable = FALSE;
3144 expected_refcount = get_refcount((IUnknown *)device) + 1;
3145 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
3146 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3147 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
3148 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3149 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
3150 refcount = get_refcount((IUnknown *)device);
3151 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3152 tmp = NULL;
3153 expected_refcount = refcount + 1;
3154 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
3155 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3156 refcount = get_refcount((IUnknown *)device);
3157 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3158 ID3D11Device_Release(tmp);
3160 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
3161 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3162 "Rasterizer state should implement ID3D10RasterizerState.\n");
3163 if (SUCCEEDED(hr))
3165 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
3166 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
3167 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
3168 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
3169 d3d10_desc.FrontCounterClockwise);
3170 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
3171 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
3172 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
3173 d3d10_desc.SlopeScaledDepthBias);
3174 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
3175 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
3176 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
3177 d3d10_desc.MultisampleEnable);
3178 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
3179 d3d10_desc.AntialiasedLineEnable);
3181 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
3182 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3185 refcount = ID3D11RasterizerState_Release(rast_state2);
3186 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3187 refcount = ID3D11RasterizerState_Release(rast_state1);
3188 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3190 refcount = ID3D11Device_Release(device);
3191 ok(!refcount, "Device has %u references left.\n", refcount);
3194 static void test_create_query(void)
3196 static const struct
3198 D3D11_QUERY query;
3199 D3D_FEATURE_LEVEL required_feature_level;
3200 BOOL is_predicate;
3201 BOOL can_use_create_predicate;
3202 BOOL todo;
3204 tests[] =
3206 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
3207 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
3208 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
3209 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
3210 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
3211 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
3212 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
3213 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
3214 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
3215 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
3216 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
3217 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
3218 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
3219 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
3220 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
3221 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
3224 ULONG refcount, expected_refcount;
3225 D3D_FEATURE_LEVEL feature_level;
3226 D3D11_QUERY_DESC query_desc;
3227 ID3D11Predicate *predicate;
3228 ID3D11Device *device, *tmp;
3229 HRESULT hr, expected_hr;
3230 ID3D11Query *query;
3231 IUnknown *iface;
3232 unsigned int i;
3234 if (!(device = create_device(NULL)))
3236 skip("Failed to create device.\n");
3237 return;
3239 feature_level = ID3D11Device_GetFeatureLevel(device);
3241 hr = ID3D11Device_CreateQuery(device, NULL, &query);
3242 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3243 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
3244 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3246 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3248 if (tests[i].required_feature_level > feature_level)
3250 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
3251 continue;
3254 query_desc.Query = tests[i].query;
3255 query_desc.MiscFlags = 0;
3257 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
3258 todo_wine_if(tests[i].todo)
3259 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3261 query_desc.Query = tests[i].query;
3262 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
3263 todo_wine_if(tests[i].todo)
3264 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3265 if (FAILED(hr))
3266 continue;
3268 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
3269 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
3270 ID3D11Query_Release(query);
3271 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3272 if (SUCCEEDED(hr))
3273 ID3D11Predicate_Release(predicate);
3275 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
3276 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
3277 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3279 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
3280 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
3281 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3282 if (SUCCEEDED(hr))
3283 ID3D11Predicate_Release(predicate);
3286 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
3287 expected_refcount = get_refcount((IUnknown *)device) + 1;
3288 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
3289 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
3290 refcount = get_refcount((IUnknown *)device);
3291 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3292 tmp = NULL;
3293 expected_refcount = refcount + 1;
3294 ID3D11Predicate_GetDevice(predicate, &tmp);
3295 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3296 refcount = get_refcount((IUnknown *)device);
3297 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3298 ID3D11Device_Release(tmp);
3299 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
3300 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3301 "Predicate should implement ID3D10Predicate.\n");
3302 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3303 ID3D11Predicate_Release(predicate);
3305 refcount = ID3D11Device_Release(device);
3306 ok(!refcount, "Device has %u references left.\n", refcount);
3309 static void test_device_removed_reason(void)
3311 ID3D11Device *device;
3312 ULONG refcount;
3313 HRESULT hr;
3315 if (!(device = create_device(NULL)))
3317 skip("Failed to create device.\n");
3318 return;
3321 hr = ID3D11Device_GetDeviceRemovedReason(device);
3322 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3323 hr = ID3D11Device_GetDeviceRemovedReason(device);
3324 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3326 refcount = ID3D11Device_Release(device);
3327 ok(!refcount, "Device has %u references left.\n", refcount);
3330 static void test_private_data(void)
3332 ULONG refcount, expected_refcount;
3333 D3D11_TEXTURE2D_DESC texture_desc;
3334 ID3D10Texture2D *d3d10_texture;
3335 ID3D11Device *test_object;
3336 ID3D11Texture2D *texture;
3337 IDXGIDevice *dxgi_device;
3338 IDXGISurface *surface;
3339 ID3D11Device *device;
3340 IUnknown *ptr;
3341 HRESULT hr;
3342 UINT size;
3344 static const GUID test_guid =
3345 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
3346 static const GUID test_guid2 =
3347 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
3348 static const DWORD data[] = {1, 2, 3, 4};
3350 if (!(device = create_device(NULL)))
3352 skip("Failed to create device.\n");
3353 return;
3356 test_object = create_device(NULL);
3358 texture_desc.Width = 512;
3359 texture_desc.Height = 512;
3360 texture_desc.MipLevels = 1;
3361 texture_desc.ArraySize = 1;
3362 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3363 texture_desc.SampleDesc.Count = 1;
3364 texture_desc.SampleDesc.Quality = 0;
3365 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3366 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3367 texture_desc.CPUAccessFlags = 0;
3368 texture_desc.MiscFlags = 0;
3370 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3371 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3372 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
3373 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
3375 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
3376 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3377 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3378 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3379 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3380 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3381 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
3382 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3384 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3385 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3386 size = sizeof(ptr) * 2;
3387 ptr = (IUnknown *)0xdeadbeef;
3388 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3389 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3390 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3391 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3393 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
3394 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
3395 size = sizeof(ptr) * 2;
3396 ptr = (IUnknown *)0xdeadbeef;
3397 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
3398 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3399 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
3400 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
3401 IDXGIDevice_Release(dxgi_device);
3403 refcount = get_refcount((IUnknown *)test_object);
3404 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3405 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3406 expected_refcount = refcount + 1;
3407 refcount = get_refcount((IUnknown *)test_object);
3408 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3409 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3410 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3411 refcount = get_refcount((IUnknown *)test_object);
3412 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3414 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
3415 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3416 --expected_refcount;
3417 refcount = get_refcount((IUnknown *)test_object);
3418 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3420 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3421 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3422 size = sizeof(data);
3423 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
3424 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3425 refcount = get_refcount((IUnknown *)test_object);
3426 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3427 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
3428 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3429 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
3430 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
3432 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
3433 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3434 ++expected_refcount;
3435 size = 2 * sizeof(ptr);
3436 ptr = NULL;
3437 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3438 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3439 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
3440 ++expected_refcount;
3441 refcount = get_refcount((IUnknown *)test_object);
3442 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3443 IUnknown_Release(ptr);
3444 --expected_refcount;
3446 ptr = (IUnknown *)0xdeadbeef;
3447 size = 1;
3448 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
3449 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3450 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3451 size = 2 * sizeof(ptr);
3452 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
3453 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3454 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3455 refcount = get_refcount((IUnknown *)test_object);
3456 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3458 size = 1;
3459 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
3460 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
3461 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
3462 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3463 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
3464 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3465 size = 0xdeadbabe;
3466 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
3467 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
3468 ok(size == 0, "Got unexpected size %u.\n", size);
3469 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3470 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
3471 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3472 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
3474 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
3475 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3476 ptr = NULL;
3477 size = sizeof(ptr);
3478 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
3479 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3480 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
3481 IUnknown_Release(ptr);
3483 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
3484 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3485 "Texture should implement ID3D10Texture2D.\n");
3486 if (SUCCEEDED(hr))
3488 ptr = NULL;
3489 size = sizeof(ptr);
3490 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
3491 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3492 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
3493 IUnknown_Release(ptr);
3494 ID3D10Texture2D_Release(d3d10_texture);
3497 IDXGISurface_Release(surface);
3498 ID3D11Texture2D_Release(texture);
3499 refcount = ID3D11Device_Release(device);
3500 ok(!refcount, "Device has %u references left.\n", refcount);
3501 refcount = ID3D11Device_Release(test_object);
3502 ok(!refcount, "Test object has %u references left.\n", refcount);
3505 static void test_blend(void)
3507 ID3D11BlendState *src_blend, *dst_blend;
3508 struct d3d11_test_context test_context;
3509 ID3D11RenderTargetView *offscreen_rtv;
3510 D3D11_SUBRESOURCE_DATA buffer_data;
3511 D3D11_TEXTURE2D_DESC texture_desc;
3512 ID3D11InputLayout *input_layout;
3513 D3D11_BUFFER_DESC buffer_desc;
3514 ID3D11DeviceContext *context;
3515 D3D11_BLEND_DESC blend_desc;
3516 unsigned int stride, offset;
3517 ID3D11Texture2D *offscreen;
3518 ID3D11VertexShader *vs;
3519 ID3D11PixelShader *ps;
3520 ID3D11Device *device;
3521 D3D11_VIEWPORT vp;
3522 ID3D11Buffer *vb;
3523 DWORD color;
3524 HRESULT hr;
3526 static const DWORD vs_code[] =
3528 #if 0
3529 struct vs_out
3531 float4 position : SV_POSITION;
3532 float4 color : COLOR;
3535 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
3537 struct vs_out o;
3539 o.position = position;
3540 o.color = color;
3542 return o;
3544 #endif
3545 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
3546 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3547 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3548 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
3549 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
3550 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
3551 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
3552 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
3553 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
3554 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
3556 static const DWORD ps_code[] =
3558 #if 0
3559 struct vs_out
3561 float4 position : SV_POSITION;
3562 float4 color : COLOR;
3565 float4 main(struct vs_out i) : SV_TARGET
3567 return i.color;
3569 #endif
3570 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
3571 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
3572 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
3573 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
3574 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3575 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3576 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3577 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
3579 static const struct
3581 struct vec3 position;
3582 DWORD diffuse;
3584 quads[] =
3586 /* quad1 */
3587 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
3588 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
3589 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
3590 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
3591 /* quad2 */
3592 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3593 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3594 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
3595 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
3597 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
3599 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
3600 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
3602 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
3603 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
3605 if (!init_test_context(&test_context, NULL))
3606 return;
3608 device = test_context.device;
3609 context = test_context.immediate_context;
3611 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
3612 vs_code, sizeof(vs_code), &input_layout);
3613 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
3615 buffer_desc.ByteWidth = sizeof(quads);
3616 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3617 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
3618 buffer_desc.CPUAccessFlags = 0;
3619 buffer_desc.MiscFlags = 0;
3620 buffer_desc.StructureByteStride = 0;
3622 buffer_data.pSysMem = quads;
3623 buffer_data.SysMemPitch = 0;
3624 buffer_data.SysMemSlicePitch = 0;
3626 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
3627 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3628 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
3629 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3630 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
3631 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3633 memset(&blend_desc, 0, sizeof(blend_desc));
3634 blend_desc.RenderTarget[0].BlendEnable = TRUE;
3635 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
3636 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
3637 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
3638 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
3639 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
3640 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
3641 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
3643 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
3644 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3646 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
3647 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
3648 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
3649 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
3651 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
3652 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3654 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
3655 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
3656 stride = sizeof(*quads);
3657 offset = 0;
3658 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
3659 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
3660 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
3662 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
3664 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3665 ID3D11DeviceContext_Draw(context, 4, 0);
3666 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3667 ID3D11DeviceContext_Draw(context, 4, 4);
3669 color = get_texture_color(test_context.backbuffer, 320, 360);
3670 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
3671 color = get_texture_color(test_context.backbuffer, 320, 120);
3672 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
3674 texture_desc.Width = 128;
3675 texture_desc.Height = 128;
3676 texture_desc.MipLevels = 1;
3677 texture_desc.ArraySize = 1;
3678 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
3679 texture_desc.SampleDesc.Count = 1;
3680 texture_desc.SampleDesc.Quality = 0;
3681 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3682 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
3683 texture_desc.CPUAccessFlags = 0;
3684 texture_desc.MiscFlags = 0;
3686 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
3687 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
3689 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
3690 goto done;
3693 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
3694 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
3696 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
3698 vp.TopLeftX = 0.0f;
3699 vp.TopLeftY = 0.0f;
3700 vp.Width = 128.0f;
3701 vp.Height = 128.0f;
3702 vp.MinDepth = 0.0f;
3703 vp.MaxDepth = 1.0f;
3704 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
3706 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
3708 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3709 ID3D11DeviceContext_Draw(context, 4, 0);
3710 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
3711 ID3D11DeviceContext_Draw(context, 4, 4);
3713 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
3714 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
3715 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
3716 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
3718 ID3D11RenderTargetView_Release(offscreen_rtv);
3719 ID3D11Texture2D_Release(offscreen);
3720 done:
3721 ID3D11BlendState_Release(dst_blend);
3722 ID3D11BlendState_Release(src_blend);
3723 ID3D11PixelShader_Release(ps);
3724 ID3D11VertexShader_Release(vs);
3725 ID3D11Buffer_Release(vb);
3726 ID3D11InputLayout_Release(input_layout);
3727 release_test_context(&test_context);
3730 static void test_texture(void)
3732 struct shader
3734 const DWORD *code;
3735 size_t size;
3737 struct texture
3739 UINT width;
3740 UINT height;
3741 UINT miplevel_count;
3742 DXGI_FORMAT format;
3743 D3D11_SUBRESOURCE_DATA data[3];
3746 struct d3d11_test_context test_context;
3747 const struct texture *current_texture;
3748 D3D11_TEXTURE2D_DESC texture_desc;
3749 D3D11_SAMPLER_DESC sampler_desc;
3750 const struct shader *current_ps;
3751 ID3D11ShaderResourceView *srv;
3752 D3D11_BUFFER_DESC buffer_desc;
3753 ID3D11DeviceContext *context;
3754 ID3D11SamplerState *sampler;
3755 struct texture_readback rb;
3756 ID3D11Texture2D *texture;
3757 ID3D11PixelShader *ps;
3758 ID3D11Device *device;
3759 unsigned int i, x, y;
3760 struct vec4 miplevel;
3761 ID3D11Buffer *cb;
3762 DWORD color;
3763 HRESULT hr;
3765 static const DWORD ps_ld_code[] =
3767 #if 0
3768 Texture2D t;
3770 float miplevel;
3772 float4 main(float4 position : SV_POSITION) : SV_TARGET
3774 float3 p;
3775 t.GetDimensions(miplevel, p.x, p.y, p.z);
3776 p.z = miplevel;
3777 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
3778 return t.Load(int3(p));
3780 #endif
3781 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
3782 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3783 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3784 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3785 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
3786 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
3787 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
3788 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
3789 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
3790 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
3791 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
3792 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
3793 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
3794 0x00107e46, 0x00000000, 0x0100003e,
3796 static const DWORD ps_ld_sint8_code[] =
3798 #if 0
3799 Texture2D<int4> t;
3801 float4 main(float4 position : SV_POSITION) : SV_TARGET
3803 float3 p, s;
3804 int4 c;
3806 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3807 t.GetDimensions(0, s.x, s.y, s.z);
3808 p *= s;
3810 c = t.Load(int3(p));
3811 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
3813 #endif
3814 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
3815 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3816 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3817 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3818 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
3819 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
3820 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3821 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3822 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3823 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3824 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3825 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3826 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3827 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
3828 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
3829 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3830 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
3831 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
3833 static const DWORD ps_ld_uint8_code[] =
3835 #if 0
3836 Texture2D<uint4> t;
3838 float4 main(float4 position : SV_POSITION) : SV_TARGET
3840 float3 p, s;
3842 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
3843 t.GetDimensions(0, s.x, s.y, s.z);
3844 p *= s;
3846 return t.Load(int3(p)) / (float4)255;
3848 #endif
3849 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
3850 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3851 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3852 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3853 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
3854 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
3855 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
3856 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
3857 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
3858 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
3859 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
3860 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
3861 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
3862 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
3863 0x3b808081, 0x0100003e,
3865 static const DWORD ps_sample_code[] =
3867 #if 0
3868 Texture2D t;
3869 SamplerState s;
3871 float4 main(float4 position : SV_POSITION) : SV_Target
3873 float2 p;
3875 p.x = position.x / 640.0f;
3876 p.y = position.y / 480.0f;
3877 return t.Sample(s, p);
3879 #endif
3880 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
3881 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3882 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3883 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3884 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
3885 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
3886 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
3887 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
3888 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
3889 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
3891 static const DWORD ps_sample_b_code[] =
3893 #if 0
3894 Texture2D t;
3895 SamplerState s;
3897 float bias;
3899 float4 main(float4 position : SV_POSITION) : SV_Target
3901 float2 p;
3903 p.x = position.x / 640.0f;
3904 p.y = position.y / 480.0f;
3905 return t.SampleBias(s, p, bias);
3907 #endif
3908 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
3909 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3910 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3911 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3912 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3913 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3914 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3915 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3916 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
3917 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3918 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3920 static const DWORD ps_sample_l_code[] =
3922 #if 0
3923 Texture2D t;
3924 SamplerState s;
3926 float level;
3928 float4 main(float4 position : SV_POSITION) : SV_Target
3930 float2 p;
3932 p.x = position.x / 640.0f;
3933 p.y = position.y / 480.0f;
3934 return t.SampleLevel(s, p, level);
3936 #endif
3937 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
3938 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3939 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
3940 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3941 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
3942 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
3943 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
3944 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
3945 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
3946 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
3947 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
3949 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
3950 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
3951 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
3952 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
3953 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
3954 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
3955 static const DWORD rgba_level_0[] =
3957 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
3958 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
3959 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
3960 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
3962 static const DWORD rgba_level_1[] =
3964 0xffffffff, 0xff0000ff,
3965 0xff000000, 0xff00ff00,
3967 static const DWORD rgba_level_2[] =
3969 0xffff0000,
3971 static const DWORD srgb_data[] =
3973 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
3974 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
3975 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
3976 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
3978 static const BYTE a8_data[] =
3980 0x00, 0x10, 0x20, 0x30,
3981 0x40, 0x50, 0x60, 0x70,
3982 0x80, 0x90, 0xa0, 0xb0,
3983 0xc0, 0xd0, 0xe0, 0xf0,
3985 static const BYTE bc1_data[] =
3987 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3988 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3989 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3990 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3992 static const BYTE bc2_data[] =
3994 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
3995 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
3996 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
3997 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
3999 static const BYTE bc3_data[] =
4001 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
4002 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
4003 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
4004 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
4006 static const BYTE bc4_data[] =
4008 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
4009 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
4010 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
4011 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
4013 static const BYTE bc5_data[] =
4015 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
4016 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
4017 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
4018 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
4020 static const struct texture rgba_texture =
4022 4, 4, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
4024 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
4025 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
4026 {rgba_level_2, sizeof(*rgba_level_2), 0},
4029 static const struct texture srgb_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
4030 {{srgb_data, 4 * sizeof(*srgb_data)}}};
4031 static const struct texture a8_texture = {4, 4, 1, DXGI_FORMAT_A8_UNORM,
4032 {{a8_data, 4 * sizeof(*a8_data)}}};
4033 static const struct texture bc1_texture = {8, 8, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
4034 static const struct texture bc2_texture = {8, 8, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
4035 static const struct texture bc3_texture = {8, 8, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
4036 static const struct texture bc4_texture = {8, 8, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
4037 static const struct texture bc5_texture = {8, 8, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
4038 static const struct texture bc1_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
4039 static const struct texture bc2_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
4040 static const struct texture bc3_texture_srgb = {8, 8, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
4041 static const struct texture sint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_SINT,
4042 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
4043 static const struct texture uint8_texture = {4, 4, 1, DXGI_FORMAT_R8G8B8A8_UINT,
4044 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
4045 static const DWORD level_1_colors[] =
4047 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
4048 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
4049 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
4050 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
4052 static const DWORD lerp_1_2_colors[] =
4054 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
4055 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
4056 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
4057 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
4059 static const DWORD level_2_colors[] =
4061 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
4062 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
4063 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
4064 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
4066 static const DWORD srgb_colors[] =
4068 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
4069 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
4070 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
4071 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
4073 static const DWORD a8_colors[] =
4075 0x00000000, 0x10000000, 0x20000000, 0x30000000,
4076 0x40000000, 0x50000000, 0x60000000, 0x70000000,
4077 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
4078 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
4080 static const DWORD bc_colors[] =
4082 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
4083 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
4084 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
4085 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
4087 static const DWORD bc4_colors[] =
4089 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
4090 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
4091 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
4092 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
4094 static const DWORD bc5_colors[] =
4096 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
4097 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
4098 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
4099 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
4101 static const DWORD sint8_colors[] =
4103 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
4104 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
4105 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
4106 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
4108 static const DWORD zero_colors[4 * 4] = {0};
4109 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4111 static const struct test
4113 const struct shader *ps;
4114 const struct texture *texture;
4115 D3D11_FILTER filter;
4116 float lod_bias;
4117 float min_lod;
4118 float max_lod;
4119 float miplevel;
4120 const DWORD *expected_colors;
4122 tests[] =
4124 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
4125 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
4126 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
4127 {&ps_ld, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
4128 {&ps_ld, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
4129 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4130 {&ps_ld, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
4131 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4132 {&ps_ld, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
4133 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4134 {&ps_ld, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
4135 {&ps_ld, &bc1_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4136 {&ps_ld, &bc2_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4137 {&ps_ld, &bc3_texture_srgb, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4138 {&ps_ld, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
4139 {&ps_ld, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
4140 {&ps_ld_sint8, &sint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
4141 {&ps_ld_uint8, &uint8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
4142 {&ps_sample, &bc1_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4143 {&ps_sample, &bc2_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4144 {&ps_sample, &bc3_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
4145 {&ps_sample, &bc4_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
4146 {&ps_sample, &bc5_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
4147 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
4148 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
4149 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
4150 {&ps_sample, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
4151 {&ps_sample, &srgb_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
4152 {&ps_sample, &a8_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
4153 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
4154 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 8.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_1_colors},
4155 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.0f, level_1_colors},
4156 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.4f, level_1_colors},
4157 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 8.5f, level_2_colors},
4158 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 9.0f, level_2_colors},
4159 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
4160 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
4161 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
4162 {&ps_sample_b, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
4163 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, rgba_level_0},
4164 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, rgba_level_0},
4165 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.4f, rgba_level_0},
4166 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.5f, level_1_colors},
4167 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_1_colors},
4168 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.4f, level_1_colors},
4169 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
4170 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 2.0f, level_2_colors},
4171 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 3.0f, level_2_colors},
4172 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 4.0f, level_2_colors},
4173 {&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},
4174 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -2.0f, rgba_level_0},
4175 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_1_colors},
4176 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_2_colors},
4177 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_2_colors},
4178 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2_colors},
4179 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
4180 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
4181 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
4182 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
4183 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
4184 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
4185 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
4186 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
4187 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
4188 {&ps_sample_l, &rgba_texture, D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
4191 if (!init_test_context(&test_context, NULL))
4192 return;
4194 device = test_context.device;
4195 context = test_context.immediate_context;
4197 buffer_desc.ByteWidth = sizeof(miplevel);
4198 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4199 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4200 buffer_desc.CPUAccessFlags = 0;
4201 buffer_desc.MiscFlags = 0;
4202 buffer_desc.StructureByteStride = 0;
4204 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
4205 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4207 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
4209 texture_desc.Width = 4;
4210 texture_desc.Height = 4;
4211 texture_desc.MipLevels = 3;
4212 texture_desc.ArraySize = 1;
4213 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4214 texture_desc.SampleDesc.Count = 1;
4215 texture_desc.SampleDesc.Quality = 0;
4216 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4217 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4218 texture_desc.CPUAccessFlags = 0;
4219 texture_desc.MiscFlags = 0;
4221 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
4222 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
4223 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
4224 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
4225 sampler_desc.MipLODBias = 0.0f;
4226 sampler_desc.MaxAnisotropy = 0;
4227 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4228 sampler_desc.BorderColor[0] = 0.0f;
4229 sampler_desc.BorderColor[1] = 0.0f;
4230 sampler_desc.BorderColor[2] = 0.0f;
4231 sampler_desc.BorderColor[3] = 0.0f;
4232 sampler_desc.MinLOD = 0.0f;
4233 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
4235 ps = NULL;
4236 srv = NULL;
4237 sampler = NULL;
4238 texture = NULL;
4239 current_ps = NULL;
4240 current_texture = NULL;
4241 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
4243 const struct test *test = &tests[i];
4245 if (current_ps != test->ps)
4247 if (ps)
4248 ID3D11PixelShader_Release(ps);
4250 current_ps = test->ps;
4252 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
4253 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
4255 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4258 if (current_texture != test->texture)
4260 if (texture)
4261 ID3D11Texture2D_Release(texture);
4262 if (srv)
4263 ID3D11ShaderResourceView_Release(srv);
4265 current_texture = test->texture;
4267 texture_desc.Width = current_texture->width;
4268 texture_desc.Height = current_texture->height;
4269 texture_desc.MipLevels = current_texture->miplevel_count;
4270 texture_desc.Format = current_texture->format;
4272 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
4273 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4275 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
4276 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
4278 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
4281 if (!sampler || (sampler_desc.Filter != test->filter
4282 || sampler_desc.MipLODBias != test->lod_bias
4283 || sampler_desc.MinLOD != test->min_lod
4284 || sampler_desc.MaxLOD != test->max_lod))
4286 if (sampler)
4287 ID3D11SamplerState_Release(sampler);
4289 sampler_desc.Filter = test->filter;
4290 sampler_desc.MipLODBias = test->lod_bias;
4291 sampler_desc.MinLOD = test->min_lod;
4292 sampler_desc.MaxLOD = test->max_lod;
4294 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
4295 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4297 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
4300 miplevel.x = test->miplevel;
4301 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &miplevel, 0, 0);
4303 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4305 draw_quad(&test_context);
4307 get_texture_readback(test_context.backbuffer, 0, &rb);
4308 for (y = 0; y < 4; ++y)
4310 for (x = 0; x < 4; ++x)
4312 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
4313 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
4314 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
4317 release_texture_readback(&rb);
4319 ID3D11ShaderResourceView_Release(srv);
4320 ID3D11SamplerState_Release(sampler);
4321 ID3D11Texture2D_Release(texture);
4322 ID3D11PixelShader_Release(ps);
4324 ID3D11Buffer_Release(cb);
4325 release_test_context(&test_context);
4328 static void test_multiple_render_targets(void)
4330 D3D11_SUBRESOURCE_DATA resource_data;
4331 D3D11_TEXTURE2D_DESC texture_desc;
4332 ID3D11InputLayout *input_layout;
4333 unsigned int stride, offset, i;
4334 ID3D11RenderTargetView *rtv[4];
4335 D3D11_BUFFER_DESC buffer_desc;
4336 ID3D11DeviceContext *context;
4337 ID3D11Texture2D *rt[4];
4338 ID3D11VertexShader *vs;
4339 ID3D11PixelShader *ps;
4340 ID3D11Device *device;
4341 D3D11_VIEWPORT vp;
4342 ID3D11Buffer *vb;
4343 ULONG refcount;
4344 HRESULT hr;
4346 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4348 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
4350 static const DWORD vs_code[] =
4352 #if 0
4353 float4 main(float4 position : POSITION) : SV_POSITION
4355 return position;
4357 #endif
4358 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
4359 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4360 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4361 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4362 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
4363 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
4364 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4366 static const DWORD ps_code[] =
4368 #if 0
4369 struct output
4371 float4 t1 : SV_TARGET0;
4372 float4 t2 : SV_Target1;
4373 float4 t3 : SV_TARGET2;
4374 float4 t4 : SV_Target3;
4377 output main(float4 position : SV_POSITION)
4379 struct output o;
4380 o.t1 = (float4)1.0f;
4381 o.t2 = (float4)0.5f;
4382 o.t3 = (float4)0.2f;
4383 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
4384 return o;
4386 #endif
4387 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
4388 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4389 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4390 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
4391 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
4392 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
4393 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
4394 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
4395 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
4396 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
4397 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
4398 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
4399 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
4400 0x3f800000, 0x0100003e,
4402 static const struct
4404 struct vec2 position;
4406 quad[] =
4408 {{-1.0f, -1.0f}},
4409 {{-1.0f, 1.0f}},
4410 {{ 1.0f, -1.0f}},
4411 {{ 1.0f, 1.0f}},
4413 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4415 if (!(device = create_device(NULL)))
4417 skip("Failed to create device.\n");
4418 return;
4421 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4422 vs_code, sizeof(vs_code), &input_layout);
4423 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4425 buffer_desc.ByteWidth = sizeof(quad);
4426 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4427 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4428 buffer_desc.CPUAccessFlags = 0;
4429 buffer_desc.MiscFlags = 0;
4430 buffer_desc.StructureByteStride = 0;
4432 resource_data.pSysMem = quad;
4433 resource_data.SysMemPitch = 0;
4434 resource_data.SysMemSlicePitch = 0;
4436 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
4437 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4439 texture_desc.Width = 640;
4440 texture_desc.Height = 480;
4441 texture_desc.MipLevels = 1;
4442 texture_desc.ArraySize = 1;
4443 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4444 texture_desc.SampleDesc.Count = 1;
4445 texture_desc.SampleDesc.Quality = 0;
4446 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4447 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4448 texture_desc.CPUAccessFlags = 0;
4449 texture_desc.MiscFlags = 0;
4451 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
4453 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
4454 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
4456 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
4457 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
4460 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4461 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4462 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4463 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4465 ID3D11Device_GetImmediateContext(device, &context);
4467 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
4468 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4469 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4470 stride = sizeof(*quad);
4471 offset = 0;
4472 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
4473 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4474 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4476 vp.TopLeftX = 0.0f;
4477 vp.TopLeftY = 0.0f;
4478 vp.Width = 640.0f;
4479 vp.Height = 480.0f;
4480 vp.MinDepth = 0.0f;
4481 vp.MaxDepth = 1.0f;
4482 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4484 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
4485 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
4487 ID3D11DeviceContext_Draw(context, 4, 0);
4489 check_texture_color(rt[0], 0xffffffff, 2);
4490 check_texture_color(rt[1], 0x7f7f7f7f, 2);
4491 check_texture_color(rt[2], 0x33333333, 2);
4492 check_texture_color(rt[3], 0xff7f3300, 2);
4494 ID3D11Buffer_Release(vb);
4495 ID3D11PixelShader_Release(ps);
4496 ID3D11VertexShader_Release(vs);
4497 ID3D11InputLayout_Release(input_layout);
4498 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
4499 ID3D11RenderTargetView_Release(rtv[i]);
4500 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
4501 ID3D11Texture2D_Release(rt[i]);
4502 ID3D11DeviceContext_Release(context);
4503 refcount = ID3D11Device_Release(device);
4504 ok(!refcount, "Device has %u references left.\n", refcount);
4507 static void test_scissor(void)
4509 struct d3d11_test_context test_context;
4510 ID3D11DeviceContext *immediate_context;
4511 D3D11_RASTERIZER_DESC rs_desc;
4512 ID3D11RasterizerState *rs;
4513 D3D11_RECT scissor_rect;
4514 ID3D11PixelShader *ps;
4515 ID3D11Device *device;
4516 DWORD color;
4517 HRESULT hr;
4519 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4520 static const DWORD ps_code[] =
4522 #if 0
4523 float4 main(float4 position : SV_POSITION) : SV_Target
4525 return float4(0.0, 1.0, 0.0, 1.0);
4527 #endif
4528 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
4529 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4530 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4531 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4532 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
4533 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
4534 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
4537 if (!init_test_context(&test_context, NULL))
4538 return;
4540 device = test_context.device;
4541 immediate_context = test_context.immediate_context;
4543 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4544 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4546 rs_desc.FillMode = D3D11_FILL_SOLID;
4547 rs_desc.CullMode = D3D11_CULL_BACK;
4548 rs_desc.FrontCounterClockwise = FALSE;
4549 rs_desc.DepthBias = 0;
4550 rs_desc.DepthBiasClamp = 0.0f;
4551 rs_desc.SlopeScaledDepthBias = 0.0f;
4552 rs_desc.DepthClipEnable = TRUE;
4553 rs_desc.ScissorEnable = TRUE;
4554 rs_desc.MultisampleEnable = FALSE;
4555 rs_desc.AntialiasedLineEnable = FALSE;
4556 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
4557 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4559 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
4561 scissor_rect.left = 160;
4562 scissor_rect.top = 120;
4563 scissor_rect.right = 480;
4564 scissor_rect.bottom = 360;
4565 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
4567 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4568 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4570 draw_quad(&test_context);
4571 color = get_texture_color(test_context.backbuffer, 320, 60);
4572 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4573 color = get_texture_color(test_context.backbuffer, 80, 240);
4574 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4575 color = get_texture_color(test_context.backbuffer, 320, 240);
4576 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4577 color = get_texture_color(test_context.backbuffer, 560, 240);
4578 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4579 color = get_texture_color(test_context.backbuffer, 320, 420);
4580 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4582 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
4583 ID3D11DeviceContext_RSSetState(immediate_context, rs);
4584 draw_quad(&test_context);
4585 color = get_texture_color(test_context.backbuffer, 320, 60);
4586 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4587 color = get_texture_color(test_context.backbuffer, 80, 240);
4588 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4589 color = get_texture_color(test_context.backbuffer, 320, 240);
4590 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4591 color = get_texture_color(test_context.backbuffer, 560, 240);
4592 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4593 color = get_texture_color(test_context.backbuffer, 320, 420);
4594 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4596 ID3D11RasterizerState_Release(rs);
4597 ID3D11PixelShader_Release(ps);
4598 release_test_context(&test_context);
4601 static void test_il_append_aligned(void)
4603 struct d3d11_test_context test_context;
4604 D3D11_SUBRESOURCE_DATA resource_data;
4605 ID3D11InputLayout *input_layout;
4606 D3D11_BUFFER_DESC buffer_desc;
4607 ID3D11DeviceContext *context;
4608 unsigned int stride, offset;
4609 ID3D11VertexShader *vs;
4610 ID3D11PixelShader *ps;
4611 ID3D11Device *device;
4612 ID3D11Buffer *vb[3];
4613 DWORD color;
4614 HRESULT hr;
4616 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
4618 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4619 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4620 {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4621 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4622 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
4623 D3D11_INPUT_PER_VERTEX_DATA, 0},
4624 {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
4625 D3D11_INPUT_PER_INSTANCE_DATA, 1},
4626 {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
4627 D3D11_INPUT_PER_INSTANCE_DATA, 2},
4629 static const DWORD vs_code[] =
4631 #if 0
4632 struct vs_in
4634 float4 position : POSITION;
4635 float2 color_xy : COLOR0;
4636 float2 color_zw : COLOR1;
4637 unsigned int instance_id : SV_INSTANCEID;
4640 struct vs_out
4642 float4 position : SV_POSITION;
4643 float2 color_xy : COLOR0;
4644 float2 color_zw : COLOR1;
4647 struct vs_out main(struct vs_in i)
4649 struct vs_out o;
4651 o.position = i.position;
4652 o.position.x += i.instance_id * 0.5;
4653 o.color_xy = i.color_xy;
4654 o.color_zw = i.color_zw;
4656 return o;
4658 #endif
4659 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
4660 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
4661 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
4662 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
4663 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
4664 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
4665 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4666 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
4667 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
4668 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
4669 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
4670 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
4671 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
4672 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
4673 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
4674 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
4675 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
4677 static const DWORD ps_code[] =
4679 #if 0
4680 struct vs_out
4682 float4 position : SV_POSITION;
4683 float2 color_xy : COLOR0;
4684 float2 color_zw : COLOR1;
4687 float4 main(struct vs_out i) : SV_TARGET
4689 return float4(i.color_xy.xy, i.color_zw.xy);
4691 #endif
4692 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
4693 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
4694 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
4695 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
4696 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
4697 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
4698 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
4699 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4700 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
4702 static const struct
4704 struct vec4 position;
4706 stream0[] =
4708 {{-1.0f, -1.0f, 0.0f, 1.0f}},
4709 {{-1.0f, 1.0f, 0.0f, 1.0f}},
4710 {{-0.5f, -1.0f, 0.0f, 1.0f}},
4711 {{-0.5f, 1.0f, 0.0f, 1.0f}},
4713 static const struct
4715 struct vec2 color2;
4716 struct vec2 color1;
4718 stream1[] =
4720 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4721 {{0.5f, 0.5f}, {1.0f, 1.0f}},
4723 static const struct
4725 struct vec2 color3;
4726 struct vec2 color0;
4728 stream2[] =
4730 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4731 {{0.5f, 0.5f}, {0.0f, 1.0f}},
4732 {{0.5f, 0.5f}, {0.0f, 0.0f}},
4733 {{0.5f, 0.5f}, {1.0f, 0.0f}},
4735 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4737 if (!init_test_context(&test_context, NULL))
4738 return;
4740 device = test_context.device;
4741 context = test_context.immediate_context;
4743 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4744 vs_code, sizeof(vs_code), &input_layout);
4745 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4747 buffer_desc.ByteWidth = sizeof(stream0);
4748 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4749 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
4750 buffer_desc.CPUAccessFlags = 0;
4751 buffer_desc.MiscFlags = 0;
4752 buffer_desc.StructureByteStride = 0;
4754 resource_data.pSysMem = stream0;
4755 resource_data.SysMemPitch = 0;
4756 resource_data.SysMemSlicePitch = 0;
4758 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]);
4759 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4761 buffer_desc.ByteWidth = sizeof(stream1);
4762 resource_data.pSysMem = stream1;
4764 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]);
4765 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4767 buffer_desc.ByteWidth = sizeof(stream2);
4768 resource_data.pSysMem = stream2;
4770 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]);
4771 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4773 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
4774 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4775 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4776 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4778 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
4779 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4780 offset = 0;
4781 stride = sizeof(*stream0);
4782 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
4783 stride = sizeof(*stream1);
4784 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
4785 stride = sizeof(*stream2);
4786 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
4787 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
4788 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4790 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4792 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
4794 color = get_texture_color(test_context.backbuffer, 80, 240);
4795 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4796 color = get_texture_color(test_context.backbuffer, 240, 240);
4797 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4798 color = get_texture_color(test_context.backbuffer, 400, 240);
4799 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4800 color = get_texture_color(test_context.backbuffer, 560, 240);
4801 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
4803 ID3D11PixelShader_Release(ps);
4804 ID3D11VertexShader_Release(vs);
4805 ID3D11Buffer_Release(vb[2]);
4806 ID3D11Buffer_Release(vb[1]);
4807 ID3D11Buffer_Release(vb[0]);
4808 ID3D11InputLayout_Release(input_layout);
4809 release_test_context(&test_context);
4812 static void test_fragment_coords(void)
4814 struct d3d11_test_context test_context;
4815 D3D11_SUBRESOURCE_DATA resource_data;
4816 ID3D11PixelShader *ps, *ps_frac;
4817 D3D11_BUFFER_DESC buffer_desc;
4818 ID3D11DeviceContext *context;
4819 ID3D11Device *device;
4820 ID3D11Buffer *ps_cb;
4821 DWORD color;
4822 HRESULT hr;
4824 static const DWORD ps_code[] =
4826 #if 0
4827 float2 cutoff;
4829 float4 main(float4 position : SV_POSITION) : SV_TARGET
4831 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
4833 if (position.x > cutoff.x)
4834 ret.y = 1.0;
4835 if (position.y > cutoff.y)
4836 ret.z = 1.0;
4838 return ret;
4840 #endif
4841 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
4842 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4843 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4844 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4845 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
4846 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
4847 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
4848 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
4849 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
4850 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
4851 0x0100003e,
4853 static const DWORD ps_frac_code[] =
4855 #if 0
4856 float4 main(float4 position : SV_POSITION) : SV_TARGET
4858 return float4(frac(position.xy), 0.0, 1.0);
4860 #endif
4861 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
4862 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4863 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4864 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4865 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
4866 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
4867 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
4868 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
4870 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4871 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
4873 if (!init_test_context(&test_context, NULL))
4874 return;
4876 device = test_context.device;
4877 context = test_context.immediate_context;
4879 buffer_desc.ByteWidth = sizeof(cutoff);
4880 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4881 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
4882 buffer_desc.CPUAccessFlags = 0;
4883 buffer_desc.MiscFlags = 0;
4884 buffer_desc.StructureByteStride = 0;
4886 resource_data.pSysMem = &cutoff;
4887 resource_data.SysMemPitch = 0;
4888 resource_data.SysMemSlicePitch = 0;
4890 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4891 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4893 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
4894 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4895 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
4896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4898 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4899 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
4901 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4903 draw_quad(&test_context);
4905 color = get_texture_color(test_context.backbuffer, 319, 239);
4906 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4907 color = get_texture_color(test_context.backbuffer, 320, 239);
4908 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4909 color = get_texture_color(test_context.backbuffer, 319, 240);
4910 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4911 color = get_texture_color(test_context.backbuffer, 320, 240);
4912 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4914 ID3D11Buffer_Release(ps_cb);
4915 cutoff.x = 16.0f;
4916 cutoff.y = 16.0f;
4917 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &ps_cb);
4918 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
4919 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
4921 draw_quad(&test_context);
4923 color = get_texture_color(test_context.backbuffer, 14, 14);
4924 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
4925 color = get_texture_color(test_context.backbuffer, 18, 14);
4926 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4927 color = get_texture_color(test_context.backbuffer, 14, 18);
4928 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
4929 color = get_texture_color(test_context.backbuffer, 18, 18);
4930 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
4932 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
4933 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
4935 ID3D11DeviceContext_Draw(context, 4, 0);
4937 color = get_texture_color(test_context.backbuffer, 14, 14);
4938 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
4940 ID3D11Buffer_Release(ps_cb);
4941 ID3D11PixelShader_Release(ps_frac);
4942 ID3D11PixelShader_Release(ps);
4943 release_test_context(&test_context);
4946 static void test_update_subresource(void)
4948 struct d3d11_test_context test_context;
4949 D3D11_TEXTURE2D_DESC texture_desc;
4950 ID3D11SamplerState *sampler_state;
4951 ID3D11ShaderResourceView *ps_srv;
4952 D3D11_SAMPLER_DESC sampler_desc;
4953 ID3D11DeviceContext *context;
4954 struct texture_readback rb;
4955 ID3D11Texture2D *texture;
4956 ID3D11PixelShader *ps;
4957 ID3D11Device *device;
4958 unsigned int i, j;
4959 D3D11_BOX box;
4960 DWORD color;
4961 HRESULT hr;
4963 static const DWORD ps_code[] =
4965 #if 0
4966 Texture2D t;
4967 SamplerState s;
4969 float4 main(float4 position : SV_POSITION) : SV_Target
4971 float2 p;
4973 p.x = position.x / 640.0f;
4974 p.y = position.y / 480.0f;
4975 return t.Sample(s, p);
4977 #endif
4978 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
4979 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4980 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
4981 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4982 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
4983 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
4984 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
4985 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
4986 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
4987 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
4989 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4990 static const DWORD bitmap_data[] =
4992 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
4993 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
4994 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
4995 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
4997 static const DWORD expected_colors[] =
4999 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
5000 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
5001 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
5002 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
5005 if (!init_test_context(&test_context, NULL))
5006 return;
5008 device = test_context.device;
5009 context = test_context.immediate_context;
5011 texture_desc.Width = 4;
5012 texture_desc.Height = 4;
5013 texture_desc.MipLevels = 1;
5014 texture_desc.ArraySize = 1;
5015 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5016 texture_desc.SampleDesc.Count = 1;
5017 texture_desc.SampleDesc.Quality = 0;
5018 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5019 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5020 texture_desc.CPUAccessFlags = 0;
5021 texture_desc.MiscFlags = 0;
5023 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5024 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
5026 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
5027 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5029 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
5030 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
5031 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
5032 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
5033 sampler_desc.MipLODBias = 0.0f;
5034 sampler_desc.MaxAnisotropy = 0;
5035 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
5036 sampler_desc.BorderColor[0] = 0.0f;
5037 sampler_desc.BorderColor[1] = 0.0f;
5038 sampler_desc.BorderColor[2] = 0.0f;
5039 sampler_desc.BorderColor[3] = 0.0f;
5040 sampler_desc.MinLOD = 0.0f;
5041 sampler_desc.MaxLOD = 0.0f;
5043 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
5044 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5046 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5047 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5049 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
5050 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
5051 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5053 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5054 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
5056 draw_quad(&test_context);
5057 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5059 set_box(&box, 1, 1, 0, 3, 3, 1);
5060 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5061 bitmap_data, 4 * sizeof(*bitmap_data), 0);
5062 set_box(&box, 0, 3, 0, 3, 4, 1);
5063 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5064 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
5065 set_box(&box, 0, 0, 0, 4, 1, 1);
5066 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5067 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
5068 set_box(&box, 0, 1, 0, 1, 3, 1);
5069 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5070 &bitmap_data[2], sizeof(*bitmap_data), 0);
5071 set_box(&box, 4, 4, 0, 3, 1, 1);
5072 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5073 bitmap_data, sizeof(*bitmap_data), 0);
5074 set_box(&box, 0, 0, 0, 4, 4, 0);
5075 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
5076 bitmap_data, 4 * sizeof(*bitmap_data), 0);
5077 draw_quad(&test_context);
5078 get_texture_readback(test_context.backbuffer, 0, &rb);
5079 for (i = 0; i < 4; ++i)
5081 for (j = 0; j < 4; ++j)
5083 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5084 ok(compare_color(color, expected_colors[j + i * 4], 1),
5085 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5086 color, j, i, expected_colors[j + i * 4]);
5089 release_texture_readback(&rb);
5091 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
5092 bitmap_data, 4 * sizeof(*bitmap_data), 0);
5093 draw_quad(&test_context);
5094 get_texture_readback(test_context.backbuffer, 0, &rb);
5095 for (i = 0; i < 4; ++i)
5097 for (j = 0; j < 4; ++j)
5099 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5100 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5101 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5102 color, j, i, bitmap_data[j + i * 4]);
5105 release_texture_readback(&rb);
5107 ID3D11PixelShader_Release(ps);
5108 ID3D11SamplerState_Release(sampler_state);
5109 ID3D11ShaderResourceView_Release(ps_srv);
5110 ID3D11Texture2D_Release(texture);
5111 release_test_context(&test_context);
5114 static void test_copy_subresource_region(void)
5116 ID3D11Texture2D *dst_texture, *src_texture;
5117 struct d3d11_test_context test_context;
5118 ID3D11Buffer *dst_buffer, *src_buffer;
5119 D3D11_SUBRESOURCE_DATA resource_data;
5120 D3D11_TEXTURE2D_DESC texture_desc;
5121 ID3D11SamplerState *sampler_state;
5122 ID3D11ShaderResourceView *ps_srv;
5123 D3D11_SAMPLER_DESC sampler_desc;
5124 D3D11_BUFFER_DESC buffer_desc;
5125 ID3D11DeviceContext *context;
5126 struct vec4 float_colors[16];
5127 struct texture_readback rb;
5128 ID3D11PixelShader *ps;
5129 ID3D11Device *device;
5130 unsigned int i, j;
5131 D3D11_BOX box;
5132 DWORD color;
5133 HRESULT hr;
5135 static const DWORD ps_code[] =
5137 #if 0
5138 Texture2D t;
5139 SamplerState s;
5141 float4 main(float4 position : SV_POSITION) : SV_Target
5143 float2 p;
5145 p.x = position.x / 640.0f;
5146 p.y = position.y / 480.0f;
5147 return t.Sample(s, p);
5149 #endif
5150 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5151 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5152 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5153 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5154 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5155 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5156 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5157 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5158 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5159 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5161 static const DWORD ps_buffer_code[] =
5163 #if 0
5164 float4 buffer[16];
5166 float4 main(float4 position : SV_POSITION) : SV_TARGET
5168 float2 p = (float2)4;
5169 p *= float2(position.x / 640.0f, position.y / 480.0f);
5170 return buffer[(int)p.y * 4 + (int)p.x];
5172 #endif
5173 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
5174 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5175 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5176 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5177 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
5178 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
5179 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
5180 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
5181 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
5182 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
5183 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
5184 0x0010000a, 0x00000000, 0x0100003e,
5186 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5187 static const DWORD bitmap_data[] =
5189 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5190 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5191 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5192 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5194 static const DWORD expected_colors[] =
5196 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5197 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
5198 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
5199 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
5202 if (!init_test_context(&test_context, NULL))
5203 return;
5205 device = test_context.device;
5206 context = test_context.immediate_context;
5208 texture_desc.Width = 4;
5209 texture_desc.Height = 4;
5210 texture_desc.MipLevels = 1;
5211 texture_desc.ArraySize = 1;
5212 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5213 texture_desc.SampleDesc.Count = 1;
5214 texture_desc.SampleDesc.Quality = 0;
5215 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5216 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5217 texture_desc.CPUAccessFlags = 0;
5218 texture_desc.MiscFlags = 0;
5220 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
5221 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
5223 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
5225 resource_data.pSysMem = bitmap_data;
5226 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
5227 resource_data.SysMemSlicePitch = 0;
5229 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
5230 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
5232 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
5233 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5235 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
5236 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
5237 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
5238 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
5239 sampler_desc.MipLODBias = 0.0f;
5240 sampler_desc.MaxAnisotropy = 0;
5241 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
5242 sampler_desc.BorderColor[0] = 0.0f;
5243 sampler_desc.BorderColor[1] = 0.0f;
5244 sampler_desc.BorderColor[2] = 0.0f;
5245 sampler_desc.BorderColor[3] = 0.0f;
5246 sampler_desc.MinLOD = 0.0f;
5247 sampler_desc.MaxLOD = 0.0f;
5249 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
5250 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5252 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5253 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5255 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
5256 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
5257 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5259 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5261 set_box(&box, 0, 0, 0, 2, 2, 1);
5262 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5263 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
5264 set_box(&box, 1, 2, 0, 4, 3, 1);
5265 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5266 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
5267 set_box(&box, 0, 3, 0, 4, 4, 1);
5268 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5269 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
5270 set_box(&box, 3, 0, 0, 4, 2, 1);
5271 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5272 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
5273 set_box(&box, 3, 1, 0, 4, 2, 1);
5274 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5275 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
5276 set_box(&box, 0, 0, 0, 4, 4, 0);
5277 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5278 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
5279 draw_quad(&test_context);
5280 get_texture_readback(test_context.backbuffer, 0, &rb);
5281 for (i = 0; i < 4; ++i)
5283 for (j = 0; j < 4; ++j)
5285 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5286 ok(compare_color(color, expected_colors[j + i * 4], 1),
5287 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5288 color, j, i, expected_colors[j + i * 4]);
5291 release_texture_readback(&rb);
5293 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
5294 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
5295 draw_quad(&test_context);
5296 get_texture_readback(test_context.backbuffer, 0, &rb);
5297 for (i = 0; i < 4; ++i)
5299 for (j = 0; j < 4; ++j)
5301 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5302 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5303 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5304 color, j, i, bitmap_data[j + i * 4]);
5307 release_texture_readback(&rb);
5309 ID3D11PixelShader_Release(ps);
5310 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
5311 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5313 ID3D11ShaderResourceView_Release(ps_srv);
5314 ps_srv = NULL;
5316 ID3D11SamplerState_Release(sampler_state);
5317 sampler_state = NULL;
5319 ID3D11Texture2D_Release(dst_texture);
5320 ID3D11Texture2D_Release(src_texture);
5322 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
5323 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
5324 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5326 buffer_desc.ByteWidth = sizeof(float_colors);
5327 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
5328 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
5329 buffer_desc.CPUAccessFlags = 0;
5330 buffer_desc.MiscFlags = 0;
5331 buffer_desc.StructureByteStride = 0;
5333 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
5334 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5336 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
5338 buffer_desc.ByteWidth = 256 * sizeof(*float_colors);
5339 buffer_desc.BindFlags = 0;
5341 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &src_buffer);
5342 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5344 for (i = 0; i < 4; ++i)
5346 for (j = 0; j < 4; ++j)
5348 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
5349 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
5350 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
5351 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
5354 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
5355 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
5357 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
5358 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5359 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5360 draw_quad(&test_context);
5361 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5363 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
5364 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5365 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5366 draw_quad(&test_context);
5367 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5369 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
5370 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5371 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5372 draw_quad(&test_context);
5373 check_texture_color(test_context.backbuffer, 0x00000000, 0);
5375 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
5376 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
5377 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
5378 draw_quad(&test_context);
5379 get_texture_readback(test_context.backbuffer, 0, &rb);
5380 for (i = 0; i < 4; ++i)
5382 for (j = 0; j < 4; ++j)
5384 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
5385 ok(compare_color(color, bitmap_data[j + i * 4], 1),
5386 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
5387 color, j, i, bitmap_data[j + i * 4]);
5390 release_texture_readback(&rb);
5392 ID3D11Buffer_Release(dst_buffer);
5393 ID3D11Buffer_Release(src_buffer);
5394 ID3D11PixelShader_Release(ps);
5395 release_test_context(&test_context);
5398 static void test_resource_map(void)
5400 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
5401 D3D11_TEXTURE3D_DESC texture3d_desc;
5402 D3D11_TEXTURE2D_DESC texture2d_desc;
5403 D3D11_BUFFER_DESC buffer_desc;
5404 ID3D11DeviceContext *context;
5405 ID3D11Texture3D *texture3d;
5406 ID3D11Texture2D *texture2d;
5407 ID3D11Buffer *buffer;
5408 ID3D11Device *device;
5409 ULONG refcount;
5410 HRESULT hr;
5411 DWORD data;
5413 if (!(device = create_device(NULL)))
5415 skip("Failed to create device.\n");
5416 return;
5419 ID3D11Device_GetImmediateContext(device, &context);
5421 buffer_desc.ByteWidth = 1024;
5422 buffer_desc.Usage = D3D11_USAGE_STAGING;
5423 buffer_desc.BindFlags = 0;
5424 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5425 buffer_desc.MiscFlags = 0;
5426 buffer_desc.StructureByteStride = 0;
5428 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
5429 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
5431 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5432 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5434 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5435 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5436 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
5437 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5438 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
5439 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5440 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
5442 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5443 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5444 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
5445 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5446 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
5447 data = *((DWORD *)mapped_subresource.pData);
5448 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5449 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
5451 refcount = ID3D11Buffer_Release(buffer);
5452 ok(!refcount, "Buffer has %u references left.\n", refcount);
5454 texture2d_desc.Width = 512;
5455 texture2d_desc.Height = 512;
5456 texture2d_desc.MipLevels = 1;
5457 texture2d_desc.ArraySize = 1;
5458 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5459 texture2d_desc.SampleDesc.Count = 1;
5460 texture2d_desc.SampleDesc.Quality = 0;
5461 texture2d_desc.Usage = D3D11_USAGE_STAGING;
5462 texture2d_desc.BindFlags = 0;
5463 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5464 texture2d_desc.MiscFlags = 0;
5466 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
5467 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
5469 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5470 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5472 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5473 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5474 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5475 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5476 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
5477 mapped_subresource.DepthPitch);
5478 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5479 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
5481 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5482 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5483 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5484 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5485 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
5486 mapped_subresource.DepthPitch);
5487 data = *((DWORD *)mapped_subresource.pData);
5488 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5489 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
5491 refcount = ID3D11Texture2D_Release(texture2d);
5492 ok(!refcount, "2D texture has %u references left.\n", refcount);
5494 texture3d_desc.Width = 64;
5495 texture3d_desc.Height = 64;
5496 texture3d_desc.Depth = 64;
5497 texture3d_desc.MipLevels = 1;
5498 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5499 texture3d_desc.Usage = D3D11_USAGE_STAGING;
5500 texture3d_desc.BindFlags = 0;
5501 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
5502 texture3d_desc.MiscFlags = 0;
5504 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
5505 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
5507 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
5508 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5510 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5511 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
5512 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5513 if (FAILED(hr)) goto done;
5514 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5515 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
5516 mapped_subresource.DepthPitch);
5517 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
5518 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
5520 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
5521 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
5522 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
5523 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
5524 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
5525 mapped_subresource.DepthPitch);
5526 data = *((DWORD *)mapped_subresource.pData);
5527 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
5528 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
5530 done:
5531 refcount = ID3D11Texture3D_Release(texture3d);
5532 ok(!refcount, "3D texture has %u references left.\n", refcount);
5534 ID3D11DeviceContext_Release(context);
5536 refcount = ID3D11Device_Release(device);
5537 ok(!refcount, "Device has %u references left.\n", refcount);
5540 static void test_texture_data_init(void)
5542 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5543 struct d3d11_test_context test_context;
5544 ID3D11DeviceContext *context;
5545 D3D11_TEXTURE2D_DESC desc;
5546 ID3D11Texture2D *texture;
5547 ID3D11Device *device;
5548 UINT count = 0;
5549 HRESULT hr;
5551 if (!init_test_context(&test_context, NULL))
5552 return;
5554 device = test_context.device;
5555 context = test_context.immediate_context;
5557 desc.Width = 640;
5558 desc.Height = 480;
5559 desc.MipLevels = 1;
5560 desc.ArraySize = 1;
5561 desc.SampleDesc.Count = 1;
5562 desc.SampleDesc.Quality = 0;
5563 desc.Usage = D3D11_USAGE_DEFAULT;
5564 desc.BindFlags = 0;
5565 desc.CPUAccessFlags = 0;
5566 desc.MiscFlags = 0;
5568 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5569 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5570 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5571 check_texture_color(texture, 0x00000000, 0);
5572 ID3D11Texture2D_Release(texture);
5574 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5575 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5576 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5577 check_texture_color(texture, 0x00000000, 0);
5578 ID3D11Texture2D_Release(texture);
5580 desc.Format = DXGI_FORMAT_D32_FLOAT;
5581 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5582 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5583 check_texture_float(texture, 0.0f, 0);
5584 ID3D11Texture2D_Release(texture);
5586 desc.ArraySize = 4;
5588 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5589 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5590 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5591 check_texture_float(texture, 0.0f, 0);
5592 ID3D11Texture2D_Release(texture);
5594 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5595 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5596 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5597 check_texture_color(texture, 0x00000000, 0);
5598 ID3D11Texture2D_Release(texture);
5600 desc.Format = DXGI_FORMAT_D32_FLOAT;
5601 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5602 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5603 check_texture_float(texture, 0.0f, 0);
5604 ID3D11Texture2D_Release(texture);
5606 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
5607 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
5608 if (!count)
5610 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
5611 release_test_context(&test_context);
5612 return;
5615 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5617 desc.ArraySize = 1;
5618 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5619 desc.SampleDesc.Count = 2;
5620 desc.SampleDesc.Quality = 0;
5621 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5622 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
5623 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5625 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
5626 (ID3D11Resource *)texture, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
5628 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 0);
5630 ID3D11Texture2D_Release(texture);
5632 release_test_context(&test_context);
5635 static void test_check_multisample_quality_levels(void)
5637 ID3D11Device *device;
5638 UINT quality_levels;
5639 ULONG refcount;
5640 HRESULT hr;
5642 if (!(device = create_device(NULL)))
5644 skip("Failed to create device.\n");
5645 return;
5648 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5649 if (!quality_levels)
5651 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
5652 goto done;
5655 quality_levels = 0xdeadbeef;
5656 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
5657 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5658 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5659 quality_levels = 0xdeadbeef;
5660 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
5661 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5662 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
5664 quality_levels = 0xdeadbeef;
5665 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
5666 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5667 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
5668 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5669 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5671 quality_levels = 0xdeadbeef;
5672 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
5673 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5674 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
5675 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5676 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
5678 quality_levels = 0xdeadbeef;
5679 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
5680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5681 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
5682 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5683 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5685 /* We assume 15 samples multisampling is never supported in practice. */
5686 quality_levels = 0xdeadbeef;
5687 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
5688 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5689 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5690 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
5691 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5692 quality_levels = 0xdeadbeef;
5693 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
5694 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5695 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5696 quality_levels = 0xdeadbeef;
5697 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
5698 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5699 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5701 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
5702 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5703 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
5705 done:
5706 refcount = ID3D11Device_Release(device);
5707 ok(!refcount, "Device has %u references left.\n", refcount);
5710 static void test_swapchain_flip(void)
5712 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
5713 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
5714 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
5715 D3D11_SUBRESOURCE_DATA resource_data;
5716 D3D11_TEXTURE2D_DESC texture_desc;
5717 ID3D11InputLayout *input_layout;
5718 D3D11_BUFFER_DESC buffer_desc;
5719 ID3D11DeviceContext *context;
5720 unsigned int stride, offset;
5721 struct swapchain_desc desc;
5722 IDXGISwapChain *swapchain;
5723 ID3D11VertexShader *vs;
5724 ID3D11PixelShader *ps;
5725 ID3D11Device *device;
5726 D3D11_VIEWPORT vp;
5727 ID3D11Buffer *vb;
5728 ULONG refcount;
5729 DWORD color;
5730 HWND window;
5731 HRESULT hr;
5733 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5735 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5737 static const DWORD vs_code[] =
5739 #if 0
5740 float4 main(float4 position : POSITION) : SV_POSITION
5742 return position;
5744 #endif
5745 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
5746 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5747 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5748 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
5749 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
5750 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
5751 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5754 static const DWORD ps_code[] =
5756 #if 0
5757 Texture2D t0, t1;
5758 SamplerState s;
5760 float4 main(float4 position : SV_POSITION) : SV_Target
5762 float2 p;
5764 p.x = 0.5;
5765 p.y = 0.5;
5766 if (position.x < 320)
5767 return t0.Sample(s, p);
5768 return t1.Sample(s, p);
5770 #endif
5771 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
5772 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
5773 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
5774 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
5775 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
5776 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
5777 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
5778 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
5779 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
5780 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
5781 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
5782 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
5783 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
5784 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
5785 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
5786 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
5787 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
5788 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
5789 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
5790 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
5791 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
5792 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
5793 0x00000000, 0x00000000, 0x00000000
5795 static const struct
5797 struct vec2 position;
5799 quad[] =
5801 {{-1.0f, -1.0f}},
5802 {{-1.0f, 1.0f}},
5803 {{ 1.0f, -1.0f}},
5804 {{ 1.0f, 1.0f}},
5806 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5807 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
5808 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
5810 if (!(device = create_device(NULL)))
5812 skip("Failed to create device, skipping tests.\n");
5813 return;
5815 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5816 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5817 desc.buffer_count = 3;
5818 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
5819 desc.windowed = TRUE;
5820 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
5821 swapchain = create_swapchain(device, window, &desc);
5823 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
5824 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
5825 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
5826 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
5827 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
5828 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
5830 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
5831 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5832 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
5833 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5834 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
5835 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5837 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
5838 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
5839 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
5840 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
5841 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
5843 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
5844 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
5845 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
5846 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
5847 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
5849 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
5850 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5851 if (SUCCEEDED(hr))
5852 ID3D11RenderTargetView_Release(offscreen_rtv);
5854 ID3D11Device_GetImmediateContext(device, &context);
5856 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
5857 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
5859 texture_desc.Width = 640;
5860 texture_desc.Height = 480;
5861 texture_desc.MipLevels = 1;
5862 texture_desc.ArraySize = 1;
5863 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5864 texture_desc.SampleDesc.Count = 1;
5865 texture_desc.SampleDesc.Quality = 0;
5866 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5867 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5868 texture_desc.CPUAccessFlags = 0;
5869 texture_desc.MiscFlags = 0;
5870 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
5871 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
5872 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5873 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5874 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5875 vp.TopLeftX = 0;
5876 vp.TopLeftY = 0;
5877 vp.Width = 640;
5878 vp.Height = 480;
5879 vp.MinDepth = 0.0f;
5880 vp.MaxDepth = 1.0f;
5881 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5883 buffer_desc.ByteWidth = sizeof(quad);
5884 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
5885 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
5886 buffer_desc.CPUAccessFlags = 0;
5887 buffer_desc.MiscFlags = 0;
5889 resource_data.pSysMem = quad;
5890 resource_data.SysMemPitch = 0;
5891 resource_data.SysMemSlicePitch = 0;
5893 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb);
5894 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
5896 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5897 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5898 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5899 vs_code, sizeof(vs_code), &input_layout);
5900 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5901 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5902 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5903 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5904 stride = sizeof(*quad);
5905 offset = 0;
5906 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5908 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5909 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5910 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5912 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
5914 ID3D11DeviceContext_Draw(context, 4, 0);
5915 color = get_texture_color(offscreen, 120, 240);
5916 todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5918 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
5919 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
5920 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
5922 * What is this good for? I don't know. Ad-hoc tests suggest that
5923 * Present() always waits for the next V-sync interval, even if there are
5924 * still untouched buffers. Buffer 0 is the buffer that is shown on the
5925 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
5926 * rendering finishes before the V-sync interval is over. I haven't found
5927 * any productive use for more than one buffer. */
5928 IDXGISwapChain_Present(swapchain, 0, 0);
5930 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
5932 ID3D11DeviceContext_Draw(context, 4, 0);
5933 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
5934 todo_wine ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5935 /* Buffer 1 is still untouched. */
5937 color = get_texture_color(backbuffer_0, 320, 240); /* green */
5938 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5939 color = get_texture_color(backbuffer_2, 320, 240); /* red */
5940 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5942 IDXGISwapChain_Present(swapchain, 0, 0);
5944 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
5946 ID3D11DeviceContext_Draw(context, 4, 0);
5947 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
5948 todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
5949 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
5950 todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5952 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
5953 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
5954 color = get_texture_color(backbuffer_1, 320, 240); /* red */
5955 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5956 color = get_texture_color(backbuffer_2, 320, 240); /* green */
5957 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5959 ID3D11VertexShader_Release(vs);
5960 ID3D11PixelShader_Release(ps);
5961 ID3D11Buffer_Release(vb);
5962 ID3D11InputLayout_Release(input_layout);
5963 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
5964 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
5965 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
5966 ID3D11RenderTargetView_Release(offscreen_rtv);
5967 ID3D11Texture2D_Release(offscreen);
5968 ID3D11Texture2D_Release(backbuffer_0);
5969 ID3D11Texture2D_Release(backbuffer_1);
5970 ID3D11Texture2D_Release(backbuffer_2);
5971 IDXGISwapChain_Release(swapchain);
5973 ID3D11DeviceContext_Release(context);
5974 refcount = ID3D11Device_Release(device);
5975 ok(!refcount, "Device has %u references left.\n", refcount);
5976 DestroyWindow(window);
5979 static void test_clear_render_target_view(void)
5981 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
5982 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
5983 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
5985 ID3D11Texture2D *texture, *srgb_texture;
5986 struct d3d11_test_context test_context;
5987 ID3D11RenderTargetView *rtv, *srgb_rtv;
5988 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
5989 D3D11_TEXTURE2D_DESC texture_desc;
5990 ID3D11DeviceContext *context;
5991 ID3D11Device *device;
5992 HRESULT hr;
5994 if (!init_test_context(&test_context, NULL))
5995 return;
5997 device = test_context.device;
5998 context = test_context.immediate_context;
6000 texture_desc.Width = 640;
6001 texture_desc.Height = 480;
6002 texture_desc.MipLevels = 1;
6003 texture_desc.ArraySize = 1;
6004 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6005 texture_desc.SampleDesc.Count = 1;
6006 texture_desc.SampleDesc.Quality = 0;
6007 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6008 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6009 texture_desc.CPUAccessFlags = 0;
6010 texture_desc.MiscFlags = 0;
6011 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6012 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
6014 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
6015 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
6016 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
6018 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6019 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6021 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
6022 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6024 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
6025 check_texture_color(test_context.backbuffer, expected_color, 1);
6027 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
6028 check_texture_color(texture, expected_color, 1);
6030 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
6031 check_texture_color(texture, expected_color, 1);
6033 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
6034 check_texture_color(srgb_texture, expected_srgb_color, 1);
6036 ID3D11RenderTargetView_Release(srgb_rtv);
6037 ID3D11RenderTargetView_Release(rtv);
6038 ID3D11Texture2D_Release(srgb_texture);
6039 ID3D11Texture2D_Release(texture);
6041 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
6042 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6043 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
6045 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
6046 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
6047 U(rtv_desc).Texture2D.MipSlice = 0;
6048 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
6049 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6051 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6052 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
6053 U(rtv_desc).Texture2D.MipSlice = 0;
6054 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
6055 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6057 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
6058 check_texture_color(texture, expected_color, 1);
6060 if (!is_warp_device(device))
6062 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
6063 todo_wine check_texture_color(texture, expected_srgb_color, 1);
6065 else
6067 win_skip("Skipping broken test on WARP.\n");
6071 ID3D11RenderTargetView_Release(srgb_rtv);
6072 ID3D11RenderTargetView_Release(rtv);
6073 ID3D11Texture2D_Release(texture);
6074 release_test_context(&test_context);
6077 static void test_clear_depth_stencil_view(void)
6079 D3D11_TEXTURE2D_DESC texture_desc;
6080 ID3D11Texture2D *depth_texture;
6081 ID3D11DeviceContext *context;
6082 ID3D11DepthStencilView *dsv;
6083 ID3D11Device *device;
6084 ULONG refcount;
6085 HRESULT hr;
6087 if (!(device = create_device(NULL)))
6089 skip("Failed to create device.\n");
6090 return;
6093 ID3D11Device_GetImmediateContext(device, &context);
6095 texture_desc.Width = 640;
6096 texture_desc.Height = 480;
6097 texture_desc.MipLevels = 1;
6098 texture_desc.ArraySize = 1;
6099 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
6100 texture_desc.SampleDesc.Count = 1;
6101 texture_desc.SampleDesc.Quality = 0;
6102 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6103 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
6104 texture_desc.CPUAccessFlags = 0;
6105 texture_desc.MiscFlags = 0;
6106 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
6107 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
6109 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
6110 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
6112 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6113 check_texture_float(depth_texture, 1.0f, 0);
6115 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
6116 check_texture_float(depth_texture, 0.25f, 0);
6118 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
6119 check_texture_float(depth_texture, 0.25f, 0);
6121 ID3D11Texture2D_Release(depth_texture);
6122 ID3D11DepthStencilView_Release(dsv);
6124 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
6125 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
6126 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
6128 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
6129 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
6131 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
6132 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
6134 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
6135 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
6137 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
6138 check_texture_color(depth_texture, 0xffffffff, 0);
6140 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
6141 check_texture_color(depth_texture, 0x00000000, 0);
6143 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
6144 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
6146 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
6147 check_texture_color(depth_texture, 0xffffffff, 0);
6149 ID3D11Texture2D_Release(depth_texture);
6150 ID3D11DepthStencilView_Release(dsv);
6152 ID3D11DeviceContext_Release(context);
6154 refcount = ID3D11Device_Release(device);
6155 ok(!refcount, "Device has %u references left.\n", refcount);
6158 static void test_draw_depth_only(void)
6160 ID3D11DepthStencilState *depth_stencil_state;
6161 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
6162 struct d3d11_test_context test_context;
6163 ID3D11PixelShader *ps_color, *ps_depth;
6164 D3D11_TEXTURE2D_DESC texture_desc;
6165 D3D11_BUFFER_DESC buffer_desc;
6166 ID3D11DeviceContext *context;
6167 ID3D11DepthStencilView *dsv;
6168 struct texture_readback rb;
6169 ID3D11Texture2D *texture;
6170 ID3D11Device *device;
6171 unsigned int i, j;
6172 D3D11_VIEWPORT vp;
6173 struct vec4 depth;
6174 ID3D11Buffer *cb;
6175 HRESULT hr;
6177 static const DWORD ps_color_code[] =
6179 #if 0
6180 float4 main(float4 position : SV_POSITION) : SV_Target
6182 return float4(0.0, 1.0, 0.0, 1.0);
6184 #endif
6185 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
6186 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6187 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6188 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6189 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
6190 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
6191 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
6193 static const DWORD ps_depth_code[] =
6195 #if 0
6196 float depth;
6198 float main() : SV_Depth
6200 return depth;
6202 #endif
6203 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
6204 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
6205 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
6206 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
6207 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
6208 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6211 if (!init_test_context(&test_context, NULL))
6212 return;
6214 device = test_context.device;
6215 context = test_context.immediate_context;
6217 buffer_desc.ByteWidth = sizeof(depth);
6218 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
6219 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
6220 buffer_desc.CPUAccessFlags = 0;
6221 buffer_desc.MiscFlags = 0;
6222 buffer_desc.StructureByteStride = 0;
6224 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
6225 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
6227 texture_desc.Width = 640;
6228 texture_desc.Height = 480;
6229 texture_desc.MipLevels = 1;
6230 texture_desc.ArraySize = 1;
6231 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
6232 texture_desc.SampleDesc.Count = 1;
6233 texture_desc.SampleDesc.Quality = 0;
6234 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6235 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
6236 texture_desc.CPUAccessFlags = 0;
6237 texture_desc.MiscFlags = 0;
6239 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6240 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6242 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
6243 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
6245 depth_stencil_desc.DepthEnable = TRUE;
6246 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
6247 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
6248 depth_stencil_desc.StencilEnable = FALSE;
6250 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
6251 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
6253 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
6254 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6255 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
6256 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6258 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6259 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
6260 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
6261 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
6263 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6264 check_texture_float(texture, 1.0f, 1);
6265 draw_quad(&test_context);
6266 check_texture_float(texture, 0.0f, 1);
6268 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
6270 depth.x = 0.7f;
6271 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
6272 draw_quad(&test_context);
6273 check_texture_float(texture, 0.0f, 1);
6274 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6275 check_texture_float(texture, 1.0f, 1);
6276 draw_quad(&test_context);
6277 check_texture_float(texture, 0.7f, 1);
6278 depth.x = 0.8f;
6279 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
6280 draw_quad(&test_context);
6281 check_texture_float(texture, 0.7f, 1);
6282 depth.x = 0.5f;
6283 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
6284 draw_quad(&test_context);
6285 check_texture_float(texture, 0.5f, 1);
6287 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6288 depth.x = 0.1f;
6289 for (i = 0; i < 4; ++i)
6291 for (j = 0; j < 4; ++j)
6293 depth.x = 1.0f / 16.0f * (j + 4 * i);
6294 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
6296 vp.TopLeftX = 160.0f * j;
6297 vp.TopLeftY = 120.0f * i;
6298 vp.Width = 160.0f;
6299 vp.Height = 120.0f;
6300 vp.MinDepth = 0.0f;
6301 vp.MaxDepth = 1.0f;
6302 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
6304 draw_quad(&test_context);
6307 get_texture_readback(texture, 0, &rb);
6308 for (i = 0; i < 4; ++i)
6310 for (j = 0; j < 4; ++j)
6312 float obtained_depth, expected_depth;
6314 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
6315 expected_depth = 1.0f / 16.0f * (j + 4 * i);
6316 ok(compare_float(obtained_depth, expected_depth, 1),
6317 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
6318 obtained_depth, j, i, expected_depth);
6321 release_texture_readback(&rb);
6323 ID3D11Buffer_Release(cb);
6324 ID3D11PixelShader_Release(ps_color);
6325 ID3D11PixelShader_Release(ps_depth);
6326 ID3D11DepthStencilView_Release(dsv);
6327 ID3D11DepthStencilState_Release(depth_stencil_state);
6328 ID3D11Texture2D_Release(texture);
6329 release_test_context(&test_context);
6332 static void test_cb_relative_addressing(void)
6334 struct d3d11_test_context test_context;
6335 D3D11_SUBRESOURCE_DATA resource_data;
6336 ID3D11Buffer *colors_cb, *index_cb;
6337 unsigned int i, index[4] = {0};
6338 D3D11_BUFFER_DESC buffer_desc;
6339 ID3D11DeviceContext *context;
6340 ID3D11PixelShader *ps;
6341 ID3D11Device *device;
6342 DWORD color;
6343 HRESULT hr;
6345 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6347 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6349 static const DWORD vs_code[] =
6351 #if 0
6352 int color_index;
6354 cbuffer colors
6356 float4 colors[8];
6359 struct vs_in
6361 float4 position : POSITION;
6364 struct vs_out
6366 float4 position : SV_POSITION;
6367 float4 color : COLOR;
6370 vs_out main(const vs_in v)
6372 vs_out o;
6374 o.position = v.position;
6375 o.color = colors[color_index];
6377 return o;
6379 #endif
6380 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
6381 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6382 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6383 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
6384 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6385 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
6386 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
6387 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
6388 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
6389 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
6390 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
6391 0x0100003e,
6393 static const DWORD ps_code[] =
6395 #if 0
6396 struct ps_in
6398 float4 position : SV_POSITION;
6399 float4 color : COLOR;
6402 float4 main(const ps_in v) : SV_TARGET
6404 return v.color;
6406 #endif
6407 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
6408 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
6409 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
6410 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
6411 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6412 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
6413 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6414 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6416 static const struct
6418 struct vec2 position;
6420 quad[] =
6422 {{-1.0f, -1.0f}},
6423 {{-1.0f, 1.0f}},
6424 {{ 1.0f, -1.0f}},
6425 {{ 1.0f, 1.0f}},
6427 static const struct
6429 float color[4];
6431 colors[10] =
6433 {{0.0f, 0.0f, 0.0f, 1.0f}},
6434 {{0.0f, 0.0f, 1.0f, 0.0f}},
6435 {{0.0f, 0.0f, 1.0f, 1.0f}},
6436 {{0.0f, 1.0f, 0.0f, 0.0f}},
6437 {{0.0f, 1.0f, 0.0f, 1.0f}},
6438 {{0.0f, 1.0f, 1.0f, 0.0f}},
6439 {{0.0f, 1.0f, 1.0f, 1.0f}},
6440 {{1.0f, 0.0f, 0.0f, 0.0f}},
6441 {{1.0f, 0.0f, 0.0f, 1.0f}},
6442 {{1.0f, 0.0f, 1.0f, 0.0f}},
6444 static const struct
6446 unsigned int index;
6447 DWORD expected;
6449 test_data[] =
6451 {0, 0xff000000},
6452 {1, 0x00ff0000},
6453 {2, 0xffff0000},
6454 {3, 0x0000ff00},
6455 {4, 0xff00ff00},
6456 {5, 0x00ffff00},
6457 {6, 0xffffff00},
6458 {7, 0x000000ff},
6460 {8, 0xff0000ff},
6461 {9, 0x00ff00ff},
6463 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
6464 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
6466 if (!init_test_context(&test_context, &feature_level))
6467 return;
6469 device = test_context.device;
6470 context = test_context.immediate_context;
6472 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6473 vs_code, sizeof(vs_code), &test_context.input_layout);
6474 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6476 buffer_desc.ByteWidth = sizeof(quad);
6477 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
6478 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
6479 buffer_desc.CPUAccessFlags = 0;
6480 buffer_desc.MiscFlags = 0;
6481 buffer_desc.StructureByteStride = 0;
6483 resource_data.pSysMem = quad;
6484 resource_data.SysMemPitch = 0;
6485 resource_data.SysMemSlicePitch = 0;
6487 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &test_context.vb);
6488 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
6490 buffer_desc.ByteWidth = sizeof(colors);
6491 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
6492 resource_data.pSysMem = &colors;
6493 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &colors_cb);
6494 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
6496 buffer_desc.ByteWidth = sizeof(index);
6497 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &index_cb);
6498 ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
6500 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
6501 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6502 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6503 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6505 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
6506 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
6507 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6509 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6511 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
6513 index[0] = test_data[i].index;
6514 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
6516 draw_quad(&test_context);
6518 color = get_texture_color(test_context.backbuffer, 319, 239);
6519 ok(compare_color(color, test_data[i].expected, 1),
6520 "Got unexpected color 0x%08x for index %u.\n", color, test_data[i].index);
6523 ID3D11Buffer_Release(index_cb);
6524 ID3D11Buffer_Release(colors_cb);
6525 ID3D11PixelShader_Release(ps);
6527 release_test_context(&test_context);
6530 static void test_getdc(void)
6532 struct device_desc device_desc;
6533 D3D11_TEXTURE2D_DESC desc;
6534 ID3D11Texture2D *texture;
6535 IDXGISurface1 *surface1;
6536 ID3D11Device *device;
6537 ULONG refcount;
6538 HRESULT hr;
6539 HDC dc;
6541 device_desc.feature_level = NULL;
6542 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
6543 if (!(device = create_device(&device_desc)))
6545 skip("Failed to create device.\n");
6546 return;
6549 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
6550 desc.Width = 512;
6551 desc.Height = 512;
6552 desc.MipLevels = 1;
6553 desc.ArraySize = 1;
6554 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
6555 desc.SampleDesc.Count = 1;
6556 desc.SampleDesc.Quality = 0;
6557 desc.Usage = D3D11_USAGE_DEFAULT;
6558 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6559 desc.CPUAccessFlags = 0;
6560 desc.MiscFlags = 0;
6561 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
6562 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6564 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1);
6565 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
6567 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
6568 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6570 IDXGISurface1_Release(surface1);
6571 ID3D11Texture2D_Release(texture);
6573 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6574 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
6575 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6577 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1);
6578 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
6580 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
6581 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6583 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
6584 todo_wine ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6586 /* One more time. */
6587 dc = (HDC)0xdeadbeef;
6588 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
6589 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6590 ok(dc == (HDC)0xdeadbeef, "Got unexpected dc %p.\n", dc);
6592 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
6593 todo_wine ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6595 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
6596 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6598 IDXGISurface1_Release(surface1);
6599 ID3D11Texture2D_Release(texture);
6601 refcount = ID3D11Device_Release(device);
6602 ok(!refcount, "Device has %u references left.\n", refcount);
6605 START_TEST(d3d11)
6607 test_create_device();
6608 test_device_interfaces();
6609 test_get_immediate_context();
6610 test_create_texture2d();
6611 test_texture2d_interfaces();
6612 test_create_texture3d();
6613 test_texture3d_interfaces();
6614 test_buffer_interfaces();
6615 test_create_depthstencil_view();
6616 test_depthstencil_view_interfaces();
6617 test_create_rendertarget_view();
6618 test_create_shader_resource_view();
6619 test_create_shader();
6620 test_create_sampler_state();
6621 test_create_blend_state();
6622 test_create_depthstencil_state();
6623 test_create_rasterizer_state();
6624 test_create_query();
6625 test_device_removed_reason();
6626 test_private_data();
6627 test_blend();
6628 test_texture();
6629 test_multiple_render_targets();
6630 test_scissor();
6631 test_il_append_aligned();
6632 test_fragment_coords();
6633 test_update_subresource();
6634 test_copy_subresource_region();
6635 test_resource_map();
6636 test_texture_data_init();
6637 test_check_multisample_quality_levels();
6638 test_swapchain_flip();
6639 test_clear_render_target_view();
6640 test_clear_depth_stencil_view();
6641 test_draw_depth_only();
6642 test_cb_relative_addressing();
6643 test_getdc();