d3d10core/tests: Add test for shaders interstage interface.
[wine.git] / dlls / d3d10core / tests / device.c
blob0d063f635e55eb3aae5a20b0adcec7dd0965a222
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <assert.h>
20 #define COBJMACROS
21 #include "initguid.h"
22 #include "d3d11.h"
23 #include "wine/test.h"
24 #include <limits.h>
26 #ifndef ARRAY_SIZE
27 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
28 #endif
30 #define BITS_NNAN 0xffc00000
31 #define BITS_NAN 0x7fc00000
32 #define BITS_NINF 0xff800000
33 #define BITS_INF 0x7f800000
34 #define BITS_N1_0 0xbf800000
35 #define BITS_1_0 0x3f800000
37 struct format_support
39 DXGI_FORMAT format;
40 BOOL optional;
43 static const struct format_support display_format_support[] =
45 {DXGI_FORMAT_R8G8B8A8_UNORM},
46 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
47 {DXGI_FORMAT_B8G8R8A8_UNORM, TRUE},
48 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE},
49 {DXGI_FORMAT_R16G16B16A16_FLOAT},
50 {DXGI_FORMAT_R10G10B10A2_UNORM},
51 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, TRUE},
54 struct vec2
56 float x, y;
59 struct vec3
61 float x, y, z;
64 struct vec4
66 float x, y, z, w;
69 struct uvec4
71 unsigned int x, y, z, w;
74 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
76 box->left = left;
77 box->top = top;
78 box->front = front;
79 box->right = right;
80 box->bottom = bottom;
81 box->back = back;
84 static ULONG get_refcount(void *iface)
86 IUnknown *unknown = iface;
87 IUnknown_AddRef(unknown);
88 return IUnknown_Release(unknown);
91 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
92 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
94 HRESULT hr, expected_hr, broken_hr;
95 IUnknown *unknown = iface, *out;
97 if (supported)
99 expected_hr = S_OK;
100 broken_hr = E_NOINTERFACE;
102 else
104 expected_hr = E_NOINTERFACE;
105 broken_hr = S_OK;
108 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
109 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
110 "Got hr %#x, expected %#x.\n", hr, expected_hr);
111 if (SUCCEEDED(hr))
112 IUnknown_Release(out);
113 return hr;
116 static BOOL compare_float(float f, float g, unsigned int ulps)
118 int x = *(int *)&f;
119 int y = *(int *)&g;
121 if (x < 0)
122 x = INT_MIN - x;
123 if (y < 0)
124 y = INT_MIN - y;
126 if (abs(x - y) > ulps)
127 return FALSE;
129 return TRUE;
132 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
134 return compare_float(v1->x, v2->x, ulps)
135 && compare_float(v1->y, v2->y, ulps)
136 && compare_float(v1->z, v2->z, ulps)
137 && compare_float(v1->w, v2->w, ulps);
140 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
142 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
145 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
147 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
148 return FALSE;
149 c1 >>= 8; c2 >>= 8;
150 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
151 return FALSE;
152 c1 >>= 8; c2 >>= 8;
153 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
154 return FALSE;
155 c1 >>= 8; c2 >>= 8;
156 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
157 return FALSE;
158 return TRUE;
161 struct srv_desc
163 DXGI_FORMAT format;
164 D3D10_SRV_DIMENSION dimension;
165 unsigned int miplevel_idx;
166 unsigned int miplevel_count;
167 unsigned int layer_idx;
168 unsigned int layer_count;
171 static void get_srv_desc(D3D10_SHADER_RESOURCE_VIEW_DESC *d3d10_desc, const struct srv_desc *desc)
173 d3d10_desc->Format = desc->format;
174 d3d10_desc->ViewDimension = desc->dimension;
175 if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1D)
177 U(*d3d10_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
178 U(*d3d10_desc).Texture1D.MipLevels = desc->miplevel_count;
180 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1DARRAY)
182 U(*d3d10_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
183 U(*d3d10_desc).Texture1DArray.MipLevels = desc->miplevel_count;
184 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
185 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
187 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
189 U(*d3d10_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
190 U(*d3d10_desc).Texture2D.MipLevels = desc->miplevel_count;
192 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
194 U(*d3d10_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
195 U(*d3d10_desc).Texture2DArray.MipLevels = desc->miplevel_count;
196 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
197 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
199 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
201 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
202 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
204 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE3D)
206 U(*d3d10_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
207 U(*d3d10_desc).Texture3D.MipLevels = desc->miplevel_count;
209 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
211 U(*d3d10_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
212 U(*d3d10_desc).TextureCube.MipLevels = desc->miplevel_count;
214 else if (desc->dimension != D3D10_SRV_DIMENSION_UNKNOWN
215 && desc->dimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
217 trace("Unhandled view dimension %#x.\n", desc->dimension);
221 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
222 static void check_srv_desc_(unsigned int line, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc,
223 const struct srv_desc *expected_desc)
225 ok_(__FILE__, line)(desc->Format == expected_desc->format,
226 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
227 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
228 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
230 if (desc->ViewDimension != expected_desc->dimension)
231 return;
233 if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D)
235 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
236 "Got MostDetailedMip %u, expected %u.\n",
237 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
238 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
239 "Got MipLevels %u, expected %u.\n",
240 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
242 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
244 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
245 "Got MostDetailedMip %u, expected %u.\n",
246 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
247 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
248 "Got MipLevels %u, expected %u.\n",
249 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
250 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
251 "Got FirstArraySlice %u, expected %u.\n",
252 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
253 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
254 "Got ArraySize %u, expected %u.\n",
255 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
257 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
259 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
260 "Got FirstArraySlice %u, expected %u.\n",
261 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
262 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
263 "Got ArraySize %u, expected %u.\n",
264 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
266 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE3D)
268 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
269 "Got MostDetailedMip %u, expected %u.\n",
270 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
271 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
272 "Got MipLevels %u, expected %u.\n",
273 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
275 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
277 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
278 "Got MostDetailedMip %u, expected %u.\n",
279 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
280 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
281 "Got MipLevels %u, expected %u.\n",
282 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
284 else if (desc->ViewDimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
286 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
290 struct rtv_desc
292 DXGI_FORMAT format;
293 D3D10_RTV_DIMENSION dimension;
294 unsigned int miplevel_idx;
295 unsigned int layer_idx;
296 unsigned int layer_count;
299 static void get_rtv_desc(D3D10_RENDER_TARGET_VIEW_DESC *d3d10_desc, const struct rtv_desc *desc)
301 d3d10_desc->Format = desc->format;
302 d3d10_desc->ViewDimension = desc->dimension;
303 if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1D)
305 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
307 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1DARRAY)
309 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
310 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
311 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
313 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
315 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
317 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
319 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
320 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
321 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
323 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
325 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
326 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
328 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE3D)
330 U(*d3d10_desc).Texture3D.MipSlice = desc->miplevel_idx;
331 U(*d3d10_desc).Texture3D.FirstWSlice = desc->layer_idx;
332 U(*d3d10_desc).Texture3D.WSize = desc->layer_count;
334 else if (desc->dimension != D3D10_RTV_DIMENSION_UNKNOWN
335 && desc->dimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
337 trace("Unhandled view dimension %#x.\n", desc->dimension);
341 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
342 static void check_rtv_desc_(unsigned int line, const D3D10_RENDER_TARGET_VIEW_DESC *desc,
343 const struct rtv_desc *expected_desc)
345 ok_(__FILE__, line)(desc->Format == expected_desc->format,
346 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
347 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
348 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
350 if (desc->ViewDimension != expected_desc->dimension)
351 return;
353 if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D)
355 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
356 "Got MipSlice %u, expected %u.\n",
357 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
359 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
361 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
362 "Got MipSlice %u, expected %u.\n",
363 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
364 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
365 "Got FirstArraySlice %u, expected %u.\n",
366 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
367 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
368 "Got ArraySize %u, expected %u.\n",
369 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
371 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
373 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
374 "Got FirstArraySlice %u, expected %u.\n",
375 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
376 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
377 "Got ArraySize %u, expected %u.\n",
378 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
380 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE3D)
382 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
383 "Got MipSlice %u, expected %u.\n",
384 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
385 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
386 "Got FirstWSlice %u, expected %u.\n",
387 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
388 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
389 "Got WSize %u, expected %u.\n",
390 U(*desc).Texture3D.WSize, expected_desc->layer_count);
392 else if (desc->ViewDimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
394 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
398 struct dsv_desc
400 DXGI_FORMAT format;
401 D3D10_DSV_DIMENSION dimension;
402 unsigned int miplevel_idx;
403 unsigned int layer_idx;
404 unsigned int layer_count;
407 static void get_dsv_desc(D3D10_DEPTH_STENCIL_VIEW_DESC *d3d10_desc, const struct dsv_desc *desc)
409 d3d10_desc->Format = desc->format;
410 d3d10_desc->ViewDimension = desc->dimension;
411 if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1D)
413 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
415 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1DARRAY)
417 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
418 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
419 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
421 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2D)
423 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
425 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
427 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
428 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
429 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
431 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
433 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
434 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
436 else if (desc->dimension != D3D10_DSV_DIMENSION_UNKNOWN
437 && desc->dimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
439 trace("Unhandled view dimension %#x.\n", desc->dimension);
443 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
444 static void check_dsv_desc_(unsigned int line, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc,
445 const struct dsv_desc *expected_desc)
447 ok_(__FILE__, line)(desc->Format == expected_desc->format,
448 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
449 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
450 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
452 if (desc->ViewDimension != expected_desc->dimension)
453 return;
455 if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D)
457 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
458 "Got MipSlice %u, expected %u.\n",
459 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
461 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
463 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
464 "Got MipSlice %u, expected %u.\n",
465 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
466 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
467 "Got FirstArraySlice %u, expected %u.\n",
468 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
469 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
470 "Got ArraySize %u, expected %u.\n",
471 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
473 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
475 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
476 "Got FirstArraySlice %u, expected %u.\n",
477 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
478 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
479 "Got ArraySize %u, expected %u.\n",
480 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
482 else if (desc->ViewDimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
484 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
488 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
489 static ID3D10Buffer *create_buffer_(unsigned int line, ID3D10Device *device,
490 unsigned int bind_flags, unsigned int size, const void *data)
492 D3D10_SUBRESOURCE_DATA resource_data;
493 D3D10_BUFFER_DESC buffer_desc;
494 ID3D10Buffer *buffer;
495 HRESULT hr;
497 buffer_desc.ByteWidth = size;
498 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
499 buffer_desc.BindFlags = bind_flags;
500 buffer_desc.CPUAccessFlags = 0;
501 buffer_desc.MiscFlags = 0;
503 resource_data.pSysMem = data;
504 resource_data.SysMemPitch = 0;
505 resource_data.SysMemSlicePitch = 0;
507 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
508 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
509 return buffer;
512 struct resource_readback
514 D3D10_RESOURCE_DIMENSION dimension;
515 ID3D10Resource *resource;
516 D3D10_MAPPED_TEXTURE2D map_desc;
517 unsigned int width, height, sub_resource_idx;
520 static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb)
522 D3D10_BUFFER_DESC buffer_desc;
523 ID3D10Device *device;
524 HRESULT hr;
526 memset(rb, 0, sizeof(*rb));
527 rb->dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
529 ID3D10Buffer_GetDevice(buffer, &device);
531 ID3D10Buffer_GetDesc(buffer, &buffer_desc);
532 buffer_desc.Usage = D3D10_USAGE_STAGING;
533 buffer_desc.BindFlags = 0;
534 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
535 buffer_desc.MiscFlags = 0;
536 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D10Buffer **)&rb->resource)))
538 trace("Failed to create texture, hr %#x.\n", hr);
539 ID3D10Device_Release(device);
540 return;
543 rb->width = buffer_desc.ByteWidth;
544 rb->height = 1;
545 rb->sub_resource_idx = 0;
547 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer);
548 if (FAILED(hr = ID3D10Buffer_Map((ID3D10Buffer *)rb->resource, D3D10_MAP_READ, 0, &rb->map_desc.pData)))
550 trace("Failed to map buffer, hr %#x.\n", hr);
551 ID3D10Resource_Release(rb->resource);
552 rb->resource = NULL;
554 rb->map_desc.RowPitch = 0;
556 ID3D10Device_Release(device);
559 static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
560 struct resource_readback *rb)
562 D3D10_TEXTURE2D_DESC texture_desc;
563 unsigned int miplevel;
564 ID3D10Device *device;
565 HRESULT hr;
567 memset(rb, 0, sizeof(*rb));
568 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
570 ID3D10Texture2D_GetDevice(texture, &device);
572 ID3D10Texture2D_GetDesc(texture, &texture_desc);
573 texture_desc.Usage = D3D10_USAGE_STAGING;
574 texture_desc.BindFlags = 0;
575 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
576 texture_desc.MiscFlags = 0;
577 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&rb->resource)))
579 trace("Failed to create texture, hr %#x.\n", hr);
580 ID3D10Device_Release(device);
581 return;
584 miplevel = sub_resource_idx % texture_desc.MipLevels;
585 rb->width = max(1, texture_desc.Width >> miplevel);
586 rb->height = max(1, texture_desc.Height >> miplevel);
587 rb->sub_resource_idx = sub_resource_idx;
589 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
590 if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx,
591 D3D10_MAP_READ, 0, &rb->map_desc)))
593 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
594 ID3D10Resource_Release(rb->resource);
595 rb->resource = NULL;
598 ID3D10Device_Release(device);
601 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
603 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
606 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
608 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
611 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
613 return *(float *)get_readback_data(rb, x, y, sizeof(float));
616 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
618 return get_readback_data(rb, x, y, sizeof(struct vec4));
621 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
623 return get_readback_data(rb, x, y, sizeof(struct uvec4));
626 static void release_resource_readback(struct resource_readback *rb)
628 switch (rb->dimension)
630 case D3D10_RESOURCE_DIMENSION_BUFFER:
631 ID3D10Buffer_Unmap((ID3D10Buffer *)rb->resource);
632 break;
633 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
634 ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx);
635 break;
636 default:
637 trace("Unhandled resource dimension %#x.\n", rb->dimension);
638 break;
640 ID3D10Resource_Release(rb->resource);
643 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
645 struct resource_readback rb;
646 DWORD color;
648 get_texture_readback(texture, 0, &rb);
649 color = get_readback_color(&rb, x, y);
650 release_resource_readback(&rb);
652 return color;
655 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
656 static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
657 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
659 struct resource_readback rb;
660 unsigned int x = 0, y = 0;
661 BOOL all_match = TRUE;
662 RECT default_rect;
663 DWORD color = 0;
665 get_texture_readback(texture, sub_resource_idx, &rb);
666 if (!rect)
668 SetRect(&default_rect, 0, 0, rb.width, rb.height);
669 rect = &default_rect;
671 for (y = rect->top; y < rect->bottom; ++y)
673 for (x = rect->left; x < rect->right; ++x)
675 color = get_readback_color(&rb, x, y);
676 if (!compare_color(color, expected_color, max_diff))
678 all_match = FALSE;
679 break;
682 if (!all_match)
683 break;
685 release_resource_readback(&rb);
686 ok_(__FILE__, line)(all_match,
687 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
688 color, expected_color, x, y, sub_resource_idx);
691 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
692 static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
693 DWORD expected_color, BYTE max_diff)
695 unsigned int sub_resource_idx, sub_resource_count;
696 D3D10_TEXTURE2D_DESC texture_desc;
698 ID3D10Texture2D_GetDesc(texture, &texture_desc);
699 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
700 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
701 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
704 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
705 static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
706 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
708 struct resource_readback rb;
709 unsigned int x = 0, y = 0;
710 BOOL all_match = TRUE;
711 float value = 0.0f;
712 RECT default_rect;
714 get_texture_readback(texture, sub_resource_idx, &rb);
715 if (!rect)
717 SetRect(&default_rect, 0, 0, rb.width, rb.height);
718 rect = &default_rect;
720 for (y = rect->top; y < rect->bottom; ++y)
722 for (x = rect->left; x < rect->right; ++x)
724 value = get_readback_float(&rb, x, y);
725 if (!compare_float(value, expected_value, max_diff))
727 all_match = FALSE;
728 break;
731 if (!all_match)
732 break;
734 release_resource_readback(&rb);
735 ok_(__FILE__, line)(all_match,
736 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
737 value, expected_value, x, y, sub_resource_idx);
740 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
741 static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
742 float expected_value, BYTE max_diff)
744 unsigned int sub_resource_idx, sub_resource_count;
745 D3D10_TEXTURE2D_DESC texture_desc;
747 ID3D10Texture2D_GetDesc(texture, &texture_desc);
748 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
749 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
750 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
753 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
754 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D10Texture2D *texture,
755 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
757 struct resource_readback rb;
758 unsigned int x = 0, y = 0;
759 struct vec4 value = {0};
760 BOOL all_match = TRUE;
761 RECT default_rect;
763 get_texture_readback(texture, sub_resource_idx, &rb);
764 if (!rect)
766 SetRect(&default_rect, 0, 0, rb.width, rb.height);
767 rect = &default_rect;
769 for (y = rect->top; y < rect->bottom; ++y)
771 for (x = rect->left; x < rect->right; ++x)
773 value = *get_readback_vec4(&rb, x, y);
774 if (!compare_vec4(&value, expected_value, max_diff))
776 all_match = FALSE;
777 break;
780 if (!all_match)
781 break;
783 release_resource_readback(&rb);
784 ok_(__FILE__, line)(all_match,
785 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
786 value.x, value.y, value.z, value.w,
787 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
788 x, y, sub_resource_idx);
791 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
792 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
793 const struct vec4 *expected_value, BYTE max_diff)
795 unsigned int sub_resource_idx, sub_resource_count;
796 D3D10_TEXTURE2D_DESC texture_desc;
798 ID3D10Texture2D_GetDesc(texture, &texture_desc);
799 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
800 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
801 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
804 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
805 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
806 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
808 struct resource_readback rb;
809 unsigned int x = 0, y = 0;
810 struct uvec4 value = {0};
811 BOOL all_match = TRUE;
812 RECT default_rect;
814 get_texture_readback(texture, sub_resource_idx, &rb);
815 if (!rect)
817 SetRect(&default_rect, 0, 0, rb.width, rb.height);
818 rect = &default_rect;
820 for (y = rect->top; y < rect->bottom; ++y)
822 for (x = rect->left; x < rect->right; ++x)
824 value = *get_readback_uvec4(&rb, x, y);
825 if (!compare_uvec4(&value, expected_value))
827 all_match = FALSE;
828 break;
831 if (!all_match)
832 break;
834 release_resource_readback(&rb);
835 ok_(__FILE__, line)(all_match,
836 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
837 "at (%u, %u), sub-resource %u.\n",
838 value.x, value.y, value.z, value.w,
839 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
840 x, y, sub_resource_idx);
843 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
844 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
845 const struct uvec4 *expected_value)
847 unsigned int sub_resource_idx, sub_resource_count;
848 D3D10_TEXTURE2D_DESC texture_desc;
850 ID3D10Texture2D_GetDesc(texture, &texture_desc);
851 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
852 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
853 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
856 static ID3D10Device *create_device(void)
858 ID3D10Device *device;
860 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
861 return device;
862 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
863 return device;
864 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
865 return device;
867 return NULL;
870 static void get_device_adapter_desc(ID3D10Device *device, DXGI_ADAPTER_DESC *adapter_desc)
872 IDXGIDevice *dxgi_device;
873 IDXGIAdapter *adapter;
874 HRESULT hr;
876 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
877 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
878 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
879 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
880 IDXGIDevice_Release(dxgi_device);
881 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
882 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
883 IDXGIAdapter_Release(adapter);
886 static BOOL is_warp_device(ID3D10Device *device)
888 DXGI_ADAPTER_DESC adapter_desc;
889 get_device_adapter_desc(device, &adapter_desc);
890 return !adapter_desc.SubSysId && !adapter_desc.Revision
891 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
892 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
895 static BOOL is_amd_device(ID3D10Device *device)
897 DXGI_ADAPTER_DESC adapter_desc;
899 if (!strcmp(winetest_platform, "wine"))
900 return FALSE;
902 get_device_adapter_desc(device, &adapter_desc);
903 return adapter_desc.VendorId == 0x1002;
906 static BOOL is_nvidia_device(ID3D10Device *device)
908 DXGI_ADAPTER_DESC adapter_desc;
910 if (!strcmp(winetest_platform, "wine"))
911 return FALSE;
913 get_device_adapter_desc(device, &adapter_desc);
914 return adapter_desc.VendorId == 0x10de;
917 static BOOL is_d3d11_interface_available(ID3D10Device *device)
919 ID3D11Device *d3d11_device;
920 HRESULT hr;
922 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
923 ID3D11Device_Release(d3d11_device);
925 return SUCCEEDED(hr);
928 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
930 struct swapchain_desc
932 BOOL windowed;
933 UINT buffer_count;
934 DXGI_SWAP_EFFECT swap_effect;
935 DWORD flags;
938 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
940 IDXGISwapChain *swapchain;
941 DXGI_SWAP_CHAIN_DESC dxgi_desc;
942 IDXGIDevice *dxgi_device;
943 IDXGIAdapter *adapter;
944 IDXGIFactory *factory;
945 HRESULT hr;
947 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
948 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
949 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
950 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
951 IDXGIDevice_Release(dxgi_device);
952 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
953 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
954 IDXGIAdapter_Release(adapter);
956 dxgi_desc.BufferDesc.Width = 640;
957 dxgi_desc.BufferDesc.Height = 480;
958 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
959 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
960 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
961 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
962 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
963 dxgi_desc.SampleDesc.Count = 1;
964 dxgi_desc.SampleDesc.Quality = 0;
965 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
966 dxgi_desc.BufferCount = 1;
967 dxgi_desc.OutputWindow = window;
968 dxgi_desc.Windowed = TRUE;
969 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
970 dxgi_desc.Flags = 0;
972 if (swapchain_desc)
974 dxgi_desc.Windowed = swapchain_desc->windowed;
975 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
976 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
978 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
979 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
982 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
983 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
984 IDXGIFactory_Release(factory);
986 return swapchain;
989 struct d3d10core_test_context
991 ID3D10Device *device;
992 HWND window;
993 IDXGISwapChain *swapchain;
994 ID3D10Texture2D *backbuffer;
995 ID3D10RenderTargetView *backbuffer_rtv;
997 ID3D10InputLayout *input_layout;
998 ID3D10VertexShader *vs;
999 ID3D10Buffer *vb;
1001 ID3D10PixelShader *ps;
1002 ID3D10Buffer *ps_cb;
1005 #define init_test_context(c) init_test_context_(__LINE__, c)
1006 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context)
1008 D3D10_VIEWPORT vp;
1009 HRESULT hr;
1010 RECT rect;
1012 memset(context, 0, sizeof(*context));
1014 if (!(context->device = create_device()))
1016 skip_(__FILE__, line)("Failed to create device.\n");
1017 return FALSE;
1019 SetRect(&rect, 0, 0, 640, 480);
1020 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1021 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1022 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1023 context->swapchain = create_swapchain(context->device, context->window, NULL);
1024 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
1025 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1027 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
1028 NULL, &context->backbuffer_rtv);
1029 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1031 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
1033 vp.TopLeftX = 0;
1034 vp.TopLeftY = 0;
1035 vp.Width = 640;
1036 vp.Height = 480;
1037 vp.MinDepth = 0.0f;
1038 vp.MaxDepth = 1.0f;
1039 ID3D10Device_RSSetViewports(context->device, 1, &vp);
1041 return TRUE;
1044 #define release_test_context(c) release_test_context_(__LINE__, c)
1045 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
1047 ULONG ref;
1049 if (context->input_layout)
1050 ID3D10InputLayout_Release(context->input_layout);
1051 if (context->vs)
1052 ID3D10VertexShader_Release(context->vs);
1053 if (context->vb)
1054 ID3D10Buffer_Release(context->vb);
1055 if (context->ps)
1056 ID3D10PixelShader_Release(context->ps);
1057 if (context->ps_cb)
1058 ID3D10Buffer_Release(context->ps_cb);
1060 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
1061 ID3D10Texture2D_Release(context->backbuffer);
1062 IDXGISwapChain_Release(context->swapchain);
1063 DestroyWindow(context->window);
1065 ref = ID3D10Device_Release(context->device);
1066 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1069 #define draw_quad(c) draw_quad_(__LINE__, c)
1070 static void draw_quad_(unsigned int line, struct d3d10core_test_context *context)
1072 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
1074 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1076 static const DWORD default_vs_code[] =
1078 #if 0
1079 float4 main(float4 position : POSITION) : SV_POSITION
1081 return position;
1083 #endif
1084 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
1085 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1086 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1087 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1088 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1089 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1090 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1092 static const struct vec2 quad[] =
1094 {-1.0f, -1.0f},
1095 {-1.0f, 1.0f},
1096 { 1.0f, -1.0f},
1097 { 1.0f, 1.0f},
1100 ID3D10Device *device = context->device;
1101 unsigned int stride, offset;
1102 HRESULT hr;
1104 if (!context->input_layout)
1106 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1107 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1108 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1110 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1112 hr = ID3D10Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), &context->vs);
1113 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1116 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1117 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1118 stride = sizeof(*quad);
1119 offset = 0;
1120 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1121 ID3D10Device_VSSetShader(context->device, context->vs);
1123 ID3D10Device_Draw(context->device, 4, 0);
1126 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1127 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context, const struct vec4 *color)
1129 static const DWORD ps_color_code[] =
1131 #if 0
1132 float4 color;
1134 float4 main() : SV_TARGET
1136 return color;
1138 #endif
1139 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1140 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1141 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1142 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1143 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1144 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1147 ID3D10Device *device = context->device;
1148 HRESULT hr;
1150 if (!context->ps)
1152 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1153 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1156 if (!context->ps_cb)
1157 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1159 ID3D10Device_PSSetShader(device, context->ps);
1160 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1162 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1164 draw_quad_(line, context);
1167 static void test_feature_level(void)
1169 D3D_FEATURE_LEVEL feature_level;
1170 ID3D10Device *d3d10_device;
1171 ID3D11Device *d3d11_device;
1172 HRESULT hr;
1174 if (!(d3d10_device = create_device()))
1176 skip("Failed to create device, skipping tests.\n");
1177 return;
1180 hr = ID3D10Device_QueryInterface(d3d10_device, &IID_ID3D11Device, (void **)&d3d11_device);
1181 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1182 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1183 if (FAILED(hr))
1185 win_skip("D3D11 is not available.\n");
1186 ID3D10Device_Release(d3d10_device);
1187 return;
1190 /* Device was created by D3D10CreateDevice. */
1191 feature_level = ID3D11Device_GetFeatureLevel(d3d11_device);
1192 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1194 ID3D11Device_Release(d3d11_device);
1195 ID3D10Device_Release(d3d10_device);
1198 static void test_device_interfaces(void)
1200 IDXGIAdapter *dxgi_adapter;
1201 IDXGIDevice *dxgi_device;
1202 ID3D10Device *device;
1203 IUnknown *iface;
1204 ULONG refcount;
1205 HRESULT hr;
1207 if (!(device = create_device()))
1209 skip("Failed to create device.\n");
1210 return;
1213 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1214 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1215 check_interface(device, &IID_IDXGIDevice1, TRUE, TRUE); /* Not available on all Windows versions. */
1216 check_interface(device, &IID_ID3D10Multithread, TRUE, FALSE);
1217 check_interface(device, &IID_ID3D10Device1, TRUE, TRUE); /* Not available on all Windows versions. */
1218 check_interface(device, &IID_ID3D11Device, TRUE, TRUE); /* Not available on all Windows versions. */
1220 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1221 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1222 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1223 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1224 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1225 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1226 IUnknown_Release(iface);
1227 IUnknown_Release(dxgi_adapter);
1228 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1229 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1230 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1231 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1232 IUnknown_Release(dxgi_adapter);
1233 IUnknown_Release(dxgi_device);
1235 refcount = ID3D10Device_Release(device);
1236 ok(!refcount, "Device has %u references left.\n", refcount);
1239 static void test_create_texture2d(void)
1241 ULONG refcount, expected_refcount;
1242 D3D10_SUBRESOURCE_DATA data = {0};
1243 ID3D10Device *device, *tmp;
1244 D3D10_TEXTURE2D_DESC desc;
1245 ID3D10Texture2D *texture;
1246 UINT quality_level_count;
1247 unsigned int i;
1248 HRESULT hr;
1250 static const struct
1252 DXGI_FORMAT format;
1253 UINT array_size;
1254 D3D10_BIND_FLAG bind_flags;
1255 UINT misc_flags;
1256 BOOL succeeds;
1257 BOOL todo;
1259 tests[] =
1261 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1262 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1263 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1264 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1265 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1266 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1267 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1268 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1269 FALSE, FALSE},
1270 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1271 FALSE, FALSE},
1272 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1273 FALSE, FALSE},
1274 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1275 TRUE, FALSE},
1276 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1277 FALSE, TRUE},
1278 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1279 FALSE, TRUE},
1280 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1281 FALSE, TRUE},
1282 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1283 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1284 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1285 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1286 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1287 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1288 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1289 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1290 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1291 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1292 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1293 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1294 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1295 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1296 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1297 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1298 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1299 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1300 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1301 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1302 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1303 TRUE, FALSE},
1304 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1305 FALSE, TRUE},
1306 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1307 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_DEPTH_STENCIL, 0,
1308 FALSE, TRUE},
1309 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1310 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1311 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1312 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1313 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1314 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1315 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1316 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1317 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1318 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1319 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1320 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1321 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1322 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1323 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1324 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1325 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1326 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1327 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1328 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1329 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1330 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1331 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1332 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1333 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1334 FALSE, TRUE},
1335 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1336 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1337 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1338 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1339 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1342 if (!(device = create_device()))
1344 skip("Failed to create device, skipping tests.\n");
1345 return;
1348 desc.Width = 512;
1349 desc.Height = 512;
1350 desc.MipLevels = 1;
1351 desc.ArraySize = 1;
1352 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1353 desc.SampleDesc.Count = 1;
1354 desc.SampleDesc.Quality = 0;
1355 desc.Usage = D3D10_USAGE_DEFAULT;
1356 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1357 desc.CPUAccessFlags = 0;
1358 desc.MiscFlags = 0;
1360 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
1361 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1363 expected_refcount = get_refcount(device) + 1;
1364 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1365 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1366 refcount = get_refcount(device);
1367 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1368 tmp = NULL;
1369 expected_refcount = refcount + 1;
1370 ID3D10Texture2D_GetDevice(texture, &tmp);
1371 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1372 refcount = get_refcount(device);
1373 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1374 ID3D10Device_Release(tmp);
1376 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1377 ID3D10Texture2D_Release(texture);
1379 desc.MipLevels = 0;
1380 expected_refcount = get_refcount(device) + 1;
1381 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1382 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1383 refcount = get_refcount(device);
1384 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1385 tmp = NULL;
1386 expected_refcount = refcount + 1;
1387 ID3D10Texture2D_GetDevice(texture, &tmp);
1388 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1389 refcount = get_refcount(device);
1390 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1391 ID3D10Device_Release(tmp);
1393 ID3D10Texture2D_GetDesc(texture, &desc);
1394 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1395 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1396 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1397 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1398 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1399 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1400 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1401 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1402 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1403 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1404 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1406 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1407 ID3D10Texture2D_Release(texture);
1409 desc.MipLevels = 1;
1410 desc.ArraySize = 2;
1411 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1412 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1413 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1414 ID3D10Texture2D_Release(texture);
1416 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1417 desc.ArraySize = 1;
1418 desc.SampleDesc.Count = 2;
1419 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1420 if (quality_level_count)
1422 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1423 ID3D10Texture2D_Release(texture);
1424 desc.SampleDesc.Quality = quality_level_count;
1425 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1427 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1429 /* We assume 15 samples multisampling is never supported in practice. */
1430 desc.SampleDesc.Count = 15;
1431 desc.SampleDesc.Quality = 0;
1432 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1433 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1435 desc.SampleDesc.Count = 1;
1436 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1438 desc.ArraySize = tests[i].array_size;
1439 desc.Format = tests[i].format;
1440 desc.BindFlags = tests[i].bind_flags;
1441 desc.MiscFlags = tests[i].misc_flags;
1442 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, (ID3D10Texture2D **)&texture);
1444 todo_wine_if(tests[i].todo)
1445 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
1446 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
1448 if (SUCCEEDED(hr))
1449 ID3D10Texture2D_Release(texture);
1452 refcount = ID3D10Device_Release(device);
1453 ok(!refcount, "Device has %u references left.\n", refcount);
1456 static void test_texture2d_interfaces(void)
1458 ID3D11Texture2D *d3d11_texture;
1459 D3D10_TEXTURE2D_DESC desc;
1460 ID3D10Texture2D *texture;
1461 ID3D10Device *device;
1462 unsigned int i;
1463 ULONG refcount;
1464 HRESULT hr;
1466 static const struct test
1468 UINT bind_flags;
1469 UINT misc_flags;
1470 UINT expected_bind_flags;
1471 UINT expected_misc_flags;
1473 desc_conversion_tests[] =
1476 D3D10_BIND_RENDER_TARGET, 0,
1477 D3D11_BIND_RENDER_TARGET, 0
1480 0, D3D10_RESOURCE_MISC_SHARED,
1481 0, D3D11_RESOURCE_MISC_SHARED
1485 if (!(device = create_device()))
1487 skip("Failed to create device, skipping tests.\n");
1488 return;
1491 desc.Width = 512;
1492 desc.Height = 512;
1493 desc.MipLevels = 0;
1494 desc.ArraySize = 1;
1495 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1496 desc.SampleDesc.Count = 1;
1497 desc.SampleDesc.Quality = 0;
1498 desc.Usage = D3D10_USAGE_DEFAULT;
1499 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1500 desc.CPUAccessFlags = 0;
1501 desc.MiscFlags = 0;
1503 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1504 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1505 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1506 hr = check_interface(texture, &IID_ID3D11Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
1507 ID3D10Texture2D_Release(texture);
1508 if (FAILED(hr))
1510 win_skip("D3D11 is not available, skipping tests.\n");
1511 ID3D10Device_Release(device);
1512 return;
1515 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1517 const struct test *current = &desc_conversion_tests[i];
1518 D3D11_TEXTURE2D_DESC d3d11_desc;
1519 ID3D11Device *d3d11_device;
1521 desc.Width = 512;
1522 desc.Height = 512;
1523 desc.MipLevels = 1;
1524 desc.ArraySize = 1;
1525 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1526 desc.SampleDesc.Count = 1;
1527 desc.SampleDesc.Quality = 0;
1528 desc.Usage = D3D10_USAGE_DEFAULT;
1529 desc.BindFlags = current->bind_flags;
1530 desc.CPUAccessFlags = 0;
1531 desc.MiscFlags = current->misc_flags;
1533 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1534 /* Shared resources are not supported by REF and WARP devices. */
1535 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1536 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1537 if (FAILED(hr))
1539 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
1540 continue;
1543 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1544 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1545 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
1546 ID3D10Texture2D_Release(texture);
1548 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
1550 ok(d3d11_desc.Width == desc.Width,
1551 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1552 ok(d3d11_desc.Height == desc.Height,
1553 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
1554 ok(d3d11_desc.MipLevels == desc.MipLevels,
1555 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1556 ok(d3d11_desc.ArraySize == desc.ArraySize,
1557 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1558 ok(d3d11_desc.Format == desc.Format,
1559 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1560 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
1561 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
1562 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1563 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
1564 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1565 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1566 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1567 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1568 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1569 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1570 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1571 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1573 d3d11_device = NULL;
1574 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
1575 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1576 ID3D11Device_Release(d3d11_device);
1578 ID3D11Texture2D_Release(d3d11_texture);
1581 refcount = ID3D10Device_Release(device);
1582 ok(!refcount, "Device has %u references left.\n", refcount);
1585 static void test_create_texture3d(void)
1587 ULONG refcount, expected_refcount;
1588 D3D10_SUBRESOURCE_DATA data = {0};
1589 ID3D10Device *device, *tmp;
1590 D3D10_TEXTURE3D_DESC desc;
1591 ID3D10Texture3D *texture;
1592 unsigned int i;
1593 HRESULT hr;
1595 static const struct
1597 DXGI_FORMAT format;
1598 D3D10_BIND_FLAG bind_flags;
1599 BOOL succeeds;
1600 BOOL todo;
1602 tests[] =
1604 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
1605 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
1606 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1607 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1608 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1609 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1610 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1611 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1612 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1613 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1614 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1615 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1618 if (!(device = create_device()))
1620 skip("Failed to create device, skipping tests.\n");
1621 return;
1624 desc.Width = 64;
1625 desc.Height = 64;
1626 desc.Depth = 64;
1627 desc.MipLevels = 1;
1628 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1629 desc.Usage = D3D10_USAGE_DEFAULT;
1630 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1631 desc.CPUAccessFlags = 0;
1632 desc.MiscFlags = 0;
1634 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
1635 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1637 expected_refcount = get_refcount(device) + 1;
1638 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1639 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1640 refcount = get_refcount(device);
1641 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1642 tmp = NULL;
1643 expected_refcount = refcount + 1;
1644 ID3D10Texture3D_GetDevice(texture, &tmp);
1645 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1646 refcount = get_refcount(device);
1647 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1648 ID3D10Device_Release(tmp);
1650 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1651 ID3D10Texture3D_Release(texture);
1653 desc.MipLevels = 0;
1654 expected_refcount = get_refcount(device) + 1;
1655 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1656 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1657 refcount = get_refcount(device);
1658 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1659 tmp = NULL;
1660 expected_refcount = refcount + 1;
1661 ID3D10Texture3D_GetDevice(texture, &tmp);
1662 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1663 refcount = get_refcount(device);
1664 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1665 ID3D10Device_Release(tmp);
1667 ID3D10Texture3D_GetDesc(texture, &desc);
1668 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1669 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1670 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1671 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1672 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1673 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1674 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1675 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1676 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1678 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1679 ID3D10Texture3D_Release(texture);
1681 desc.MipLevels = 1;
1682 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1684 desc.Format = tests[i].format;
1685 desc.BindFlags = tests[i].bind_flags;
1686 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, (ID3D10Texture3D **)&texture);
1688 todo_wine_if(tests[i].todo)
1689 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1691 if (SUCCEEDED(hr))
1692 ID3D10Texture3D_Release(texture);
1695 refcount = ID3D10Device_Release(device);
1696 ok(!refcount, "Device has %u references left.\n", refcount);
1699 static void test_create_buffer(void)
1701 ID3D11Buffer *d3d11_buffer;
1702 HRESULT expected_hr, hr;
1703 D3D10_BUFFER_DESC desc;
1704 ID3D10Buffer *buffer;
1705 ID3D10Device *device;
1706 unsigned int i;
1707 ULONG refcount;
1709 static const struct test
1711 UINT bind_flags;
1712 UINT misc_flags;
1713 UINT expected_bind_flags;
1714 UINT expected_misc_flags;
1716 desc_conversion_tests[] =
1719 D3D10_BIND_VERTEX_BUFFER, 0,
1720 D3D11_BIND_VERTEX_BUFFER, 0
1723 D3D10_BIND_INDEX_BUFFER, 0,
1724 D3D11_BIND_INDEX_BUFFER, 0
1727 D3D10_BIND_CONSTANT_BUFFER, 0,
1728 D3D11_BIND_CONSTANT_BUFFER, 0
1731 D3D10_BIND_SHADER_RESOURCE, 0,
1732 D3D11_BIND_SHADER_RESOURCE, 0
1735 D3D10_BIND_STREAM_OUTPUT, 0,
1736 D3D11_BIND_STREAM_OUTPUT, 0
1739 D3D10_BIND_RENDER_TARGET, 0,
1740 D3D11_BIND_RENDER_TARGET, 0
1743 0, D3D10_RESOURCE_MISC_SHARED,
1744 0, D3D11_RESOURCE_MISC_SHARED
1748 if (!(device = create_device()))
1750 skip("Failed to create device.\n");
1751 return;
1754 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
1755 hr = check_interface(buffer, &IID_ID3D11Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
1756 ID3D10Buffer_Release(buffer);
1757 if (FAILED(hr))
1759 win_skip("D3D11 is not available.\n");
1760 ID3D10Device_Release(device);
1761 return;
1764 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1766 const struct test *current = &desc_conversion_tests[i];
1767 D3D11_BUFFER_DESC d3d11_desc;
1768 ID3D11Device *d3d11_device;
1770 desc.ByteWidth = 1024;
1771 desc.Usage = D3D10_USAGE_DEFAULT;
1772 desc.BindFlags = current->bind_flags;
1773 desc.CPUAccessFlags = 0;
1774 desc.MiscFlags = current->misc_flags;
1776 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1777 /* Shared resources are not supported by REF and WARP devices. */
1778 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1779 if (FAILED(hr))
1781 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1782 continue;
1785 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
1786 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
1787 ID3D10Buffer_Release(buffer);
1789 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
1791 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
1792 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
1793 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1794 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1795 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1796 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1797 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1798 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1799 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1800 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1801 ok(d3d11_desc.StructureByteStride == 0,
1802 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
1804 d3d11_device = NULL;
1805 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
1806 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1807 ID3D11Device_Release(d3d11_device);
1809 ID3D11Buffer_Release(d3d11_buffer);
1812 desc.ByteWidth = 1024;
1813 desc.Usage = D3D10_USAGE_DEFAULT;
1814 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1815 desc.CPUAccessFlags = 0;
1816 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
1818 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1819 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1820 if (SUCCEEDED(hr))
1821 ID3D10Buffer_Release(buffer);
1823 memset(&desc, 0, sizeof(desc));
1824 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
1825 for (i = 0; i <= 32; ++i)
1827 desc.ByteWidth = i;
1828 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
1829 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1830 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
1831 if (SUCCEEDED(hr))
1832 ID3D10Buffer_Release(buffer);
1835 refcount = ID3D10Device_Release(device);
1836 ok(!refcount, "Device has %u references left.\n", refcount);
1839 static void test_create_depthstencil_view(void)
1841 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1842 D3D10_TEXTURE2D_DESC texture_desc;
1843 ULONG refcount, expected_refcount;
1844 ID3D10DepthStencilView *dsview;
1845 ID3D10Device *device, *tmp;
1846 ID3D10Texture2D *texture;
1847 unsigned int i;
1848 HRESULT hr;
1850 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
1851 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
1852 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
1853 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
1854 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
1855 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
1856 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
1857 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
1858 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
1859 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
1860 static const struct
1862 struct
1864 unsigned int miplevel_count;
1865 unsigned int array_size;
1866 DXGI_FORMAT format;
1867 } texture;
1868 struct dsv_desc dsv_desc;
1869 struct dsv_desc expected_dsv_desc;
1871 tests[] =
1873 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1874 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1875 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1876 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
1877 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
1878 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1879 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1880 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1881 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1882 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1883 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
1884 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
1885 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
1886 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
1887 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
1888 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
1889 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
1890 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1891 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1892 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1893 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1894 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1895 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1896 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1897 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1898 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1899 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1901 static const struct
1903 struct
1905 unsigned int miplevel_count;
1906 unsigned int array_size;
1907 DXGI_FORMAT format;
1908 } texture;
1909 struct dsv_desc dsv_desc;
1911 invalid_desc_tests[] =
1913 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
1914 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
1915 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
1916 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
1917 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
1918 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
1919 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
1920 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
1921 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
1922 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
1923 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
1924 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
1925 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
1927 #undef FMT_UNKNOWN
1928 #undef D24S8
1929 #undef R24S8_TL
1930 #undef DIM_UNKNOWN
1931 #undef TEX_1D
1932 #undef TEX_1D_ARRAY
1933 #undef TEX_2D
1934 #undef TEX_2D_ARRAY
1935 #undef TEX_2DMS
1936 #undef TEX_2DMS_ARR
1938 if (!(device = create_device()))
1940 skip("Failed to create device.\n");
1941 return;
1944 texture_desc.Width = 512;
1945 texture_desc.Height = 512;
1946 texture_desc.MipLevels = 1;
1947 texture_desc.ArraySize = 1;
1948 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1949 texture_desc.SampleDesc.Count = 1;
1950 texture_desc.SampleDesc.Quality = 0;
1951 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1952 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1953 texture_desc.CPUAccessFlags = 0;
1954 texture_desc.MiscFlags = 0;
1956 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1957 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1959 expected_refcount = get_refcount(device) + 1;
1960 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
1961 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1962 refcount = get_refcount(device);
1963 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1964 tmp = NULL;
1965 expected_refcount = refcount + 1;
1966 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
1967 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1968 refcount = get_refcount(device);
1969 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1970 ID3D10Device_Release(tmp);
1972 memset(&dsv_desc, 0, sizeof(dsv_desc));
1973 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
1974 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1975 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
1976 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1977 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1979 ID3D10DepthStencilView_Release(dsview);
1980 ID3D10Texture2D_Release(texture);
1982 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1984 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
1986 texture_desc.MipLevels = tests[i].texture.miplevel_count;
1987 texture_desc.ArraySize = tests[i].texture.array_size;
1988 texture_desc.Format = tests[i].texture.format;
1990 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1991 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
1993 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
1995 current_desc = NULL;
1997 else
1999 current_desc = &dsv_desc;
2000 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2003 expected_refcount = get_refcount(texture);
2004 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
2005 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2006 refcount = get_refcount(texture);
2007 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2009 /* Not available on all Windows versions. */
2010 check_interface(dsview, &IID_ID3D11DepthStencilView, TRUE, TRUE);
2012 memset(&dsv_desc, 0, sizeof(dsv_desc));
2013 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2014 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2016 ID3D10DepthStencilView_Release(dsview);
2017 ID3D10Texture2D_Release(texture);
2020 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2022 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2023 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2024 texture_desc.Format = invalid_desc_tests[i].texture.format;
2026 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2027 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2029 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2030 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2031 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2033 ID3D10Texture2D_Release(texture);
2036 refcount = ID3D10Device_Release(device);
2037 ok(!refcount, "Device has %u references left.\n", refcount);
2040 static void test_depthstencil_view_interfaces(void)
2042 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2043 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2044 ID3D11DepthStencilView *d3d11_dsview;
2045 D3D10_TEXTURE2D_DESC texture_desc;
2046 ID3D10DepthStencilView *dsview;
2047 ID3D10Texture2D *texture;
2048 ID3D10Device *device;
2049 ULONG refcount;
2050 HRESULT hr;
2052 if (!(device = create_device()))
2054 skip("Failed to create device.\n");
2055 return;
2058 texture_desc.Width = 512;
2059 texture_desc.Height = 512;
2060 texture_desc.MipLevels = 1;
2061 texture_desc.ArraySize = 1;
2062 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2063 texture_desc.SampleDesc.Count = 1;
2064 texture_desc.SampleDesc.Quality = 0;
2065 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2066 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2067 texture_desc.CPUAccessFlags = 0;
2068 texture_desc.MiscFlags = 0;
2070 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2071 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2073 dsv_desc.Format = texture_desc.Format;
2074 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2075 U(dsv_desc).Texture2D.MipSlice = 0;
2077 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2078 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2080 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2081 ID3D10DepthStencilView_Release(dsview);
2082 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2083 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2085 if (SUCCEEDED(hr))
2087 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2088 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2089 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2090 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2091 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2092 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2093 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2095 ID3D11DepthStencilView_Release(d3d11_dsview);
2097 else
2099 win_skip("D3D11 is not available.\n");
2102 ID3D10Texture2D_Release(texture);
2104 refcount = ID3D10Device_Release(device);
2105 ok(!refcount, "Device has %u references left.\n", refcount);
2108 static void test_create_rendertarget_view(void)
2110 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2111 D3D10_TEXTURE3D_DESC texture3d_desc;
2112 D3D10_TEXTURE2D_DESC texture2d_desc;
2113 D3D10_SUBRESOURCE_DATA data = {0};
2114 ULONG refcount, expected_refcount;
2115 ID3D10RenderTargetView *rtview;
2116 D3D10_BUFFER_DESC buffer_desc;
2117 ID3D10Device *device, *tmp;
2118 ID3D10Texture3D *texture3d;
2119 ID3D10Texture2D *texture2d;
2120 ID3D10Resource *texture;
2121 ID3D10Buffer *buffer;
2122 unsigned int i;
2123 HRESULT hr;
2125 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2126 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2127 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2128 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2129 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2130 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2131 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2132 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2133 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2134 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2135 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2136 static const struct
2138 struct
2140 unsigned int miplevel_count;
2141 unsigned int depth_or_array_size;
2142 DXGI_FORMAT format;
2143 } texture;
2144 struct rtv_desc rtv_desc;
2145 struct rtv_desc expected_rtv_desc;
2147 tests[] =
2149 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2150 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2151 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2152 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2153 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2154 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2155 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2156 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2157 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2158 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2159 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2160 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2161 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2162 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2163 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2164 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2165 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2166 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2167 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2168 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2169 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2170 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2171 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2172 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2173 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2174 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2175 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2176 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2177 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2178 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2179 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2180 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2181 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2182 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2183 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2184 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2185 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2186 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2187 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2188 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2189 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2190 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2191 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2192 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2194 static const struct
2196 struct
2198 D3D10_RTV_DIMENSION dimension;
2199 unsigned int miplevel_count;
2200 unsigned int depth_or_array_size;
2201 DXGI_FORMAT format;
2202 } texture;
2203 struct rtv_desc rtv_desc;
2205 invalid_desc_tests[] =
2207 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2208 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2209 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2210 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2211 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2212 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2213 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2214 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2215 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2216 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2217 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2218 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2219 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2220 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2221 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2222 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2223 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2224 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2225 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2226 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2227 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2228 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2229 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2230 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2231 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2232 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2233 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2234 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2235 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2236 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2237 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2238 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2239 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2240 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2241 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2243 #undef FMT_UNKNOWN
2244 #undef RGBA8_UNORM
2245 #undef RGBA8_TL
2246 #undef DIM_UNKNOWN
2247 #undef TEX_1D
2248 #undef TEX_1D_ARRAY
2249 #undef TEX_2D
2250 #undef TEX_2D_ARRAY
2251 #undef TEX_2DMS
2252 #undef TEX_2DMS_ARR
2253 #undef TEX_3D
2255 if (!(device = create_device()))
2257 skip("Failed to create device.\n");
2258 return;
2261 buffer_desc.ByteWidth = 1024;
2262 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2263 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2264 buffer_desc.CPUAccessFlags = 0;
2265 buffer_desc.MiscFlags = 0;
2267 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2268 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2270 expected_refcount = get_refcount(device) + 1;
2271 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2272 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2273 refcount = get_refcount(device);
2274 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2275 tmp = NULL;
2276 expected_refcount = refcount + 1;
2277 ID3D10Buffer_GetDevice(buffer, &tmp);
2278 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2279 refcount = get_refcount(device);
2280 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2281 ID3D10Device_Release(tmp);
2283 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2284 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2285 U(rtv_desc).Buffer.ElementOffset = 0;
2286 U(rtv_desc).Buffer.ElementWidth = 64;
2288 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2289 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2291 expected_refcount = get_refcount(device) + 1;
2292 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2293 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2294 refcount = get_refcount(device);
2295 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2296 tmp = NULL;
2297 expected_refcount = refcount + 1;
2298 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2299 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2300 refcount = get_refcount(device);
2301 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2302 ID3D10Device_Release(tmp);
2304 /* Not available on all Windows versions. */
2305 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2307 ID3D10RenderTargetView_Release(rtview);
2308 ID3D10Buffer_Release(buffer);
2310 texture2d_desc.Width = 512;
2311 texture2d_desc.Height = 512;
2312 texture2d_desc.SampleDesc.Count = 1;
2313 texture2d_desc.SampleDesc.Quality = 0;
2314 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2315 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2316 texture2d_desc.CPUAccessFlags = 0;
2317 texture2d_desc.MiscFlags = 0;
2319 texture3d_desc.Width = 64;
2320 texture3d_desc.Height = 64;
2321 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2322 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2323 texture3d_desc.CPUAccessFlags = 0;
2324 texture3d_desc.MiscFlags = 0;
2326 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2328 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2330 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2332 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2333 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2334 texture2d_desc.Format = tests[i].texture.format;
2336 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2337 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2338 texture = (ID3D10Resource *)texture2d;
2340 else
2342 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2343 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2344 texture3d_desc.Format = tests[i].texture.format;
2346 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2347 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2348 texture = (ID3D10Resource *)texture3d;
2351 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
2353 current_desc = NULL;
2355 else
2357 current_desc = &rtv_desc;
2358 get_rtv_desc(current_desc, &tests[i].rtv_desc);
2361 expected_refcount = get_refcount(texture);
2362 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
2363 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2364 refcount = get_refcount(texture);
2365 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2367 /* Not available on all Windows versions. */
2368 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2370 memset(&rtv_desc, 0, sizeof(rtv_desc));
2371 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
2372 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
2374 ID3D10RenderTargetView_Release(rtview);
2375 ID3D10Resource_Release(texture);
2378 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2380 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
2381 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
2383 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2385 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2386 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2387 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2389 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2390 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2391 texture = (ID3D10Resource *)texture2d;
2393 else
2395 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2396 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2397 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2399 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2400 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2401 texture = (ID3D10Resource *)texture3d;
2404 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
2405 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
2406 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2408 ID3D10Resource_Release(texture);
2411 refcount = ID3D10Device_Release(device);
2412 ok(!refcount, "Device has %u references left.\n", refcount);
2415 static void test_render_target_views(void)
2417 struct texture
2419 UINT miplevel_count;
2420 UINT array_size;
2422 struct rtv
2424 DXGI_FORMAT format;
2425 D3D10_RTV_DIMENSION dimension;
2426 unsigned int miplevel_idx;
2427 unsigned int layer_idx;
2428 unsigned int layer_count;
2431 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
2432 static struct test
2434 struct texture texture;
2435 struct rtv_desc rtv;
2436 DWORD expected_colors[4];
2438 tests[] =
2440 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2441 {0xff0000ff, 0x00000000}},
2442 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
2443 {0x00000000, 0xff0000ff}},
2444 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2445 {0xff0000ff, 0x00000000}},
2446 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2447 {0x00000000, 0xff0000ff}},
2448 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2449 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2450 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2451 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2452 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2453 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2454 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
2455 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2456 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
2457 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2458 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
2459 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2460 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2461 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2462 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2463 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2464 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2465 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2466 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2467 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2468 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
2469 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2472 struct d3d10core_test_context test_context;
2473 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2474 D3D10_TEXTURE2D_DESC texture_desc;
2475 ID3D10RenderTargetView *rtv;
2476 ID3D10Texture2D *texture;
2477 ID3D10Device *device;
2478 unsigned int i, j, k;
2479 void *data;
2480 HRESULT hr;
2482 if (!init_test_context(&test_context))
2483 return;
2485 device = test_context.device;
2487 texture_desc.Width = 32;
2488 texture_desc.Height = 32;
2489 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2490 texture_desc.SampleDesc.Count = 1;
2491 texture_desc.SampleDesc.Quality = 0;
2492 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2493 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2494 texture_desc.CPUAccessFlags = 0;
2495 texture_desc.MiscFlags = 0;
2497 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
2498 ok(!!data, "Failed to allocate memory.\n");
2500 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2502 const struct test *test = &tests[i];
2503 unsigned int sub_resource_count;
2505 texture_desc.MipLevels = test->texture.miplevel_count;
2506 texture_desc.ArraySize = test->texture.array_size;
2508 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2509 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
2511 get_rtv_desc(&rtv_desc, &test->rtv);
2512 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2513 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2515 for (j = 0; j < texture_desc.ArraySize; ++j)
2517 for (k = 0; k < texture_desc.MipLevels; ++k)
2519 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
2520 ID3D10Device_UpdateSubresource(device,
2521 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
2524 check_texture_color(texture, 0, 0);
2526 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2527 draw_color_quad(&test_context, &red);
2529 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
2530 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
2531 for (j = 0; j < sub_resource_count; ++j)
2532 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
2534 ID3D10RenderTargetView_Release(rtv);
2535 ID3D10Texture2D_Release(texture);
2538 HeapFree(GetProcessHeap(), 0, data);
2539 release_test_context(&test_context);
2542 static void test_layered_rendering(void)
2544 struct
2546 unsigned int layer_offset;
2547 unsigned int draw_id;
2548 unsigned int padding[2];
2549 } constant;
2550 struct d3d10core_test_context test_context;
2551 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2552 unsigned int i, sub_resource_count;
2553 D3D10_TEXTURE2D_DESC texture_desc;
2554 ID3D10RenderTargetView *rtv;
2555 ID3D10Texture2D *texture;
2556 ID3D10GeometryShader *gs;
2557 ID3D10PixelShader *ps;
2558 ID3D10Device *device;
2559 ID3D10Buffer *cb;
2560 HRESULT hr;
2562 static const DWORD gs_code[] =
2564 #if 0
2565 uint layer_offset;
2567 struct gs_in
2569 float4 pos : SV_Position;
2572 struct gs_out
2574 float4 pos : SV_Position;
2575 uint layer : SV_RenderTargetArrayIndex;
2578 [maxvertexcount(12)]
2579 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
2581 gs_out o;
2582 for (uint instance_id = 0; instance_id < 4; ++instance_id)
2584 o.layer = layer_offset + instance_id;
2585 for (uint i = 0; i < 3; ++i)
2587 o.pos = vin[i].pos;
2588 vout.Append(o);
2590 vout.RestartStrip();
2593 #endif
2594 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
2595 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2596 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
2597 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
2598 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
2599 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
2600 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
2601 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
2602 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
2603 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
2604 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
2605 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
2606 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
2607 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
2608 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
2609 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
2610 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
2611 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
2612 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
2614 static const DWORD ps_code[] =
2616 #if 0
2617 uint layer_offset;
2618 uint draw_id;
2620 float4 main(in float4 pos : SV_Position,
2621 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
2623 return float4(layer, draw_id, 0, 0);
2625 #endif
2626 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
2627 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
2628 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
2629 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
2630 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
2631 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2632 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
2633 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
2634 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
2635 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
2636 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
2638 static const struct vec4 expected_values[] =
2640 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
2641 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
2642 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
2643 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
2646 if (!init_test_context(&test_context))
2647 return;
2649 device = test_context.device;
2651 memset(&constant, 0, sizeof(constant));
2652 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
2653 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
2654 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
2656 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
2657 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
2658 ID3D10Device_GSSetShader(device, gs);
2659 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
2660 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
2661 ID3D10Device_PSSetShader(device, ps);
2663 texture_desc.Width = 32;
2664 texture_desc.Height = 32;
2665 texture_desc.MipLevels = 3;
2666 texture_desc.ArraySize = 8;
2667 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2668 texture_desc.SampleDesc.Count = 1;
2669 texture_desc.SampleDesc.Quality = 0;
2670 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2671 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2672 texture_desc.CPUAccessFlags = 0;
2673 texture_desc.MiscFlags = 0;
2674 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2675 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2677 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
2678 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
2679 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2680 constant.layer_offset = 0;
2681 constant.draw_id = 0;
2682 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2683 draw_quad(&test_context);
2684 constant.layer_offset = 4;
2685 constant.draw_id = 1;
2686 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2687 draw_quad(&test_context);
2688 ID3D10RenderTargetView_Release(rtv);
2690 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
2691 rtv_desc.Format = texture_desc.Format;
2692 U(rtv_desc).Texture2DArray.MipSlice = 0;
2693 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
2694 U(rtv_desc).Texture2DArray.ArraySize = 1;
2695 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2696 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
2697 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2698 constant.layer_offset = 1;
2699 constant.draw_id = 2;
2700 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2701 draw_quad(&test_context);
2702 ID3D10RenderTargetView_Release(rtv);
2704 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
2705 U(rtv_desc).Texture2DArray.MipSlice = 1;
2706 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
2707 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
2708 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2709 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
2710 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2711 constant.layer_offset = 0;
2712 constant.draw_id = 3;
2713 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2714 draw_quad(&test_context);
2715 constant.layer_offset = 4;
2716 constant.draw_id = 3;
2717 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2718 draw_quad(&test_context);
2719 ID3D10RenderTargetView_Release(rtv);
2721 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
2722 U(rtv_desc).Texture2DArray.MipSlice = 2;
2723 U(rtv_desc).Texture2DArray.ArraySize = 1;
2724 for (i = 0; i < texture_desc.ArraySize; ++i)
2726 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
2727 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2728 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
2729 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2730 constant.layer_offset = 0;
2731 constant.draw_id = 4 + i;
2732 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
2733 draw_quad(&test_context);
2734 ID3D10RenderTargetView_Release(rtv);
2737 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
2738 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
2739 for (i = 0; i < sub_resource_count; ++i)
2740 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
2742 ID3D10Texture2D_Release(texture);
2744 ID3D10Buffer_Release(cb);
2745 ID3D10GeometryShader_Release(gs);
2746 ID3D10PixelShader_Release(ps);
2747 release_test_context(&test_context);
2750 static void test_create_shader_resource_view(void)
2752 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
2753 D3D10_TEXTURE3D_DESC texture3d_desc;
2754 D3D10_TEXTURE2D_DESC texture2d_desc;
2755 ULONG refcount, expected_refcount;
2756 ID3D10ShaderResourceView *srview;
2757 ID3D10Device *device, *tmp;
2758 ID3D10Texture3D *texture3d;
2759 ID3D10Texture2D *texture2d;
2760 ID3D10Resource *texture;
2761 ID3D10Buffer *buffer;
2762 unsigned int i;
2763 HRESULT hr;
2765 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2766 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2767 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2768 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
2769 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
2770 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
2771 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
2772 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
2773 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
2774 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
2775 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
2776 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
2777 static const struct
2779 struct
2781 unsigned int miplevel_count;
2782 unsigned int depth_or_array_size;
2783 DXGI_FORMAT format;
2784 } texture;
2785 struct srv_desc srv_desc;
2786 struct srv_desc expected_srv_desc;
2788 tests[] =
2790 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2791 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2792 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2793 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2794 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2795 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2796 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2797 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2798 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
2799 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
2800 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
2801 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
2802 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
2803 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
2804 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
2805 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2806 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2807 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2808 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2809 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2810 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2811 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2815 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2816 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2817 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2818 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
2819 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2820 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2821 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2822 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
2823 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
2825 static const struct
2827 struct
2829 D3D10_SRV_DIMENSION dimension;
2830 unsigned int miplevel_count;
2831 unsigned int depth_or_array_size;
2832 DXGI_FORMAT format;
2833 } texture;
2834 struct srv_desc srv_desc;
2836 invalid_desc_tests[] =
2838 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2839 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2840 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2841 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2842 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2843 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
2844 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
2845 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
2846 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
2847 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
2848 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
2849 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
2850 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
2851 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
2852 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
2853 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
2854 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
2855 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
2856 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
2857 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
2858 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
2859 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
2860 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2861 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
2862 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2863 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2864 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2865 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2866 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2867 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2868 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2869 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2870 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2871 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2872 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
2873 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
2874 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
2875 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
2876 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
2877 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
2879 #undef FMT_UNKNOWN
2880 #undef RGBA8_UNORM
2881 #undef DIM_UNKNOWN
2882 #undef TEX_1D
2883 #undef TEX_1D_ARRAY
2884 #undef TEX_2D
2885 #undef TEX_2D_ARRAY
2886 #undef TEX_2DMS
2887 #undef TEX_2DMS_ARR
2888 #undef TEX_3D
2889 #undef TEX_CUBE
2891 if (!(device = create_device()))
2893 skip("Failed to create device.\n");
2894 return;
2897 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
2899 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
2900 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2902 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2903 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
2904 U(srv_desc).Buffer.ElementOffset = 0;
2905 U(srv_desc).Buffer.ElementWidth = 64;
2907 expected_refcount = get_refcount(device) + 1;
2908 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
2909 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2910 refcount = get_refcount(device);
2911 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2912 tmp = NULL;
2913 expected_refcount = refcount + 1;
2914 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
2915 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2916 refcount = get_refcount(device);
2917 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2918 ID3D10Device_Release(tmp);
2920 /* Not available on all Windows versions. */
2921 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
2922 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
2924 ID3D10ShaderResourceView_Release(srview);
2925 ID3D10Buffer_Release(buffer);
2927 texture2d_desc.Width = 512;
2928 texture2d_desc.Height = 512;
2929 texture2d_desc.SampleDesc.Count = 1;
2930 texture2d_desc.SampleDesc.Quality = 0;
2931 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2932 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2933 texture2d_desc.CPUAccessFlags = 0;
2935 texture3d_desc.Width = 64;
2936 texture3d_desc.Height = 64;
2937 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2938 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2939 texture3d_desc.CPUAccessFlags = 0;
2940 texture3d_desc.MiscFlags = 0;
2942 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2944 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
2946 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
2948 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2949 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2950 texture2d_desc.Format = tests[i].texture.format;
2951 texture2d_desc.MiscFlags = 0;
2953 if (tests[i].expected_srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
2954 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
2956 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2957 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2958 texture = (ID3D10Resource *)texture2d;
2960 else
2962 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2963 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2964 texture3d_desc.Format = tests[i].texture.format;
2966 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2967 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2968 texture = (ID3D10Resource *)texture3d;
2971 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
2973 current_desc = NULL;
2975 else
2977 current_desc = &srv_desc;
2978 get_srv_desc(current_desc, &tests[i].srv_desc);
2981 expected_refcount = get_refcount(texture);
2982 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
2983 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
2984 refcount = get_refcount(texture);
2985 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2987 /* Not available on all Windows versions. */
2988 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
2989 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
2991 memset(&srv_desc, 0, sizeof(srv_desc));
2992 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
2993 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
2995 ID3D10ShaderResourceView_Release(srview);
2996 ID3D10Resource_Release(texture);
2999 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3001 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
3002 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
3004 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
3006 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3007 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3008 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3009 texture2d_desc.MiscFlags = 0;
3011 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3012 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3014 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3015 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3016 texture = (ID3D10Resource *)texture2d;
3018 else
3020 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3021 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3022 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3024 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3025 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3026 texture = (ID3D10Resource *)texture3d;
3029 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3030 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3031 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3033 ID3D10Resource_Release(texture);
3036 refcount = ID3D10Device_Release(device);
3037 ok(!refcount, "Device has %u references left.\n", refcount);
3040 static void test_create_shader(void)
3042 #if 0
3043 float4 light;
3044 float4x4 mat;
3046 struct input
3048 float4 position : POSITION;
3049 float3 normal : NORMAL;
3052 struct output
3054 float4 position : POSITION;
3055 float4 diffuse : COLOR;
3058 output main(const input v)
3060 output o;
3062 o.position = mul(v.position, mat);
3063 o.diffuse = dot((float3)light, v.normal);
3065 return o;
3067 #endif
3068 static const DWORD vs_4_0[] =
3070 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3071 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3072 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3073 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3074 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3075 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3076 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3077 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3078 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3079 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3080 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3081 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3082 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3083 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3084 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3085 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3088 static const DWORD vs_2_0[] =
3090 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3091 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3092 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3093 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3094 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3095 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3096 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3097 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3098 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3099 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3100 0x90e40001, 0x0000ffff,
3103 static const DWORD vs_3_0[] =
3105 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3106 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3107 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3108 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3109 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3110 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3111 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3112 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3113 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3114 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3115 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3116 0x0000ffff,
3119 #if 0
3120 float4 main(const float4 color : COLOR) : SV_TARGET
3122 float4 o;
3124 o = color;
3126 return o;
3128 #endif
3129 static const DWORD ps_4_0[] =
3131 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3132 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3133 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3134 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3135 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3136 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3137 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3140 #if 0
3141 struct gs_out
3143 float4 pos : SV_POSITION;
3146 [maxvertexcount(4)]
3147 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3149 float offset = 0.1 * vin[0].w;
3150 gs_out v;
3152 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3153 vout.Append(v);
3154 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3155 vout.Append(v);
3156 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3157 vout.Append(v);
3158 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3159 vout.Append(v);
3161 #endif
3162 static const DWORD gs_4_0[] =
3164 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3165 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3166 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3167 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3168 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3169 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3170 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3171 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3172 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3173 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3174 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3175 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3176 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3177 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3178 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3179 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3180 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3181 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3184 ULONG refcount, expected_refcount;
3185 ID3D10Device *device, *tmp;
3186 ID3D10GeometryShader *gs;
3187 ID3D10VertexShader *vs;
3188 ID3D10PixelShader *ps;
3189 HRESULT hr;
3191 if (!(device = create_device()))
3193 skip("Failed to create device, skipping tests.\n");
3194 return;
3197 /* vertex shader */
3198 expected_refcount = get_refcount(device) + 1;
3199 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
3200 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3202 refcount = get_refcount(device);
3203 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3204 tmp = NULL;
3205 expected_refcount = refcount + 1;
3206 ID3D10VertexShader_GetDevice(vs, &tmp);
3207 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3208 refcount = get_refcount(device);
3209 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3210 ID3D10Device_Release(tmp);
3212 /* Not available on all Windows versions. */
3213 check_interface(vs, &IID_ID3D11VertexShader, TRUE, TRUE);
3215 refcount = ID3D10VertexShader_Release(vs);
3216 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3218 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
3219 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
3221 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
3222 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
3224 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
3225 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3227 /* pixel shader */
3228 expected_refcount = get_refcount(device) + 1;
3229 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3230 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x.\n", hr);
3232 refcount = get_refcount(device);
3233 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3234 tmp = NULL;
3235 expected_refcount = refcount + 1;
3236 ID3D10PixelShader_GetDevice(ps, &tmp);
3237 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3238 refcount = get_refcount(device);
3239 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3240 ID3D10Device_Release(tmp);
3242 /* Not available on all Windows versions. */
3243 check_interface(ps, &IID_ID3D11PixelShader, TRUE, TRUE);
3245 refcount = ID3D10PixelShader_Release(ps);
3246 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3248 /* geometry shader */
3249 expected_refcount = get_refcount(device) + 1;
3250 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3251 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3253 refcount = get_refcount(device);
3254 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3255 tmp = NULL;
3256 expected_refcount = refcount + 1;
3257 ID3D10GeometryShader_GetDevice(gs, &tmp);
3258 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3259 refcount = get_refcount(device);
3260 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3261 ID3D10Device_Release(tmp);
3263 /* Not available on all Windows versions. */
3264 check_interface(gs, &IID_ID3D11GeometryShader, TRUE, TRUE);
3266 refcount = ID3D10GeometryShader_Release(gs);
3267 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3269 refcount = ID3D10Device_Release(device);
3270 ok(!refcount, "Device has %u references left.\n", refcount);
3273 static void test_create_sampler_state(void)
3275 static const struct test
3277 D3D10_FILTER filter;
3278 D3D11_FILTER expected_filter;
3280 desc_conversion_tests[] =
3282 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3283 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3284 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3285 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3286 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3287 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3288 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3289 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3290 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3291 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3292 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3294 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3295 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3297 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3298 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3300 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3301 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3303 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3304 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3305 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3308 ID3D10SamplerState *sampler_state1, *sampler_state2;
3309 ID3D11SamplerState *d3d11_sampler_state;
3310 ULONG refcount, expected_refcount;
3311 ID3D10Device *device, *tmp;
3312 ID3D11Device *d3d11_device;
3313 D3D10_SAMPLER_DESC desc;
3314 unsigned int i;
3315 HRESULT hr;
3317 if (!(device = create_device()))
3319 skip("Failed to create device, skipping tests.\n");
3320 return;
3323 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3324 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3326 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3327 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3328 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3329 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3330 desc.MipLODBias = 0.0f;
3331 desc.MaxAnisotropy = 16;
3332 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3333 desc.BorderColor[0] = 0.0f;
3334 desc.BorderColor[1] = 1.0f;
3335 desc.BorderColor[2] = 0.0f;
3336 desc.BorderColor[3] = 1.0f;
3337 desc.MinLOD = 0.0f;
3338 desc.MaxLOD = 16.0f;
3340 expected_refcount = get_refcount(device) + 1;
3341 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3342 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3343 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
3344 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3345 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
3346 refcount = get_refcount(device);
3347 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3348 tmp = NULL;
3349 expected_refcount = refcount + 1;
3350 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
3351 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3352 refcount = get_refcount(device);
3353 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3354 ID3D10Device_Release(tmp);
3356 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
3357 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
3358 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
3359 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
3360 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
3361 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
3362 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
3363 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
3364 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
3365 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
3366 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
3367 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
3368 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
3369 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
3371 refcount = ID3D10SamplerState_Release(sampler_state2);
3372 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3373 refcount = ID3D10SamplerState_Release(sampler_state1);
3374 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3376 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3377 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3378 "Device should implement ID3D11Device.\n");
3379 if (FAILED(hr))
3381 win_skip("D3D11 is not available.\n");
3382 goto done;
3385 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3387 const struct test *current = &desc_conversion_tests[i];
3388 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
3390 desc.Filter = current->filter;
3391 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3392 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3393 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
3394 desc.MipLODBias = 0.0f;
3395 desc.MaxAnisotropy = 16;
3396 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3397 desc.BorderColor[0] = 0.0f;
3398 desc.BorderColor[1] = 1.0f;
3399 desc.BorderColor[2] = 0.0f;
3400 desc.BorderColor[3] = 1.0f;
3401 desc.MinLOD = 0.0f;
3402 desc.MaxLOD = 16.0f;
3404 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3405 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3407 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
3408 (void **)&d3d11_sampler_state);
3409 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
3411 memcpy(&expected_desc, &desc, sizeof(expected_desc));
3412 expected_desc.Filter = current->expected_filter;
3413 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
3414 expected_desc.MaxAnisotropy = 0;
3415 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
3416 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3418 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
3419 ok(d3d11_desc.Filter == expected_desc.Filter,
3420 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
3421 ok(d3d11_desc.AddressU == expected_desc.AddressU,
3422 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
3423 ok(d3d11_desc.AddressV == expected_desc.AddressV,
3424 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
3425 ok(d3d11_desc.AddressW == expected_desc.AddressW,
3426 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
3427 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
3428 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
3429 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
3430 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
3431 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
3432 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
3433 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
3434 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
3435 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
3436 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
3437 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
3438 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
3439 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
3440 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
3441 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
3442 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
3443 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
3445 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3446 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3448 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
3449 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3450 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
3451 (void **)&sampler_state2);
3452 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
3453 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
3455 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3456 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3457 refcount = ID3D10SamplerState_Release(sampler_state2);
3458 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3459 refcount = ID3D10SamplerState_Release(sampler_state1);
3460 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3463 ID3D11Device_Release(d3d11_device);
3465 done:
3466 refcount = ID3D10Device_Release(device);
3467 ok(!refcount, "Device has %u references left.\n", refcount);
3470 static void test_create_blend_state(void)
3472 ID3D10BlendState *blend_state1, *blend_state2;
3473 ID3D11BlendState *d3d11_blend_state;
3474 ULONG refcount, expected_refcount;
3475 D3D11_BLEND_DESC d3d11_blend_desc;
3476 D3D10_BLEND_DESC blend_desc;
3477 ID3D11Device *d3d11_device;
3478 ID3D10Device *device, *tmp;
3479 unsigned int i;
3480 HRESULT hr;
3482 if (!(device = create_device()))
3484 skip("Failed to create device.\n");
3485 return;
3488 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
3489 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3491 blend_desc.AlphaToCoverageEnable = FALSE;
3492 blend_desc.SrcBlend = D3D10_BLEND_ONE;
3493 blend_desc.DestBlend = D3D10_BLEND_ZERO;
3494 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
3495 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
3496 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
3497 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
3498 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3500 blend_desc.BlendEnable[i] = FALSE;
3501 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
3504 expected_refcount = get_refcount(device) + 1;
3505 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3506 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3507 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
3508 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3509 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3510 refcount = get_refcount(device);
3511 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3512 tmp = NULL;
3513 expected_refcount = refcount + 1;
3514 ID3D10BlendState_GetDevice(blend_state1, &tmp);
3515 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3516 refcount = get_refcount(device);
3517 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3518 ID3D10Device_Release(tmp);
3520 /* Not available on all Windows versions. */
3521 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
3523 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3524 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3525 "Device should implement ID3D11Device.\n");
3526 if (FAILED(hr))
3528 win_skip("D3D11 is not available.\n");
3529 goto done;
3532 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3533 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3535 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3536 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3537 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3538 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
3539 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3540 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3542 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3543 "Got unexpected blend enable %#x for render target %u.\n",
3544 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3545 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3546 "Got unexpected src blend %u for render target %u.\n",
3547 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3548 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3549 "Got unexpected dest blend %u for render target %u.\n",
3550 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3551 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3552 "Got unexpected blend op %u for render target %u.\n",
3553 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3554 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3555 "Got unexpected src blend alpha %u for render target %u.\n",
3556 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3557 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3558 "Got unexpected dest blend alpha %u for render target %u.\n",
3559 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3560 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3561 "Got unexpected blend op alpha %u for render target %u.\n",
3562 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3563 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3564 "Got unexpected render target write mask %#x for render target %u.\n",
3565 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3568 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3569 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3570 refcount = ID3D10BlendState_Release(blend_state2);
3571 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3573 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3574 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3576 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3577 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3578 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3580 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3581 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3582 refcount = ID3D10BlendState_Release(blend_state2);
3583 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3584 refcount = ID3D10BlendState_Release(blend_state1);
3585 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3587 blend_desc.BlendEnable[0] = TRUE;
3588 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
3589 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
3590 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
3592 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3593 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3595 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3596 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3598 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3599 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3600 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3601 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
3602 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3603 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3605 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3606 "Got unexpected blend enable %#x for render target %u.\n",
3607 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3608 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3609 "Got unexpected src blend %u for render target %u.\n",
3610 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3611 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3612 "Got unexpected dest blend %u for render target %u.\n",
3613 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3614 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3615 "Got unexpected blend op %u for render target %u.\n",
3616 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3617 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3618 "Got unexpected src blend alpha %u for render target %u.\n",
3619 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3620 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3621 "Got unexpected dest blend alpha %u for render target %u.\n",
3622 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3623 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3624 "Got unexpected blend op alpha %u for render target %u.\n",
3625 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3626 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3627 "Got unexpected render target write mask %#x for render target %u.\n",
3628 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3631 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3632 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3634 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3635 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3637 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3638 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3639 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3641 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3642 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3644 ID3D11Device_Release(d3d11_device);
3646 done:
3647 refcount = ID3D10BlendState_Release(blend_state2);
3648 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3649 refcount = ID3D10BlendState_Release(blend_state1);
3650 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3652 refcount = ID3D10Device_Release(device);
3653 ok(!refcount, "Device has %u references left.\n", refcount);
3656 static void test_create_depthstencil_state(void)
3658 ID3D10DepthStencilState *ds_state1, *ds_state2;
3659 ULONG refcount, expected_refcount;
3660 D3D10_DEPTH_STENCIL_DESC ds_desc;
3661 ID3D10Device *device, *tmp;
3662 HRESULT hr;
3664 if (!(device = create_device()))
3666 skip("Failed to create device, skipping tests.\n");
3667 return;
3670 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
3671 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3673 ds_desc.DepthEnable = TRUE;
3674 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
3675 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
3676 ds_desc.StencilEnable = FALSE;
3677 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
3678 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
3679 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3680 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3681 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3682 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3683 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3684 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3685 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3686 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3688 expected_refcount = get_refcount(device) + 1;
3689 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3690 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3691 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
3692 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3693 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
3694 refcount = get_refcount(device);
3695 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3696 tmp = NULL;
3697 expected_refcount = refcount + 1;
3698 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
3699 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3700 refcount = get_refcount(device);
3701 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3702 ID3D10Device_Release(tmp);
3704 refcount = ID3D10DepthStencilState_Release(ds_state2);
3705 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3706 refcount = ID3D10DepthStencilState_Release(ds_state1);
3707 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3709 ds_desc.DepthEnable = FALSE;
3710 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
3711 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
3712 ds_desc.StencilEnable = FALSE;
3713 ds_desc.StencilReadMask = 0;
3714 ds_desc.StencilWriteMask = 0;
3715 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
3716 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
3717 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
3718 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
3719 ds_desc.BackFace = ds_desc.FrontFace;
3721 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3722 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3724 memset(&ds_desc, 0, sizeof(ds_desc));
3725 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
3726 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
3727 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
3728 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
3729 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
3730 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
3731 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
3732 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
3733 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
3734 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
3735 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
3736 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
3737 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3738 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
3739 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3740 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
3741 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3742 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
3743 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3744 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
3745 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3746 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
3747 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3748 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
3749 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3750 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
3751 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3752 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
3754 ID3D10DepthStencilState_Release(ds_state1);
3756 refcount = ID3D10Device_Release(device);
3757 ok(!refcount, "Device has %u references left.\n", refcount);
3760 static void test_create_rasterizer_state(void)
3762 ID3D10RasterizerState *rast_state1, *rast_state2;
3763 ULONG refcount, expected_refcount;
3764 D3D10_RASTERIZER_DESC rast_desc;
3765 ID3D10Device *device, *tmp;
3766 HRESULT hr;
3768 if (!(device = create_device()))
3770 skip("Failed to create device, skipping tests.\n");
3771 return;
3774 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
3775 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3777 rast_desc.FillMode = D3D10_FILL_SOLID;
3778 rast_desc.CullMode = D3D10_CULL_BACK;
3779 rast_desc.FrontCounterClockwise = FALSE;
3780 rast_desc.DepthBias = 0;
3781 rast_desc.DepthBiasClamp = 0.0f;
3782 rast_desc.SlopeScaledDepthBias = 0.0f;
3783 rast_desc.DepthClipEnable = TRUE;
3784 rast_desc.ScissorEnable = FALSE;
3785 rast_desc.MultisampleEnable = FALSE;
3786 rast_desc.AntialiasedLineEnable = FALSE;
3788 expected_refcount = get_refcount(device) + 1;
3789 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
3790 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3791 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
3792 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3793 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
3794 refcount = get_refcount(device);
3795 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3796 tmp = NULL;
3797 expected_refcount = refcount + 1;
3798 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
3799 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3800 refcount = get_refcount(device);
3801 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3802 ID3D10Device_Release(tmp);
3804 refcount = ID3D10RasterizerState_Release(rast_state2);
3805 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3806 refcount = ID3D10RasterizerState_Release(rast_state1);
3807 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3809 refcount = ID3D10Device_Release(device);
3810 ok(!refcount, "Device has %u references left.\n", refcount);
3813 static void test_create_query(void)
3815 static const struct
3817 D3D10_QUERY query;
3818 BOOL is_predicate;
3819 BOOL todo;
3821 tests[] =
3823 {D3D10_QUERY_EVENT, FALSE, FALSE},
3824 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
3825 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
3826 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
3827 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, FALSE},
3828 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
3829 {D3D10_QUERY_SO_STATISTICS, FALSE, TRUE},
3830 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
3833 ULONG refcount, expected_refcount;
3834 D3D10_QUERY_DESC query_desc;
3835 ID3D10Predicate *predicate;
3836 ID3D10Device *device, *tmp;
3837 HRESULT hr, expected_hr;
3838 ID3D10Query *query;
3839 unsigned int i;
3841 if (!(device = create_device()))
3843 skip("Failed to create device.\n");
3844 return;
3847 hr = ID3D10Device_CreateQuery(device, NULL, &query);
3848 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3849 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
3850 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3852 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3854 query_desc.Query = tests[i].query;
3855 query_desc.MiscFlags = 0;
3857 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
3858 todo_wine_if(tests[i].todo)
3859 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3861 query_desc.Query = tests[i].query;
3862 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
3863 todo_wine_if(tests[i].todo)
3864 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3865 if (FAILED(hr))
3866 continue;
3868 check_interface(query, &IID_ID3D10Predicate, tests[i].is_predicate, FALSE);
3869 ID3D10Query_Release(query);
3871 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
3872 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
3873 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3875 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
3876 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3877 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3878 if (SUCCEEDED(hr))
3879 ID3D10Predicate_Release(predicate);
3882 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
3883 expected_refcount = get_refcount(device) + 1;
3884 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3885 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
3886 refcount = get_refcount(device);
3887 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3888 tmp = NULL;
3889 expected_refcount = refcount + 1;
3890 ID3D10Predicate_GetDevice(predicate, &tmp);
3891 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3892 refcount = get_refcount(device);
3893 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3894 ID3D10Device_Release(tmp);
3895 /* Not available on all Windows versions. */
3896 check_interface(predicate, &IID_ID3D11Predicate, TRUE, TRUE);
3897 ID3D10Predicate_Release(predicate);
3899 refcount = ID3D10Device_Release(device);
3900 ok(!refcount, "Device has %u references left.\n", refcount);
3903 #define get_query_data(a, b, c) get_query_data_(__LINE__, a, b, c)
3904 static void get_query_data_(unsigned int line, ID3D10Asynchronous *query,
3905 void *data, unsigned int data_size)
3907 unsigned int i;
3908 HRESULT hr;
3910 for (i = 0; i < 500; ++i)
3912 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3913 break;
3914 Sleep(10);
3916 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3917 memset(data, 0xff, data_size);
3918 hr = ID3D10Asynchronous_GetData(query, data, data_size, 0);
3919 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3922 static void test_occlusion_query(void)
3924 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3925 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
3927 struct d3d10core_test_context test_context;
3928 D3D10_TEXTURE2D_DESC texture_desc;
3929 ID3D10RenderTargetView *rtv;
3930 D3D10_QUERY_DESC query_desc;
3931 ID3D10Asynchronous *query;
3932 unsigned int data_size, i;
3933 ID3D10Texture2D *texture;
3934 ID3D10Device *device;
3935 D3D10_VIEWPORT vp;
3936 union
3938 UINT64 uint;
3939 DWORD dword[2];
3940 } data;
3941 HRESULT hr;
3943 if (!init_test_context(&test_context))
3944 return;
3946 device = test_context.device;
3948 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
3950 query_desc.Query = D3D10_QUERY_OCCLUSION;
3951 query_desc.MiscFlags = 0;
3952 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
3953 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3954 data_size = ID3D10Asynchronous_GetDataSize(query);
3955 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
3957 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3958 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3959 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3960 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3962 ID3D10Asynchronous_End(query);
3963 ID3D10Asynchronous_Begin(query);
3964 ID3D10Asynchronous_Begin(query);
3966 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3967 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3968 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3969 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3971 draw_color_quad(&test_context, &red);
3973 ID3D10Asynchronous_End(query);
3974 get_query_data(query, &data, sizeof(data));
3975 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3977 memset(&data, 0xff, sizeof(data));
3978 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
3979 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3980 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
3981 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3982 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
3983 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3984 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
3985 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3986 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3987 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3989 memset(&data, 0xff, sizeof(data));
3990 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
3991 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3992 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3993 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3995 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
3996 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3997 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
3998 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4000 ID3D10Asynchronous_Begin(query);
4001 ID3D10Asynchronous_End(query);
4002 ID3D10Asynchronous_End(query);
4004 get_query_data(query, &data, sizeof(data));
4005 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4006 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4007 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4009 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4010 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4011 texture_desc.MipLevels = 1;
4012 texture_desc.ArraySize = 1;
4013 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4014 texture_desc.SampleDesc.Count = 1;
4015 texture_desc.SampleDesc.Quality = 0;
4016 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4017 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4018 texture_desc.CPUAccessFlags = 0;
4019 texture_desc.MiscFlags = 0;
4020 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4021 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4022 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
4023 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4025 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
4026 vp.TopLeftX = 0;
4027 vp.TopLeftY = 0;
4028 vp.Width = texture_desc.Width;
4029 vp.Height = texture_desc.Height;
4030 vp.MinDepth = 0.0f;
4031 vp.MaxDepth = 1.0f;
4032 ID3D10Device_RSSetViewports(device, 1, &vp);
4034 ID3D10Asynchronous_Begin(query);
4035 for (i = 0; i < 100; i++)
4036 draw_color_quad(&test_context, &red);
4037 ID3D10Asynchronous_End(query);
4039 get_query_data(query, &data, sizeof(data));
4040 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4041 || (data.dword[0] == 0xffffffff && !data.dword[1])
4042 || broken(!data.uint),
4043 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4045 ID3D10Asynchronous_Release(query);
4046 ID3D10RenderTargetView_Release(rtv);
4047 ID3D10Texture2D_Release(texture);
4048 release_test_context(&test_context);
4051 static void test_pipeline_statistics_query(void)
4053 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4054 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4056 struct d3d10core_test_context test_context;
4057 D3D10_QUERY_DATA_PIPELINE_STATISTICS data;
4058 D3D10_QUERY_DESC query_desc;
4059 ID3D10Asynchronous *query;
4060 unsigned int data_size;
4061 ID3D10Device *device;
4062 HRESULT hr;
4064 if (!init_test_context(&test_context))
4065 return;
4067 device = test_context.device;
4069 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4071 query_desc.Query = D3D10_QUERY_PIPELINE_STATISTICS;
4072 query_desc.MiscFlags = 0;
4073 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4074 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4075 data_size = ID3D10Asynchronous_GetDataSize(query);
4076 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4078 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4079 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4080 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4081 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4083 ID3D10Asynchronous_End(query);
4084 ID3D10Asynchronous_Begin(query);
4085 ID3D10Asynchronous_Begin(query);
4087 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4088 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4089 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4090 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4092 draw_quad(&test_context);
4094 ID3D10Asynchronous_End(query);
4095 get_query_data(query, &data, sizeof(data));
4096 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4097 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4098 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4099 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4100 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4101 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4102 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4103 todo_wine
4104 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4106 ID3D10Asynchronous_Begin(query);
4107 draw_color_quad(&test_context, &red);
4108 ID3D10Asynchronous_End(query);
4109 get_query_data(query, &data, sizeof(data));
4110 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4111 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4112 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4113 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4114 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4115 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4116 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4117 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4119 ID3D10Asynchronous_Release(query);
4120 release_test_context(&test_context);
4123 static void test_timestamp_query(void)
4125 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4127 ID3D10Asynchronous *timestamp_query, *timestamp_disjoint_query;
4128 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4129 struct d3d10core_test_context test_context;
4130 D3D10_QUERY_DESC query_desc;
4131 unsigned int data_size;
4132 ID3D10Device *device;
4133 UINT64 timestamp;
4134 HRESULT hr;
4136 if (!init_test_context(&test_context))
4137 return;
4139 device = test_context.device;
4141 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4142 query_desc.MiscFlags = 0;
4143 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4144 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4145 data_size = ID3D10Asynchronous_GetDataSize(timestamp_query);
4146 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4148 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
4149 query_desc.MiscFlags = 0;
4150 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_disjoint_query);
4151 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4152 data_size = ID3D10Asynchronous_GetDataSize(timestamp_disjoint_query);
4153 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4155 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4156 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4157 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4158 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4160 /* Test a TIMESTAMP_DISJOINT query. */
4161 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4163 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4164 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4165 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4166 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4168 ID3D10Asynchronous_End(timestamp_disjoint_query);
4169 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4170 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4171 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4173 prev_disjoint = disjoint;
4175 disjoint.Frequency = 0xdeadbeef;
4176 disjoint.Disjoint = 0xff;
4177 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4178 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4179 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4180 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4181 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4182 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4183 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4184 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4185 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4186 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4188 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4189 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4190 memset(&disjoint, 0xff, sizeof(disjoint));
4191 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query,
4192 &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
4193 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4194 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
4195 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
4197 hr = ID3D10Asynchronous_GetData(timestamp_query, NULL, 0, 0);
4198 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4199 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4200 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4202 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4203 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4205 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4206 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4208 draw_color_quad(&test_context, &red);
4210 ID3D10Asynchronous_End(timestamp_query);
4211 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4213 timestamp = 0xdeadbeef;
4214 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4215 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4216 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4218 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4219 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4220 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4222 timestamp = 0xdeadbeef;
4223 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4224 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4225 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4226 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4227 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4228 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4229 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4230 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4231 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4233 ID3D10Asynchronous_End(timestamp_disjoint_query);
4234 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4235 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4236 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4238 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4239 ID3D10Asynchronous_Release(timestamp_query);
4240 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4241 query_desc.MiscFlags = 0;
4242 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4243 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4245 draw_color_quad(&test_context, &red);
4247 ID3D10Asynchronous_End(timestamp_query);
4248 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4250 ID3D10Asynchronous_Release(timestamp_query);
4251 ID3D10Asynchronous_Release(timestamp_disjoint_query);
4252 release_test_context(&test_context);
4255 static void test_device_removed_reason(void)
4257 ID3D10Device *device;
4258 ULONG refcount;
4259 HRESULT hr;
4261 if (!(device = create_device()))
4263 skip("Failed to create device, skipping tests.\n");
4264 return;
4267 hr = ID3D10Device_GetDeviceRemovedReason(device);
4268 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4269 hr = ID3D10Device_GetDeviceRemovedReason(device);
4270 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4272 refcount = ID3D10Device_Release(device);
4273 ok(!refcount, "Device has %u references left.\n", refcount);
4276 static void test_scissor(void)
4278 struct d3d10core_test_context test_context;
4279 D3D10_RASTERIZER_DESC rs_desc;
4280 ID3D10RasterizerState *rs;
4281 D3D10_RECT scissor_rect;
4282 ID3D10Device *device;
4283 DWORD color;
4284 HRESULT hr;
4286 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4287 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
4289 if (!init_test_context(&test_context))
4290 return;
4292 device = test_context.device;
4294 rs_desc.FillMode = D3D10_FILL_SOLID;
4295 rs_desc.CullMode = D3D10_CULL_BACK;
4296 rs_desc.FrontCounterClockwise = FALSE;
4297 rs_desc.DepthBias = 0;
4298 rs_desc.DepthBiasClamp = 0.0f;
4299 rs_desc.SlopeScaledDepthBias = 0.0f;
4300 rs_desc.DepthClipEnable = TRUE;
4301 rs_desc.ScissorEnable = TRUE;
4302 rs_desc.MultisampleEnable = FALSE;
4303 rs_desc.AntialiasedLineEnable = FALSE;
4304 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
4305 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4307 scissor_rect.left = 160;
4308 scissor_rect.top = 120;
4309 scissor_rect.right = 480;
4310 scissor_rect.bottom = 360;
4311 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
4313 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4314 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4316 draw_color_quad(&test_context, &green);
4317 color = get_texture_color(test_context.backbuffer, 320, 60);
4318 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4319 color = get_texture_color(test_context.backbuffer, 80, 240);
4320 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4321 color = get_texture_color(test_context.backbuffer, 320, 240);
4322 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4323 color = get_texture_color(test_context.backbuffer, 560, 240);
4324 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4325 color = get_texture_color(test_context.backbuffer, 320, 420);
4326 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4328 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4329 ID3D10Device_RSSetState(device, rs);
4330 draw_color_quad(&test_context, &green);
4331 color = get_texture_color(test_context.backbuffer, 320, 60);
4332 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4333 color = get_texture_color(test_context.backbuffer, 80, 240);
4334 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4335 color = get_texture_color(test_context.backbuffer, 320, 240);
4336 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4337 color = get_texture_color(test_context.backbuffer, 560, 240);
4338 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4339 color = get_texture_color(test_context.backbuffer, 320, 420);
4340 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4342 ID3D10RasterizerState_Release(rs);
4343 release_test_context(&test_context);
4346 static void test_clear_state(void)
4348 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4350 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4352 #if 0
4353 float4 main(float4 pos : POSITION) : POSITION
4355 return pos;
4357 #endif
4358 static const DWORD simple_vs[] =
4360 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
4361 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4362 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4363 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4364 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
4365 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4366 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4369 #if 0
4370 struct gs_out
4372 float4 pos : SV_POSITION;
4375 [maxvertexcount(4)]
4376 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4378 float offset = 0.1 * vin[0].w;
4379 gs_out v;
4381 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4382 vout.Append(v);
4383 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4384 vout.Append(v);
4385 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4386 vout.Append(v);
4387 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4388 vout.Append(v);
4390 #endif
4391 static const DWORD simple_gs[] =
4393 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4394 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4395 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4396 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4397 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4398 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4399 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4400 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4401 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4402 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4403 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4404 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4405 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4406 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4407 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4408 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4409 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4410 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4413 #if 0
4414 float4 main(float4 color : COLOR) : SV_TARGET
4416 return color;
4418 #endif
4419 static const DWORD simple_ps[] =
4421 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4422 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4423 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4424 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4425 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4426 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4427 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4430 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4431 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4432 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4433 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4434 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4435 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4436 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4437 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4438 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4439 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4440 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4441 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4442 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4443 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4444 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
4445 ID3D10InputLayout *tmp_input_layout, *input_layout;
4446 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
4447 ID3D10BlendState *tmp_blend_state, *blend_state;
4448 ID3D10RasterizerState *tmp_rs_state, *rs_state;
4449 ID3D10Predicate *tmp_predicate, *predicate;
4450 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4451 ID3D10DepthStencilView *tmp_dsv, *dsv;
4452 D3D10_PRIMITIVE_TOPOLOGY topology;
4453 D3D10_TEXTURE2D_DESC texture_desc;
4454 ID3D10GeometryShader *tmp_gs, *gs;
4455 D3D10_DEPTH_STENCIL_DESC ds_desc;
4456 ID3D10VertexShader *tmp_vs, *vs;
4457 D3D10_SAMPLER_DESC sampler_desc;
4458 D3D10_QUERY_DESC predicate_desc;
4459 ID3D10PixelShader *tmp_ps, *ps;
4460 D3D10_RASTERIZER_DESC rs_desc;
4461 D3D10_BLEND_DESC blend_desc;
4462 ID3D10Texture2D *ds_texture;
4463 float tmp_blend_factor[4];
4464 float blend_factor[4];
4465 ID3D10Device *device;
4466 BOOL predicate_value;
4467 DXGI_FORMAT format;
4468 UINT sample_mask;
4469 UINT stencil_ref;
4470 ULONG refcount;
4471 UINT count, i;
4472 HRESULT hr;
4474 if (!(device = create_device()))
4476 skip("Failed to create device, skipping tests.\n");
4477 return;
4480 /* Verify the initial state after device creation. */
4482 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4483 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4485 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4487 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4488 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4490 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4492 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4493 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4495 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4497 ID3D10Device_VSGetShader(device, &tmp_vs);
4498 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4500 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4501 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4503 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4505 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4506 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4508 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4510 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4511 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4513 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4515 ID3D10Device_GSGetShader(device, &tmp_gs);
4516 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4518 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4519 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4521 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4523 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4524 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4526 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4528 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4529 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4531 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4533 ID3D10Device_PSGetShader(device, &tmp_ps);
4534 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4536 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4537 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4539 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4540 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4541 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4543 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4544 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4545 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4546 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4547 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4548 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4549 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4550 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4552 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4553 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4554 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4555 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4556 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4557 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4558 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4559 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4560 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4561 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4562 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4563 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4565 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4567 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4569 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4570 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4571 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4572 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4573 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4574 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4576 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4577 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4579 ID3D10Device_RSGetViewports(device, &count, NULL);
4580 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4581 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4582 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4583 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4584 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4586 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4587 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4588 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4589 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4590 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4592 ID3D10Device_RSGetState(device, &tmp_rs_state);
4593 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4595 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4596 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4598 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4599 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4602 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4603 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4604 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4606 /* Create resources. */
4608 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4609 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
4611 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4613 buffer[i] = create_buffer(device,
4614 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
4615 1024, NULL);
4617 stride[i] = (i + 1) * 4;
4618 offset[i] = (i + 1) * 16;
4621 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4622 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
4624 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4625 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
4626 U(srv_desc).Buffer.ElementOffset = 0;
4627 U(srv_desc).Buffer.ElementWidth = 64;
4629 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4631 hr = ID3D10Device_CreateShaderResourceView(device,
4632 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
4633 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4636 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4637 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4638 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4639 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4640 sampler_desc.MipLODBias = 0.0f;
4641 sampler_desc.MaxAnisotropy = 16;
4642 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4643 sampler_desc.BorderColor[0] = 0.0f;
4644 sampler_desc.BorderColor[1] = 0.0f;
4645 sampler_desc.BorderColor[2] = 0.0f;
4646 sampler_desc.BorderColor[3] = 0.0f;
4647 sampler_desc.MinLOD = 0.0f;
4648 sampler_desc.MaxLOD = 16.0f;
4650 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4652 sampler_desc.MinLOD = (float)i;
4654 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
4655 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4658 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
4659 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4661 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
4662 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
4664 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
4665 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4667 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
4668 simple_vs, sizeof(simple_vs), &input_layout);
4669 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4671 blend_desc.AlphaToCoverageEnable = FALSE;
4672 blend_desc.BlendEnable[0] = FALSE;
4673 blend_desc.BlendEnable[1] = FALSE;
4674 blend_desc.BlendEnable[2] = FALSE;
4675 blend_desc.BlendEnable[3] = FALSE;
4676 blend_desc.BlendEnable[4] = FALSE;
4677 blend_desc.BlendEnable[5] = FALSE;
4678 blend_desc.BlendEnable[6] = FALSE;
4679 blend_desc.BlendEnable[7] = FALSE;
4680 blend_desc.SrcBlend = D3D10_BLEND_ONE;
4681 blend_desc.DestBlend = D3D10_BLEND_ZERO;
4682 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
4683 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
4684 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
4685 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
4686 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
4687 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
4688 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
4689 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
4690 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
4691 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
4692 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
4693 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
4695 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
4696 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4698 ds_desc.DepthEnable = TRUE;
4699 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4700 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4701 ds_desc.StencilEnable = FALSE;
4702 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4703 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4704 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4705 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4706 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4707 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4708 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4709 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4710 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4711 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4713 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
4714 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4716 texture_desc.Width = 512;
4717 texture_desc.Height = 512;
4718 texture_desc.MipLevels = 1;
4719 texture_desc.ArraySize = 1;
4720 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4721 texture_desc.SampleDesc.Count = 1;
4722 texture_desc.SampleDesc.Quality = 0;
4723 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4724 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4725 texture_desc.CPUAccessFlags = 0;
4726 texture_desc.MiscFlags = 0;
4728 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4730 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
4731 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4734 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
4735 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
4737 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
4738 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4740 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4742 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
4743 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4746 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
4747 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
4749 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4751 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
4753 tmp_viewport[i].TopLeftX = i * 3;
4754 tmp_viewport[i].TopLeftY = i * 4;
4755 tmp_viewport[i].Width = 3;
4756 tmp_viewport[i].Height = 4;
4757 tmp_viewport[i].MinDepth = i * 0.01f;
4758 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
4761 rs_desc.FillMode = D3D10_FILL_SOLID;
4762 rs_desc.CullMode = D3D10_CULL_BACK;
4763 rs_desc.FrontCounterClockwise = FALSE;
4764 rs_desc.DepthBias = 0;
4765 rs_desc.DepthBiasClamp = 0.0f;
4766 rs_desc.SlopeScaledDepthBias = 0.0f;
4767 rs_desc.DepthClipEnable = TRUE;
4768 rs_desc.ScissorEnable = FALSE;
4769 rs_desc.MultisampleEnable = FALSE;
4770 rs_desc.AntialiasedLineEnable = FALSE;
4772 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
4773 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4775 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4776 predicate_desc.MiscFlags = 0;
4778 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
4779 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4781 /* Verify the behavior of set state methods. */
4783 blend_factor[0] = 0.1f;
4784 blend_factor[1] = 0.2f;
4785 blend_factor[2] = 0.3f;
4786 blend_factor[3] = 0.4f;
4787 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4788 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4789 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
4790 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
4791 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4792 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4793 ID3D10BlendState_Release(tmp_blend_state);
4795 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
4796 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4797 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
4798 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
4799 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4800 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4801 ID3D10BlendState_Release(tmp_blend_state);
4803 /* Setup state. */
4805 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4806 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4807 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4808 ID3D10Device_VSSetShader(device, vs);
4810 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4811 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4812 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4813 ID3D10Device_GSSetShader(device, gs);
4815 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4816 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4817 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4818 ID3D10Device_PSSetShader(device, ps);
4820 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
4821 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
4822 ID3D10Device_IASetInputLayout(device, input_layout);
4823 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4825 blend_factor[0] = 0.1f;
4826 blend_factor[1] = 0.2f;
4827 blend_factor[2] = 0.3f;
4828 blend_factor[3] = 0.4f;
4829 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
4830 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
4831 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
4833 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
4834 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
4835 ID3D10Device_RSSetState(device, rs_state);
4837 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
4839 ID3D10Device_SetPredication(device, predicate, TRUE);
4841 /* Verify the set state. */
4843 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4844 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4846 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4847 tmp_buffer[i], i, cb[i]);
4848 ID3D10Buffer_Release(tmp_buffer[i]);
4850 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4851 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4853 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4854 tmp_srv[i], i, srv[i]);
4855 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4857 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4858 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4860 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4861 tmp_sampler[i], i, sampler[i]);
4862 ID3D10SamplerState_Release(tmp_sampler[i]);
4864 ID3D10Device_VSGetShader(device, &tmp_vs);
4865 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
4866 ID3D10VertexShader_Release(tmp_vs);
4868 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4869 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4871 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4872 tmp_buffer[i], i, cb[i]);
4873 ID3D10Buffer_Release(tmp_buffer[i]);
4875 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4876 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4878 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4879 tmp_srv[i], i, srv[i]);
4880 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4882 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4883 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4885 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4886 tmp_sampler[i], i, sampler[i]);
4887 ID3D10SamplerState_Release(tmp_sampler[i]);
4889 ID3D10Device_GSGetShader(device, &tmp_gs);
4890 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
4891 ID3D10GeometryShader_Release(tmp_gs);
4893 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4894 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4896 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4897 tmp_buffer[i], i, cb[i]);
4898 ID3D10Buffer_Release(tmp_buffer[i]);
4900 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4901 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4903 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4904 tmp_srv[i], i, srv[i]);
4905 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4907 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4908 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4910 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4911 tmp_sampler[i], i, sampler[i]);
4912 ID3D10SamplerState_Release(tmp_sampler[i]);
4914 ID3D10Device_PSGetShader(device, &tmp_ps);
4915 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
4916 ID3D10PixelShader_Release(tmp_ps);
4918 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4919 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4921 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
4922 tmp_buffer[i], i, buffer[i]);
4923 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
4924 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
4925 ID3D10Buffer_Release(tmp_buffer[i]);
4927 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4928 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
4929 ID3D10Buffer_Release(tmp_buffer[0]);
4930 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
4931 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
4932 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4933 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
4934 tmp_input_layout, input_layout);
4935 ID3D10InputLayout_Release(tmp_input_layout);
4936 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4937 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
4939 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4940 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
4941 ID3D10BlendState_Release(tmp_blend_state);
4942 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
4943 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
4944 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4945 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4946 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
4947 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4948 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
4949 ID3D10DepthStencilState_Release(tmp_ds_state);
4950 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
4951 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4952 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4954 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
4955 tmp_rtv[i], i, rtv[i]);
4956 ID3D10RenderTargetView_Release(tmp_rtv[i]);
4958 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
4959 ID3D10DepthStencilView_Release(tmp_dsv);
4961 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4962 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4963 "Got unexpected scissor rect count %u.\n", count);
4964 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4965 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4966 for (i = 0; i < count; ++i)
4968 ok(tmp_rect[i].left == i
4969 && tmp_rect[i].top == i * 2
4970 && tmp_rect[i].right == i + 1
4971 && tmp_rect[i].bottom == (i + 1) * 2,
4972 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4974 ID3D10Device_RSGetViewports(device, &count, NULL);
4975 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4976 "Got unexpected viewport count %u.\n", count);
4977 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4978 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4979 for (i = 0; i < count; ++i)
4981 ok(tmp_viewport[i].TopLeftX == i * 3
4982 && tmp_viewport[i].TopLeftY == i * 4
4983 && tmp_viewport[i].Width == 3
4984 && tmp_viewport[i].Height == 4
4985 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
4986 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
4987 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4988 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4989 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4991 ID3D10Device_RSGetState(device, &tmp_rs_state);
4992 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
4993 ID3D10RasterizerState_Release(tmp_rs_state);
4995 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4996 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4998 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
4999 tmp_buffer[i], i, so_buffer[i]);
5000 ID3D10Buffer_Release(tmp_buffer[i]);
5001 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5004 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5005 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
5006 ID3D10Predicate_Release(tmp_predicate);
5007 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5009 /* Verify ClearState(). */
5011 ID3D10Device_ClearState(device);
5013 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5014 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5016 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5018 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5019 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5021 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5023 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5024 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5026 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5028 ID3D10Device_VSGetShader(device, &tmp_vs);
5029 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5031 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5032 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5034 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5036 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5037 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5039 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5041 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5042 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5044 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5046 ID3D10Device_GSGetShader(device, &tmp_gs);
5047 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5049 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5050 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5052 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5054 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5055 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5057 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5059 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5060 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5062 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5064 ID3D10Device_PSGetShader(device, &tmp_ps);
5065 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5067 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5068 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5070 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5071 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5072 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5074 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5075 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5076 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5077 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5078 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5079 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5080 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5081 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5083 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5084 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5085 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5086 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5087 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5088 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5089 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5090 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5091 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5092 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5093 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5094 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5096 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5098 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5100 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5101 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
5102 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5103 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5104 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5105 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5107 todo_wine_if(!i)
5108 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5109 "Got unexpected scissor rect %s in slot %u.\n",
5110 wine_dbgstr_rect(&tmp_rect[i]), i);
5112 ID3D10Device_RSGetViewports(device, &count, NULL);
5113 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
5114 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5115 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5116 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5117 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5119 todo_wine_if(!i)
5120 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5121 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5122 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5123 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5124 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5126 ID3D10Device_RSGetState(device, &tmp_rs_state);
5127 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5129 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5130 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5132 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5133 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5136 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5137 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5138 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5140 /* Cleanup. */
5142 ID3D10Predicate_Release(predicate);
5143 ID3D10RasterizerState_Release(rs_state);
5144 ID3D10DepthStencilView_Release(dsv);
5145 ID3D10Texture2D_Release(ds_texture);
5147 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5149 ID3D10RenderTargetView_Release(rtv[i]);
5150 ID3D10Texture2D_Release(rt_texture[i]);
5153 ID3D10DepthStencilState_Release(ds_state);
5154 ID3D10BlendState_Release(blend_state);
5155 ID3D10InputLayout_Release(input_layout);
5156 ID3D10VertexShader_Release(vs);
5157 ID3D10GeometryShader_Release(gs);
5158 ID3D10PixelShader_Release(ps);
5160 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5162 ID3D10SamplerState_Release(sampler[i]);
5165 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5167 ID3D10ShaderResourceView_Release(srv[i]);
5170 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5172 ID3D10Buffer_Release(so_buffer[i]);
5175 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5177 ID3D10Buffer_Release(buffer[i]);
5180 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5182 ID3D10Buffer_Release(cb[i]);
5185 refcount = ID3D10Device_Release(device);
5186 ok(!refcount, "Device has %u references left.\n", refcount);
5189 static void test_blend(void)
5191 struct d3d10core_test_context test_context;
5192 ID3D10BlendState *src_blend, *dst_blend;
5193 ID3D10RenderTargetView *offscreen_rtv;
5194 D3D10_TEXTURE2D_DESC texture_desc;
5195 ID3D10InputLayout *input_layout;
5196 D3D10_BLEND_DESC blend_desc;
5197 unsigned int stride, offset;
5198 ID3D10Texture2D *offscreen;
5199 ID3D10VertexShader *vs;
5200 ID3D10PixelShader *ps;
5201 ID3D10Device *device;
5202 D3D10_VIEWPORT vp;
5203 ID3D10Buffer *vb;
5204 DWORD color;
5205 HRESULT hr;
5207 static const DWORD vs_code[] =
5209 #if 0
5210 struct vs_out
5212 float4 position : SV_POSITION;
5213 float4 color : COLOR;
5216 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5218 struct vs_out o;
5220 o.position = position;
5221 o.color = color;
5223 return o;
5225 #endif
5226 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5227 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5228 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5229 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5230 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5231 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5232 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5233 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5234 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5235 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5237 static const DWORD ps_code[] =
5239 #if 0
5240 struct vs_out
5242 float4 position : SV_POSITION;
5243 float4 color : COLOR;
5246 float4 main(struct vs_out i) : SV_TARGET
5248 return i.color;
5250 #endif
5251 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5252 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5253 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5254 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5255 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5256 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5257 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5258 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5260 static const struct
5262 struct vec3 position;
5263 DWORD diffuse;
5265 quads[] =
5267 /* quad1 */
5268 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5269 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5270 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5271 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5272 /* quad2 */
5273 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5274 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5275 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5276 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5278 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5280 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5281 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
5283 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5284 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5286 if (!init_test_context(&test_context))
5287 return;
5289 device = test_context.device;
5291 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5292 vs_code, sizeof(vs_code), &input_layout);
5293 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5295 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5296 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
5297 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5298 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
5299 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5301 memset(&blend_desc, 0, sizeof(blend_desc));
5302 blend_desc.BlendEnable[0] = TRUE;
5303 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
5304 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
5305 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5306 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
5307 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
5308 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5309 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5311 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
5312 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5314 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
5315 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
5316 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
5317 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
5319 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
5320 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5322 ID3D10Device_IASetInputLayout(device, input_layout);
5323 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5324 stride = sizeof(*quads);
5325 offset = 0;
5326 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
5327 ID3D10Device_VSSetShader(device, vs);
5328 ID3D10Device_PSSetShader(device, ps);
5330 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5332 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5333 ID3D10Device_Draw(device, 4, 0);
5334 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5335 ID3D10Device_Draw(device, 4, 4);
5337 color = get_texture_color(test_context.backbuffer, 320, 360);
5338 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5339 color = get_texture_color(test_context.backbuffer, 320, 120);
5340 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5342 texture_desc.Width = 128;
5343 texture_desc.Height = 128;
5344 texture_desc.MipLevels = 1;
5345 texture_desc.ArraySize = 1;
5346 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5347 texture_desc.SampleDesc.Count = 1;
5348 texture_desc.SampleDesc.Quality = 0;
5349 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5350 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
5351 texture_desc.CPUAccessFlags = 0;
5352 texture_desc.MiscFlags = 0;
5354 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5355 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5357 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
5358 goto done;
5361 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
5362 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5364 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
5366 vp.TopLeftX = 0;
5367 vp.TopLeftY = 0;
5368 vp.Width = 128;
5369 vp.Height = 128;
5370 vp.MinDepth = 0.0f;
5371 vp.MaxDepth = 1.0f;
5372 ID3D10Device_RSSetViewports(device, 1, &vp);
5374 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
5376 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5377 ID3D10Device_Draw(device, 4, 0);
5378 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5379 ID3D10Device_Draw(device, 4, 4);
5381 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5382 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5383 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5384 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5386 ID3D10RenderTargetView_Release(offscreen_rtv);
5387 ID3D10Texture2D_Release(offscreen);
5388 done:
5389 ID3D10BlendState_Release(dst_blend);
5390 ID3D10BlendState_Release(src_blend);
5391 ID3D10PixelShader_Release(ps);
5392 ID3D10VertexShader_Release(vs);
5393 ID3D10Buffer_Release(vb);
5394 ID3D10InputLayout_Release(input_layout);
5395 release_test_context(&test_context);
5398 static void test_texture(void)
5400 struct shader
5402 const DWORD *code;
5403 size_t size;
5405 struct texture
5407 UINT width;
5408 UINT height;
5409 UINT miplevel_count;
5410 UINT array_size;
5411 DXGI_FORMAT format;
5412 D3D10_SUBRESOURCE_DATA data[3];
5415 struct d3d10core_test_context test_context;
5416 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5417 const struct texture *current_texture;
5418 D3D10_TEXTURE2D_DESC texture_desc;
5419 D3D10_SAMPLER_DESC sampler_desc;
5420 const struct shader *current_ps;
5421 ID3D10ShaderResourceView *srv;
5422 ID3D10SamplerState *sampler;
5423 struct resource_readback rb;
5424 ID3D10Texture2D *texture;
5425 struct vec4 ps_constant;
5426 ID3D10PixelShader *ps;
5427 ID3D10Device *device;
5428 unsigned int i, x, y;
5429 ID3D10Buffer *cb;
5430 DWORD color;
5431 HRESULT hr;
5433 static const DWORD ps_ld_code[] =
5435 #if 0
5436 Texture2D t;
5438 float miplevel;
5440 float4 main(float4 position : SV_POSITION) : SV_TARGET
5442 float3 p;
5443 t.GetDimensions(miplevel, p.x, p.y, p.z);
5444 p.z = miplevel;
5445 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5446 return t.Load(int3(p));
5448 #endif
5449 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5450 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5451 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5452 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5453 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5454 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5455 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5456 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5457 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5458 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5459 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5460 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5461 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5462 0x00107e46, 0x00000000, 0x0100003e,
5464 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5465 static const DWORD ps_ld_sint8_code[] =
5467 #if 0
5468 Texture2D<int4> t;
5470 float4 main(float4 position : SV_POSITION) : SV_TARGET
5472 float3 p, s;
5473 int4 c;
5475 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5476 t.GetDimensions(0, s.x, s.y, s.z);
5477 p *= s;
5479 c = t.Load(int3(p));
5480 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5482 #endif
5483 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5484 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5485 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5486 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5487 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5488 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5489 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5490 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5491 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5492 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5493 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5494 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5495 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5496 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5497 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5498 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5499 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5500 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5502 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5503 static const DWORD ps_ld_uint8_code[] =
5505 #if 0
5506 Texture2D<uint4> t;
5508 float4 main(float4 position : SV_POSITION) : SV_TARGET
5510 float3 p, s;
5512 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5513 t.GetDimensions(0, s.x, s.y, s.z);
5514 p *= s;
5516 return t.Load(int3(p)) / (float4)255;
5518 #endif
5519 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5520 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5521 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5522 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5523 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5524 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5525 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5526 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5527 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5528 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5529 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5530 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5531 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5532 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5533 0x3b808081, 0x0100003e,
5535 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5536 static const DWORD ps_sample_code[] =
5538 #if 0
5539 Texture2D t;
5540 SamplerState s;
5542 float4 main(float4 position : SV_POSITION) : SV_Target
5544 float2 p;
5546 p.x = position.x / 640.0f;
5547 p.y = position.y / 480.0f;
5548 return t.Sample(s, p);
5550 #endif
5551 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5552 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5553 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5554 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5555 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5556 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5557 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5558 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5559 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5560 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5562 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5563 static const DWORD ps_sample_b_code[] =
5565 #if 0
5566 Texture2D t;
5567 SamplerState s;
5569 float bias;
5571 float4 main(float4 position : SV_POSITION) : SV_Target
5573 float2 p;
5575 p.x = position.x / 640.0f;
5576 p.y = position.y / 480.0f;
5577 return t.SampleBias(s, p, bias);
5579 #endif
5580 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5581 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5582 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5583 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5584 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5585 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5586 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5587 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5588 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5589 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5590 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5592 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5593 static const DWORD ps_sample_l_code[] =
5595 #if 0
5596 Texture2D t;
5597 SamplerState s;
5599 float level;
5601 float4 main(float4 position : SV_POSITION) : SV_Target
5603 float2 p;
5605 p.x = position.x / 640.0f;
5606 p.y = position.y / 480.0f;
5607 return t.SampleLevel(s, p, level);
5609 #endif
5610 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5611 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5612 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5613 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5614 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5615 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5616 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5617 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5618 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5619 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5620 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5622 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5623 static const DWORD ps_sample_2d_array_code[] =
5625 #if 0
5626 Texture2DArray t;
5627 SamplerState s;
5629 float layer;
5631 float4 main(float4 position : SV_POSITION) : SV_TARGET
5633 float3 d;
5634 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5635 t.GetDimensions(d.x, d.y, d.z);
5636 d.z = layer;
5637 return t.Sample(s, p * d);
5639 #endif
5640 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5641 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5642 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5643 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5644 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5645 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5646 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5647 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5648 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5649 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5650 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5651 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5652 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5654 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5655 static const DWORD red_data[] =
5657 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5658 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5659 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5660 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5662 static const DWORD green_data[] =
5664 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5665 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5666 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5667 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5669 static const DWORD blue_data[] =
5671 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5672 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5673 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5674 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5676 static const DWORD rgba_level_0[] =
5678 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5679 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5680 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5681 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5683 static const DWORD rgba_level_1[] =
5685 0xffffffff, 0xff0000ff,
5686 0xff000000, 0xff00ff00,
5688 static const DWORD rgba_level_2[] =
5690 0xffff0000,
5692 static const DWORD srgb_data[] =
5694 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5695 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5696 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5697 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5699 static const BYTE a8_data[] =
5701 0x00, 0x10, 0x20, 0x30,
5702 0x40, 0x50, 0x60, 0x70,
5703 0x80, 0x90, 0xa0, 0xb0,
5704 0xc0, 0xd0, 0xe0, 0xf0,
5706 static const BYTE bc1_data[] =
5708 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5709 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5710 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5711 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5713 static const BYTE bc2_data[] =
5715 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5716 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5717 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5718 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5720 static const BYTE bc3_data[] =
5722 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5723 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5724 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5725 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5727 static const BYTE bc4_data[] =
5729 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5730 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5731 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5732 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5734 static const BYTE bc5_data[] =
5736 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5737 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5738 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5739 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5741 static const float r32_float[] =
5743 0.0f, 1.0f, 0.5f, 0.50f,
5744 1.0f, 0.0f, 0.0f, 0.75f,
5745 0.0f, 1.0f, 0.5f, 0.25f,
5746 1.0f, 0.0f, 0.0f, 0.75f,
5748 static const DWORD r32_uint[] =
5750 0, 1, 2, 3,
5751 100, 200, 255, 128,
5752 40, 30, 20, 10,
5753 250, 210, 155, 190,
5755 static const DWORD r9g9b9e5_data[] =
5757 0x80000100, 0x80020000, 0x84000000, 0x84000100,
5758 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
5759 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
5760 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
5762 static const struct texture rgba_texture =
5764 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5766 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5767 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5768 {rgba_level_2, sizeof(*rgba_level_2), 0},
5771 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5772 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5773 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5774 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5775 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5776 {{a8_data, 4 * sizeof(*a8_data)}}};
5777 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5778 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5779 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5780 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5781 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5782 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5783 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5784 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5785 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5786 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5787 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5788 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5789 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5790 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5791 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5792 static const struct texture array_2d_texture =
5794 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5796 {red_data, 6 * sizeof(*red_data)},
5797 {green_data, 4 * sizeof(*green_data)},
5798 {blue_data, 5 * sizeof(*blue_data)},
5801 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5802 {{r32_float, 4 * sizeof(*r32_float)}}};
5803 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5804 {{r32_uint, 4 * sizeof(*r32_uint)}}};
5805 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
5806 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
5807 static const DWORD red_colors[] =
5809 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5810 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5811 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5812 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5814 static const DWORD blue_colors[] =
5816 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5817 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5818 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5819 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5821 static const DWORD level_1_colors[] =
5823 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5824 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5825 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5826 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5828 static const DWORD lerp_1_2_colors[] =
5830 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5831 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5832 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5833 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5835 static const DWORD level_2_colors[] =
5837 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5838 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5839 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5840 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5842 static const DWORD srgb_colors[] =
5844 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5845 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5846 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5847 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5849 static const DWORD a8_colors[] =
5851 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5852 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5853 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5854 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5856 static const DWORD bc_colors[] =
5858 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5859 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5860 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5861 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5863 static const DWORD bc4_colors[] =
5865 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5866 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5867 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5868 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5870 static const DWORD bc5_colors[] =
5872 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5873 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5874 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5875 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5877 static const DWORD sint8_colors[] =
5879 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5880 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5881 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5882 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5884 static const DWORD r32f_colors[] =
5886 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
5887 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
5888 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
5889 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
5891 static const DWORD r32u_colors[16] =
5893 0x01000000, 0x01000001, 0x01000002, 0x01000003,
5894 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
5895 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
5896 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
5898 static const DWORD r9g9b9e5_colors[16] =
5900 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
5901 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
5902 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
5903 0xff000033, 0xff003300, 0xff330000, 0xff333333,
5905 static const DWORD zero_colors[4 * 4] = {0};
5906 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5908 static const struct texture_test
5910 const struct shader *ps;
5911 const struct texture *texture;
5912 D3D10_FILTER filter;
5913 float lod_bias;
5914 float min_lod;
5915 float max_lod;
5916 float ps_constant;
5917 const DWORD *expected_colors;
5919 texture_tests[] =
5921 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
5922 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
5923 #define MIP_MAX D3D10_FLOAT32_MAX
5924 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5925 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5926 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5927 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5928 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5929 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5930 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5931 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5932 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5933 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5934 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5935 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5936 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5937 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5938 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5939 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5940 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
5941 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5942 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5943 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5944 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5945 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5946 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5947 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5948 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5949 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5950 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5951 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5952 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5953 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5954 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5955 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5956 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
5957 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5958 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5959 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5960 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5961 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5962 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5963 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5964 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5965 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5966 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5967 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5968 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5969 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5970 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5971 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5972 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5973 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5974 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5975 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5976 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5977 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5978 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5979 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5980 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5981 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5982 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5983 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5984 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5985 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5986 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5987 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5988 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5989 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5990 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5991 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5992 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5993 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5994 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5995 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5996 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5997 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5998 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5999 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6000 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6001 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6002 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6003 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6004 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6005 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6006 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6007 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6008 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6009 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6010 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6011 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6012 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6013 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6014 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6015 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6016 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6017 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6018 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6019 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6020 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6021 #undef POINT
6022 #undef POINT_LINEAR
6023 #undef MIP_MAX
6025 static const struct srv_test
6027 const struct shader *ps;
6028 const struct texture *texture;
6029 struct srv_desc srv_desc;
6030 float ps_constant;
6031 const DWORD *expected_colors;
6033 srv_tests[] =
6035 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
6036 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
6037 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6038 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6039 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6040 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6041 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6042 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6043 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6044 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6045 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6046 #define R32_UINT DXGI_FORMAT_R32_UINT
6047 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6048 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6049 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6050 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6051 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6052 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6053 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6054 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6055 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6056 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6057 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6058 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6059 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6060 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6061 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6062 #undef TEX_2D
6063 #undef TEX_2D_ARRAY
6064 #undef BC1_UNORM
6065 #undef BC1_UNORM_SRGB
6066 #undef BC2_UNORM
6067 #undef BC2_UNORM_SRGB
6068 #undef BC3_UNORM
6069 #undef BC3_UNORM_SRGB
6070 #undef R8G8B8A8_UNORM_SRGB
6071 #undef R8G8B8A8_UNORM
6072 #undef R32_FLOAT
6073 #undef R32_UINT
6074 #undef FMT_UNKNOWN
6077 if (!init_test_context(&test_context))
6078 return;
6080 device = test_context.device;
6082 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6084 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6086 texture_desc.SampleDesc.Count = 1;
6087 texture_desc.SampleDesc.Quality = 0;
6088 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6089 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6090 texture_desc.CPUAccessFlags = 0;
6091 texture_desc.MiscFlags = 0;
6093 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6094 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6095 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6096 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6097 sampler_desc.MipLODBias = 0.0f;
6098 sampler_desc.MaxAnisotropy = 0;
6099 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6100 sampler_desc.BorderColor[0] = 0.0f;
6101 sampler_desc.BorderColor[1] = 0.0f;
6102 sampler_desc.BorderColor[2] = 0.0f;
6103 sampler_desc.BorderColor[3] = 0.0f;
6104 sampler_desc.MinLOD = 0.0f;
6105 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6107 ps = NULL;
6108 srv = NULL;
6109 sampler = NULL;
6110 texture = NULL;
6111 current_ps = NULL;
6112 current_texture = NULL;
6113 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6115 const struct texture_test *test = &texture_tests[i];
6117 if (current_ps != test->ps)
6119 if (ps)
6120 ID3D10PixelShader_Release(ps);
6122 current_ps = test->ps;
6124 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6125 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6127 ID3D10Device_PSSetShader(device, ps);
6130 if (current_texture != test->texture)
6132 if (texture)
6133 ID3D10Texture2D_Release(texture);
6134 if (srv)
6135 ID3D10ShaderResourceView_Release(srv);
6137 current_texture = test->texture;
6139 if (current_texture)
6141 texture_desc.Width = current_texture->width;
6142 texture_desc.Height = current_texture->height;
6143 texture_desc.MipLevels = current_texture->miplevel_count;
6144 texture_desc.ArraySize = current_texture->array_size;
6145 texture_desc.Format = current_texture->format;
6147 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6148 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6150 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
6151 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6153 else
6155 texture = NULL;
6156 srv = NULL;
6159 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6162 if (!sampler || (sampler_desc.Filter != test->filter
6163 || sampler_desc.MipLODBias != test->lod_bias
6164 || sampler_desc.MinLOD != test->min_lod
6165 || sampler_desc.MaxLOD != test->max_lod))
6167 if (sampler)
6168 ID3D10SamplerState_Release(sampler);
6170 sampler_desc.Filter = test->filter;
6171 sampler_desc.MipLODBias = test->lod_bias;
6172 sampler_desc.MinLOD = test->min_lod;
6173 sampler_desc.MaxLOD = test->max_lod;
6175 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6176 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6178 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6181 ps_constant.x = test->ps_constant;
6182 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6184 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6186 draw_quad(&test_context);
6188 get_texture_readback(test_context.backbuffer, 0, &rb);
6189 for (y = 0; y < 4; ++y)
6191 for (x = 0; x < 4; ++x)
6193 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6194 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6195 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6198 release_resource_readback(&rb);
6200 if (srv)
6201 ID3D10ShaderResourceView_Release(srv);
6202 ID3D10SamplerState_Release(sampler);
6203 if (texture)
6204 ID3D10Texture2D_Release(texture);
6205 ID3D10PixelShader_Release(ps);
6207 if (is_warp_device(device) && !is_d3d11_interface_available(device))
6209 win_skip("SRV tests are broken on WARP.\n");
6210 ID3D10Buffer_Release(cb);
6211 release_test_context(&test_context);
6212 return;
6215 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6216 sampler_desc.MipLODBias = 0.0f;
6217 sampler_desc.MinLOD = 0.0f;
6218 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6220 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6221 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6223 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6225 ps = NULL;
6226 srv = NULL;
6227 texture = NULL;
6228 current_ps = NULL;
6229 current_texture = NULL;
6230 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6232 const struct srv_test *test = &srv_tests[i];
6234 if (current_ps != test->ps)
6236 if (ps)
6237 ID3D10PixelShader_Release(ps);
6239 current_ps = test->ps;
6241 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6242 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6244 ID3D10Device_PSSetShader(device, ps);
6247 if (current_texture != test->texture)
6249 if (texture)
6250 ID3D10Texture2D_Release(texture);
6252 current_texture = test->texture;
6254 texture_desc.Width = current_texture->width;
6255 texture_desc.Height = current_texture->height;
6256 texture_desc.MipLevels = current_texture->miplevel_count;
6257 texture_desc.ArraySize = current_texture->array_size;
6258 texture_desc.Format = current_texture->format;
6260 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6261 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6264 if (srv)
6265 ID3D10ShaderResourceView_Release(srv);
6267 get_srv_desc(&srv_desc, &test->srv_desc);
6268 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
6269 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6271 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6273 ps_constant.x = test->ps_constant;
6274 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6276 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6278 draw_quad(&test_context);
6280 get_texture_readback(test_context.backbuffer, 0, &rb);
6281 for (y = 0; y < 4; ++y)
6283 for (x = 0; x < 4; ++x)
6285 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6286 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6287 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6290 release_resource_readback(&rb);
6292 ID3D10PixelShader_Release(ps);
6293 ID3D10Texture2D_Release(texture);
6294 ID3D10ShaderResourceView_Release(srv);
6295 ID3D10SamplerState_Release(sampler);
6297 ID3D10Buffer_Release(cb);
6298 release_test_context(&test_context);
6301 static void test_cube_maps(void)
6303 unsigned int i, j, sub_resource_idx, sub_resource_count;
6304 struct d3d10core_test_context test_context;
6305 D3D10_TEXTURE2D_DESC texture_desc;
6306 ID3D10ShaderResourceView *srv;
6307 ID3D10Texture2D *rtv_texture;
6308 ID3D10RenderTargetView *rtv;
6309 struct vec4 expected_result;
6310 ID3D10Resource *texture;
6311 ID3D10PixelShader *ps;
6312 ID3D10Device *device;
6313 float data[64 * 64];
6314 ID3D10Buffer *cb;
6315 HRESULT hr;
6316 RECT rect;
6317 struct
6319 unsigned int face;
6320 unsigned int level;
6321 unsigned int padding[2];
6322 } constant;
6324 static const DWORD ps_cube_code[] =
6326 #if 0
6327 TextureCube t;
6328 SamplerState s;
6330 uint face;
6331 uint level;
6333 float4 main(float4 position : SV_POSITION) : SV_Target
6335 float2 p;
6336 p.x = position.x / 640.0f;
6337 p.y = position.y / 480.0f;
6339 float3 coord;
6340 switch (face)
6342 case 0:
6343 coord = float3(1.0f, p.x, p.y);
6344 break;
6345 case 1:
6346 coord = float3(-1.0f, p.x, p.y);
6347 break;
6348 case 2:
6349 coord = float3(p.x, 1.0f, p.y);
6350 break;
6351 case 3:
6352 coord = float3(p.x, -1.0f, p.y);
6353 break;
6354 case 4:
6355 coord = float3(p.x, p.y, 1.0f);
6356 break;
6357 case 5:
6358 default:
6359 coord = float3(p.x, p.y, -1.0f);
6360 break;
6362 return t.SampleLevel(s, coord, level);
6364 #endif
6365 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6366 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6367 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6368 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6369 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6370 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6371 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6372 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6373 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6374 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6375 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6376 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6377 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6378 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6379 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6380 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6381 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6382 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6383 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6384 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6385 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6386 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6387 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6388 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6389 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6391 static const struct test
6393 unsigned int miplevel_count;
6394 unsigned int array_size;
6396 tests[] =
6398 {1, 6},
6399 {2, 6},
6400 {3, 6},
6401 {0, 0},
6404 if (!init_test_context(&test_context))
6405 return;
6407 device = test_context.device;
6409 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6410 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6411 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6412 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6413 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
6414 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6416 memset(&constant, 0, sizeof(constant));
6417 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6419 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
6420 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6422 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
6423 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6424 ID3D10Device_PSSetShader(device, ps);
6426 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6428 const struct test *test = &tests[i];
6430 if (!test->miplevel_count)
6432 srv = NULL;
6433 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6435 memset(&expected_result, 0, sizeof(expected_result));
6437 memset(&constant, 0, sizeof(constant));
6438 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
6439 draw_quad(&test_context);
6440 check_texture_vec4(rtv_texture, &expected_result, 0);
6441 constant.level = 1;
6442 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
6443 draw_quad(&test_context);
6444 check_texture_vec4(rtv_texture, &expected_result, 0);
6445 continue;
6448 texture_desc.Width = 64;
6449 texture_desc.Height = 64;
6450 texture_desc.MipLevels = test->miplevel_count;
6451 texture_desc.ArraySize = test->array_size;
6452 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6453 texture_desc.SampleDesc.Count = 1;
6454 texture_desc.SampleDesc.Quality = 0;
6455 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6456 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6457 texture_desc.CPUAccessFlags = 0;
6458 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
6459 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
6460 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6462 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
6463 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6464 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6466 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6467 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6469 for (j = 0; j < ARRAY_SIZE(data); ++j)
6470 data[j] = sub_resource_idx;
6471 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, sub_resource_idx, NULL,
6472 data, texture_desc.Width * sizeof(*data), 0);
6475 expected_result.y = expected_result.z = 0.0f;
6476 expected_result.w = 1.0f;
6477 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6479 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
6480 constant.level = sub_resource_idx % texture_desc.MipLevels;
6481 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
6483 draw_quad(&test_context);
6484 expected_result.x = sub_resource_idx;
6485 /* Avoid testing values affected by seamless cube map filtering. */
6486 SetRect(&rect, 100, 100, 540, 380);
6487 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
6490 ID3D10Resource_Release(texture);
6491 ID3D10ShaderResourceView_Release(srv);
6494 ID3D10Buffer_Release(cb);
6495 ID3D10PixelShader_Release(ps);
6496 ID3D10RenderTargetView_Release(rtv);
6497 ID3D10Texture2D_Release(rtv_texture);
6498 release_test_context(&test_context);
6501 static void test_depth_stencil_sampling(void)
6503 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6504 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
6505 struct d3d10core_test_context test_context;
6506 ID3D10SamplerState *cmp_sampler, *sampler;
6507 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6508 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6509 ID3D10Texture2D *texture, *rt_texture;
6510 D3D10_TEXTURE2D_DESC texture_desc;
6511 D3D10_SAMPLER_DESC sampler_desc;
6512 ID3D10DepthStencilView *dsv;
6513 ID3D10RenderTargetView *rtv;
6514 struct vec4 ps_constant;
6515 ID3D10Device *device;
6516 ID3D10Buffer *cb;
6517 unsigned int i;
6518 HRESULT hr;
6520 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6521 static const DWORD ps_compare_code[] =
6523 #if 0
6524 Texture2D t;
6525 SamplerComparisonState s;
6527 float ref;
6529 float4 main(float4 position : SV_Position) : SV_Target
6531 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
6533 #endif
6534 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
6535 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6536 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6537 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6538 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
6539 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
6540 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6541 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6542 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
6543 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
6544 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
6545 0x0100003e,
6547 static const DWORD ps_sample_code[] =
6549 #if 0
6550 Texture2D t;
6551 SamplerState s;
6553 float4 main(float4 position : SV_Position) : SV_Target
6555 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
6557 #endif
6558 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
6559 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6560 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6561 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6562 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6563 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6564 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6565 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6566 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6567 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6569 static const DWORD ps_stencil_code[] =
6571 #if 0
6572 Texture2D<uint4> t;
6574 float4 main(float4 position : SV_Position) : SV_Target
6576 float2 s;
6577 t.GetDimensions(s.x, s.y);
6578 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
6580 #endif
6581 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
6582 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6583 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6584 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6585 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
6586 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6587 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
6588 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
6589 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
6590 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
6591 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
6592 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6593 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
6595 static const DWORD ps_depth_stencil_code[] =
6597 #if 0
6598 SamplerState samp;
6599 Texture2D depth_tex;
6600 Texture2D<uint4> stencil_tex;
6602 float main(float4 position: SV_Position) : SV_Target
6604 float2 s, p;
6605 float depth, stencil;
6606 depth_tex.GetDimensions(s.x, s.y);
6607 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
6608 depth = depth_tex.Sample(samp, p).r;
6609 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
6610 return depth + stencil;
6612 #endif
6613 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
6614 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6615 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6616 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6617 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
6618 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6619 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6620 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
6621 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
6622 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
6623 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
6624 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
6625 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
6626 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
6627 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
6628 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
6630 static const struct test
6632 DXGI_FORMAT typeless_format;
6633 DXGI_FORMAT dsv_format;
6634 DXGI_FORMAT depth_view_format;
6635 DXGI_FORMAT stencil_view_format;
6637 tests[] =
6639 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
6640 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
6641 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
6642 DXGI_FORMAT_R32_FLOAT},
6643 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
6644 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
6645 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
6646 DXGI_FORMAT_R16_UNORM},
6649 if (!init_test_context(&test_context))
6650 return;
6652 device = test_context.device;
6654 if (is_amd_device(device))
6656 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
6657 win_skip("Some AMD drivers have a bug affecting the test.\n");
6658 release_test_context(&test_context);
6659 return;
6662 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
6663 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6664 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6665 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6666 sampler_desc.MipLODBias = 0.0f;
6667 sampler_desc.MaxAnisotropy = 0;
6668 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
6669 sampler_desc.BorderColor[0] = 0.0f;
6670 sampler_desc.BorderColor[1] = 0.0f;
6671 sampler_desc.BorderColor[2] = 0.0f;
6672 sampler_desc.BorderColor[3] = 0.0f;
6673 sampler_desc.MinLOD = 0.0f;
6674 sampler_desc.MaxLOD = 0.0f;
6675 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
6676 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6678 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6679 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6680 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6681 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6683 texture_desc.Width = 640;
6684 texture_desc.Height = 480;
6685 texture_desc.MipLevels = 1;
6686 texture_desc.ArraySize = 1;
6687 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6688 texture_desc.SampleDesc.Count = 1;
6689 texture_desc.SampleDesc.Quality = 0;
6690 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6691 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6692 texture_desc.CPUAccessFlags = 0;
6693 texture_desc.MiscFlags = 0;
6694 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
6695 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6696 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
6697 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6698 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
6700 memset(&ps_constant, 0, sizeof(ps_constant));
6701 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
6702 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6704 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
6705 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6706 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
6707 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6708 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
6709 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6710 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
6711 &ps_depth_stencil);
6712 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6714 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6716 texture_desc.Format = tests[i].typeless_format;
6717 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
6718 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6719 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
6720 texture_desc.Format, hr);
6722 dsv_desc.Format = tests[i].dsv_format;
6723 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
6724 U(dsv_desc).Texture2D.MipSlice = 0;
6725 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
6726 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
6727 dsv_desc.Format, hr);
6729 srv_desc.Format = tests[i].depth_view_format;
6730 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
6731 U(srv_desc).Texture2D.MostDetailedMip = 0;
6732 U(srv_desc).Texture2D.MipLevels = 1;
6733 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
6734 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
6735 srv_desc.Format, hr);
6737 ID3D10Device_PSSetShader(device, ps_cmp);
6738 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
6739 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
6741 ps_constant.x = 0.5f;
6742 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
6743 NULL, &ps_constant, 0, 0);
6745 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
6746 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6747 draw_quad(&test_context);
6748 check_texture_float(rt_texture, 0.0f, 2);
6750 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
6751 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6752 draw_quad(&test_context);
6753 check_texture_float(rt_texture, 1.0f, 2);
6755 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
6756 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6757 draw_quad(&test_context);
6758 check_texture_float(rt_texture, 0.0f, 2);
6760 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
6761 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6762 draw_quad(&test_context);
6763 check_texture_float(rt_texture, 0.0f, 2);
6765 ps_constant.x = 0.7f;
6766 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
6767 NULL, &ps_constant, 0, 0);
6769 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6770 draw_quad(&test_context);
6771 check_texture_float(rt_texture, 1.0f, 2);
6773 ID3D10Device_PSSetShader(device, ps_depth);
6774 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6776 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
6777 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6778 draw_quad(&test_context);
6779 check_texture_float(rt_texture, 1.0f, 2);
6781 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
6782 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6783 draw_quad(&test_context);
6784 check_texture_float(rt_texture, 0.2f, 2);
6786 if (!tests[i].stencil_view_format)
6788 ID3D10DepthStencilView_Release(dsv);
6789 ID3D10ShaderResourceView_Release(depth_srv);
6790 ID3D10Texture2D_Release(texture);
6791 continue;
6794 srv_desc.Format = tests[i].stencil_view_format;
6795 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
6796 if (hr == E_OUTOFMEMORY)
6798 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
6799 ID3D10DepthStencilView_Release(dsv);
6800 ID3D10ShaderResourceView_Release(depth_srv);
6801 ID3D10Texture2D_Release(texture);
6802 continue;
6804 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
6805 srv_desc.Format, hr);
6807 ID3D10Device_PSSetShader(device, ps_stencil);
6808 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
6810 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
6811 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6812 draw_quad(&test_context);
6813 check_texture_float(rt_texture, 0.0f, 0);
6815 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
6816 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6817 draw_quad(&test_context);
6818 check_texture_float(rt_texture, 100.0f, 0);
6820 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
6821 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6822 draw_quad(&test_context);
6823 check_texture_float(rt_texture, 255.0f, 0);
6825 ID3D10Device_PSSetShader(device, ps_depth_stencil);
6826 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
6827 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
6829 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
6830 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6831 draw_quad(&test_context);
6832 check_texture_float(rt_texture, 3.3f, 2);
6834 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
6835 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6836 draw_quad(&test_context);
6837 check_texture_float(rt_texture, 4.0f, 2);
6839 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
6840 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6841 draw_quad(&test_context);
6842 check_texture_float(rt_texture, 0.0f, 2);
6844 ID3D10DepthStencilView_Release(dsv);
6845 ID3D10ShaderResourceView_Release(depth_srv);
6846 ID3D10ShaderResourceView_Release(stencil_srv);
6847 ID3D10Texture2D_Release(texture);
6850 ID3D10Buffer_Release(cb);
6851 ID3D10PixelShader_Release(ps_cmp);
6852 ID3D10PixelShader_Release(ps_depth);
6853 ID3D10PixelShader_Release(ps_depth_stencil);
6854 ID3D10PixelShader_Release(ps_stencil);
6855 ID3D10RenderTargetView_Release(rtv);
6856 ID3D10SamplerState_Release(cmp_sampler);
6857 ID3D10SamplerState_Release(sampler);
6858 ID3D10Texture2D_Release(rt_texture);
6859 release_test_context(&test_context);
6862 static void test_multiple_render_targets(void)
6864 D3D10_TEXTURE2D_DESC texture_desc;
6865 ID3D10InputLayout *input_layout;
6866 unsigned int stride, offset, i;
6867 ID3D10RenderTargetView *rtv[4];
6868 ID3D10Texture2D *rt[4];
6869 ID3D10VertexShader *vs;
6870 ID3D10PixelShader *ps;
6871 ID3D10Device *device;
6872 D3D10_VIEWPORT vp;
6873 ID3D10Buffer *vb;
6874 ULONG refcount;
6875 HRESULT hr;
6877 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6879 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6881 static const DWORD vs_code[] =
6883 #if 0
6884 float4 main(float4 position : POSITION) : SV_POSITION
6886 return position;
6888 #endif
6889 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6890 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6891 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6892 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6893 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6894 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6895 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6897 static const DWORD ps_code[] =
6899 #if 0
6900 struct output
6902 float4 t1 : SV_TARGET0;
6903 float4 t2 : SV_Target1;
6904 float4 t3 : SV_TARGET2;
6905 float4 t4 : SV_Target3;
6908 output main(float4 position : SV_POSITION)
6910 struct output o;
6911 o.t1 = (float4)1.0f;
6912 o.t2 = (float4)0.5f;
6913 o.t3 = (float4)0.2f;
6914 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6915 return o;
6917 #endif
6918 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6919 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6920 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6921 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6922 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6923 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6924 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6925 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6926 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6927 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6928 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6929 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6930 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6931 0x3f800000, 0x0100003e,
6933 static const struct vec2 quad[] =
6935 {-1.0f, -1.0f},
6936 {-1.0f, 1.0f},
6937 { 1.0f, -1.0f},
6938 { 1.0f, 1.0f},
6940 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6942 if (!(device = create_device()))
6944 skip("Failed to create device.\n");
6945 return;
6948 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6949 vs_code, sizeof(vs_code), &input_layout);
6950 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6952 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6954 texture_desc.Width = 640;
6955 texture_desc.Height = 480;
6956 texture_desc.MipLevels = 1;
6957 texture_desc.ArraySize = 1;
6958 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6959 texture_desc.SampleDesc.Count = 1;
6960 texture_desc.SampleDesc.Quality = 0;
6961 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6962 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6963 texture_desc.CPUAccessFlags = 0;
6964 texture_desc.MiscFlags = 0;
6966 for (i = 0; i < ARRAY_SIZE(rt); ++i)
6968 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6969 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6971 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
6972 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6975 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6976 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6977 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6978 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6980 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
6981 ID3D10Device_IASetInputLayout(device, input_layout);
6982 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6983 stride = sizeof(*quad);
6984 offset = 0;
6985 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6986 ID3D10Device_VSSetShader(device, vs);
6987 ID3D10Device_PSSetShader(device, ps);
6989 vp.TopLeftX = 0;
6990 vp.TopLeftY = 0;
6991 vp.Width = 640;
6992 vp.Height = 480;
6993 vp.MinDepth = 0.0f;
6994 vp.MaxDepth = 1.0f;
6995 ID3D10Device_RSSetViewports(device, 1, &vp);
6997 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
6998 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
7000 ID3D10Device_Draw(device, 4, 0);
7002 check_texture_color(rt[0], 0xffffffff, 2);
7003 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7004 check_texture_color(rt[2], 0x33333333, 2);
7005 check_texture_color(rt[3], 0xff7f3300, 2);
7007 ID3D10Buffer_Release(vb);
7008 ID3D10PixelShader_Release(ps);
7009 ID3D10VertexShader_Release(vs);
7010 ID3D10InputLayout_Release(input_layout);
7011 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7012 ID3D10RenderTargetView_Release(rtv[i]);
7013 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7014 ID3D10Texture2D_Release(rt[i]);
7015 refcount = ID3D10Device_Release(device);
7016 ok(!refcount, "Device has %u references left.\n", refcount);
7019 static void test_private_data(void)
7021 D3D10_TEXTURE2D_DESC texture_desc;
7022 ULONG refcount, expected_refcount;
7023 ID3D11Texture2D *d3d11_texture;
7024 ID3D11Device *d3d11_device;
7025 ID3D10Device *test_object;
7026 ID3D10Texture2D *texture;
7027 IDXGIDevice *dxgi_device;
7028 IDXGISurface *surface;
7029 ID3D10Device *device;
7030 IUnknown *ptr;
7031 HRESULT hr;
7032 UINT size;
7034 static const GUID test_guid =
7035 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
7036 static const GUID test_guid2 =
7037 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
7038 static const DWORD data[] = {1, 2, 3, 4};
7040 if (!(device = create_device()))
7042 skip("Failed to create device, skipping tests.\n");
7043 return;
7046 test_object = create_device();
7048 texture_desc.Width = 512;
7049 texture_desc.Height = 512;
7050 texture_desc.MipLevels = 1;
7051 texture_desc.ArraySize = 1;
7052 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7053 texture_desc.SampleDesc.Count = 1;
7054 texture_desc.SampleDesc.Quality = 0;
7055 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7056 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7057 texture_desc.CPUAccessFlags = 0;
7058 texture_desc.MiscFlags = 0;
7060 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7061 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7062 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
7063 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
7065 /* SetPrivateData() with a pointer of NULL has the purpose of
7066 * FreePrivateData() in previous D3D versions. A successful clear returns
7067 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
7068 * considered a clear but as setting an interface pointer that happens to
7069 * be NULL. */
7070 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
7071 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7072 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7073 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7074 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
7075 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7076 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
7077 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7079 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7080 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7081 size = sizeof(ptr) * 2;
7082 ptr = (IUnknown *)0xdeadbeef;
7083 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
7084 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7085 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
7086 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
7088 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7089 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
7090 size = sizeof(ptr) * 2;
7091 ptr = (IUnknown *)0xdeadbeef;
7092 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
7093 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7094 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
7095 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
7096 IDXGIDevice_Release(dxgi_device);
7098 refcount = get_refcount(test_object);
7099 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7100 (IUnknown *)test_object);
7101 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7102 expected_refcount = refcount + 1;
7103 refcount = get_refcount(test_object);
7104 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7105 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7106 (IUnknown *)test_object);
7107 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7108 refcount = get_refcount(test_object);
7109 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7111 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7112 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7113 --expected_refcount;
7114 refcount = get_refcount(test_object);
7115 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7117 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7118 (IUnknown *)test_object);
7119 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7120 size = sizeof(data);
7121 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
7122 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7123 refcount = get_refcount(test_object);
7124 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7125 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
7126 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7127 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
7128 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7130 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7131 (IUnknown *)test_object);
7132 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7133 ++expected_refcount;
7134 size = 2 * sizeof(ptr);
7135 ptr = NULL;
7136 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
7137 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7138 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
7139 ++expected_refcount;
7140 refcount = get_refcount(test_object);
7141 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7142 IUnknown_Release(ptr);
7143 --expected_refcount;
7145 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
7146 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
7147 "Device should implement ID3D11Device.\n");
7148 if (SUCCEEDED(hr))
7150 ptr = NULL;
7151 size = sizeof(ptr);
7152 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
7153 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7154 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
7155 IUnknown_Release(ptr);
7156 ID3D11Device_Release(d3d11_device);
7157 refcount = get_refcount(test_object);
7158 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
7159 refcount, expected_refcount);
7162 ptr = (IUnknown *)0xdeadbeef;
7163 size = 1;
7164 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
7165 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7166 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
7167 size = 2 * sizeof(ptr);
7168 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
7169 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7170 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
7171 refcount = get_refcount(test_object);
7172 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7174 size = 1;
7175 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
7176 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
7177 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
7178 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7179 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
7180 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7181 size = 0xdeadbabe;
7182 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
7183 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
7184 ok(size == 0, "Got unexpected size %u.\n", size);
7185 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7186 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
7187 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7188 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7190 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
7191 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7192 ptr = NULL;
7193 size = sizeof(ptr);
7194 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
7195 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7196 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
7197 IUnknown_Release(ptr);
7199 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
7200 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
7201 "Texture should implement ID3D11Texture2D.\n");
7202 if (SUCCEEDED(hr))
7204 ptr = NULL;
7205 size = sizeof(ptr);
7206 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
7207 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7208 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
7209 IUnknown_Release(ptr);
7210 ID3D11Texture2D_Release(d3d11_texture);
7213 IDXGISurface_Release(surface);
7214 ID3D10Texture2D_Release(texture);
7215 refcount = ID3D10Device_Release(device);
7216 ok(!refcount, "Device has %u references left.\n", refcount);
7217 refcount = ID3D10Device_Release(test_object);
7218 ok(!refcount, "Test object has %u references left.\n", refcount);
7221 static void test_il_append_aligned(void)
7223 struct d3d10core_test_context test_context;
7224 ID3D10InputLayout *input_layout;
7225 unsigned int stride, offset;
7226 ID3D10VertexShader *vs;
7227 ID3D10PixelShader *ps;
7228 ID3D10Device *device;
7229 ID3D10Buffer *vb[3];
7230 DWORD color;
7231 HRESULT hr;
7233 /* Semantic names are case-insensitive. */
7234 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7236 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
7237 D3D10_INPUT_PER_INSTANCE_DATA, 2},
7238 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
7239 D3D10_INPUT_PER_INSTANCE_DATA, 1},
7240 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
7241 D3D10_INPUT_PER_VERTEX_DATA, 0},
7242 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
7243 D3D10_INPUT_PER_INSTANCE_DATA, 1},
7244 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
7245 D3D10_INPUT_PER_INSTANCE_DATA, 2},
7247 static const DWORD vs_code[] =
7249 #if 0
7250 struct vs_in
7252 float4 position : POSITION;
7253 float2 color_xy : COLOR0;
7254 float2 color_zw : COLOR1;
7255 unsigned int instance_id : SV_INSTANCEID;
7258 struct vs_out
7260 float4 position : SV_POSITION;
7261 float2 color_xy : COLOR0;
7262 float2 color_zw : COLOR1;
7265 struct vs_out main(struct vs_in i)
7267 struct vs_out o;
7269 o.position = i.position;
7270 o.position.x += i.instance_id * 0.5;
7271 o.color_xy = i.color_xy;
7272 o.color_zw = i.color_zw;
7274 return o;
7276 #endif
7277 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
7278 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
7279 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
7280 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
7281 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
7282 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
7283 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
7284 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
7285 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
7286 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
7287 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
7288 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
7289 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
7290 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
7291 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
7292 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
7293 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
7295 static const DWORD ps_code[] =
7297 #if 0
7298 struct vs_out
7300 float4 position : SV_POSITION;
7301 float2 color_xy : COLOR0;
7302 float2 color_zw : COLOR1;
7305 float4 main(struct vs_out i) : SV_TARGET
7307 return float4(i.color_xy.xy, i.color_zw.xy);
7309 #endif
7310 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
7311 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
7312 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
7313 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
7314 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
7315 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
7316 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
7317 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7318 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7320 static const struct
7322 struct vec4 position;
7324 stream0[] =
7326 {{-1.0f, -1.0f, 0.0f, 1.0f}},
7327 {{-1.0f, 1.0f, 0.0f, 1.0f}},
7328 {{-0.5f, -1.0f, 0.0f, 1.0f}},
7329 {{-0.5f, 1.0f, 0.0f, 1.0f}},
7331 static const struct
7333 struct vec2 color2;
7334 struct vec2 color1;
7336 stream1[] =
7338 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7339 {{0.5f, 0.5f}, {1.0f, 1.0f}},
7341 static const struct
7343 struct vec2 color3;
7344 struct vec2 color0;
7346 stream2[] =
7348 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7349 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7350 {{0.5f, 0.5f}, {0.0f, 0.0f}},
7351 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7353 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7355 if (!init_test_context(&test_context))
7356 return;
7358 device = test_context.device;
7360 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7361 vs_code, sizeof(vs_code), &input_layout);
7362 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7364 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
7365 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
7366 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
7368 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7369 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7370 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7371 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7373 ID3D10Device_IASetInputLayout(device, input_layout);
7374 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7375 offset = 0;
7376 stride = sizeof(*stream0);
7377 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
7378 stride = sizeof(*stream1);
7379 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
7380 stride = sizeof(*stream2);
7381 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
7382 ID3D10Device_VSSetShader(device, vs);
7383 ID3D10Device_PSSetShader(device, ps);
7385 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7387 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
7389 color = get_texture_color(test_context.backbuffer, 80, 240);
7390 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7391 color = get_texture_color(test_context.backbuffer, 240, 240);
7392 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7393 color = get_texture_color(test_context.backbuffer, 400, 240);
7394 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7395 color = get_texture_color(test_context.backbuffer, 560, 240);
7396 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
7398 ID3D10PixelShader_Release(ps);
7399 ID3D10VertexShader_Release(vs);
7400 ID3D10Buffer_Release(vb[2]);
7401 ID3D10Buffer_Release(vb[1]);
7402 ID3D10Buffer_Release(vb[0]);
7403 ID3D10InputLayout_Release(input_layout);
7404 release_test_context(&test_context);
7407 static void test_fragment_coords(void)
7409 struct d3d10core_test_context test_context;
7410 ID3D10PixelShader *ps, *ps_frac;
7411 ID3D10Device *device;
7412 ID3D10Buffer *ps_cb;
7413 DWORD color;
7414 HRESULT hr;
7416 static const DWORD ps_code[] =
7418 #if 0
7419 float2 cutoff;
7421 float4 main(float4 position : SV_POSITION) : SV_TARGET
7423 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
7425 if (position.x > cutoff.x)
7426 ret.y = 1.0;
7427 if (position.y > cutoff.y)
7428 ret.z = 1.0;
7430 return ret;
7432 #endif
7433 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
7434 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7435 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7436 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7437 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
7438 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
7439 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
7440 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
7441 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
7442 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
7443 0x0100003e,
7445 static const DWORD ps_frac_code[] =
7447 #if 0
7448 float4 main(float4 position : SV_POSITION) : SV_TARGET
7450 return float4(frac(position.xy), 0.0, 1.0);
7452 #endif
7453 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
7454 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7455 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7456 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7457 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
7458 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7459 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
7460 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
7462 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7463 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
7465 if (!init_test_context(&test_context))
7466 return;
7468 device = test_context.device;
7470 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7472 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7473 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7474 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
7475 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7477 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
7478 ID3D10Device_PSSetShader(device, ps);
7480 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7482 draw_quad(&test_context);
7484 color = get_texture_color(test_context.backbuffer, 319, 239);
7485 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7486 color = get_texture_color(test_context.backbuffer, 320, 239);
7487 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7488 color = get_texture_color(test_context.backbuffer, 319, 240);
7489 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7490 color = get_texture_color(test_context.backbuffer, 320, 240);
7491 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7493 ID3D10Buffer_Release(ps_cb);
7494 cutoff.x = 16.0f;
7495 cutoff.y = 16.0f;
7496 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7497 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
7499 draw_quad(&test_context);
7501 color = get_texture_color(test_context.backbuffer, 14, 14);
7502 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7503 color = get_texture_color(test_context.backbuffer, 18, 14);
7504 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7505 color = get_texture_color(test_context.backbuffer, 14, 18);
7506 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7507 color = get_texture_color(test_context.backbuffer, 18, 18);
7508 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7510 ID3D10Device_PSSetShader(device, ps_frac);
7511 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7513 draw_quad(&test_context);
7515 color = get_texture_color(test_context.backbuffer, 14, 14);
7516 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
7518 ID3D10Buffer_Release(ps_cb);
7519 ID3D10PixelShader_Release(ps_frac);
7520 ID3D10PixelShader_Release(ps);
7521 release_test_context(&test_context);
7524 static void test_update_subresource(void)
7526 struct d3d10core_test_context test_context;
7527 D3D10_SUBRESOURCE_DATA resource_data;
7528 D3D10_TEXTURE2D_DESC texture_desc;
7529 ID3D10SamplerState *sampler_state;
7530 ID3D10ShaderResourceView *ps_srv;
7531 D3D10_SAMPLER_DESC sampler_desc;
7532 struct resource_readback rb;
7533 ID3D10Texture2D *texture;
7534 ID3D10PixelShader *ps;
7535 ID3D10Device *device;
7536 unsigned int i, j;
7537 D3D10_BOX box;
7538 DWORD color;
7539 HRESULT hr;
7541 static const DWORD ps_code[] =
7543 #if 0
7544 Texture2D t;
7545 SamplerState s;
7547 float4 main(float4 position : SV_POSITION) : SV_Target
7549 float2 p;
7551 p.x = position.x / 640.0f;
7552 p.y = position.y / 480.0f;
7553 return t.Sample(s, p);
7555 #endif
7556 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7557 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7558 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7559 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7560 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7561 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7562 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7563 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7564 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7565 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7567 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7568 static const DWORD initial_data[16] = {0};
7569 static const DWORD bitmap_data[] =
7571 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7572 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7573 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7574 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7576 static const DWORD expected_colors[] =
7578 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
7579 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7580 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
7581 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
7584 if (!init_test_context(&test_context))
7585 return;
7587 device = test_context.device;
7589 texture_desc.Width = 4;
7590 texture_desc.Height = 4;
7591 texture_desc.MipLevels = 1;
7592 texture_desc.ArraySize = 1;
7593 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7594 texture_desc.SampleDesc.Count = 1;
7595 texture_desc.SampleDesc.Quality = 0;
7596 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7597 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7598 texture_desc.CPUAccessFlags = 0;
7599 texture_desc.MiscFlags = 0;
7601 resource_data.pSysMem = initial_data;
7602 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7603 resource_data.SysMemSlicePitch = 0;
7605 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
7606 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
7608 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
7609 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
7611 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7612 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7613 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7614 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7615 sampler_desc.MipLODBias = 0.0f;
7616 sampler_desc.MaxAnisotropy = 0;
7617 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7618 sampler_desc.BorderColor[0] = 0.0f;
7619 sampler_desc.BorderColor[1] = 0.0f;
7620 sampler_desc.BorderColor[2] = 0.0f;
7621 sampler_desc.BorderColor[3] = 0.0f;
7622 sampler_desc.MinLOD = 0.0f;
7623 sampler_desc.MaxLOD = 0.0f;
7625 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7626 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7628 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7629 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7631 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7632 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7633 ID3D10Device_PSSetShader(device, ps);
7635 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7636 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
7638 draw_quad(&test_context);
7639 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7641 set_box(&box, 1, 1, 0, 3, 3, 1);
7642 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7643 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7644 set_box(&box, 0, 3, 0, 3, 4, 1);
7645 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7646 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
7647 set_box(&box, 0, 0, 0, 4, 1, 1);
7648 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7649 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
7650 set_box(&box, 0, 1, 0, 1, 3, 1);
7651 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7652 &bitmap_data[2], sizeof(*bitmap_data), 0);
7653 set_box(&box, 4, 4, 0, 3, 1, 1);
7654 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7655 bitmap_data, sizeof(*bitmap_data), 0);
7656 set_box(&box, 0, 0, 0, 4, 4, 0);
7657 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7658 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7659 draw_quad(&test_context);
7660 get_texture_readback(test_context.backbuffer, 0, &rb);
7661 for (i = 0; i < 4; ++i)
7663 for (j = 0; j < 4; ++j)
7665 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7666 ok(compare_color(color, expected_colors[j + i * 4], 1),
7667 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7668 color, j, i, expected_colors[j + i * 4]);
7671 release_resource_readback(&rb);
7673 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
7674 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7675 draw_quad(&test_context);
7676 get_texture_readback(test_context.backbuffer, 0, &rb);
7677 for (i = 0; i < 4; ++i)
7679 for (j = 0; j < 4; ++j)
7681 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7682 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7683 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7684 color, j, i, bitmap_data[j + i * 4]);
7687 release_resource_readback(&rb);
7689 ID3D10PixelShader_Release(ps);
7690 ID3D10SamplerState_Release(sampler_state);
7691 ID3D10ShaderResourceView_Release(ps_srv);
7692 ID3D10Texture2D_Release(texture);
7693 release_test_context(&test_context);
7696 static void test_copy_subresource_region(void)
7698 struct d3d10core_test_context test_context;
7699 ID3D10Texture2D *dst_texture, *src_texture;
7700 ID3D10Buffer *dst_buffer, *src_buffer;
7701 D3D10_SUBRESOURCE_DATA resource_data;
7702 D3D10_TEXTURE2D_DESC texture_desc;
7703 ID3D10SamplerState *sampler_state;
7704 ID3D10ShaderResourceView *ps_srv;
7705 D3D10_SAMPLER_DESC sampler_desc;
7706 struct vec4 float_colors[16];
7707 struct resource_readback rb;
7708 ID3D10PixelShader *ps;
7709 ID3D10Device *device;
7710 unsigned int i, j;
7711 D3D10_BOX box;
7712 DWORD color;
7713 HRESULT hr;
7715 static const DWORD ps_code[] =
7717 #if 0
7718 Texture2D t;
7719 SamplerState s;
7721 float4 main(float4 position : SV_POSITION) : SV_Target
7723 float2 p;
7725 p.x = position.x / 640.0f;
7726 p.y = position.y / 480.0f;
7727 return t.Sample(s, p);
7729 #endif
7730 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7731 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7732 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7733 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7734 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7735 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7736 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7737 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7738 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7739 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7741 static const DWORD ps_buffer_code[] =
7743 #if 0
7744 float4 buffer[16];
7746 float4 main(float4 position : SV_POSITION) : SV_TARGET
7748 float2 p = (float2)4;
7749 p *= float2(position.x / 640.0f, position.y / 480.0f);
7750 return buffer[(int)p.y * 4 + (int)p.x];
7752 #endif
7753 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
7754 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7755 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7756 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7757 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
7758 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
7759 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7760 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
7761 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
7762 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
7763 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
7764 0x0010000a, 0x00000000, 0x0100003e,
7766 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7767 static const DWORD initial_data[16] = {0};
7768 static const DWORD bitmap_data[] =
7770 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7771 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7772 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7773 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7775 static const DWORD expected_colors[] =
7777 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7778 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7779 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
7780 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
7783 if (!init_test_context(&test_context))
7784 return;
7786 device = test_context.device;
7788 texture_desc.Width = 4;
7789 texture_desc.Height = 4;
7790 texture_desc.MipLevels = 1;
7791 texture_desc.ArraySize = 1;
7792 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7793 texture_desc.SampleDesc.Count = 1;
7794 texture_desc.SampleDesc.Quality = 0;
7795 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7796 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7797 texture_desc.CPUAccessFlags = 0;
7798 texture_desc.MiscFlags = 0;
7800 resource_data.pSysMem = initial_data;
7801 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7802 resource_data.SysMemSlicePitch = 0;
7804 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
7805 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7807 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
7809 resource_data.pSysMem = bitmap_data;
7810 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
7811 resource_data.SysMemSlicePitch = 0;
7813 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
7814 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7816 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
7817 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7819 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7820 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7821 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7822 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7823 sampler_desc.MipLODBias = 0.0f;
7824 sampler_desc.MaxAnisotropy = 0;
7825 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7826 sampler_desc.BorderColor[0] = 0.0f;
7827 sampler_desc.BorderColor[1] = 0.0f;
7828 sampler_desc.BorderColor[2] = 0.0f;
7829 sampler_desc.BorderColor[3] = 0.0f;
7830 sampler_desc.MinLOD = 0.0f;
7831 sampler_desc.MaxLOD = 0.0f;
7833 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7834 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7836 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7837 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7839 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7840 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7841 ID3D10Device_PSSetShader(device, ps);
7843 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7845 set_box(&box, 0, 0, 0, 2, 2, 1);
7846 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7847 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
7848 set_box(&box, 1, 2, 0, 4, 3, 1);
7849 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7850 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
7851 set_box(&box, 0, 3, 0, 4, 4, 1);
7852 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7853 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
7854 set_box(&box, 3, 0, 0, 4, 2, 1);
7855 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7856 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
7857 set_box(&box, 3, 1, 0, 4, 2, 1);
7858 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7859 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
7860 set_box(&box, 0, 0, 0, 4, 4, 0);
7861 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7862 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
7863 draw_quad(&test_context);
7864 get_texture_readback(test_context.backbuffer, 0, &rb);
7865 for (i = 0; i < 4; ++i)
7867 for (j = 0; j < 4; ++j)
7869 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7870 ok(compare_color(color, expected_colors[j + i * 4], 1),
7871 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7872 color, j, i, expected_colors[j + i * 4]);
7875 release_resource_readback(&rb);
7877 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7878 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
7879 draw_quad(&test_context);
7880 get_texture_readback(test_context.backbuffer, 0, &rb);
7881 for (i = 0; i < 4; ++i)
7883 for (j = 0; j < 4; ++j)
7885 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7886 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7887 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7888 color, j, i, bitmap_data[j + i * 4]);
7891 release_resource_readback(&rb);
7893 ID3D10PixelShader_Release(ps);
7894 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
7895 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7897 ID3D10ShaderResourceView_Release(ps_srv);
7898 ps_srv = NULL;
7900 ID3D10SamplerState_Release(sampler_state);
7901 sampler_state = NULL;
7903 ID3D10Texture2D_Release(dst_texture);
7904 ID3D10Texture2D_Release(src_texture);
7906 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7907 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7908 ID3D10Device_PSSetShader(device, ps);
7910 memset(float_colors, 0, sizeof(float_colors));
7911 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
7913 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
7915 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7917 for (i = 0; i < 4; ++i)
7919 for (j = 0; j < 4; ++j)
7921 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7922 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7923 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7924 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7927 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7928 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7930 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7931 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7932 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7933 draw_quad(&test_context);
7934 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7936 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7937 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7938 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7939 draw_quad(&test_context);
7940 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7942 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7943 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7944 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7945 draw_quad(&test_context);
7946 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7948 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7949 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7950 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7951 draw_quad(&test_context);
7952 get_texture_readback(test_context.backbuffer, 0, &rb);
7953 for (i = 0; i < 4; ++i)
7955 for (j = 0; j < 4; ++j)
7957 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7958 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7959 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7960 color, j, i, bitmap_data[j + i * 4]);
7963 release_resource_readback(&rb);
7965 ID3D10Buffer_Release(dst_buffer);
7966 ID3D10Buffer_Release(src_buffer);
7967 ID3D10PixelShader_Release(ps);
7968 release_test_context(&test_context);
7971 static void test_check_multisample_quality_levels(void)
7973 ID3D10Device *device;
7974 UINT quality_levels;
7975 ULONG refcount;
7976 HRESULT hr;
7978 if (!(device = create_device()))
7980 skip("Failed to create device.\n");
7981 return;
7984 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7985 if (!quality_levels)
7987 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7988 goto done;
7991 quality_levels = 0xdeadbeef;
7992 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7993 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7994 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7995 quality_levels = 0xdeadbeef;
7996 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7997 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7998 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
8000 quality_levels = 0xdeadbeef;
8001 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
8002 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8003 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
8004 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8005 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8007 quality_levels = 0xdeadbeef;
8008 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
8009 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8010 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
8011 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8012 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
8014 quality_levels = 0xdeadbeef;
8015 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
8016 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8017 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8018 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8019 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8021 /* We assume 15 samples multisampling is never supported in practice. */
8022 quality_levels = 0xdeadbeef;
8023 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
8024 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8025 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8026 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
8027 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8028 quality_levels = 0xdeadbeef;
8029 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
8030 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8031 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8032 quality_levels = 0xdeadbeef;
8033 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
8034 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8035 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8037 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
8038 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8039 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8041 done:
8042 refcount = ID3D10Device_Release(device);
8043 ok(!refcount, "Device has %u references left.\n", refcount);
8046 static void test_cb_relative_addressing(void)
8048 struct d3d10core_test_context test_context;
8049 ID3D10Buffer *vb, *colors_cb, *index_cb;
8050 ID3D10InputLayout *input_layout;
8051 unsigned int i, index[4] = {0};
8052 unsigned int stride, offset;
8053 ID3D10VertexShader *vs;
8054 ID3D10PixelShader *ps;
8055 ID3D10Device *device;
8056 DWORD color;
8057 HRESULT hr;
8059 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8061 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8063 static const DWORD vs_code[] =
8065 #if 0
8066 int color_index;
8068 cbuffer colors
8070 float4 colors[8];
8073 struct vs_in
8075 float4 position : POSITION;
8078 struct vs_out
8080 float4 position : SV_POSITION;
8081 float4 color : COLOR;
8084 vs_out main(const vs_in v)
8086 vs_out o;
8088 o.position = v.position;
8089 o.color = colors[color_index];
8091 return o;
8093 #endif
8094 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
8095 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8096 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8097 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8098 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8099 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
8100 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
8101 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8102 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
8103 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8104 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
8106 static const DWORD ps_code[] =
8108 #if 0
8109 struct ps_in
8111 float4 position : SV_POSITION;
8112 float4 color : COLOR;
8115 float4 main(const ps_in v) : SV_TARGET
8117 return v.color;
8119 #endif
8120 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
8121 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8122 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8123 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8124 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8125 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
8126 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8127 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8129 static const struct vec2 quad[] =
8131 {-1.0f, -1.0f},
8132 {-1.0f, 1.0f},
8133 { 1.0f, -1.0f},
8134 { 1.0f, 1.0f},
8136 static const struct
8138 float color[4];
8140 colors[10] =
8142 {{0.0f, 0.0f, 0.0f, 1.0f}},
8143 {{0.0f, 0.0f, 1.0f, 0.0f}},
8144 {{0.0f, 0.0f, 1.0f, 1.0f}},
8145 {{0.0f, 1.0f, 0.0f, 0.0f}},
8146 {{0.0f, 1.0f, 0.0f, 1.0f}},
8147 {{0.0f, 1.0f, 1.0f, 0.0f}},
8148 {{0.0f, 1.0f, 1.0f, 1.0f}},
8149 {{1.0f, 0.0f, 0.0f, 0.0f}},
8150 {{1.0f, 0.0f, 0.0f, 1.0f}},
8151 {{1.0f, 0.0f, 1.0f, 0.0f}},
8153 static const struct
8155 int index;
8156 DWORD expected;
8158 test_data[] =
8160 { 0, 0xff000000},
8161 { 1, 0x00ff0000},
8162 { 2, 0xffff0000},
8163 { 3, 0x0000ff00},
8164 { 4, 0xff00ff00},
8165 { 5, 0x00ffff00},
8166 { 6, 0xffffff00},
8167 { 7, 0x000000ff},
8169 { 8, 0xff0000ff},
8170 { 9, 0x00ff00ff},
8172 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
8174 if (!init_test_context(&test_context))
8175 return;
8177 device = test_context.device;
8179 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8180 vs_code, sizeof(vs_code), &input_layout);
8181 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8183 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8184 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
8185 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
8187 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8188 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8189 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8190 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8192 ID3D10Device_IASetInputLayout(device, input_layout);
8193 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8194 stride = sizeof(*quad);
8195 offset = 0;
8196 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8197 ID3D10Device_VSSetShader(device, vs);
8198 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
8199 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
8200 ID3D10Device_PSSetShader(device, ps);
8202 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
8204 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
8206 index[0] = test_data[i].index;
8207 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
8209 ID3D10Device_Draw(device, 4, 0);
8211 color = get_texture_color(test_context.backbuffer, 319, 239);
8212 ok(compare_color(color, test_data[i].expected, 1),
8213 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
8216 ID3D10Buffer_Release(index_cb);
8217 ID3D10Buffer_Release(colors_cb);
8219 ID3D10PixelShader_Release(ps);
8220 ID3D10VertexShader_Release(vs);
8221 ID3D10Buffer_Release(vb);
8222 ID3D10InputLayout_Release(input_layout);
8223 release_test_context(&test_context);
8226 static void test_swapchain_formats(void)
8228 DXGI_SWAP_CHAIN_DESC swapchain_desc;
8229 IDXGISwapChain *swapchain;
8230 IDXGIDevice *dxgi_device;
8231 IDXGIAdapter *adapter;
8232 IDXGIFactory *factory;
8233 ID3D10Device *device;
8234 unsigned int i;
8235 ULONG refcount;
8236 HRESULT hr;
8238 if (!(device = create_device()))
8240 skip("Failed to create device.\n");
8241 return;
8244 swapchain_desc.BufferDesc.Width = 800;
8245 swapchain_desc.BufferDesc.Height = 600;
8246 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
8247 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
8248 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
8249 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
8250 swapchain_desc.SampleDesc.Count = 1;
8251 swapchain_desc.SampleDesc.Quality = 0;
8252 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
8253 swapchain_desc.BufferCount = 1;
8254 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
8255 swapchain_desc.Windowed = TRUE;
8256 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
8257 swapchain_desc.Flags = 0;
8259 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8260 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
8261 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
8262 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
8263 IDXGIDevice_Release(dxgi_device);
8264 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
8265 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
8266 IDXGIAdapter_Release(adapter);
8268 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8269 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8270 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
8271 if (SUCCEEDED(hr))
8272 IDXGISwapChain_Release(swapchain);
8274 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
8276 if (display_format_support[i].optional)
8277 continue;
8279 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
8280 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8281 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
8282 refcount = IDXGISwapChain_Release(swapchain);
8283 ok(!refcount, "Swapchain has %u references left.\n", refcount);
8286 refcount = ID3D10Device_Release(device);
8287 ok(!refcount, "Device has %u references left.\n", refcount);
8288 refcount = IDXGIFactory_Release(factory);
8289 ok(!refcount, "Factory has %u references left.\n", refcount);
8290 DestroyWindow(swapchain_desc.OutputWindow);
8293 static void test_swapchain_views(void)
8295 struct d3d10core_test_context test_context;
8296 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
8297 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
8298 ID3D10ShaderResourceView *srv;
8299 ID3D10RenderTargetView *rtv;
8300 ID3D10Device *device;
8301 ULONG refcount;
8302 HRESULT hr;
8304 if (!init_test_context(&test_context))
8305 return;
8307 device = test_context.device;
8309 refcount = get_refcount(test_context.backbuffer);
8310 ok(refcount == 1, "Got refcount %u.\n", refcount);
8312 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8313 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
8314 U(rtv_desc).Texture2D.MipSlice = 0;
8315 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
8316 /* This seems to work only on Windows 7. */
8317 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
8318 if (SUCCEEDED(hr))
8319 ID3D10RenderTargetView_Release(rtv);
8321 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8322 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
8323 U(srv_desc).Texture2D.MostDetailedMip = 0;
8324 U(srv_desc).Texture2D.MipLevels = 1;
8325 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
8326 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8327 if (SUCCEEDED(hr))
8328 ID3D10ShaderResourceView_Release(srv);
8330 release_test_context(&test_context);
8333 static void test_swapchain_flip(void)
8335 IDXGISwapChain *swapchain;
8336 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
8337 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
8338 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
8339 D3D10_TEXTURE2D_DESC texture_desc;
8340 ID3D10VertexShader *vs;
8341 ID3D10PixelShader *ps;
8342 ID3D10InputLayout *input_layout;
8343 ID3D10Buffer *vb;
8344 unsigned int stride, offset;
8345 ID3D10Device *device;
8346 D3D10_VIEWPORT vp;
8347 ULONG refcount;
8348 DWORD color;
8349 HWND window;
8350 HRESULT hr;
8351 RECT rect;
8353 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8355 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8357 static const DWORD vs_code[] =
8359 #if 0
8360 float4 main(float4 position : POSITION) : SV_POSITION
8362 return position;
8364 #endif
8365 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8366 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8367 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8368 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8369 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8370 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8371 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8374 static const DWORD ps_code[] =
8376 #if 0
8377 Texture2D t0, t1;
8378 SamplerState s;
8380 float4 main(float4 position : SV_POSITION) : SV_Target
8382 float2 p;
8384 p.x = 0.5;
8385 p.y = 0.5;
8386 if (position.x < 320)
8387 return t0.Sample(s, p);
8388 return t1.Sample(s, p);
8390 #endif
8391 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
8392 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8393 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8394 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8395 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
8396 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8397 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
8398 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
8399 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
8400 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
8401 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
8402 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
8403 0x00000000, 0x0100003e,
8405 static const struct vec2 quad[] =
8407 {-1.0f, -1.0f},
8408 {-1.0f, 1.0f},
8409 { 1.0f, -1.0f},
8410 { 1.0f, 1.0f},
8412 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8413 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8414 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
8415 struct swapchain_desc desc;
8417 if (!(device = create_device()))
8419 skip("Failed to create device, skipping tests.\n");
8420 return;
8422 SetRect(&rect, 0, 0, 640, 480);
8423 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
8424 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8425 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
8426 desc.buffer_count = 3;
8427 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
8428 desc.windowed = TRUE;
8429 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
8430 swapchain = create_swapchain(device, window, &desc);
8432 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
8433 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8434 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
8435 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8436 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
8437 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8439 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
8440 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8441 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
8442 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8443 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
8444 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8446 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
8447 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
8448 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
8449 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8450 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8452 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
8453 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
8454 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
8455 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8456 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8458 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
8459 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8460 if (SUCCEEDED(hr))
8461 ID3D10RenderTargetView_Release(offscreen_rtv);
8463 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
8464 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
8466 texture_desc.Width = 640;
8467 texture_desc.Height = 480;
8468 texture_desc.MipLevels = 1;
8469 texture_desc.ArraySize = 1;
8470 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8471 texture_desc.SampleDesc.Count = 1;
8472 texture_desc.SampleDesc.Quality = 0;
8473 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8474 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8475 texture_desc.CPUAccessFlags = 0;
8476 texture_desc.MiscFlags = 0;
8477 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
8478 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
8479 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
8480 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8481 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
8482 vp.TopLeftX = 0;
8483 vp.TopLeftY = 0;
8484 vp.Width = 640;
8485 vp.Height = 480;
8486 vp.MinDepth = 0.0f;
8487 vp.MaxDepth = 1.0f;
8488 ID3D10Device_RSSetViewports(device, 1, &vp);
8490 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8492 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8493 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8494 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8495 vs_code, sizeof(vs_code), &input_layout);
8496 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8497 ID3D10Device_IASetInputLayout(device, input_layout);
8498 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8499 ID3D10Device_VSSetShader(device, vs);
8500 stride = sizeof(*quad);
8501 offset = 0;
8502 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8504 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8505 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8506 ID3D10Device_PSSetShader(device, ps);
8508 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
8510 ID3D10Device_Draw(device, 4, 0);
8511 color = get_texture_color(offscreen, 120, 240);
8512 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8514 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
8515 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
8516 * 0 can be rendered to.
8518 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
8519 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
8520 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
8521 * rendering finishes before the vsync interval is over. I haven't found any productive use
8522 * for more than one buffer. */
8523 IDXGISwapChain_Present(swapchain, 0, 0);
8525 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
8527 ID3D10Device_Draw(device, 4, 0);
8528 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
8529 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8530 /* Buffer 1 is still untouched. */
8532 color = get_texture_color(backbuffer_0, 320, 240); /* green */
8533 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8534 color = get_texture_color(backbuffer_2, 320, 240); /* red */
8535 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8537 IDXGISwapChain_Present(swapchain, 0, 0);
8539 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
8541 ID3D10Device_Draw(device, 4, 0);
8542 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
8543 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8544 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
8545 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8547 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
8548 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8549 color = get_texture_color(backbuffer_1, 320, 240); /* red */
8550 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8551 color = get_texture_color(backbuffer_2, 320, 240); /* green */
8552 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8554 ID3D10VertexShader_Release(vs);
8555 ID3D10PixelShader_Release(ps);
8556 ID3D10Buffer_Release(vb);
8557 ID3D10InputLayout_Release(input_layout);
8558 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
8559 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
8560 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
8561 ID3D10RenderTargetView_Release(offscreen_rtv);
8562 ID3D10Texture2D_Release(offscreen);
8563 ID3D10Texture2D_Release(backbuffer_0);
8564 ID3D10Texture2D_Release(backbuffer_1);
8565 ID3D10Texture2D_Release(backbuffer_2);
8566 IDXGISwapChain_Release(swapchain);
8568 refcount = ID3D10Device_Release(device);
8569 ok(!refcount, "Device has %u references left.\n", refcount);
8570 DestroyWindow(window);
8573 static void test_clear_render_target_view(void)
8575 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
8576 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
8577 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8579 struct d3d10core_test_context test_context;
8580 ID3D10Texture2D *texture, *srgb_texture;
8581 ID3D10RenderTargetView *rtv, *srgb_rtv;
8582 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
8583 D3D10_TEXTURE2D_DESC texture_desc;
8584 struct resource_readback rb;
8585 ID3D10Device *device;
8586 unsigned int i, j;
8587 HRESULT hr;
8589 if (!init_test_context(&test_context))
8590 return;
8592 device = test_context.device;
8594 texture_desc.Width = 640;
8595 texture_desc.Height = 480;
8596 texture_desc.MipLevels = 1;
8597 texture_desc.ArraySize = 1;
8598 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8599 texture_desc.SampleDesc.Count = 1;
8600 texture_desc.SampleDesc.Quality = 0;
8601 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8602 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8603 texture_desc.CPUAccessFlags = 0;
8604 texture_desc.MiscFlags = 0;
8605 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8606 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8608 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8609 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
8610 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8612 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8613 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8615 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
8616 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8618 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
8619 check_texture_color(test_context.backbuffer, expected_color, 1);
8621 ID3D10Device_ClearRenderTargetView(device, rtv, color);
8622 check_texture_color(texture, expected_color, 1);
8624 if (is_d3d11_interface_available(device))
8626 ID3D10Device_ClearRenderTargetView(device, NULL, green);
8627 check_texture_color(texture, expected_color, 1);
8629 else
8631 win_skip("D3D11 is not available.\n");
8634 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
8635 check_texture_color(srgb_texture, expected_srgb_color, 1);
8637 ID3D10RenderTargetView_Release(srgb_rtv);
8638 ID3D10RenderTargetView_Release(rtv);
8639 ID3D10Texture2D_Release(srgb_texture);
8640 ID3D10Texture2D_Release(texture);
8642 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8643 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8644 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8646 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8647 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
8648 U(rtv_desc).Texture2D.MipSlice = 0;
8649 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
8650 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8652 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8653 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
8654 U(rtv_desc).Texture2D.MipSlice = 0;
8655 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
8656 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8658 ID3D10Device_ClearRenderTargetView(device, rtv, color);
8659 check_texture_color(texture, expected_color, 1);
8661 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
8662 get_texture_readback(texture, 0, &rb);
8663 for (i = 0; i < 4; ++i)
8665 for (j = 0; j < 4; ++j)
8667 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
8668 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
8669 ok(compare_color(color, expected_srgb_color, 1)
8670 || broken(compare_color(color, expected_color, 1) && broken_device),
8671 "Got unexpected color 0x%08x.\n", color);
8674 release_resource_readback(&rb);
8676 ID3D10RenderTargetView_Release(srgb_rtv);
8677 ID3D10RenderTargetView_Release(rtv);
8678 ID3D10Texture2D_Release(texture);
8679 release_test_context(&test_context);
8682 static void test_clear_depth_stencil_view(void)
8684 D3D10_TEXTURE2D_DESC texture_desc;
8685 ID3D10Texture2D *depth_texture;
8686 ID3D10DepthStencilView *dsv;
8687 ID3D10Device *device;
8688 ULONG refcount;
8689 HRESULT hr;
8691 if (!(device = create_device()))
8693 skip("Failed to create device.\n");
8694 return;
8697 texture_desc.Width = 640;
8698 texture_desc.Height = 480;
8699 texture_desc.MipLevels = 1;
8700 texture_desc.ArraySize = 1;
8701 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8702 texture_desc.SampleDesc.Count = 1;
8703 texture_desc.SampleDesc.Quality = 0;
8704 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8705 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
8706 texture_desc.CPUAccessFlags = 0;
8707 texture_desc.MiscFlags = 0;
8708 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8709 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8711 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
8712 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8714 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8715 check_texture_float(depth_texture, 1.0f, 0);
8717 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
8718 check_texture_float(depth_texture, 0.25f, 0);
8720 ID3D10Texture2D_Release(depth_texture);
8721 ID3D10DepthStencilView_Release(dsv);
8723 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8724 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8725 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8727 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
8728 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8730 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
8731 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8733 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
8734 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
8736 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
8737 check_texture_color(depth_texture, 0xffffffff, 0);
8739 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
8740 check_texture_color(depth_texture, 0x00000000, 0);
8742 if (is_d3d11_interface_available(device))
8744 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
8745 check_texture_color(depth_texture, 0x00000000, 0);
8747 else
8748 win_skip("D3D11 is not available, skipping test.\n");
8750 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
8751 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8753 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
8754 check_texture_color(depth_texture, 0xffffffff, 0);
8756 ID3D10Texture2D_Release(depth_texture);
8757 ID3D10DepthStencilView_Release(dsv);
8759 refcount = ID3D10Device_Release(device);
8760 ok(!refcount, "Device has %u references left.\n", refcount);
8763 static void test_draw_depth_only(void)
8765 ID3D10DepthStencilState *depth_stencil_state;
8766 D3D10_DEPTH_STENCIL_DESC depth_stencil_desc;
8767 struct d3d10core_test_context test_context;
8768 ID3D10PixelShader *ps_color, *ps_depth;
8769 D3D10_TEXTURE2D_DESC texture_desc;
8770 ID3D10DepthStencilView *dsv;
8771 struct resource_readback rb;
8772 ID3D10Texture2D *texture;
8773 ID3D10Device *device;
8774 unsigned int i, j;
8775 D3D10_VIEWPORT vp;
8776 struct vec4 depth;
8777 ID3D10Buffer *cb;
8778 HRESULT hr;
8780 static const DWORD ps_color_code[] =
8782 #if 0
8783 float4 main(float4 position : SV_POSITION) : SV_Target
8785 return float4(0.0, 1.0, 0.0, 1.0);
8787 #endif
8788 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
8789 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8790 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8791 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8792 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
8793 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
8794 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
8796 static const DWORD ps_depth_code[] =
8798 #if 0
8799 float depth;
8801 float main() : SV_Depth
8803 return depth;
8805 #endif
8806 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
8807 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8808 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
8809 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8810 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
8811 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8814 if (!init_test_context(&test_context))
8815 return;
8817 device = test_context.device;
8819 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
8821 texture_desc.Width = 640;
8822 texture_desc.Height = 480;
8823 texture_desc.MipLevels = 1;
8824 texture_desc.ArraySize = 1;
8825 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8826 texture_desc.SampleDesc.Count = 1;
8827 texture_desc.SampleDesc.Quality = 0;
8828 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8829 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
8830 texture_desc.CPUAccessFlags = 0;
8831 texture_desc.MiscFlags = 0;
8833 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8834 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8836 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
8837 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8839 depth_stencil_desc.DepthEnable = TRUE;
8840 depth_stencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
8841 depth_stencil_desc.DepthFunc = D3D10_COMPARISON_LESS;
8842 depth_stencil_desc.StencilEnable = FALSE;
8844 hr = ID3D10Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
8845 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
8847 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
8848 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8849 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
8850 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8852 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8853 ID3D10Device_PSSetShader(device, ps_color);
8854 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
8855 ID3D10Device_OMSetDepthStencilState(device, depth_stencil_state, 0);
8857 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8858 check_texture_float(texture, 1.0f, 1);
8859 draw_quad(&test_context);
8860 check_texture_float(texture, 0.0f, 1);
8862 ID3D10Device_PSSetShader(device, ps_depth);
8864 depth.x = 0.7f;
8865 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8866 draw_quad(&test_context);
8867 check_texture_float(texture, 0.0f, 1);
8868 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8869 check_texture_float(texture, 1.0f, 1);
8870 draw_quad(&test_context);
8871 check_texture_float(texture, 0.7f, 1);
8872 depth.x = 0.8f;
8873 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8874 draw_quad(&test_context);
8875 check_texture_float(texture, 0.7f, 1);
8876 depth.x = 0.5f;
8877 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8878 draw_quad(&test_context);
8879 check_texture_float(texture, 0.5f, 1);
8881 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8882 for (i = 0; i < 4; ++i)
8884 for (j = 0; j < 4; ++j)
8886 depth.x = 1.0f / 16.0f * (j + 4 * i);
8887 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8889 vp.TopLeftX = 160 * j;
8890 vp.TopLeftY = 120 * i;
8891 vp.Width = 160;
8892 vp.Height = 120;
8893 vp.MinDepth = 0.0f;
8894 vp.MaxDepth = 1.0f;
8895 ID3D10Device_RSSetViewports(device, 1, &vp);
8897 draw_quad(&test_context);
8900 get_texture_readback(texture, 0, &rb);
8901 for (i = 0; i < 4; ++i)
8903 for (j = 0; j < 4; ++j)
8905 float obtained_depth, expected_depth;
8907 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8908 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8909 ok(compare_float(obtained_depth, expected_depth, 1),
8910 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8911 obtained_depth, j, i, expected_depth);
8914 release_resource_readback(&rb);
8916 ID3D10Buffer_Release(cb);
8917 ID3D10PixelShader_Release(ps_color);
8918 ID3D10PixelShader_Release(ps_depth);
8919 ID3D10DepthStencilView_Release(dsv);
8920 ID3D10DepthStencilState_Release(depth_stencil_state);
8921 ID3D10Texture2D_Release(texture);
8922 release_test_context(&test_context);
8925 static void test_shader_stage_input_output_matching(void)
8927 struct d3d10core_test_context test_context;
8928 D3D10_TEXTURE2D_DESC texture_desc;
8929 ID3D10Texture2D *render_target;
8930 ID3D10RenderTargetView *rtv[2];
8931 ID3D10VertexShader *vs;
8932 ID3D10PixelShader *ps;
8933 ID3D10Device *device;
8934 HRESULT hr;
8936 static const DWORD vs_code[] =
8938 #if 0
8939 struct output
8941 float4 position : SV_PoSiTion;
8942 float4 color0 : COLOR0;
8943 float4 color1 : COLOR1;
8946 void main(uint id : SV_VertexID, out output o)
8948 float2 coords = float2((id << 1) & 2, id & 2);
8949 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8950 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8951 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8953 #endif
8954 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8955 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8956 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8957 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8958 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8959 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8960 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8961 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8962 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8963 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8964 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8965 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8966 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8967 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8968 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8969 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8970 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8971 0x0100003e,
8973 static const DWORD ps_code[] =
8975 #if 0
8976 struct input
8978 float4 position : SV_PoSiTiOn;
8979 float4 color1 : COLOR1;
8980 float4 color0 : COLOR0;
8983 struct output
8985 float4 target0 : SV_Target0;
8986 float4 target1 : SV_Target1;
8989 void main(const in input i, out output o)
8991 o.target0 = i.color0;
8992 o.target1 = i.color1;
8994 #endif
8995 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8996 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8997 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8998 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8999 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
9000 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9001 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
9002 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
9003 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
9004 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
9005 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
9008 if (!init_test_context(&test_context))
9009 return;
9011 device = test_context.device;
9013 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9014 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9015 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9016 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9018 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9019 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9020 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9022 rtv[0] = test_context.backbuffer_rtv;
9023 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
9024 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9026 ID3D10Device_VSSetShader(device, vs);
9027 ID3D10Device_PSSetShader(device, ps);
9028 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
9029 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
9030 ID3D10Device_Draw(device, 3, 0);
9032 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9033 check_texture_color(render_target, 0xff0000ff, 0);
9035 ID3D10RenderTargetView_Release(rtv[1]);
9036 ID3D10Texture2D_Release(render_target);
9037 ID3D10PixelShader_Release(ps);
9038 ID3D10VertexShader_Release(vs);
9039 release_test_context(&test_context);
9042 static void test_shader_interstage_interface(void)
9044 struct d3d10core_test_context test_context;
9045 D3D10_TEXTURE2D_DESC texture_desc;
9046 ID3D10InputLayout *input_layout;
9047 ID3D10Texture2D *render_target;
9048 ID3D10RenderTargetView *rtv;
9049 ID3D10VertexShader *vs;
9050 ID3D10PixelShader *ps;
9051 ID3D10Device *device;
9052 UINT stride, offset;
9053 ID3D10Buffer *vb;
9054 HRESULT hr;
9056 static const DWORD vs_code[] =
9058 #if 0
9059 struct vertex
9061 float4 position : SV_Position;
9062 float2 t0 : TEXCOORD0;
9063 nointerpolation float t1 : TEXCOORD1;
9064 uint t2 : TEXCOORD2;
9065 uint t3 : TEXCOORD3;
9066 float t4 : TEXCOORD4;
9069 void main(in vertex vin, out vertex vout)
9071 vout = vin;
9073 #endif
9074 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
9075 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
9076 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
9077 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9078 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
9079 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
9080 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
9081 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
9082 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9083 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
9084 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
9085 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
9086 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
9087 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
9088 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
9089 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
9090 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
9091 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
9092 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
9093 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
9094 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
9095 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
9097 static const DWORD ps_code[] =
9099 #if 0
9100 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
9101 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
9102 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
9104 o.x = t0.y + t1;
9105 o.y = t2 + t3;
9106 o.z = t4;
9107 o.w = t0.x;
9109 #endif
9110 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
9111 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
9112 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
9113 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
9114 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
9115 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
9116 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
9117 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
9118 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
9119 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
9120 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
9121 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
9122 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
9123 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
9124 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
9126 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9128 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9129 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
9130 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9131 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
9132 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
9133 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
9135 static const struct
9137 struct vec2 position;
9138 struct vec2 t0;
9139 float t1;
9140 unsigned int t2;
9141 unsigned int t3;
9142 float t4;
9144 quad[] =
9146 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
9147 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
9148 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
9149 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
9151 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9152 static const struct vec4 expected_result = {10.0f, 8.0f, 7.0f, 3.0f};
9154 if (!init_test_context(&test_context))
9155 return;
9157 device = test_context.device;
9159 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9160 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9161 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9162 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9164 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9165 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9166 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9167 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9169 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
9170 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9172 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9173 vs_code, sizeof(vs_code), &input_layout);
9174 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9176 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9178 ID3D10Device_ClearRenderTargetView(device, rtv, white);
9180 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9182 ID3D10Device_PSSetShader(device, ps);
9183 ID3D10Device_VSSetShader(device, vs);
9184 ID3D10Device_IASetInputLayout(device, input_layout);
9185 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9186 offset = 0;
9187 stride = sizeof(*quad);
9188 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9189 ID3D10Device_Draw(device, 4, 0);
9190 check_texture_vec4(render_target, &expected_result, 0);
9192 ID3D10InputLayout_Release(input_layout);
9193 ID3D10RenderTargetView_Release(rtv);
9194 ID3D10Texture2D_Release(render_target);
9195 ID3D10PixelShader_Release(ps);
9196 ID3D10VertexShader_Release(vs);
9197 ID3D10Buffer_Release(vb);
9198 release_test_context(&test_context);
9201 static void test_sm4_if_instruction(void)
9203 struct d3d10core_test_context test_context;
9204 ID3D10PixelShader *ps_if_nz, *ps_if_z;
9205 ID3D10Device *device;
9206 unsigned int bits[4];
9207 DWORD expected_color;
9208 ID3D10Buffer *cb;
9209 unsigned int i;
9210 HRESULT hr;
9212 static const DWORD ps_if_nz_code[] =
9214 #if 0
9215 uint bits;
9217 float4 main() : SV_TARGET
9219 if (bits)
9220 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9221 else
9222 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9224 #endif
9225 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
9226 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9227 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9228 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9229 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
9230 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9231 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9232 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9234 static const DWORD ps_if_z_code[] =
9236 #if 0
9237 uint bits;
9239 float4 main() : SV_TARGET
9241 if (!bits)
9242 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9243 else
9244 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9246 #endif
9247 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
9248 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9249 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9250 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9251 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
9252 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9253 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9254 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9256 static unsigned int bit_patterns[] =
9258 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
9261 if (!init_test_context(&test_context))
9262 return;
9264 device = test_context.device;
9266 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
9267 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
9268 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
9269 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
9271 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
9272 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
9274 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
9276 *bits = bit_patterns[i];
9277 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
9279 ID3D10Device_PSSetShader(device, ps_if_nz);
9280 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
9281 draw_quad(&test_context);
9282 check_texture_color(test_context.backbuffer, expected_color, 0);
9284 ID3D10Device_PSSetShader(device, ps_if_z);
9285 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
9286 draw_quad(&test_context);
9287 check_texture_color(test_context.backbuffer, expected_color, 0);
9290 ID3D10Buffer_Release(cb);
9291 ID3D10PixelShader_Release(ps_if_z);
9292 ID3D10PixelShader_Release(ps_if_nz);
9293 release_test_context(&test_context);
9296 static void test_sm4_breakc_instruction(void)
9298 struct d3d10core_test_context test_context;
9299 ID3D10PixelShader *ps;
9300 ID3D10Device *device;
9301 HRESULT hr;
9303 static const DWORD ps_breakc_nz_code[] =
9305 #if 0
9306 float4 main() : SV_TARGET
9308 uint counter = 0;
9310 for (uint i = 0; i < 255; ++i)
9311 ++counter;
9313 if (counter == 255)
9314 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9315 else
9316 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9318 #endif
9319 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
9320 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9321 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9322 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
9323 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
9324 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
9325 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9326 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
9327 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
9328 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
9329 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
9330 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9331 0x01000015, 0x0100003e,
9333 static const DWORD ps_breakc_z_code[] =
9335 #if 0
9336 float4 main() : SV_TARGET
9338 uint counter = 0;
9340 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
9341 ++counter;
9343 if (counter == 255)
9344 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9345 else
9346 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9348 #endif
9349 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
9350 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9351 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9352 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
9353 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
9354 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
9355 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
9356 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
9357 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
9358 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
9359 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
9360 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9361 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9362 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9365 if (!init_test_context(&test_context))
9366 return;
9368 device = test_context.device;
9370 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
9371 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
9372 ID3D10Device_PSSetShader(device, ps);
9373 draw_quad(&test_context);
9374 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9375 ID3D10PixelShader_Release(ps);
9377 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
9378 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
9379 ID3D10Device_PSSetShader(device, ps);
9380 draw_quad(&test_context);
9381 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9382 ID3D10PixelShader_Release(ps);
9384 release_test_context(&test_context);
9387 static void test_sm4_continuec_instruction(void)
9389 struct d3d10core_test_context test_context;
9390 ID3D10PixelShader *ps;
9391 ID3D10Device *device;
9392 HRESULT hr;
9394 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
9395 * with a normal continue inside, the shaders have been compiled with
9396 * the /Gfa flag. */
9397 static const DWORD ps_continuec_nz_code[] =
9399 #if 0
9400 float4 main() : SV_TARGET
9402 uint counter = 0;
9403 int i = -1;
9405 while (i < 255) {
9406 ++i;
9408 if (i != 0)
9409 continue;
9411 ++counter;
9414 if (counter == 1)
9415 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9416 else
9417 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9419 #endif
9420 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
9421 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9422 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9423 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
9424 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
9425 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
9426 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9427 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
9428 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
9429 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
9430 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
9431 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
9432 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
9433 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
9434 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
9435 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
9436 0x3f800000, 0x0100003e,
9439 static const DWORD ps_continuec_z_code[] =
9441 #if 0
9442 float4 main() : SV_TARGET
9444 uint counter = 0;
9445 int i = -1;
9447 while (i < 255) {
9448 ++i;
9450 if (i == 0)
9451 continue;
9453 ++counter;
9456 if (counter == 255)
9457 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9458 else
9459 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9461 #endif
9462 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
9463 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9464 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9465 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
9466 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
9467 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
9468 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9469 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
9470 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
9471 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
9472 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
9473 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
9474 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
9475 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
9476 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9479 if (!init_test_context(&test_context))
9480 return;
9482 device = test_context.device;
9484 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), &ps);
9485 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
9486 ID3D10Device_PSSetShader(device, ps);
9487 draw_quad(&test_context);
9488 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9489 ID3D10PixelShader_Release(ps);
9491 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), &ps);
9492 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
9493 ID3D10Device_PSSetShader(device, ps);
9494 draw_quad(&test_context);
9495 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9496 ID3D10PixelShader_Release(ps);
9498 release_test_context(&test_context);
9501 static void test_create_input_layout(void)
9503 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9505 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9507 ULONG refcount, expected_refcount;
9508 ID3D10InputLayout *input_layout;
9509 ID3D10Device *device;
9510 unsigned int i;
9511 HRESULT hr;
9513 static const DWORD vs_code[] =
9515 #if 0
9516 float4 main(float4 position : POSITION) : SV_POSITION
9518 return position;
9520 #endif
9521 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9522 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9523 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9524 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9525 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9526 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9527 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9529 static const DXGI_FORMAT vertex_formats[] =
9531 DXGI_FORMAT_R32G32_FLOAT,
9532 DXGI_FORMAT_R32G32_UINT,
9533 DXGI_FORMAT_R32G32_SINT,
9534 DXGI_FORMAT_R16G16_FLOAT,
9535 DXGI_FORMAT_R16G16_UINT,
9536 DXGI_FORMAT_R16G16_SINT,
9537 DXGI_FORMAT_R32_FLOAT,
9538 DXGI_FORMAT_R32_UINT,
9539 DXGI_FORMAT_R32_SINT,
9540 DXGI_FORMAT_R16_UINT,
9541 DXGI_FORMAT_R16_SINT,
9542 DXGI_FORMAT_R8_UINT,
9543 DXGI_FORMAT_R8_SINT,
9546 if (!(device = create_device()))
9548 skip("Failed to create device.\n");
9549 return;
9552 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
9554 expected_refcount = get_refcount(device) + 1;
9555 layout_desc->Format = vertex_formats[i];
9556 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9557 vs_code, sizeof(vs_code), &input_layout);
9558 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
9559 vertex_formats[i], hr);
9560 refcount = get_refcount(device);
9561 ok(refcount >= expected_refcount, "Got refcount %u, expected >= %u.\n",
9562 refcount, expected_refcount);
9563 ID3D10InputLayout_Release(input_layout);
9566 refcount = ID3D10Device_Release(device);
9567 ok(!refcount, "Device has %u references left.\n", refcount);
9570 static void test_input_assembler(void)
9572 enum layout_id
9574 LAYOUT_FLOAT32,
9575 LAYOUT_UINT16,
9576 LAYOUT_SINT16,
9577 LAYOUT_UNORM16,
9578 LAYOUT_SNORM16,
9579 LAYOUT_UINT8,
9580 LAYOUT_SINT8,
9581 LAYOUT_UNORM8,
9582 LAYOUT_SNORM8,
9583 LAYOUT_UNORM10_2,
9584 LAYOUT_UINT10_2,
9586 LAYOUT_COUNT,
9589 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
9591 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9592 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9594 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
9595 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
9596 struct d3d10core_test_context test_context;
9597 ID3D10Buffer *vb_position, *vb_attribute;
9598 D3D10_TEXTURE2D_DESC texture_desc;
9599 unsigned int i, j, stride, offset;
9600 ID3D10Texture2D *render_target;
9601 ID3D10RenderTargetView *rtv;
9602 ID3D10PixelShader *ps;
9603 ID3D10Device *device;
9604 HRESULT hr;
9606 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
9608 DXGI_FORMAT_R32G32B32A32_FLOAT,
9609 DXGI_FORMAT_R16G16B16A16_UINT,
9610 DXGI_FORMAT_R16G16B16A16_SINT,
9611 DXGI_FORMAT_R16G16B16A16_UNORM,
9612 DXGI_FORMAT_R16G16B16A16_SNORM,
9613 DXGI_FORMAT_R8G8B8A8_UINT,
9614 DXGI_FORMAT_R8G8B8A8_SINT,
9615 DXGI_FORMAT_R8G8B8A8_UNORM,
9616 DXGI_FORMAT_R8G8B8A8_SNORM,
9617 DXGI_FORMAT_R10G10B10A2_UNORM,
9618 DXGI_FORMAT_R10G10B10A2_UINT,
9620 static const struct vec2 quad[] =
9622 {-1.0f, -1.0f},
9623 {-1.0f, 1.0f},
9624 { 1.0f, -1.0f},
9625 { 1.0f, 1.0f},
9627 static const DWORD ps_code[] =
9629 #if 0
9630 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
9632 return color;
9634 #endif
9635 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
9636 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
9637 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
9638 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
9639 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9640 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9641 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
9642 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9644 static const DWORD vs_float_code[] =
9646 #if 0
9647 struct output
9649 float4 position : SV_Position;
9650 float4 color : COLOR;
9653 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
9655 o.position = position;
9656 o.color = color;
9658 #endif
9659 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
9660 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9661 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9662 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9663 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9664 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9665 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9666 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9667 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9668 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9669 0x0100003e,
9671 static const DWORD vs_uint_code[] =
9673 #if 0
9674 struct output
9676 float4 position : SV_Position;
9677 float4 color : COLOR;
9680 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
9682 o.position = position;
9683 o.color = color;
9685 #endif
9686 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
9687 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9688 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9689 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9690 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9691 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9692 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9693 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9694 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9695 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9696 0x0100003e,
9698 static const DWORD vs_sint_code[] =
9700 #if 0
9701 struct output
9703 float4 position : SV_Position;
9704 float4 color : COLOR;
9707 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
9709 o.position = position;
9710 o.color = color;
9712 #endif
9713 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
9714 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9715 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9716 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9717 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9718 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9719 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9720 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9721 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9722 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9723 0x0100003e,
9725 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
9726 static const unsigned short uint16_data[] = {6, 8, 55, 777};
9727 static const short sint16_data[] = {-1, 33, 8, -77};
9728 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
9729 static const short snorm16_data[] = {-32768, 0, 32767, 0};
9730 static const unsigned char uint8_data[] = {0, 64, 128, 255};
9731 static const signed char sint8_data[] = {-128, 0, 127, 64};
9732 static const unsigned int uint32_zero = 0;
9733 static const unsigned int uint32_max = 0xffffffff;
9734 static const unsigned int unorm10_2_data= 0xa00003ff;
9735 static const unsigned int g10_data = 0x000ffc00;
9736 static const unsigned int a2_data = 0xc0000000;
9737 static const struct
9739 enum layout_id layout_id;
9740 unsigned int stride;
9741 const void *data;
9742 struct vec4 expected_color;
9743 BOOL todo;
9745 tests[] =
9747 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
9748 {1.0f, 2.0f, 3.0f, 4.0f}},
9749 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
9750 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
9751 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
9752 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
9753 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
9754 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
9755 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
9756 {-1.0f, 0.0f, 1.0f, 0.0f}},
9757 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
9758 {0.0f, 0.0f, 0.0f, 0.0f}},
9759 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
9760 {255.0f, 255.0f, 255.0f, 255.0f}},
9761 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
9762 {0.0f, 64.0f, 128.0f, 255.0f}},
9763 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
9764 {0.0f, 0.0f, 0.0f, 0.0f}},
9765 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
9766 {-1.0f, -1.0f, -1.0f, -1.0f}},
9767 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
9768 {-128.0f, 0.0f, 127.0f, 64.0f}},
9769 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
9770 {0.0f, 0.0f, 0.0f, 0.0f}},
9771 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
9772 {1.0f, 1.0f, 1.0f, 1.0f}},
9773 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
9774 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
9775 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
9776 {0.0f, 0.0f, 0.0f, 0.0f}},
9777 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
9778 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
9779 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
9780 {0.0f, 0.0f, 0.0f, 0.0f}},
9781 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
9782 {1.0f, 1.0f, 1.0f, 1.0f}},
9783 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
9784 {0.0f, 1.0f, 0.0f, 0.0f}},
9785 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
9786 {0.0f, 0.0f, 0.0f, 1.0f}},
9787 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9788 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
9789 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
9790 {0.0f, 0.0f, 0.0f, 0.0f}},
9791 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
9792 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
9793 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
9794 {0.0f, 1023.0f, 0.0f, 0.0f}},
9795 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
9796 {0.0f, 0.0f, 0.0f, 3.0f}},
9797 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9798 {1023.0f, 0.0f, 512.0f, 2.0f}},
9801 if (!init_test_context(&test_context))
9802 return;
9804 device = test_context.device;
9806 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9807 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9809 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
9810 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
9811 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
9812 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
9813 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
9814 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
9816 for (i = 0; i < LAYOUT_COUNT; ++i)
9818 input_layout_desc[1].Format = layout_formats[i];
9819 input_layout[i] = NULL;
9820 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
9821 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
9822 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
9823 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
9826 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9827 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
9829 texture_desc.Width = 640;
9830 texture_desc.Height = 480;
9831 texture_desc.MipLevels = 1;
9832 texture_desc.ArraySize = 1;
9833 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9834 texture_desc.SampleDesc.Count = 1;
9835 texture_desc.SampleDesc.Quality = 0;
9836 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9837 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
9838 texture_desc.CPUAccessFlags = 0;
9839 texture_desc.MiscFlags = 0;
9841 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9842 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9844 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
9845 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9847 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9848 offset = 0;
9849 stride = sizeof(*quad);
9850 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
9851 ID3D10Device_PSSetShader(device, ps);
9852 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9854 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9856 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
9858 if (tests[i].layout_id == LAYOUT_UINT10_2)
9859 continue;
9861 assert(tests[i].layout_id < LAYOUT_COUNT);
9862 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
9864 assert(4 * tests[i].stride <= 1024);
9865 box.right = tests[i].stride;
9866 for (j = 0; j < 4; ++j)
9868 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
9869 &box, tests[i].data, 0, 0);
9870 box.left += tests[i].stride;
9871 box.right += tests[i].stride;
9874 stride = tests[i].stride;
9875 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
9877 switch (layout_formats[tests[i].layout_id])
9879 case DXGI_FORMAT_R16G16B16A16_UINT:
9880 case DXGI_FORMAT_R10G10B10A2_UINT:
9881 case DXGI_FORMAT_R8G8B8A8_UINT:
9882 ID3D10Device_VSSetShader(device, vs_uint);
9883 break;
9884 case DXGI_FORMAT_R16G16B16A16_SINT:
9885 case DXGI_FORMAT_R8G8B8A8_SINT:
9886 ID3D10Device_VSSetShader(device, vs_sint);
9887 break;
9889 default:
9890 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
9891 /* Fall through. */
9892 case DXGI_FORMAT_R32G32B32A32_FLOAT:
9893 case DXGI_FORMAT_R16G16B16A16_UNORM:
9894 case DXGI_FORMAT_R16G16B16A16_SNORM:
9895 case DXGI_FORMAT_R10G10B10A2_UNORM:
9896 case DXGI_FORMAT_R8G8B8A8_UNORM:
9897 case DXGI_FORMAT_R8G8B8A8_SNORM:
9898 ID3D10Device_VSSetShader(device, vs_float);
9899 break;
9902 ID3D10Device_Draw(device, 4, 0);
9903 check_texture_vec4(render_target, &tests[i].expected_color, 2);
9906 ID3D10Texture2D_Release(render_target);
9907 ID3D10RenderTargetView_Release(rtv);
9908 ID3D10Buffer_Release(vb_attribute);
9909 ID3D10Buffer_Release(vb_position);
9910 for (i = 0; i < LAYOUT_COUNT; ++i)
9912 if (input_layout[i])
9913 ID3D10InputLayout_Release(input_layout[i]);
9915 ID3D10PixelShader_Release(ps);
9916 ID3D10VertexShader_Release(vs_float);
9917 ID3D10VertexShader_Release(vs_uint);
9918 ID3D10VertexShader_Release(vs_sint);
9919 release_test_context(&test_context);
9922 static void test_null_sampler(void)
9924 struct d3d10core_test_context test_context;
9925 D3D10_TEXTURE2D_DESC texture_desc;
9926 ID3D10ShaderResourceView *srv;
9927 ID3D10RenderTargetView *rtv;
9928 ID3D10SamplerState *sampler;
9929 ID3D10Texture2D *texture;
9930 ID3D10PixelShader *ps;
9931 ID3D10Device *device;
9932 HRESULT hr;
9934 static const DWORD ps_code[] =
9936 #if 0
9937 Texture2D t;
9938 SamplerState s;
9940 float4 main(float4 position : SV_POSITION) : SV_Target
9942 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
9944 #endif
9945 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9946 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9947 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9948 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9949 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9950 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9951 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9952 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9953 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9954 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9956 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
9958 if (!init_test_context(&test_context))
9959 return;
9961 device = test_context.device;
9963 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9964 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9966 texture_desc.Width = 64;
9967 texture_desc.Height = 64;
9968 texture_desc.MipLevels = 1;
9969 texture_desc.ArraySize = 1;
9970 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9971 texture_desc.SampleDesc.Count = 1;
9972 texture_desc.SampleDesc.Quality = 0;
9973 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9974 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
9975 texture_desc.CPUAccessFlags = 0;
9976 texture_desc.MiscFlags = 0;
9978 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9979 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9981 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9982 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9984 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
9985 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9987 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
9989 ID3D10Device_PSSetShader(device, ps);
9990 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
9991 sampler = NULL;
9992 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
9993 draw_quad(&test_context);
9994 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9996 ID3D10ShaderResourceView_Release(srv);
9997 ID3D10RenderTargetView_Release(rtv);
9998 ID3D10Texture2D_Release(texture);
9999 ID3D10PixelShader_Release(ps);
10000 release_test_context(&test_context);
10003 static void test_immediate_constant_buffer(void)
10005 struct d3d10core_test_context test_context;
10006 D3D10_TEXTURE2D_DESC texture_desc;
10007 ID3D10RenderTargetView *rtv;
10008 unsigned int index[4] = {0};
10009 ID3D10Texture2D *texture;
10010 ID3D10PixelShader *ps;
10011 ID3D10Device *device;
10012 ID3D10Buffer *cb;
10013 unsigned int i;
10014 HRESULT hr;
10016 static const DWORD ps_code[] =
10018 #if 0
10019 uint index;
10021 static const int int_array[6] =
10023 310, 111, 212, -513, -318, 0,
10026 static const uint uint_array[6] =
10028 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
10031 static const float float_array[6] =
10033 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
10036 float4 main() : SV_Target
10038 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
10040 #endif
10041 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
10042 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10043 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10044 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
10045 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
10046 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
10047 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
10048 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
10049 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
10050 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
10051 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
10052 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
10053 0x0100003e,
10055 static struct vec4 expected_result[] =
10057 { 310.0f, 2.0f, 76.00f, 1.0f},
10058 { 111.0f, 7.0f, 83.50f, 1.0f},
10059 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
10060 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
10061 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
10062 { 0.0f, 0.0f, 0.0f, 1.0f},
10065 if (!init_test_context(&test_context))
10066 return;
10068 device = test_context.device;
10070 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10071 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10072 ID3D10Device_PSSetShader(device, ps);
10074 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10075 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
10077 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10078 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10079 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10080 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10082 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10083 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10084 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10086 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
10088 *index = i;
10089 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
10091 draw_quad(&test_context);
10092 check_texture_vec4(texture, &expected_result[i], 0);
10095 ID3D10Buffer_Release(cb);
10096 ID3D10PixelShader_Release(ps);
10097 ID3D10Texture2D_Release(texture);
10098 ID3D10RenderTargetView_Release(rtv);
10099 release_test_context(&test_context);
10102 static void test_fp_specials(void)
10104 struct d3d10core_test_context test_context;
10105 D3D10_TEXTURE2D_DESC texture_desc;
10106 ID3D10RenderTargetView *rtv;
10107 ID3D10Texture2D *texture;
10108 ID3D10PixelShader *ps;
10109 ID3D10Device *device;
10110 HRESULT hr;
10112 static const DWORD ps_code[] =
10114 #if 0
10115 float4 main() : SV_Target
10117 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
10119 #endif
10120 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
10121 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10122 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10123 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10124 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
10125 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
10127 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
10129 if (!init_test_context(&test_context))
10130 return;
10132 device = test_context.device;
10134 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10135 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10136 ID3D10Device_PSSetShader(device, ps);
10138 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10139 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10140 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10141 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10143 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10144 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10146 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10148 draw_quad(&test_context);
10149 check_texture_uvec4(texture, &expected_result);
10151 ID3D10PixelShader_Release(ps);
10152 ID3D10Texture2D_Release(texture);
10153 ID3D10RenderTargetView_Release(rtv);
10154 release_test_context(&test_context);
10157 static void test_uint_shader_instructions(void)
10159 struct shader
10161 const DWORD *code;
10162 size_t size;
10165 struct d3d10core_test_context test_context;
10166 D3D10_TEXTURE2D_DESC texture_desc;
10167 ID3D10RenderTargetView *rtv;
10168 ID3D10Texture2D *texture;
10169 ID3D10PixelShader *ps;
10170 ID3D10Device *device;
10171 ID3D10Buffer *cb;
10172 unsigned int i;
10173 HRESULT hr;
10175 static const DWORD ps_ftou_code[] =
10177 #if 0
10178 float f;
10180 uint4 main() : SV_Target
10182 return uint4(f, -f, 0, 0);
10184 #endif
10185 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
10186 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10187 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10188 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
10189 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
10190 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
10191 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
10192 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
10194 static const DWORD ps_not_code[] =
10196 #if 0
10197 uint2 bits;
10199 uint4 main() : SV_Target
10201 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
10203 #endif
10204 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
10205 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10206 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10207 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10208 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10209 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
10210 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
10211 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
10213 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
10214 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
10215 static const struct
10217 const struct shader *ps;
10218 unsigned int bits[4];
10219 struct uvec4 expected_result;
10220 BOOL todo;
10222 tests[] =
10224 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
10225 {&ps_ftou, {BITS_NAN}, { 0, 0}},
10226 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
10227 {&ps_ftou, {BITS_INF}, {~0u, 0}},
10228 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
10229 {&ps_ftou, {BITS_1_0}, { 1, 0}},
10231 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
10232 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
10235 if (!init_test_context(&test_context))
10236 return;
10238 device = test_context.device;
10240 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
10241 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
10243 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10244 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
10245 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10246 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10248 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10249 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10251 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10253 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10255 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
10256 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10257 ID3D10Device_PSSetShader(device, ps);
10259 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
10261 draw_quad(&test_context);
10262 todo_wine_if(tests[i].todo)
10263 check_texture_uvec4(texture, &tests[i].expected_result);
10265 ID3D10PixelShader_Release(ps);
10268 ID3D10Buffer_Release(cb);
10269 ID3D10Texture2D_Release(texture);
10270 ID3D10RenderTargetView_Release(rtv);
10271 release_test_context(&test_context);
10274 static void test_index_buffer_offset(void)
10276 struct d3d10core_test_context test_context;
10277 ID3D10Buffer *vb, *ib, *so_buffer;
10278 ID3D10InputLayout *input_layout;
10279 struct resource_readback rb;
10280 ID3D10GeometryShader *gs;
10281 const struct vec4 *data;
10282 ID3D10VertexShader *vs;
10283 ID3D10Device *device;
10284 UINT stride, offset;
10285 unsigned int i;
10286 HRESULT hr;
10288 static const DWORD vs_code[] =
10290 #if 0
10291 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
10292 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
10294 out_position = position;
10295 out_attrib = attrib;
10297 #endif
10298 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
10299 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10300 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10301 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10302 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10303 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10304 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
10305 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10306 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10307 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10308 0x0100003e,
10310 static const DWORD gs_code[] =
10312 #if 0
10313 struct vertex
10315 float4 position : SV_POSITION;
10316 float4 attrib : ATTRIB;
10319 [maxvertexcount(1)]
10320 void main(point vertex input[1], inout PointStream<vertex> output)
10322 output.Append(input[0]);
10323 output.RestartStrip();
10325 #endif
10326 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
10327 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10328 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10329 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10330 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10331 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10332 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
10333 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
10334 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10335 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
10336 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
10337 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
10339 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
10341 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10342 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
10344 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
10346 {"SV_Position", 0, 0, 4, 0},
10347 {"ATTRIB", 0, 0, 4, 0},
10349 static const struct
10351 struct vec4 position;
10352 struct vec4 attrib;
10354 vertices[] =
10356 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
10357 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
10358 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
10359 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
10361 static const unsigned int indices[] =
10363 0, 1, 2, 3,
10364 3, 2, 1, 0,
10365 1, 3, 2, 0,
10367 static const struct vec4 expected_data[] =
10369 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10370 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10371 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10372 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10374 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10375 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10376 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10377 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10379 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10380 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10381 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10382 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10385 if (!init_test_context(&test_context))
10386 return;
10388 device = test_context.device;
10390 hr = ID3D10Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
10391 vs_code, sizeof(vs_code), &input_layout);
10392 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10394 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
10395 so_declaration, ARRAY_SIZE(so_declaration), 32, &gs);
10396 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
10398 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10399 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10401 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
10402 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
10403 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
10405 ID3D10Device_VSSetShader(device, vs);
10406 ID3D10Device_GSSetShader(device, gs);
10408 ID3D10Device_IASetInputLayout(device, input_layout);
10409 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
10410 stride = sizeof(*vertices);
10411 offset = 0;
10412 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10414 offset = 0;
10415 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
10417 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
10418 ID3D10Device_DrawIndexed(device, 4, 0, 0);
10420 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
10421 ID3D10Device_DrawIndexed(device, 4, 0, 0);
10423 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
10424 ID3D10Device_DrawIndexed(device, 4, 0, 0);
10426 get_buffer_readback(so_buffer, &rb);
10427 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
10429 data = get_readback_vec4(&rb, i, 0);
10430 ok(compare_vec4(data, &expected_data[i], 0),
10431 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
10432 data->x, data->y, data->z, data->w, i);
10434 release_resource_readback(&rb);
10436 ID3D10Buffer_Release(so_buffer);
10437 ID3D10Buffer_Release(ib);
10438 ID3D10Buffer_Release(vb);
10439 ID3D10VertexShader_Release(vs);
10440 ID3D10GeometryShader_Release(gs);
10441 ID3D10InputLayout_Release(input_layout);
10442 release_test_context(&test_context);
10445 static void test_face_culling(void)
10447 struct d3d10core_test_context test_context;
10448 D3D10_RASTERIZER_DESC rasterizer_desc;
10449 ID3D10RasterizerState *state;
10450 ID3D10Buffer *cw_vb, *ccw_vb;
10451 ID3D10Device *device;
10452 BOOL broken_warp;
10453 unsigned int i;
10454 HRESULT hr;
10456 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10457 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10458 static const DWORD ps_code[] =
10460 #if 0
10461 float4 main(uint front : SV_IsFrontFace) : SV_Target
10463 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
10465 #endif
10466 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
10467 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
10468 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
10469 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10470 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
10471 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
10472 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
10473 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
10474 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
10475 0x3f800000, 0x0100003e,
10477 static const struct vec2 ccw_quad[] =
10479 {-1.0f, 1.0f},
10480 {-1.0f, -1.0f},
10481 { 1.0f, 1.0f},
10482 { 1.0f, -1.0f},
10484 static const struct
10486 D3D10_CULL_MODE cull_mode;
10487 BOOL front_ccw;
10488 BOOL expected_cw;
10489 BOOL expected_ccw;
10491 tests[] =
10493 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
10494 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
10495 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
10496 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
10497 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
10498 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
10501 if (!init_test_context(&test_context))
10502 return;
10504 device = test_context.device;
10506 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10507 draw_color_quad(&test_context, &green);
10508 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10510 cw_vb = test_context.vb;
10511 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
10513 test_context.vb = ccw_vb;
10514 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10515 draw_color_quad(&test_context, &green);
10516 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
10518 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
10519 rasterizer_desc.CullMode = D3D10_CULL_BACK;
10520 rasterizer_desc.FrontCounterClockwise = FALSE;
10521 rasterizer_desc.DepthBias = 0;
10522 rasterizer_desc.DepthBiasClamp = 0.0f;
10523 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10524 rasterizer_desc.DepthClipEnable = TRUE;
10525 rasterizer_desc.ScissorEnable = FALSE;
10526 rasterizer_desc.MultisampleEnable = FALSE;
10527 rasterizer_desc.AntialiasedLineEnable = FALSE;
10529 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10531 rasterizer_desc.CullMode = tests[i].cull_mode;
10532 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
10533 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10534 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
10536 ID3D10Device_RSSetState(device, state);
10538 test_context.vb = cw_vb;
10539 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10540 draw_color_quad(&test_context, &green);
10541 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
10543 test_context.vb = ccw_vb;
10544 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10545 draw_color_quad(&test_context, &green);
10546 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
10548 ID3D10RasterizerState_Release(state);
10551 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
10553 /* Test SV_IsFrontFace. */
10554 ID3D10PixelShader_Release(test_context.ps);
10555 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
10556 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10558 rasterizer_desc.CullMode = D3D10_CULL_NONE;
10559 rasterizer_desc.FrontCounterClockwise = FALSE;
10560 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10561 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10562 ID3D10Device_RSSetState(device, state);
10564 test_context.vb = cw_vb;
10565 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10566 draw_color_quad(&test_context, &green);
10567 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10568 test_context.vb = ccw_vb;
10569 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10570 draw_color_quad(&test_context, &green);
10571 if (!broken_warp)
10572 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10573 else
10574 win_skip("Broken WARP.\n");
10576 ID3D10RasterizerState_Release(state);
10578 rasterizer_desc.CullMode = D3D10_CULL_NONE;
10579 rasterizer_desc.FrontCounterClockwise = TRUE;
10580 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10581 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10582 ID3D10Device_RSSetState(device, state);
10584 test_context.vb = cw_vb;
10585 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10586 draw_color_quad(&test_context, &green);
10587 if (!broken_warp)
10588 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
10589 else
10590 win_skip("Broken WARP.\n");
10591 test_context.vb = ccw_vb;
10592 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10593 draw_color_quad(&test_context, &green);
10594 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10596 ID3D10RasterizerState_Release(state);
10598 test_context.vb = cw_vb;
10599 ID3D10Buffer_Release(ccw_vb);
10600 release_test_context(&test_context);
10603 static void test_line_antialiasing_blending(void)
10605 struct d3d10core_test_context test_context;
10606 ID3D10RasterizerState *rasterizer_state;
10607 D3D10_RASTERIZER_DESC rasterizer_desc;
10608 ID3D10BlendState *blend_state;
10609 D3D10_BLEND_DESC blend_desc;
10610 ID3D10Device *device;
10611 HRESULT hr;
10613 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
10614 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
10616 if (!init_test_context(&test_context))
10617 return;
10619 device = test_context.device;
10621 memset(&blend_desc, 0, sizeof(blend_desc));
10622 blend_desc.AlphaToCoverageEnable = FALSE;
10623 blend_desc.BlendEnable[0] = TRUE;
10624 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
10625 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
10626 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
10627 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
10628 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
10629 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
10630 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
10632 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
10633 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
10634 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
10636 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10637 draw_color_quad(&test_context, &green);
10638 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10640 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
10641 draw_color_quad(&test_context, &red);
10642 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10644 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
10645 ID3D10BlendState_Release(blend_state);
10647 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10648 draw_color_quad(&test_context, &green);
10649 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10651 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
10652 draw_color_quad(&test_context, &red);
10653 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10655 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
10656 rasterizer_desc.CullMode = D3D10_CULL_BACK;
10657 rasterizer_desc.FrontCounterClockwise = FALSE;
10658 rasterizer_desc.DepthBias = 0;
10659 rasterizer_desc.DepthBiasClamp = 0.0f;
10660 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10661 rasterizer_desc.DepthClipEnable = TRUE;
10662 rasterizer_desc.ScissorEnable = FALSE;
10663 rasterizer_desc.MultisampleEnable = FALSE;
10664 rasterizer_desc.AntialiasedLineEnable = TRUE;
10666 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
10667 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10668 ID3D10Device_RSSetState(device, rasterizer_state);
10670 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
10671 draw_color_quad(&test_context, &green);
10672 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10674 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
10675 draw_color_quad(&test_context, &red);
10676 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10678 ID3D10RasterizerState_Release(rasterizer_state);
10679 release_test_context(&test_context);
10682 static void check_format_support(const unsigned int *format_support,
10683 const struct format_support *formats, unsigned int format_count,
10684 unsigned int feature_flag, const char *feature_name)
10686 unsigned int i;
10688 for (i = 0; i < format_count; ++i)
10690 DXGI_FORMAT format = formats[i].format;
10691 unsigned int supported = format_support[format] & feature_flag;
10693 if (formats[i].optional)
10695 if (supported)
10696 trace("Optional format %#x - %s supported.\n", format, feature_name);
10697 continue;
10700 ok(supported, "Format %#x - %s supported, format support %#x.\n",
10701 format, feature_name, format_support[format]);
10705 static void test_required_format_support(void)
10707 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
10708 ID3D10Device *device;
10709 DXGI_FORMAT format;
10710 ULONG refcount;
10711 HRESULT hr;
10713 static const struct format_support index_buffers[] =
10715 {DXGI_FORMAT_R32_UINT},
10716 {DXGI_FORMAT_R16_UINT},
10719 if (!(device = create_device()))
10721 skip("Failed to create device.\n");
10722 return;
10725 memset(format_support, 0, sizeof(format_support));
10726 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
10728 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
10729 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
10730 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
10731 format, hr, format_support[format]);
10733 if (hr == E_NOTIMPL)
10735 skip("CheckFormatSupport not implemented.\n");
10736 ID3D10Device_Release(device);
10737 return;
10740 check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
10741 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
10743 check_format_support(format_support, display_format_support, ARRAY_SIZE(display_format_support),
10744 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
10746 refcount = ID3D10Device_Release(device);
10747 ok(!refcount, "Device has %u references left.\n", refcount);
10750 static void test_ddy(void)
10752 static const struct
10754 struct vec4 position;
10755 unsigned int color;
10757 quad[] =
10759 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
10760 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10761 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
10762 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10764 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10766 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10767 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
10769 #if 0
10770 struct vs_data
10772 float4 pos : SV_POSITION;
10773 float4 color : COLOR;
10776 void main(in struct vs_data vs_input, out struct vs_data vs_output)
10778 vs_output.pos = vs_input.pos;
10779 vs_output.color = vs_input.color;
10781 #endif
10782 static const DWORD vs_code[] =
10784 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
10785 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10786 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10787 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10788 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10789 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10790 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10791 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10792 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10793 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10794 0x0100003e,
10796 #if 0
10797 struct ps_data
10799 float4 pos : SV_POSITION;
10800 float4 color : COLOR;
10803 float4 main(struct ps_data ps_input) : SV_Target
10805 return ddy(ps_input.color) * 240.0 + 0.5;
10807 #endif
10808 static const DWORD ps_code[] =
10810 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
10811 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10812 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10813 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10814 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10815 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
10816 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10817 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
10818 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
10819 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
10821 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10822 struct d3d10core_test_context test_context;
10823 D3D10_TEXTURE2D_DESC texture_desc;
10824 ID3D10InputLayout *input_layout;
10825 unsigned int stride, offset;
10826 struct resource_readback rb;
10827 ID3D10RenderTargetView *rtv;
10828 ID3D10Texture2D *texture;
10829 ID3D10VertexShader *vs;
10830 ID3D10PixelShader *ps;
10831 ID3D10Device *device;
10832 ID3D10Buffer *vb;
10833 DWORD color;
10834 HRESULT hr;
10836 if (!init_test_context(&test_context))
10837 return;
10839 device = test_context.device;
10841 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10842 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10843 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10845 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10846 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10848 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10849 vs_code, sizeof(vs_code), &input_layout);
10850 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10852 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10854 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10855 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10857 ID3D10Device_IASetInputLayout(device, input_layout);
10858 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10859 stride = sizeof(*quad);
10860 offset = 0;
10861 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10862 ID3D10Device_VSSetShader(device, vs);
10864 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10865 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10867 ID3D10Device_PSSetShader(device, ps);
10869 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10870 ID3D10Device_ClearRenderTargetView(device, rtv, red);
10871 ID3D10Device_Draw(device, 4, 0);
10873 get_texture_readback(texture, 0, &rb);
10874 color = get_readback_color(&rb, 320, 190);
10875 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10876 color = get_readback_color(&rb, 255, 240);
10877 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10878 color = get_readback_color(&rb, 320, 240);
10879 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10880 color = get_readback_color(&rb, 385, 240);
10881 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10882 color = get_readback_color(&rb, 320, 290);
10883 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10884 release_resource_readback(&rb);
10886 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
10887 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
10888 ID3D10Device_Draw(device, 4, 0);
10890 get_texture_readback(test_context.backbuffer, 0, &rb);
10891 color = get_readback_color(&rb, 320, 190);
10892 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10893 color = get_readback_color(&rb, 255, 240);
10894 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10895 color = get_readback_color(&rb, 320, 240);
10896 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10897 color = get_readback_color(&rb, 385, 240);
10898 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10899 color = get_readback_color(&rb, 320, 290);
10900 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10901 release_resource_readback(&rb);
10903 ID3D10PixelShader_Release(ps);
10904 ID3D10VertexShader_Release(vs);
10905 ID3D10Buffer_Release(vb);
10906 ID3D10InputLayout_Release(input_layout);
10907 ID3D10Texture2D_Release(texture);
10908 ID3D10RenderTargetView_Release(rtv);
10909 release_test_context(&test_context);
10912 static void test_shader_input_registers_limits(void)
10914 struct d3d10core_test_context test_context;
10915 D3D10_SUBRESOURCE_DATA resource_data;
10916 D3D10_TEXTURE2D_DESC texture_desc;
10917 D3D10_SAMPLER_DESC sampler_desc;
10918 ID3D10ShaderResourceView *srv;
10919 ID3D10SamplerState *sampler;
10920 ID3D10Texture2D *texture;
10921 ID3D10PixelShader *ps;
10922 ID3D10Device *device;
10923 HRESULT hr;
10925 static const DWORD ps_last_register_code[] =
10927 #if 0
10928 Texture2D t : register(t127);
10929 SamplerState s : register(s15);
10931 void main(out float4 target : SV_Target)
10933 target = t.Sample(s, float2(0, 0));
10935 #endif
10936 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
10937 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10938 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10939 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
10940 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
10941 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
10942 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
10944 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10945 static const DWORD texture_data[] = {0xff00ff00};
10947 if (!init_test_context(&test_context))
10948 return;
10950 device = test_context.device;
10952 texture_desc.Width = 1;
10953 texture_desc.Height = 1;
10954 texture_desc.MipLevels = 0;
10955 texture_desc.ArraySize = 1;
10956 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10957 texture_desc.SampleDesc.Count = 1;
10958 texture_desc.SampleDesc.Quality = 0;
10959 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10960 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
10961 texture_desc.CPUAccessFlags = 0;
10962 texture_desc.MiscFlags = 0;
10964 resource_data.pSysMem = texture_data;
10965 resource_data.SysMemPitch = sizeof(texture_data);
10966 resource_data.SysMemSlicePitch = 0;
10968 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
10969 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10971 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
10972 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10974 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
10975 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
10976 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
10977 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
10978 sampler_desc.MipLODBias = 0.0f;
10979 sampler_desc.MaxAnisotropy = 0;
10980 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
10981 sampler_desc.BorderColor[0] = 0.0f;
10982 sampler_desc.BorderColor[1] = 0.0f;
10983 sampler_desc.BorderColor[2] = 0.0f;
10984 sampler_desc.BorderColor[3] = 0.0f;
10985 sampler_desc.MinLOD = 0.0f;
10986 sampler_desc.MaxLOD = 0.0f;
10988 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
10989 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10991 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
10992 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10993 ID3D10Device_PSSetShader(device, ps);
10995 ID3D10Device_PSSetShaderResources(device,
10996 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
10997 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
10998 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10999 draw_quad(&test_context);
11000 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11002 ID3D10PixelShader_Release(ps);
11003 ID3D10SamplerState_Release(sampler);
11004 ID3D10ShaderResourceView_Release(srv);
11005 ID3D10Texture2D_Release(texture);
11006 release_test_context(&test_context);
11009 static void test_unbind_shader_resource_view(void)
11011 struct d3d10core_test_context test_context;
11012 D3D10_SUBRESOURCE_DATA resource_data;
11013 ID3D10ShaderResourceView *srv, *srv2;
11014 D3D10_TEXTURE2D_DESC texture_desc;
11015 ID3D10Texture2D *texture;
11016 ID3D10PixelShader *ps;
11017 ID3D10Device *device;
11018 HRESULT hr;
11020 static const DWORD ps_code[] =
11022 #if 0
11023 Texture2D t0;
11024 Texture2D t1;
11025 SamplerState s;
11027 float4 main() : SV_Target
11029 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
11031 #endif
11032 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
11033 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11034 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11035 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
11036 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
11037 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
11038 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
11039 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
11040 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
11041 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
11042 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
11043 0x3f800000, 0x0100003e,
11045 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11046 static const DWORD texture_data[] = {0xff00ff00};
11048 if (!init_test_context(&test_context))
11049 return;
11051 device = test_context.device;
11053 texture_desc.Width = 1;
11054 texture_desc.Height = 1;
11055 texture_desc.MipLevels = 0;
11056 texture_desc.ArraySize = 1;
11057 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11058 texture_desc.SampleDesc.Count = 1;
11059 texture_desc.SampleDesc.Quality = 0;
11060 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11061 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
11062 texture_desc.CPUAccessFlags = 0;
11063 texture_desc.MiscFlags = 0;
11065 resource_data.pSysMem = texture_data;
11066 resource_data.SysMemPitch = sizeof(texture_data);
11067 resource_data.SysMemSlicePitch = 0;
11069 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
11070 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11071 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
11072 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11073 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11074 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11075 ID3D10Device_PSSetShader(device, ps);
11077 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
11078 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv);
11079 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11080 draw_quad(&test_context);
11081 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11083 srv2 = NULL;
11084 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv2);
11085 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv2);
11086 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11087 draw_quad(&test_context);
11088 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
11090 ID3D10PixelShader_Release(ps);
11091 ID3D10ShaderResourceView_Release(srv);
11092 ID3D10Texture2D_Release(texture);
11093 release_test_context(&test_context);
11096 static void test_stencil_separate(void)
11098 struct d3d10core_test_context test_context;
11099 D3D10_TEXTURE2D_DESC texture_desc;
11100 D3D10_DEPTH_STENCIL_DESC ds_desc;
11101 ID3D10DepthStencilState *ds_state;
11102 ID3D10DepthStencilView *ds_view;
11103 D3D10_RASTERIZER_DESC rs_desc;
11104 ID3D10RasterizerState *rs;
11105 ID3D10Texture2D *texture;
11106 ID3D10Device *device;
11107 HRESULT hr;
11109 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11110 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11111 static const struct vec2 ccw_quad[] =
11113 {-1.0f, -1.0f},
11114 { 1.0f, -1.0f},
11115 {-1.0f, 1.0f},
11116 { 1.0f, 1.0f},
11119 if (!init_test_context(&test_context))
11120 return;
11122 device = test_context.device;
11124 texture_desc.Width = 640;
11125 texture_desc.Height = 480;
11126 texture_desc.MipLevels = 1;
11127 texture_desc.ArraySize = 1;
11128 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11129 texture_desc.SampleDesc.Count = 1;
11130 texture_desc.SampleDesc.Quality = 0;
11131 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11132 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11133 texture_desc.CPUAccessFlags = 0;
11134 texture_desc.MiscFlags = 0;
11135 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11136 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11137 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
11138 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11140 ds_desc.DepthEnable = TRUE;
11141 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
11142 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
11143 ds_desc.StencilEnable = TRUE;
11144 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
11145 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
11146 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
11147 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
11148 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
11149 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
11150 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
11151 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
11152 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
11153 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
11154 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
11155 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11157 rs_desc.FillMode = D3D10_FILL_SOLID;
11158 rs_desc.CullMode = D3D10_CULL_NONE;
11159 rs_desc.FrontCounterClockwise = FALSE;
11160 rs_desc.DepthBias = 0;
11161 rs_desc.DepthBiasClamp = 0.0f;
11162 rs_desc.SlopeScaledDepthBias = 0.0f;
11163 rs_desc.DepthClipEnable = TRUE;
11164 rs_desc.ScissorEnable = FALSE;
11165 rs_desc.MultisampleEnable = FALSE;
11166 rs_desc.AntialiasedLineEnable = FALSE;
11167 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
11168 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11170 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
11171 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
11172 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
11173 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
11174 ID3D10Device_RSSetState(device, rs);
11176 draw_color_quad(&test_context, &green);
11177 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11179 ID3D10Buffer_Release(test_context.vb);
11180 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
11182 draw_color_quad(&test_context, &green);
11183 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11185 ID3D10RasterizerState_Release(rs);
11186 rs_desc.FrontCounterClockwise = TRUE;
11187 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
11188 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11189 ID3D10Device_RSSetState(device, rs);
11191 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
11192 draw_color_quad(&test_context, &green);
11193 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11195 ID3D10DepthStencilState_Release(ds_state);
11196 ID3D10DepthStencilView_Release(ds_view);
11197 ID3D10RasterizerState_Release(rs);
11198 ID3D10Texture2D_Release(texture);
11199 release_test_context(&test_context);
11202 static void test_sm4_ret_instruction(void)
11204 struct d3d10core_test_context test_context;
11205 ID3D10PixelShader *ps;
11206 struct uvec4 constant;
11207 ID3D10Device *device;
11208 ID3D10Buffer *cb;
11209 HRESULT hr;
11211 static const DWORD ps_code[] =
11213 #if 0
11214 uint c;
11216 float4 main() : SV_TARGET
11218 if (c == 1)
11219 return float4(1, 0, 0, 1);
11220 if (c == 2)
11221 return float4(0, 1, 0, 1);
11222 if (c == 3)
11223 return float4(0, 0, 1, 1);
11224 return float4(1, 1, 1, 1);
11226 #endif
11227 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
11228 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11229 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11230 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
11231 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11232 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
11233 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11234 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
11235 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
11236 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
11237 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
11238 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
11239 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
11240 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
11241 0x0100003e,
11244 if (!init_test_context(&test_context))
11245 return;
11247 device = test_context.device;
11249 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11250 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
11251 ID3D10Device_PSSetShader(device, ps);
11252 memset(&constant, 0, sizeof(constant));
11253 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11254 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11256 draw_quad(&test_context);
11257 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
11259 constant.x = 1;
11260 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
11261 draw_quad(&test_context);
11262 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
11264 constant.x = 2;
11265 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
11266 draw_quad(&test_context);
11267 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11269 constant.x = 3;
11270 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
11271 draw_quad(&test_context);
11272 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11274 constant.x = 4;
11275 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
11276 draw_quad(&test_context);
11277 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
11279 ID3D10Buffer_Release(cb);
11280 ID3D10PixelShader_Release(ps);
11281 release_test_context(&test_context);
11284 static void test_primitive_restart(void)
11286 struct d3d10core_test_context test_context;
11287 ID3D10Buffer *ib32, *ib16, *vb;
11288 unsigned int stride, offset;
11289 ID3D10InputLayout *layout;
11290 ID3D10VertexShader *vs;
11291 ID3D10PixelShader *ps;
11292 ID3D10Device *device;
11293 unsigned int i;
11294 HRESULT hr;
11295 RECT rect;
11297 static const DWORD ps_code[] =
11299 #if 0
11300 struct vs_out
11302 float4 position : SV_Position;
11303 float4 color : color;
11306 float4 main(vs_out input) : SV_TARGET
11308 return input.color;
11310 #endif
11311 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
11312 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11313 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11314 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
11315 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11316 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
11317 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11318 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11320 static const DWORD vs_code[] =
11322 #if 0
11323 struct vs_out
11325 float4 position : SV_Position;
11326 float4 color : color;
11329 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
11331 output.position = position;
11332 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
11334 #endif
11335 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
11336 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
11337 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
11338 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
11339 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11340 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11341 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
11342 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
11343 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
11344 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
11345 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
11346 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
11347 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11349 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
11351 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11353 static const struct vec2 vertices[] =
11355 {-1.00f, -1.0f},
11356 {-1.00f, 1.0f},
11357 {-0.25f, -1.0f},
11358 {-0.25f, 1.0f},
11359 { 0.25f, -1.0f},
11360 { 0.25f, 1.0f},
11361 { 1.00f, -1.0f},
11362 { 1.00f, 1.0f},
11364 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
11365 static const unsigned short indices16[] =
11367 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
11369 static const unsigned int indices32[] =
11371 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
11374 if (!init_test_context(&test_context))
11375 return;
11377 device = test_context.device;
11379 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11380 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11381 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11382 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
11384 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
11385 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
11387 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11388 vs_code, sizeof(vs_code), &layout);
11389 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11391 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
11393 ID3D10Device_VSSetShader(device, vs);
11394 ID3D10Device_PSSetShader(device, ps);
11396 ID3D10Device_IASetInputLayout(device, layout);
11397 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11398 stride = sizeof(*vertices);
11399 offset = 0;
11400 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
11402 for (i = 0; i < 2; ++i)
11404 if (!i)
11405 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
11406 else
11407 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
11409 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
11410 ID3D10Device_DrawIndexed(device, 9, 0, 0);
11411 SetRect(&rect, 0, 0, 240, 480);
11412 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
11413 SetRect(&rect, 240, 0, 400, 480);
11414 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
11415 SetRect(&rect, 400, 0, 640, 480);
11416 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
11419 ID3D10Buffer_Release(ib16);
11420 ID3D10Buffer_Release(ib32);
11421 ID3D10Buffer_Release(vb);
11422 ID3D10InputLayout_Release(layout);
11423 ID3D10PixelShader_Release(ps);
11424 ID3D10VertexShader_Release(vs);
11425 release_test_context(&test_context);
11428 static void test_resinfo_instruction(void)
11430 struct shader
11432 const DWORD *code;
11433 size_t size;
11436 struct d3d10core_test_context test_context;
11437 D3D10_TEXTURE3D_DESC texture3d_desc;
11438 D3D10_TEXTURE2D_DESC texture_desc;
11439 const struct shader *current_ps;
11440 ID3D10ShaderResourceView *srv;
11441 ID3D10Texture2D *rtv_texture;
11442 ID3D10RenderTargetView *rtv;
11443 ID3D10Resource *texture;
11444 struct uvec4 constant;
11445 ID3D10PixelShader *ps;
11446 ID3D10Device *device;
11447 unsigned int i, type;
11448 ID3D10Buffer *cb;
11449 HRESULT hr;
11451 static const DWORD ps_2d_code[] =
11453 #if 0
11454 Texture2D t;
11456 uint type;
11457 uint level;
11459 float4 main() : SV_TARGET
11461 if (!type)
11463 float width, height, miplevels;
11464 t.GetDimensions(level, width, height, miplevels);
11465 return float4(width, height, miplevels, 0);
11467 else
11469 uint width, height, miplevels;
11470 t.GetDimensions(level, width, height, miplevels);
11471 return float4(width, height, miplevels, 0);
11474 #endif
11475 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
11476 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11477 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11478 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
11479 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11480 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
11481 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
11482 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
11483 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
11484 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
11485 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
11486 0x01000015, 0x0100003e,
11488 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
11489 static const DWORD ps_2d_array_code[] =
11491 #if 0
11492 Texture2DArray t;
11494 uint type;
11495 uint level;
11497 float4 main() : SV_TARGET
11499 if (!type)
11501 float width, height, elements, miplevels;
11502 t.GetDimensions(level, width, height, elements, miplevels);
11503 return float4(width, height, elements, miplevels);
11505 else
11507 uint width, height, elements, miplevels;
11508 t.GetDimensions(level, width, height, elements, miplevels);
11509 return float4(width, height, elements, miplevels);
11512 #endif
11513 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
11514 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11515 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11516 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
11517 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
11518 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
11519 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
11520 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
11521 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
11522 0x0100003e, 0x01000015, 0x0100003e,
11524 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
11525 static const DWORD ps_3d_code[] =
11527 #if 0
11528 Texture3D t;
11530 uint type;
11531 uint level;
11533 float4 main() : SV_TARGET
11535 if (!type)
11537 float width, height, depth, miplevels;
11538 t.GetDimensions(level, width, height, depth, miplevels);
11539 return float4(width, height, depth, miplevels);
11541 else
11543 uint width, height, depth, miplevels;
11544 t.GetDimensions(level, width, height, depth, miplevels);
11545 return float4(width, height, depth, miplevels);
11548 #endif
11549 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
11550 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11551 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11552 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
11553 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
11554 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
11555 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
11556 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
11557 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
11558 0x0100003e, 0x01000015, 0x0100003e,
11560 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
11561 static const DWORD ps_cube_code[] =
11563 #if 0
11564 TextureCube t;
11566 uint type;
11567 uint level;
11569 float4 main() : SV_TARGET
11571 if (!type)
11573 float width, height, miplevels;
11574 t.GetDimensions(level, width, height, miplevels);
11575 return float4(width, height, miplevels, 0);
11577 else
11579 uint width, height, miplevels;
11580 t.GetDimensions(level, width, height, miplevels);
11581 return float4(width, height, miplevels, 0);
11584 #endif
11585 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
11586 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11587 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11588 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
11589 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
11590 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
11591 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
11592 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
11593 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
11594 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
11595 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
11596 0x01000015, 0x0100003e,
11598 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
11599 static const struct test
11601 const struct shader *ps;
11602 struct
11604 unsigned int width;
11605 unsigned int height;
11606 unsigned int depth;
11607 unsigned int miplevel_count;
11608 unsigned int array_size;
11609 unsigned int cube_count;
11610 } texture_desc;
11611 unsigned int miplevel;
11612 struct vec4 expected_result;
11614 tests[] =
11616 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
11617 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
11618 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
11619 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
11621 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
11622 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
11623 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
11624 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
11626 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
11627 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
11628 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
11629 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
11630 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
11631 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
11632 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
11633 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
11634 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
11636 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
11637 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
11638 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
11639 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
11640 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
11643 if (!init_test_context(&test_context))
11644 return;
11646 device = test_context.device;
11648 texture_desc.Width = 64;
11649 texture_desc.Height = 64;
11650 texture_desc.MipLevels = 1;
11651 texture_desc.ArraySize = 1;
11652 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11653 texture_desc.SampleDesc.Count = 1;
11654 texture_desc.SampleDesc.Quality = 0;
11655 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11656 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11657 texture_desc.CPUAccessFlags = 0;
11658 texture_desc.MiscFlags = 0;
11659 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
11660 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11661 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
11662 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11664 memset(&constant, 0, sizeof(constant));
11665 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11667 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11668 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11670 ps = NULL;
11671 current_ps = NULL;
11672 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11674 const struct test *test = &tests[i];
11676 if (current_ps != test->ps)
11678 if (ps)
11679 ID3D10PixelShader_Release(ps);
11681 current_ps = test->ps;
11683 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
11684 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
11685 ID3D10Device_PSSetShader(device, ps);
11688 if (test->texture_desc.depth != 1)
11690 texture3d_desc.Width = test->texture_desc.width;
11691 texture3d_desc.Height = test->texture_desc.height;
11692 texture3d_desc.Depth = test->texture_desc.depth;
11693 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
11694 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
11695 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
11696 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
11697 texture3d_desc.CPUAccessFlags = 0;
11698 texture3d_desc.MiscFlags = 0;
11699 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D10Texture3D **)&texture);
11700 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11702 else
11704 texture_desc.Width = test->texture_desc.width;
11705 texture_desc.Height = test->texture_desc.height;
11706 texture_desc.MipLevels = test->texture_desc.miplevel_count;
11707 texture_desc.ArraySize = test->texture_desc.array_size;
11708 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
11709 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
11710 texture_desc.MiscFlags = 0;
11711 if (test->texture_desc.cube_count)
11712 texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
11713 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
11714 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11717 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
11718 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
11719 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
11721 for (type = 0; type < 2; ++type)
11723 constant.x = type;
11724 constant.y = test->miplevel;
11725 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
11727 draw_quad(&test_context);
11728 check_texture_vec4(rtv_texture, &test->expected_result, 0);
11731 ID3D10Resource_Release(texture);
11732 ID3D10ShaderResourceView_Release(srv);
11734 ID3D10PixelShader_Release(ps);
11736 ID3D10Buffer_Release(cb);
11737 ID3D10RenderTargetView_Release(rtv);
11738 ID3D10Texture2D_Release(rtv_texture);
11739 release_test_context(&test_context);
11742 static void test_render_target_device_mismatch(void)
11744 struct d3d10core_test_context test_context;
11745 ID3D10RenderTargetView *rtv;
11746 ID3D10Device *device;
11747 ULONG refcount;
11749 if (!init_test_context(&test_context))
11750 return;
11752 device = create_device();
11753 ok(!!device, "Failed to create device.\n");
11755 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
11756 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
11757 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
11758 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
11759 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
11760 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
11761 ID3D10RenderTargetView_Release(rtv);
11763 rtv = NULL;
11764 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11766 refcount = ID3D10Device_Release(device);
11767 ok(!refcount, "Device has %u references left.\n", refcount);
11768 release_test_context(&test_context);
11771 static void test_buffer_srv(void)
11773 struct buffer
11775 unsigned int byte_count;
11776 unsigned int data_offset;
11777 const void *data;
11780 struct d3d10core_test_context test_context;
11781 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
11782 D3D10_SUBRESOURCE_DATA resource_data;
11783 const struct buffer *current_buffer;
11784 ID3D10ShaderResourceView *srv;
11785 D3D10_BUFFER_DESC buffer_desc;
11786 DWORD color, expected_color;
11787 struct resource_readback rb;
11788 ID3D10Buffer *cb, *buffer;
11789 ID3D10PixelShader *ps;
11790 ID3D10Device *device;
11791 unsigned int i, x, y;
11792 struct vec4 cb_size;
11793 HRESULT hr;
11795 static const DWORD ps_float4_code[] =
11797 #if 0
11798 Buffer<float4> b;
11800 float2 size;
11802 float4 main(float4 position : SV_POSITION) : SV_Target
11804 float2 p;
11805 int2 coords;
11806 p.x = position.x / 640.0f;
11807 p.y = position.y / 480.0f;
11808 coords = int2(p.x * size.x, p.y * size.y);
11809 return b.Load(coords.y * size.x + coords.x);
11811 #endif
11812 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
11813 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11814 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11815 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11816 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
11817 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
11818 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11819 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
11820 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
11821 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
11822 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
11823 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11824 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
11826 static const DWORD rgba16[] =
11828 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
11829 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
11830 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
11831 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
11833 static const DWORD rgba4[] =
11835 0xffffffff, 0xff0000ff,
11836 0xff000000, 0xff00ff00,
11838 static const BYTE r4[] =
11840 0xde, 0xad,
11841 0xba, 0xbe,
11843 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
11844 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
11845 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
11846 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
11847 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
11848 static const DWORD rgba16_colors2x2[] =
11850 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
11851 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
11852 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
11853 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
11855 static const DWORD rgba16_colors1x1[] =
11857 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
11858 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
11859 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
11860 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
11862 static const DWORD rgba4_colors[] =
11864 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
11865 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
11866 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
11867 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
11869 static const DWORD r4_colors[] =
11871 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
11872 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
11873 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
11874 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
11876 static const DWORD zero_colors[16] = {0};
11877 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11879 static const struct test
11881 const struct buffer *buffer;
11882 DXGI_FORMAT srv_format;
11883 UINT srv_first_element;
11884 UINT srv_element_count;
11885 struct vec2 size;
11886 const DWORD *expected_colors;
11888 tests[] =
11890 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
11891 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
11892 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
11893 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
11894 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
11895 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
11896 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
11897 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
11900 if (!init_test_context(&test_context))
11901 return;
11903 device = test_context.device;
11905 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
11907 hr = ID3D10Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), &ps);
11908 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11910 ID3D10Device_PSSetShader(device, ps);
11911 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11913 srv = NULL;
11914 buffer = NULL;
11915 current_buffer = NULL;
11916 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11918 const struct test *test = &tests[i];
11920 if (current_buffer != test->buffer)
11922 if (buffer)
11923 ID3D10Buffer_Release(buffer);
11925 current_buffer = test->buffer;
11926 if (current_buffer)
11928 BYTE *data = NULL;
11930 buffer_desc.ByteWidth = current_buffer->byte_count;
11931 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
11932 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
11933 buffer_desc.CPUAccessFlags = 0;
11934 buffer_desc.MiscFlags = 0;
11935 resource_data.SysMemPitch = 0;
11936 resource_data.SysMemSlicePitch = 0;
11937 if (current_buffer->data_offset)
11939 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
11940 ok(!!data, "Failed to allocate memory.\n");
11941 memcpy(data + current_buffer->data_offset, current_buffer->data,
11942 current_buffer->byte_count - current_buffer->data_offset);
11943 resource_data.pSysMem = data;
11945 else
11947 resource_data.pSysMem = current_buffer->data;
11949 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
11950 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
11951 HeapFree(GetProcessHeap(), 0, data);
11953 else
11955 buffer = NULL;
11959 if (srv)
11960 ID3D10ShaderResourceView_Release(srv);
11961 if (current_buffer)
11963 srv_desc.Format = test->srv_format;
11964 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
11965 U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
11966 U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
11967 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
11968 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
11970 else
11972 srv = NULL;
11974 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
11976 cb_size.x = test->size.x;
11977 cb_size.y = test->size.y;
11978 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_size, 0, 0);
11980 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
11981 draw_quad(&test_context);
11983 get_texture_readback(test_context.backbuffer, 0, &rb);
11984 for (y = 0; y < 4; ++y)
11986 for (x = 0; x < 4; ++x)
11988 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
11989 expected_color = test->expected_colors[y * 4 + x];
11990 ok(compare_color(color, expected_color, 1),
11991 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
11992 i, color, expected_color, x, y);
11995 release_resource_readback(&rb);
11997 if (srv)
11998 ID3D10ShaderResourceView_Release(srv);
11999 if (buffer)
12000 ID3D10Buffer_Release(buffer);
12002 ID3D10Buffer_Release(cb);
12003 ID3D10PixelShader_Release(ps);
12004 release_test_context(&test_context);
12007 static void test_geometry_shader(void)
12009 static const struct
12011 struct vec4 position;
12012 unsigned int color;
12014 vertex[] =
12016 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
12018 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
12020 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12021 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
12023 #if 0
12024 struct vs_data
12026 float4 pos : SV_POSITION;
12027 float4 color : COLOR;
12030 void main(in struct vs_data vs_input, out struct vs_data vs_output)
12032 vs_output.pos = vs_input.pos;
12033 vs_output.color = vs_input.color;
12035 #endif
12036 static const DWORD vs_code[] =
12038 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
12039 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12040 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12041 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12042 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12043 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12044 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12045 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12046 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12047 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12048 0x0100003e,
12050 #if 0
12051 struct gs_data
12053 float4 pos : SV_POSITION;
12054 float4 color : COLOR;
12057 [maxvertexcount(4)]
12058 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
12060 float offset = 0.2 * vin[0].pos.w;
12061 gs_data v;
12063 v.color = vin[0].color;
12065 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
12066 vout.Append(v);
12067 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
12068 vout.Append(v);
12069 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
12070 vout.Append(v);
12071 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
12072 vout.Append(v);
12074 #endif
12075 static const DWORD gs_code[] =
12077 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
12078 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12079 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12080 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12081 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12082 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12083 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
12084 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
12085 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
12086 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
12087 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
12088 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
12089 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
12090 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
12091 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
12092 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
12093 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
12094 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
12095 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
12096 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
12097 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
12098 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
12099 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
12100 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
12101 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
12102 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
12103 0x00000001, 0x01000013, 0x0100003e,
12105 #if 0
12106 struct ps_data
12108 float4 pos : SV_POSITION;
12109 float4 color : COLOR;
12112 float4 main(struct ps_data ps_input) : SV_Target
12114 return ps_input.color;
12116 #endif
12117 static const DWORD ps_code[] =
12119 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
12120 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12121 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12122 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12123 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12124 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
12125 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
12126 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12128 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12129 struct d3d10core_test_context test_context;
12130 ID3D10InputLayout *input_layout;
12131 D3D10_RASTERIZER_DESC rs_desc;
12132 unsigned int stride, offset;
12133 struct resource_readback rb;
12134 ID3D10RasterizerState *rs;
12135 ID3D10GeometryShader *gs;
12136 ID3D10VertexShader *vs;
12137 ID3D10PixelShader *ps;
12138 ID3D10Device *device;
12139 ID3D10Buffer *vb;
12140 DWORD color;
12141 HRESULT hr;
12143 if (!init_test_context(&test_context))
12144 return;
12146 device = test_context.device;
12148 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12149 vs_code, sizeof(vs_code), &input_layout);
12150 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12152 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
12154 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
12155 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12156 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
12157 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12158 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12159 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12161 rs_desc.FillMode = D3D10_FILL_SOLID;
12162 rs_desc.CullMode = D3D10_CULL_BACK;
12163 rs_desc.FrontCounterClockwise = FALSE;
12164 rs_desc.DepthBias = 0;
12165 rs_desc.DepthBiasClamp = 0.0f;
12166 rs_desc.SlopeScaledDepthBias = 0.0f;
12167 rs_desc.DepthClipEnable = TRUE;
12168 rs_desc.ScissorEnable = TRUE;
12169 rs_desc.MultisampleEnable = FALSE;
12170 rs_desc.AntialiasedLineEnable = FALSE;
12171 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
12172 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12174 ID3D10Device_IASetInputLayout(device, input_layout);
12175 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
12176 stride = sizeof(*vertex);
12177 offset = 0;
12178 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
12179 ID3D10Device_VSSetShader(device, vs);
12180 ID3D10Device_GSSetShader(device, gs);
12181 ID3D10Device_PSSetShader(device, ps);
12183 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
12184 ID3D10Device_Draw(device, 1, 0);
12186 get_texture_readback(test_context.backbuffer, 0, &rb);
12187 color = get_readback_color(&rb, 320, 190);
12188 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
12189 color = get_readback_color(&rb, 255, 240);
12190 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
12191 color = get_readback_color(&rb, 320, 240);
12192 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
12193 color = get_readback_color(&rb, 385, 240);
12194 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
12195 color = get_readback_color(&rb, 320, 290);
12196 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
12197 release_resource_readback(&rb);
12199 ID3D10RasterizerState_Release(rs);
12200 ID3D10PixelShader_Release(ps);
12201 ID3D10GeometryShader_Release(gs);
12202 ID3D10VertexShader_Release(vs);
12203 ID3D10Buffer_Release(vb);
12204 ID3D10InputLayout_Release(input_layout);
12205 release_test_context(&test_context);
12208 #define check_so_desc(a, b, c, d, e, f, g) check_so_desc_(__LINE__, a, b, c, d, e, f, g)
12209 static void check_so_desc_(unsigned int line, ID3D10Device *device,
12210 const DWORD *code, size_t code_size, const D3D10_SO_DECLARATION_ENTRY *entry,
12211 unsigned int entry_count, unsigned int stride, BOOL valid)
12213 ID3D10GeometryShader *gs = (ID3D10GeometryShader *)0xdeadbeef;
12214 HRESULT hr;
12216 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
12217 entry, entry_count, stride, &gs);
12218 ok_(__FILE__, line)(hr == (valid ? S_OK : E_INVALIDARG), "Got unexpected hr %#x.\n", hr);
12219 if (!valid)
12220 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
12221 if (SUCCEEDED(hr))
12222 ID3D10GeometryShader_Release(gs);
12225 static void test_stream_output(void)
12227 struct d3d10core_test_context test_context;
12228 unsigned int i, count;
12229 ID3D10Device *device;
12231 static const DWORD vs_code[] =
12233 #if 0
12234 struct data
12236 float4 position : SV_Position;
12237 float4 attrib1 : ATTRIB1;
12238 float3 attrib2 : attrib2;
12239 float2 attrib3 : ATTriB3;
12240 float attrib4 : ATTRIB4;
12243 void main(in data i, out data o)
12245 o = i;
12247 #endif
12248 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
12249 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
12250 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
12251 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
12252 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
12253 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
12254 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
12255 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
12256 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
12257 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
12258 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
12259 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
12260 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
12261 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
12262 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12263 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
12264 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
12265 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
12266 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
12267 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
12269 static const DWORD gs_code[] =
12271 #if 0
12272 struct data
12274 float4 position : SV_Position;
12275 float4 attrib1 : ATTRIB1;
12276 float3 attrib2 : attrib2;
12277 float2 attrib3 : ATTriB3;
12278 float attrib4 : ATTRIB4;
12281 [maxvertexcount(1)]
12282 void main(point data i[1], inout PointStream<data> o)
12284 o.Append(i[0]);
12286 #endif
12287 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
12288 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
12289 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
12290 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
12291 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
12292 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
12293 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
12294 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
12295 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
12296 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
12297 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
12298 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
12299 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
12300 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
12301 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
12302 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12303 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
12304 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
12305 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
12306 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
12307 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
12309 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
12311 {"SV_Position", 0, 0, 4, 0},
12313 static const D3D10_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
12315 {"SV_Position", 0, 0, 4, 0},
12316 {NULL, 0, 0, 0, 0},
12318 static const D3D10_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
12320 /* SemanticName and SemanticIndex */
12322 {"sv_position", 0, 0, 4, 0},
12323 {"attrib", 1, 0, 4, 0},
12326 {"sv_position", 0, 0, 4, 0},
12327 {"ATTRIB", 1, 0, 4, 0},
12329 /* Gaps */
12331 {"SV_POSITION", 0, 0, 4, 0},
12332 {NULL, 0, 0, 8, 0},
12333 {"ATTRIB", 1, 0, 4, 0},
12336 {"SV_POSITION", 0, 0, 4, 0},
12337 {NULL, 0, 0, 4, 0},
12338 {NULL, 0, 0, 4, 0},
12339 {"ATTRIB", 1, 0, 4, 0},
12341 /* ComponentCount */
12343 {"ATTRIB", 1, 0, 4, 0},
12346 {"ATTRIB", 2, 0, 3, 0},
12349 {"ATTRIB", 3, 0, 2, 0},
12352 {"ATTRIB", 4, 0, 1, 0},
12354 /* ComponentIndex */
12356 {"ATTRIB", 1, 1, 3, 0},
12359 {"ATTRIB", 1, 2, 2, 0},
12362 {"ATTRIB", 1, 3, 1, 0},
12365 {"ATTRIB", 3, 1, 1, 0},
12367 /* OutputSlot */
12369 {"attrib", 1, 0, 4, 0},
12372 {"attrib", 1, 0, 4, 1},
12375 {"attrib", 1, 0, 4, 2},
12378 {"attrib", 1, 0, 4, 3},
12381 {"attrib", 1, 0, 4, 0},
12382 {"attrib", 2, 0, 3, 0},
12383 {"attrib", 3, 0, 2, 0},
12384 {"attrib", 4, 0, 1, 0},
12387 {"attrib", 1, 0, 4, 0},
12388 {"attrib", 2, 0, 3, 1},
12389 {"attrib", 3, 0, 2, 2},
12390 {"attrib", 4, 0, 1, 3},
12393 {"attrib", 1, 0, 4, 0},
12394 {"attrib", 2, 0, 3, 3},
12397 {"attrib", 1, 0, 4, 0},
12398 {"attrib", 2, 0, 3, 0},
12399 {"attrib", 3, 0, 2, 0},
12400 {NULL, 0, 0, 1, 0},
12401 {"attrib", 4, 0, 1, 0},
12403 /* Multiple occurrences of the same output */
12405 {"ATTRIB", 1, 0, 2, 0},
12406 {"ATTRIB", 1, 2, 2, 1},
12409 {"ATTRIB", 1, 0, 1, 0},
12410 {"ATTRIB", 1, 1, 3, 0},
12413 static const D3D10_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
12415 /* SemanticName and SemanticIndex */
12417 {"SV_Position", 0, 0, 4, 0},
12418 {"ATTRIB", 0, 0, 4, 0},
12421 {"sv_position", 0, 0, 4, 0},
12422 {"ATTRIB_", 1, 0, 4, 0},
12424 /* Gaps */
12426 {"SV_POSITION", 0, 0, 4, 0},
12427 {NULL, 0, 1, 8, 0},
12428 {"ATTRIB", 1, 0, 4, 0},
12431 {"SV_POSITION", 0, 0, 4, 0},
12432 {NULL, 1, 0, 8, 0},
12433 {"ATTRIB", 1, 0, 4, 0},
12435 /* Buffer stride */
12437 {"SV_POSITION", 0, 0, 4, 0},
12438 {NULL, 0, 0, 8, 0},
12439 {NULL, 0, 0, 8, 0},
12440 {"ATTRIB", 1, 0, 4, 0},
12442 /* ComponentCount */
12444 {"ATTRIB", 2, 0, 5, 0},
12447 {"ATTRIB", 2, 0, 4, 0},
12450 {"ATTRIB", 3, 0, 3, 0},
12453 {"ATTRIB", 4, 0, 2, 0},
12455 /* ComponentIndex */
12457 {"ATTRIB", 1, 1, 4, 0},
12460 {"ATTRIB", 1, 2, 3, 0},
12463 {"ATTRIB", 1, 3, 2, 0},
12466 {"ATTRIB", 1, 4, 0, 0},
12469 {"ATTRIB", 1, 4, 1, 0},
12472 {"ATTRIB", 3, 2, 1, 0},
12475 {"ATTRIB", 3, 2, 0, 0},
12477 /* OutputSlot */
12479 {"attrib", 1, 0, 4, 0},
12480 {NULL, 0, 0, 4, 0},
12481 {"attrib", 4, 0, 1, 3},
12484 {"attrib", 1, 0, 4, 0},
12485 {NULL, 0, 0, 4, 0},
12486 {NULL, 0, 0, 4, 0},
12487 {"attrib", 4, 0, 1, 3},
12490 {"attrib", 1, 0, 4, 0},
12491 {"attrib", 2, 0, 3, 0},
12492 {"attrib", 3, 0, 2, 0},
12493 {"attrib", 4, 0, 1, 1},
12496 {"attrib", 1, 0, 4, 0},
12497 {"attrib", 2, 0, 3, 0},
12498 {"attrib", 3, 0, 2, 3},
12499 {NULL, 0, 0, 1, 3},
12500 {"attrib", 4, 0, 1, 3},
12503 {"attrib", 1, 0, 4, 0},
12504 {"attrib", 1, 0, 3, 1},
12505 {"attrib", 1, 0, 2, 2},
12506 {"attrib", 1, 0, 1, 3},
12507 {NULL, 0, 0, 3, 3},
12509 /* Multiple occurrences of the same output */
12511 {"ATTRIB", 1, 0, 4, 0},
12512 {"ATTRIB", 1, 0, 4, 1},
12516 if (!init_test_context(&test_context))
12517 return;
12519 device = test_context.device;
12521 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 0, TRUE);
12522 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 64, FALSE);
12523 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
12524 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
12526 todo_wine
12527 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
12529 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, 64, FALSE);
12530 check_so_desc(device, gs_code, sizeof(gs_code),
12531 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
12532 check_so_desc(device, gs_code, sizeof(gs_code),
12533 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
12535 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, 64, FALSE);
12536 check_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, 64, FALSE);
12538 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
12540 unsigned int max_output_slot = 0;
12541 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
12543 const D3D10_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
12544 max_output_slot = max(max_output_slot, e->OutputSlot);
12545 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
12546 break;
12549 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 0, !!max_output_slot);
12550 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 64, !max_output_slot);
12553 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
12555 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
12557 const D3D10_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
12558 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
12559 break;
12562 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 0, FALSE);
12563 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 64, FALSE);
12566 /* Buffer stride */
12567 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 63, FALSE);
12568 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 1, FALSE);
12569 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
12571 release_test_context(&test_context);
12574 static void test_stream_output_resume(void)
12576 struct d3d10core_test_context test_context;
12577 ID3D10Buffer *cb, *so_buffer, *buffer;
12578 unsigned int i, j, idx, offset;
12579 struct resource_readback rb;
12580 ID3D10GeometryShader *gs;
12581 const struct vec4 *data;
12582 ID3D10Device *device;
12583 HRESULT hr;
12585 static const DWORD gs_code[] =
12587 #if 0
12588 float4 constant;
12590 struct vertex
12592 float4 position : SV_POSITION;
12595 struct element
12597 float4 position : SV_POSITION;
12598 float4 so_output : so_output;
12601 [maxvertexcount(3)]
12602 void main(triangle vertex input[3], inout TriangleStream<element> output)
12604 element o;
12605 o.so_output = constant;
12606 o.position = input[0].position;
12607 output.Append(o);
12608 o.position = input[1].position;
12609 output.Append(o);
12610 o.position = input[2].position;
12611 output.Append(o);
12613 #endif
12614 0x43425844, 0x76f5793f, 0x08760f12, 0xb730b512, 0x3728e75c, 0x00000001, 0x000001b8, 0x00000003,
12615 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12616 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
12617 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12618 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12619 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
12620 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
12621 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
12622 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
12623 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
12624 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
12625 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
12626 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
12627 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
12629 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
12631 {"so_output", 0, 0, 4, 0},
12633 static const struct vec4 constants[] =
12635 {0.5f, 0.250f, 0.0f, 0.0f},
12636 {0.0f, 0.125f, 0.0f, 1.0f},
12637 {1.0f, 1.000f, 1.0f, 0.0f}
12639 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
12640 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
12641 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
12643 if (!init_test_context(&test_context))
12644 return;
12646 device = test_context.device;
12648 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
12649 so_declaration, ARRAY_SIZE(so_declaration), 16, &gs);
12650 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
12652 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
12653 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
12655 ID3D10Device_GSSetShader(device, gs);
12656 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
12658 offset = 0;
12659 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
12661 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
12662 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
12664 draw_color_quad(&test_context, &red);
12665 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
12667 ID3D10Device_GSSetShader(device, NULL);
12668 draw_color_quad(&test_context, &green);
12669 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12671 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[1], 0, 0);
12672 ID3D10Device_GSSetShader(device, gs);
12673 draw_color_quad(&test_context, &red);
12674 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
12676 ID3D10Device_GSSetShader(device, NULL);
12677 draw_color_quad(&test_context, &red);
12678 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
12680 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[2], 0, 0);
12681 ID3D10Device_GSSetShader(device, gs);
12682 draw_color_quad(&test_context, &white);
12683 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
12685 ID3D10Device_GSSetShader(device, NULL);
12686 draw_color_quad(&test_context, &green);
12687 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12689 buffer = NULL;
12690 ID3D10Device_SOSetTargets(device, 1, &buffer, &offset);
12691 ID3D10Device_GSSetShader(device, NULL);
12692 draw_color_quad(&test_context, &white);
12693 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
12695 idx = 0;
12696 get_buffer_readback(so_buffer, &rb);
12697 for (i = 0; i < ARRAY_SIZE(constants); ++i)
12699 for (j = 0; j < 6; ++j) /* 2 triangles */
12701 data = get_readback_vec4(&rb, idx++, 0);
12702 ok(compare_vec4(data, &constants[i], 0),
12703 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
12704 data->x, data->y, data->z, data->w, idx, i, j);
12707 release_resource_readback(&rb);
12709 ID3D10Buffer_Release(cb);
12710 ID3D10Buffer_Release(so_buffer);
12711 ID3D10GeometryShader_Release(gs);
12712 release_test_context(&test_context);
12715 START_TEST(device)
12717 test_feature_level();
12718 test_device_interfaces();
12719 test_create_texture2d();
12720 test_texture2d_interfaces();
12721 test_create_texture3d();
12722 test_create_buffer();
12723 test_create_depthstencil_view();
12724 test_depthstencil_view_interfaces();
12725 test_create_rendertarget_view();
12726 test_render_target_views();
12727 test_layered_rendering();
12728 test_create_shader_resource_view();
12729 test_create_shader();
12730 test_create_sampler_state();
12731 test_create_blend_state();
12732 test_create_depthstencil_state();
12733 test_create_rasterizer_state();
12734 test_create_query();
12735 test_occlusion_query();
12736 test_pipeline_statistics_query();
12737 test_timestamp_query();
12738 test_device_removed_reason();
12739 test_scissor();
12740 test_clear_state();
12741 test_blend();
12742 test_texture();
12743 test_cube_maps();
12744 test_depth_stencil_sampling();
12745 test_multiple_render_targets();
12746 test_private_data();
12747 test_il_append_aligned();
12748 test_fragment_coords();
12749 test_update_subresource();
12750 test_copy_subresource_region();
12751 test_check_multisample_quality_levels();
12752 test_cb_relative_addressing();
12753 test_swapchain_formats();
12754 test_swapchain_views();
12755 test_swapchain_flip();
12756 test_clear_render_target_view();
12757 test_clear_depth_stencil_view();
12758 test_draw_depth_only();
12759 test_shader_stage_input_output_matching();
12760 test_shader_interstage_interface();
12761 test_sm4_if_instruction();
12762 test_sm4_breakc_instruction();
12763 test_sm4_continuec_instruction();
12764 test_create_input_layout();
12765 test_input_assembler();
12766 test_null_sampler();
12767 test_immediate_constant_buffer();
12768 test_fp_specials();
12769 test_uint_shader_instructions();
12770 test_index_buffer_offset();
12771 test_face_culling();
12772 test_line_antialiasing_blending();
12773 test_required_format_support();
12774 test_ddy();
12775 test_shader_input_registers_limits();
12776 test_unbind_shader_resource_view();
12777 test_stencil_separate();
12778 test_sm4_ret_instruction();
12779 test_primitive_restart();
12780 test_resinfo_instruction();
12781 test_render_target_device_mismatch();
12782 test_buffer_srv();
12783 test_geometry_shader();
12784 test_stream_output();
12785 test_stream_output_resume();