device.c 255 KB
Newer Older
1
/*
2
 * Copyright 2008-2012 Henri Verbeet for CodeWeavers
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 *
 */

20
#define NONAMELESSUNION
21
#define WINE_NO_NAMELESS_EXTENSION
22
#include "d3d11_private.h"
23

24
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
{
    SIZE_T max_capacity, new_capacity;
    void *new_elements;

    if (count <= *capacity)
        return TRUE;

    max_capacity = ~(SIZE_T)0 / size;
    if (count > max_capacity)
        return FALSE;

    new_capacity = max(1, *capacity);
    while (new_capacity < count && new_capacity <= max_capacity / 2)
        new_capacity *= 2;
    if (new_capacity < count)
        new_capacity = count;

    if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
        return FALSE;

    *elements = new_elements;
    *capacity = new_capacity;
    return TRUE;
}

52
static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
53

54
static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
55
{
56
    d3d_null_wined3d_object_destroyed,
57 58
};

59 60
static inline BOOL d3d_device_is_d3d10_active(struct d3d_device *device)
{
61 62 63
    return !device->state
                || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device)
                || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device1);
64 65
}

66 67 68 69 70
static D3D_FEATURE_LEVEL d3d_feature_level_from_wined3d(enum wined3d_feature_level level)
{
    return (D3D_FEATURE_LEVEL)level;
}

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/* ID3DDeviceContextState methods */

static inline struct d3d_device_context_state *impl_from_ID3DDeviceContextState(ID3DDeviceContextState *iface)
{
    return CONTAINING_RECORD(iface, struct d3d_device_context_state, ID3DDeviceContextState_iface);
}

static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface,
        REFIID iid, void **out)
{
    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

    if (IsEqualGUID(iid, &IID_ID3DDeviceContextState)
            || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
            || IsEqualGUID(iid, &IID_IUnknown))
    {
        ID3DDeviceContextState_AddRef(iface);
        *out = iface;
        return S_OK;
    }

    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
    *out = NULL;

    return E_NOINTERFACE;
}

98 99 100 101 102 103 104 105 106
static ULONG d3d_device_context_state_private_addref(struct d3d_device_context_state *state)
{
    ULONG refcount = InterlockedIncrement(&state->private_refcount);

    TRACE("%p increasing private refcount to %u.\n", state, refcount);

    return refcount;
}

107 108 109 110 111 112 113
static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
    ULONG refcount = InterlockedIncrement(&state->refcount);

    TRACE("%p increasing refcount to %u.\n", state, refcount);

114 115 116 117 118 119
    if (refcount == 1)
    {
        d3d_device_context_state_private_addref(state);
        ID3D11Device2_AddRef(state->device);
    }

120 121 122
    return refcount;
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
static void d3d_device_remove_context_state(struct d3d_device *device, struct d3d_device_context_state *state)
{
    unsigned int i;

    for (i = 0; i < device->context_state_count; ++i)
    {
        if (device->context_states[i] != state)
            continue;

        if (i != device->context_state_count - 1)
            device->context_states[i] = device->context_states[device->context_state_count - 1];
        --device->context_state_count;
        break;
    }
}

139
static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
140
{
141
    ULONG refcount = InterlockedDecrement(&state->private_refcount);
142 143
    struct d3d_device_context_state_entry *entry;
    struct d3d_device *device;
144
    unsigned int i;
145

146
    TRACE("%p decreasing private refcount to %u.\n", state, refcount);
147 148 149 150

    if (!refcount)
    {
        wined3d_private_store_cleanup(&state->private_store);
151
        for (i = 0; i < state->entry_count; ++i)
152
        {
153 154 155 156 157 158 159
            entry = &state->entries[i];
            device = entry->device;

            if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
                wined3d_state_destroy(entry->wined3d_state);

            d3d_device_remove_context_state(device, state);
160
        }
161
        heap_free(state->entries);
162
        wined3d_device_decref(state->wined3d_device);
163 164
        heap_free(state);
    }
165 166 167 168 169 170 171 172 173 174 175 176 177 178
}

static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
    ULONG refcount = InterlockedDecrement(&state->refcount);

    TRACE("%p decreasing refcount to %u.\n", state, refcount);

    if (!refcount)
    {
        ID3D11Device2_Release(state->device);
        d3d_device_context_state_private_release(state);
    }
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

    return refcount;
}

static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);

    TRACE("iface %p, device %p.\n", iface, device);

    *device = (ID3D11Device *)state->device;
    ID3D11Device_AddRef(*device);
}

static HRESULT STDMETHODCALLTYPE d3d_device_context_state_GetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
        UINT *data_size, void *data)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);

    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_get_private_data(&state->private_store, guid, data_size, data);
}

static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
        UINT data_size, const void *data)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);

    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_set_private_data(&state->private_store, guid, data_size, data);
}

static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateDataInterface(ID3DDeviceContextState *iface,
        REFGUID guid, const IUnknown *data)
{
    struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);

    TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);

    return d3d_set_private_data_interface(&state->private_store, guid, data);
}

static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
{
    /* IUnknown methods */
    d3d_device_context_state_QueryInterface,
    d3d_device_context_state_AddRef,
    d3d_device_context_state_Release,
    /* ID3D11DeviceChild methods */
    d3d_device_context_state_GetDevice,
    d3d_device_context_state_GetPrivateData,
    d3d_device_context_state_SetPrivateData,
    d3d_device_context_state_SetPrivateDataInterface,
    /* ID3DDeviceContextState methods */
};

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
static struct d3d_device_context_state_entry *d3d_device_context_state_get_entry(
        struct d3d_device_context_state *state, struct d3d_device *device)
{
    unsigned int i;

    for (i = 0; i < state->entry_count; ++i)
    {
        if (state->entries[i].device == device)
            return &state->entries[i];
    }

    return NULL;
}

static BOOL d3d_device_context_state_add_entry(struct d3d_device_context_state *state,
        struct d3d_device *device, struct wined3d_state *wined3d_state)
{
    struct d3d_device_context_state_entry *entry;

    if (!d3d_array_reserve((void **)&state->entries, &state->entries_size,
            state->entry_count + 1, sizeof(*state->entries)))
        return FALSE;

    if (!d3d_array_reserve((void **)&device->context_states, &device->context_states_size,
            device->context_state_count + 1, sizeof(*device->context_states)))
        return FALSE;

    entry = &state->entries[state->entry_count++];
    entry->device = device;
    entry->wined3d_state = wined3d_state;

    device->context_states[device->context_state_count++] = state;

    return TRUE;
}

static void d3d_device_context_state_remove_entry(struct d3d_device_context_state *state, struct d3d_device *device)
{
    struct d3d_device_context_state_entry *entry;
    unsigned int i;

    for (i = 0; i < state->entry_count; ++i)
    {
        entry = &state->entries[i];
        if (entry->device != device)
            continue;

        if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
            wined3d_state_destroy(entry->wined3d_state);

        if (i != state->entry_count)
            state->entries[i] = state->entries[state->entry_count - 1];
        --state->entry_count;

        break;
    }
}

static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d3d_device_context_state *state,
        struct d3d_device *device)
{
    struct d3d_device_context_state_entry *entry;
    struct wined3d_state *wined3d_state;

    if ((entry = d3d_device_context_state_get_entry(state, device)))
        return entry->wined3d_state;

304
    if (FAILED(wined3d_state_create(device->wined3d_device,
305
            (enum wined3d_feature_level *)&state->feature_level, 1, &wined3d_state)))
306 307 308 309 310 311 312 313 314 315 316
        return NULL;

    if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
    {
        wined3d_state_destroy(wined3d_state);
        return NULL;
    }

    return wined3d_state;
}

317 318
static void d3d_device_context_state_init(struct d3d_device_context_state *state,
        struct d3d_device *device, D3D_FEATURE_LEVEL feature_level, REFIID emulated_interface)
319 320
{
    state->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl;
321
    state->refcount = state->private_refcount = 0;
322 323 324

    wined3d_private_store_init(&state->private_store);

325
    state->feature_level = feature_level;
326
    state->emulated_interface = *emulated_interface;
327
    wined3d_device_incref(state->wined3d_device = device->wined3d_device);
328
    state->device = &device->ID3D11Device2_iface;
329 330

    d3d_device_context_state_AddRef(&state->ID3DDeviceContextState_iface);
331 332
}

333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
/* ID3D11CommandList methods */

static inline struct d3d11_command_list *impl_from_ID3D11CommandList(ID3D11CommandList *iface)
{
    return CONTAINING_RECORD(iface, struct d3d11_command_list, ID3D11CommandList_iface);
}

static HRESULT STDMETHODCALLTYPE d3d11_command_list_QueryInterface(ID3D11CommandList *iface, REFIID iid, void **out)
{
    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

    if (IsEqualGUID(iid, &IID_ID3D11CommandList)
            || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
            || IsEqualGUID(iid, &IID_IUnknown))
    {
        ID3D11CommandList_AddRef(iface);
        *out = iface;
        return S_OK;
    }

    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
    *out = NULL;

    return E_NOINTERFACE;
}

static ULONG STDMETHODCALLTYPE d3d11_command_list_AddRef(ID3D11CommandList *iface)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
    ULONG refcount = InterlockedIncrement(&list->refcount);

    TRACE("%p increasing refcount to %u.\n", list, refcount);

    return refcount;
}

static ULONG STDMETHODCALLTYPE d3d11_command_list_Release(ID3D11CommandList *iface)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
    ULONG refcount = InterlockedDecrement(&list->refcount);

    TRACE("%p decreasing refcount to %u.\n", list, refcount);

    if (!refcount)
    {
        wined3d_mutex_lock();
        wined3d_command_list_decref(list->wined3d_list);
        wined3d_mutex_unlock();
        wined3d_private_store_cleanup(&list->private_store);
        ID3D11Device2_Release(list->device);
        heap_free(list);
    }

    return refcount;
}

static void STDMETHODCALLTYPE d3d11_command_list_GetDevice(ID3D11CommandList *iface, ID3D11Device **device)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);

    TRACE("iface %p, device %p.\n", iface, device);

    *device = (ID3D11Device *)list->device;
    ID3D11Device2_AddRef(list->device);
}

static HRESULT STDMETHODCALLTYPE d3d11_command_list_GetPrivateData(ID3D11CommandList *iface, REFGUID guid,
        UINT *data_size, void *data)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);

    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_get_private_data(&list->private_store, guid, data_size, data);
}

static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateData(ID3D11CommandList *iface, REFGUID guid,
        UINT data_size, const void *data)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);

    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_set_private_data(&list->private_store, guid, data_size, data);
}

static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateDataInterface(ID3D11CommandList *iface,
        REFGUID guid, const IUnknown *data)
{
    struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);

    TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);

    return d3d_set_private_data_interface(&list->private_store, guid, data);
}

static UINT STDMETHODCALLTYPE d3d11_command_list_GetContextFlags(ID3D11CommandList *iface)
{
    TRACE("iface %p.\n", iface);

    return 0;
}

static const struct ID3D11CommandListVtbl d3d11_command_list_vtbl =
{
    /* IUnknown methods */
    d3d11_command_list_QueryInterface,
    d3d11_command_list_AddRef,
    d3d11_command_list_Release,
    /* ID3D11DeviceChild methods */
    d3d11_command_list_GetDevice,
    d3d11_command_list_GetPrivateData,
    d3d11_command_list_SetPrivateData,
    d3d11_command_list_SetPrivateDataInterface,
    /* ID3D11CommandList methods */
    d3d11_command_list_GetContextFlags,
};

451 452 453 454 455 456 457 458
static struct d3d11_command_list *unsafe_impl_from_ID3D11CommandList(ID3D11CommandList *iface)
{
    if (!iface)
        return NULL;
    assert(iface->lpVtbl == &d3d11_command_list_vtbl);
    return impl_from_ID3D11CommandList(iface);
}

459 460 461 462 463
static void d3d11_device_context_cleanup(struct d3d11_device_context *context)
{
    wined3d_private_store_cleanup(&context->private_store);
}

464 465
/* ID3D11DeviceContext - immediate context methods */

466
static inline struct d3d11_device_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
467
{
468
    return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11DeviceContext1_iface);
469 470
}

471
static HRESULT STDMETHODCALLTYPE d3d11_device_context_QueryInterface(ID3D11DeviceContext1 *iface,
472
        REFIID iid, void **out)
473
{
474
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
475

476 477 478 479 480 481
    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

    if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
            || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
            || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
            || IsEqualGUID(iid, &IID_IUnknown))
482
    {
483 484
        *out = &context->ID3D11DeviceContext1_iface;
    }
485
    else if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE && IsEqualGUID(iid, &IID_ID3D11Multithread))
486 487 488 489 490 491 492 493
    {
        *out = &context->ID3D11Multithread_iface;
    }
    else
    {
        WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
        *out = NULL;
        return E_NOINTERFACE;
494 495
    }

496 497
    ID3D11DeviceContext1_AddRef(iface);
    return S_OK;
498 499
}

500
static ULONG STDMETHODCALLTYPE d3d11_device_context_AddRef(ID3D11DeviceContext1 *iface)
501
{
502
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
503 504 505 506 507 508
    ULONG refcount = InterlockedIncrement(&context->refcount);

    TRACE("%p increasing refcount to %u.\n", context, refcount);

    if (refcount == 1)
    {
509
        ID3D11Device2_AddRef(&context->device->ID3D11Device2_iface);
510 511 512 513 514
    }

    return refcount;
}

515
static ULONG STDMETHODCALLTYPE d3d11_device_context_Release(ID3D11DeviceContext1 *iface)
516
{
517
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
518 519 520 521 522 523
    ULONG refcount = InterlockedDecrement(&context->refcount);

    TRACE("%p decreasing refcount to %u.\n", context, refcount);

    if (!refcount)
    {
524
        ID3D11Device2 *device = &context->device->ID3D11Device2_iface;
525 526 527 528 529 530
        if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
        {
            wined3d_deferred_context_destroy(context->wined3d_context);
            d3d11_device_context_cleanup(context);
            heap_free(context);
        }
531
        ID3D11Device2_Release(device);
532 533 534 535 536
    }

    return refcount;
}

537 538 539
static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer **buffers,
        unsigned int *offsets, unsigned int *counts)
540
{
541
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
542 543 544 545 546
    unsigned int i;

    wined3d_mutex_lock();
    for (i = 0; i < buffer_count; ++i)
    {
547
        struct wined3d_constant_buffer_state state;
548 549
        struct d3d_buffer *buffer_impl;

550 551 552 553 554 555 556 557
        wined3d_device_context_get_constant_buffer(context->wined3d_context, type, start_slot + i, &state);

        if (offsets)
            offsets[i] = state.offset / sizeof(struct wined3d_vec4);
        if (counts)
            counts[i] = state.size / sizeof(struct wined3d_vec4);

        if (!state.buffer)
558 559 560 561 562
        {
            buffers[i] = NULL;
            continue;
        }

563
        buffer_impl = wined3d_buffer_get_parent(state.buffer);
564 565 566 567 568 569
        buffers[i] = &buffer_impl->ID3D11Buffer_iface;
        ID3D11Buffer_AddRef(buffers[i]);
    }
    wined3d_mutex_unlock();
}

570
static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
571 572
        unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer *const *buffers,
        const unsigned int *offsets, const unsigned int *counts)
573
{
574 575
    static const unsigned int alignment = D3D11_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT;
    struct wined3d_constant_buffer_state wined3d_buffers[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
576
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
577 578
    unsigned int i;

579 580 581 582 583 584
    if (buffer_count > ARRAY_SIZE(wined3d_buffers))
    {
        WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
        return;
    }

585 586 587 588 589 590
    if (!offsets != !counts)
    {
        WARN("Got offsets pointer %p but counts pointer %p; ignoring call.\n", offsets, counts);
        return;
    }

591 592 593 594
    for (i = 0; i < buffer_count; ++i)
    {
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);

595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        if (offsets && (offsets[i] & (alignment - 1)))
        {
            WARN("Offset %u is not aligned.\n", offsets[i]);
            return;
        }

        if (counts && (counts[i] & (alignment - 1)))
        {
            WARN("Count %u is not aligned.\n", counts[i]);
            return;
        }

        wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        wined3d_buffers[i].offset = (offsets ? offsets[i] : 0) * sizeof(struct wined3d_vec4);
        wined3d_buffers[i].size = (counts ? counts[i] : WINED3D_MAX_CONSTANT_BUFFER_SIZE) * sizeof(struct wined3d_vec4);
610
    }
611 612 613 614

    wined3d_mutex_lock();
    wined3d_device_context_set_constant_buffers(context->wined3d_context,
            type, start_slot, buffer_count, wined3d_buffers);
615 616 617
    wined3d_mutex_unlock();
}

618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
static void d3d11_device_context_set_shader_resource_views(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int count, ID3D11ShaderResourceView *const *views)
{
    struct wined3d_shader_resource_view *wined3d_views[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
    unsigned int i;

    if (count > ARRAY_SIZE(wined3d_views))
    {
        WARN("View count %u exceeds limit; ignoring call.\n", count);
        return;
    }

    for (i = 0; i < count; ++i)
    {
        struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);

        wined3d_views[i] = view ? view->wined3d_view : NULL;
    }

    wined3d_mutex_lock();
    wined3d_device_context_set_shader_resource_views(context->wined3d_context,
            type, start_slot, count, wined3d_views);
    wined3d_mutex_unlock();
}

644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
static void d3d11_device_context_set_samplers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int count, ID3D11SamplerState *const *samplers)
{
    struct wined3d_sampler *wined3d_samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
    unsigned int i;

    if (count > ARRAY_SIZE(wined3d_samplers))
    {
        WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
        return;
    }

    for (i = 0; i < count; ++i)
    {
        struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);

        wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
    }

    wined3d_mutex_lock();
    wined3d_device_context_set_samplers(context->wined3d_context, type, start_slot, count, wined3d_samplers);
    wined3d_mutex_unlock();
}

669
static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
670
{
671
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
672 673 674

    TRACE("iface %p, device %p.\n", iface, device);

675
    *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
676 677 678
    ID3D11Device_AddRef(*device);
}

679
static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
680 681
        UINT *data_size, void *data)
{
682
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
683

684 685 686
    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_get_private_data(&context->private_store, guid, data_size, data);
687 688
}

689
static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
690 691
        UINT data_size, const void *data)
{
692
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
693

694 695 696
    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);

    return d3d_set_private_data(&context->private_store, guid, data_size, data);
697 698
}

699
static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
700 701
        REFGUID guid, const IUnknown *data)
{
702
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
703

704 705 706
    TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);

    return d3d_set_private_data_interface(&context->private_store, guid, data);
707 708
}

709
static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
710 711
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
712
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
713
            iface, start_slot, buffer_count, buffers);
714

715
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
716
            buffer_count, buffers, NULL, NULL);
717 718
}

719
static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
720 721
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
722
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
723
            iface, start_slot, view_count, views);
724

725
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
726 727
}

728
static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
729 730
        ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
731
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
732 733 734
    struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
735
            iface, shader, class_instances, class_instance_count);
736 737 738 739 740

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
741 742
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
            ps ? ps->wined3d_shader : NULL);
743
    wined3d_mutex_unlock();
744 745
}

746
static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
747 748
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
749
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
750
            iface, start_slot, sampler_count, samplers);
751

752
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
753 754
}

755
static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
756 757
        ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
758
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
759 760 761
    struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
762
            iface, shader, class_instances, class_instance_count);
763 764 765 766 767

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
768 769
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
            vs ? vs->wined3d_shader : NULL);
770
    wined3d_mutex_unlock();
771 772
}

773
static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
774 775
        UINT index_count, UINT start_index_location, INT base_vertex_location)
{
776
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
777 778

    TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
779
            iface, index_count, start_index_location, base_vertex_location);
780 781

    wined3d_mutex_lock();
782 783
    wined3d_device_context_draw_indexed(context->wined3d_context,
            base_vertex_location, start_index_location, index_count, 0, 0);
784
    wined3d_mutex_unlock();
785 786
}

787
static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
788 789
        UINT vertex_count, UINT start_vertex_location)
{
790
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
791 792

    TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
793
            iface, vertex_count, start_vertex_location);
794 795

    wined3d_mutex_lock();
796
    wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
797
    wined3d_mutex_unlock();
798 799
}

800
static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
801 802
        UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
{
803
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
804 805 806 807 808
    struct wined3d_resource *wined3d_resource;
    struct wined3d_map_desc map_desc;
    HRESULT hr;

    TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
809 810
            iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);

811 812 813
    if (map_flags)
        FIXME("Ignoring map_flags %#x.\n", map_flags);

814 815 816 817
    if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE
            && map_type != D3D11_MAP_WRITE_DISCARD && map_type != D3D11_MAP_WRITE_NO_OVERWRITE)
        return E_INVALIDARG;

818 819 820
    wined3d_resource = wined3d_resource_from_d3d11_resource(resource);

    wined3d_mutex_lock();
821
    hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
822 823 824 825 826 827 828 829
            &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
    wined3d_mutex_unlock();

    mapped_subresource->pData = map_desc.data;
    mapped_subresource->RowPitch = map_desc.row_pitch;
    mapped_subresource->DepthPitch = map_desc.slice_pitch;

    return hr;
830 831
}

832
static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
833 834
        UINT subresource_idx)
{
835
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
836 837 838 839 840 841 842
    struct wined3d_resource *wined3d_resource;

    TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);

    wined3d_resource = wined3d_resource_from_d3d11_resource(resource);

    wined3d_mutex_lock();
843
    wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
844
    wined3d_mutex_unlock();
845 846
}

847
static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
848 849
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
850
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
851
            iface, start_slot, buffer_count, buffers);
852

853
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
854
            buffer_count, buffers, NULL, NULL);
855 856
}

857
static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
858 859
        ID3D11InputLayout *input_layout)
{
860
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
861 862 863 864 865
    struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);

    TRACE("iface %p, input_layout %p.\n", iface, input_layout);

    wined3d_mutex_lock();
866
    wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
867
    wined3d_mutex_unlock();
868 869
}

870
static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
871 872
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
{
873
    struct wined3d_stream_state streams[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
874
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
875 876 877
    unsigned int i;

    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
878
            iface, start_slot, buffer_count, buffers, strides, offsets);
879

880 881 882 883 884 885
    if (buffer_count > ARRAY_SIZE(streams))
    {
        WARN("Buffer count %u exceeds limit.\n", buffer_count);
        buffer_count = ARRAY_SIZE(streams);
    }

886 887 888 889
    for (i = 0; i < buffer_count; ++i)
    {
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);

890 891 892 893 894
        streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        streams[i].offset = offsets[i];
        streams[i].stride = strides[i];
        streams[i].frequency = 1;
        streams[i].flags = 0;
895
    }
896 897 898

    wined3d_mutex_lock();
    wined3d_device_context_set_stream_sources(context->wined3d_context, start_slot, buffer_count, streams);
899
    wined3d_mutex_unlock();
900 901
}

902
static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
903 904
        ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
{
905
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
906 907 908
    struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);

    TRACE("iface %p, buffer %p, format %s, offset %u.\n",
909
            iface, buffer, debug_dxgi_format(format), offset);
910 911

    wined3d_mutex_lock();
912
    wined3d_device_context_set_index_buffer(context->wined3d_context,
913
            buffer_impl ? buffer_impl->wined3d_buffer : NULL,
914
            wined3dformat_from_dxgi_format(format), offset);
915
    wined3d_mutex_unlock();
916 917
}

918
static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
919 920 921
        UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
        UINT start_instance_location)
{
922
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
923 924 925

    TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
            "base_vertex_location %d, start_instance_location %u.\n",
926 927
            iface, instance_index_count, instance_count, start_index_location,
            base_vertex_location, start_instance_location);
928 929

    wined3d_mutex_lock();
930 931
    wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
            start_index_location, instance_index_count, start_instance_location, instance_count);
932
    wined3d_mutex_unlock();
933 934
}

935
static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
936 937
        UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
{
938
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
939 940 941

    TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
            "start_instance_location %u.\n",
942 943
            iface, instance_vertex_count, instance_count, start_vertex_location,
            start_instance_location);
944 945

    wined3d_mutex_lock();
946
    wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
947 948
            instance_vertex_count, start_instance_location, instance_count);
    wined3d_mutex_unlock();
949 950
}

951
static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
952 953
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
954
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
955
            iface, start_slot, buffer_count, buffers);
956

957
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
958
            buffer_count, buffers, NULL, NULL);
959 960
}

961
static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
962 963
        ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
964
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
965 966 967
    struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
968
            iface, shader, class_instances, class_instance_count);
969 970 971 972 973

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
974 975
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
            gs ? gs->wined3d_shader : NULL);
976
    wined3d_mutex_unlock();
977 978
}

979
static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
980 981
        D3D11_PRIMITIVE_TOPOLOGY topology)
{
982
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
983 984
    enum wined3d_primitive_type primitive_type;
    unsigned int patch_vertex_count;
985

986 987 988
    TRACE("iface %p, topology %#x.\n", iface, topology);

    wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
989 990

    wined3d_mutex_lock();
991
    wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
992
    wined3d_mutex_unlock();
993 994
}

995
static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
996 997
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
998 999
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

1000
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
1001 1002
}

1003
static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
1004 1005
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
1006
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1007
            iface, start_slot, sampler_count, samplers);
1008

1009
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
1010 1011
}

1012
static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
1013 1014
        ID3D11Asynchronous *asynchronous)
{
1015
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1016 1017 1018 1019 1020
    struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);

    TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);

    wined3d_mutex_lock();
1021
    wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
1022
    wined3d_mutex_unlock();
1023 1024
}

1025
static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
1026 1027
        ID3D11Asynchronous *asynchronous)
{
1028
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1029 1030 1031 1032 1033
    struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);

    TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);

    wined3d_mutex_lock();
1034
    wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
1035
    wined3d_mutex_unlock();
1036 1037
}

1038
static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
1039 1040
        ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
{
1041 1042 1043 1044 1045
    struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
    unsigned int wined3d_flags;
    HRESULT hr;

    TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
1046 1047
            iface, asynchronous, data, data_size, data_flags);

1048 1049 1050
    if (!data && data_size)
        return E_INVALIDARG;

1051 1052 1053 1054 1055 1056
    wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);

    wined3d_mutex_lock();
    if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
    {
        hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
1057 1058
        if (hr == WINED3DERR_INVALIDCALL)
            hr = DXGI_ERROR_INVALID_CALL;
1059 1060 1061 1062 1063 1064 1065 1066 1067
    }
    else
    {
        WARN("Invalid data size %u.\n", data_size);
        hr = E_INVALIDARG;
    }
    wined3d_mutex_unlock();

    return hr;
1068 1069
}

1070
static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1071 1072
        ID3D11Predicate *predicate, BOOL value)
{
1073
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1074 1075 1076 1077 1078 1079 1080
    struct d3d_query *query;

    TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);

    query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);

    wined3d_mutex_lock();
1081
    wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1082
    wined3d_mutex_unlock();
1083 1084
}

1085
static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1086 1087
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
1088 1089
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

1090
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
1091 1092
}

1093
static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1094 1095
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
1096
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1097
            iface, start_slot, sampler_count, samplers);
1098

1099
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
1100 1101
}

1102
static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1103
        UINT rtv_count, ID3D11RenderTargetView *const *rtvs, ID3D11DepthStencilView *depth_stencil_view)
1104
{
1105
    struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1106
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1107 1108 1109
    struct d3d_depthstencil_view *dsv;
    unsigned int i;

1110
    TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
1111

1112
    if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
1113
    {
1114 1115
        WARN("View count %u exceeds limit.\n", rtv_count);
        rtv_count = ARRAY_SIZE(wined3d_rtvs);
1116
    }
1117 1118

    for (i = 0; i < rtv_count; ++i)
1119
    {
1120 1121 1122
        struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(rtvs[i]);

        wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1123 1124 1125
    }

    dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1126 1127 1128 1129

    wined3d_mutex_lock();
    wined3d_device_context_set_rendertarget_views(context->wined3d_context, 0,
            ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
1130
    wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
1131
    wined3d_mutex_unlock();
1132 1133
}

1134
static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1135 1136 1137
        ID3D11DeviceContext1 *iface, UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
        ID3D11DepthStencilView *depth_stencil_view, UINT uav_start_idx, UINT uav_count,
        ID3D11UnorderedAccessView *const *uavs, const UINT *initial_counts)
1138
{
1139
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1140 1141 1142
    unsigned int i;

    TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1143
            "uav_start_idx %u, uav_count %u, uavs %p, initial_counts %p.\n",
1144
            iface, render_target_view_count, render_target_views, depth_stencil_view,
1145
            uav_start_idx, uav_count, uavs, initial_counts);
1146 1147 1148

    if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
    {
1149
        d3d11_device_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
1150 1151
                depth_stencil_view);
    }
1152

1153
    if (uav_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1154
    {
1155 1156 1157 1158
        struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0};
        unsigned int wined3d_initial_counts[D3D11_PS_CS_UAV_REGISTER_COUNT];

        if (!wined3d_bound_range(uav_start_idx, uav_count, ARRAY_SIZE(wined3d_views)))
1159
        {
1160 1161
            WARN("View count %u exceeds limit; ignoring call.\n", uav_count);
            return;
1162 1163
        }

1164 1165 1166
        memset(wined3d_initial_counts, 0xff, sizeof(wined3d_initial_counts));

        for (i = 0; i < uav_count; ++i)
1167
        {
1168 1169 1170 1171 1172
            struct d3d11_unordered_access_view *view =
                    unsafe_impl_from_ID3D11UnorderedAccessView(uavs[i]);

            wined3d_views[uav_start_idx + i] = view ? view->wined3d_view : NULL;
            wined3d_initial_counts[uav_start_idx + i] = initial_counts ? initial_counts[i] : ~0u;
1173
        }
1174 1175 1176 1177

        wined3d_mutex_lock();
        wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_GRAPHICS,
                0, ARRAY_SIZE(wined3d_views), wined3d_views, wined3d_initial_counts);
1178 1179
        wined3d_mutex_unlock();
    }
1180 1181
}

1182
static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1183
        ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1184
{
1185
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1186
    static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1187
    struct d3d_blend_state *blend_state_impl;
1188

1189 1190
    TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
            iface, blend_state, debug_float4(blend_factor), sample_mask);
1191 1192 1193

    if (!blend_factor)
        blend_factor = default_blend_factor;
1194 1195

    wined3d_mutex_lock();
1196
    if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1197
        wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1198
                (const struct wined3d_color *)blend_factor, sample_mask);
1199
    else
1200
        wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1201
                (const struct wined3d_color *)blend_factor, sample_mask);
1202
    wined3d_mutex_unlock();
1203 1204
}

1205
static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1206 1207
        ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
{
1208
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1209
    struct d3d_depthstencil_state *state_impl;
1210 1211 1212 1213 1214

    TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
            iface, depth_stencil_state, stencil_ref);

    wined3d_mutex_lock();
1215
    if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1216
    {
1217
        wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1218 1219 1220 1221
        wined3d_mutex_unlock();
        return;
    }

1222
    wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1223
    wined3d_mutex_unlock();
1224 1225
}

1226
static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1227 1228
        ID3D11Buffer *const *buffers, const UINT *offsets)
{
1229
    struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
1230
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1231 1232 1233 1234
    unsigned int count, i;

    TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);

1235
    count = min(buffer_count, ARRAY_SIZE(outputs));
1236 1237 1238 1239
    for (i = 0; i < count; ++i)
    {
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);

1240 1241
        outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        outputs[i].offset = offsets ? offsets[i] : 0;
1242
    }
1243 1244 1245

    wined3d_mutex_lock();
    wined3d_device_context_set_stream_outputs(context->wined3d_context, outputs);
1246
    wined3d_mutex_unlock();
1247 1248
}

1249
static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1250 1251 1252 1253
{
    FIXME("iface %p stub!\n", iface);
}

1254
static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1255 1256
        ID3D11Buffer *buffer, UINT offset)
{
1257
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1258 1259 1260 1261 1262 1263 1264
    struct d3d_buffer *d3d_buffer;

    TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);

    d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);

    wined3d_mutex_lock();
1265
    wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1266
    wined3d_mutex_unlock();
1267 1268
}

1269
static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1270 1271
        ID3D11Buffer *buffer, UINT offset)
{
1272
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1273 1274 1275 1276 1277 1278 1279
    struct d3d_buffer *d3d_buffer;

    TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);

    d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);

    wined3d_mutex_lock();
1280
    wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1281
    wined3d_mutex_unlock();
1282 1283
}

1284
static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1285 1286
        UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
{
1287
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1288 1289

    TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1290
            iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1291 1292

    wined3d_mutex_lock();
1293
    wined3d_device_context_dispatch(context->wined3d_context,
1294 1295
            thread_group_count_x, thread_group_count_y, thread_group_count_z);
    wined3d_mutex_unlock();
1296 1297
}

1298
static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1299 1300
        ID3D11Buffer *buffer, UINT offset)
{
1301
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1302 1303 1304 1305 1306 1307 1308
    struct d3d_buffer *buffer_impl;

    TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);

    buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);

    wined3d_mutex_lock();
1309
    wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1310
    wined3d_mutex_unlock();
1311 1312
}

1313
static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1314 1315
        ID3D11RasterizerState *rasterizer_state)
{
1316
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1317
    struct d3d_rasterizer_state *rasterizer_state_impl;
1318 1319 1320 1321

    TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);

    wined3d_mutex_lock();
1322 1323 1324
    rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
    wined3d_device_context_set_rasterizer_state(context->wined3d_context,
            rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1325
    wined3d_mutex_unlock();
1326 1327
}

1328
static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1329 1330
        UINT viewport_count, const D3D11_VIEWPORT *viewports)
{
1331
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1332 1333
    struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
    unsigned int i;
1334 1335 1336

    TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);

1337
    if (viewport_count > ARRAY_SIZE(wined3d_vp))
1338 1339
        return;

1340 1341 1342 1343 1344 1345 1346 1347 1348
    for (i = 0; i < viewport_count; ++i)
    {
        wined3d_vp[i].x = viewports[i].TopLeftX;
        wined3d_vp[i].y = viewports[i].TopLeftY;
        wined3d_vp[i].width = viewports[i].Width;
        wined3d_vp[i].height = viewports[i].Height;
        wined3d_vp[i].min_z = viewports[i].MinDepth;
        wined3d_vp[i].max_z = viewports[i].MaxDepth;
    }
1349 1350

    wined3d_mutex_lock();
1351
    wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1352
    wined3d_mutex_unlock();
1353 1354
}

1355
static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1356 1357
        UINT rect_count, const D3D11_RECT *rects)
{
1358
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1359 1360 1361

    TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);

1362
    if (rect_count > WINED3D_MAX_VIEWPORTS)
1363 1364 1365
        return;

    wined3d_mutex_lock();
1366
    wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1367
    wined3d_mutex_unlock();
1368 1369
}

1370
static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1371 1372 1373
        ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
        ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
{
1374
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1375 1376 1377 1378 1379
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
    struct wined3d_box wined3d_src_box;

    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
            "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1380 1381
            iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
            src_resource, src_subresource_idx, src_box);
1382

1383 1384 1385
    if (!dst_resource || !src_resource)
        return;

1386
    if (src_box)
1387 1388
        wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
                src_box->right, src_box->bottom, src_box->front, src_box->back);
1389 1390 1391 1392

    wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
    wined3d_mutex_lock();
1393
    wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1394
            dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1395
    wined3d_mutex_unlock();
1396 1397
}

1398
static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1399 1400
        ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
{
1401
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1402 1403 1404 1405 1406 1407 1408
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;

    TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);

    wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
    wined3d_mutex_lock();
1409
    wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1410
    wined3d_mutex_unlock();
1411 1412
}

1413
static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1414 1415 1416
        ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
        const void *data, UINT row_pitch, UINT depth_pitch)
{
1417
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1418 1419 1420 1421
    struct wined3d_resource *wined3d_resource;
    struct wined3d_box wined3d_box;

    TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1422
            iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1423 1424

    if (box)
1425
        wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1426 1427 1428

    wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
    wined3d_mutex_lock();
1429
    wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1430
            subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1431
    wined3d_mutex_unlock();
1432 1433
}

1434
static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1435 1436
        ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
{
1437
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1438 1439 1440 1441
    struct d3d11_unordered_access_view *uav;
    struct d3d_buffer *buffer_impl;

    TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1442
            iface, dst_buffer, dst_offset, src_view);
1443 1444 1445 1446 1447

    buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
    uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);

    wined3d_mutex_lock();
1448
    wined3d_device_context_copy_uav_counter(context->wined3d_context,
1449 1450
            buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
    wined3d_mutex_unlock();
1451 1452
}

1453
static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1454
        ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1455
{
1456
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1457 1458 1459 1460
    struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
    const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
    HRESULT hr;

1461 1462
    TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
            iface, render_target_view, debug_float4(color_rgba));
1463

1464 1465 1466
    if (!view)
        return;

1467
    wined3d_mutex_lock();
1468
    if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1469
            WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1470 1471
        ERR("Failed to clear view, hr %#x.\n", hr);
    wined3d_mutex_unlock();
1472 1473
}

1474
static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1475 1476
        ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
{
1477
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1478 1479 1480
    struct d3d11_unordered_access_view *view;

    TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1481
            iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1482 1483 1484

    view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
    wined3d_mutex_lock();
1485
    wined3d_device_context_clear_uav_uint(context->wined3d_context,
1486 1487
            view->wined3d_view, (const struct wined3d_uvec4 *)values);
    wined3d_mutex_unlock();
1488 1489
}

1490
static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1491
        ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1492
{
1493 1494 1495 1496
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
    struct d3d11_unordered_access_view *view;

    TRACE("iface %p, unordered_access_view %p, values %s.\n",
1497
            iface, unordered_access_view, debug_float4(values));
1498 1499 1500 1501 1502 1503

    view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
    wined3d_mutex_lock();
    wined3d_device_context_clear_uav_float(context->wined3d_context,
            view->wined3d_view, (const struct wined3d_vec4 *)values);
    wined3d_mutex_unlock();
1504 1505
}

1506
static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1507 1508
        ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
{
1509
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1510 1511 1512 1513 1514
    struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
    DWORD wined3d_flags;
    HRESULT hr;

    TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1515
            iface, depth_stencil_view, flags, depth, stencil);
1516

1517 1518 1519
    if (!view)
        return;

1520 1521 1522
    wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);

    wined3d_mutex_lock();
1523
    if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1524 1525 1526
            wined3d_flags, NULL, depth, stencil)))
        ERR("Failed to clear view, hr %#x.\n", hr);
    wined3d_mutex_unlock();
1527 1528
}

1529
static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1530 1531
        ID3D11ShaderResourceView *view)
{
1532
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1533 1534 1535 1536 1537
    struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);

    TRACE("iface %p, view %p.\n", iface, view);

    wined3d_mutex_lock();
1538
    wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1539
    wined3d_mutex_unlock();
1540 1541
}

1542
static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1543 1544 1545 1546 1547
        ID3D11Resource *resource, FLOAT min_lod)
{
    FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
}

1548
static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1549 1550 1551 1552 1553 1554 1555
        ID3D11Resource *resource)
{
    FIXME("iface %p, resource %p stub!\n", iface, resource);

    return 0.0f;
}

1556
static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1557 1558 1559 1560
        ID3D11Resource *dst_resource, UINT dst_subresource_idx,
        ID3D11Resource *src_resource, UINT src_subresource_idx,
        DXGI_FORMAT format)
{
1561
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
    enum wined3d_format_id wined3d_format;

    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
            "src_resource %p, src_subresource_idx %u, format %s.\n",
            iface, dst_resource, dst_subresource_idx,
            src_resource, src_subresource_idx, debug_dxgi_format(format));

    wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
    wined3d_format = wined3dformat_from_dxgi_format(format);
    wined3d_mutex_lock();
1574
    wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1575 1576 1577
            wined3d_dst_resource, dst_subresource_idx,
            wined3d_src_resource, src_subresource_idx, wined3d_format);
    wined3d_mutex_unlock();
1578 1579
}

1580
static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1581 1582
        ID3D11CommandList *command_list, BOOL restore_state)
{
1583 1584 1585 1586 1587 1588 1589 1590
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
    struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);

    TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);

    wined3d_mutex_lock();
    wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
    wined3d_mutex_unlock();
1591 1592
}

1593
static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1594 1595
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
1596
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1597
            iface, start_slot, view_count, views);
1598

1599
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_HULL, start_slot, view_count, views);
1600 1601
}

1602
static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1603 1604
        ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
1605
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1606 1607 1608
    struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1609
            iface, shader, class_instances, class_instance_count);
1610 1611 1612 1613 1614

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
1615 1616
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
            hs ? hs->wined3d_shader : NULL);
1617
    wined3d_mutex_unlock();
1618 1619
}

1620
static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1621 1622
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
1623
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1624
            iface, start_slot, sampler_count, samplers);
1625

1626
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_HULL, start_slot, sampler_count, samplers);
1627 1628
}

1629
static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1630 1631
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
1632
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1633
            iface, start_slot, buffer_count, buffers);
1634

1635
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1636
            buffer_count, buffers, NULL, NULL);
1637 1638
}

1639
static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1640 1641
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
1642
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1643
            iface, start_slot, view_count, views);
1644

1645
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, view_count, views);
1646 1647
}

1648
static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1649 1650
        ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
1651
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1652 1653 1654
    struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1655
            iface, shader, class_instances, class_instance_count);
1656 1657 1658 1659 1660

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
1661 1662
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
            ds ? ds->wined3d_shader : NULL);
1663
    wined3d_mutex_unlock();
1664 1665
}

1666
static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1667 1668
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
1669
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1670
            iface, start_slot, sampler_count, samplers);
1671

1672
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, sampler_count, samplers);
1673 1674
}

1675
static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1676 1677
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
1678
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1679
            iface, start_slot, buffer_count, buffers);
1680

1681
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1682
            buffer_count, buffers, NULL, NULL);
1683 1684
}

1685
static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1686 1687
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
{
1688
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1689
            iface, start_slot, view_count, views);
1690

1691
    d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, view_count, views);
1692 1693
}

1694
static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1695 1696
        UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
{
1697
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1698
    struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT];
1699 1700 1701
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1702
            iface, start_slot, view_count, views, initial_counts);
1703

1704 1705 1706 1707 1708 1709
    if (view_count > ARRAY_SIZE(wined3d_views))
    {
        WARN("View count %u exceeds limit; ignoring call.\n", view_count);
        return;
    }

1710 1711 1712 1713
    for (i = 0; i < view_count; ++i)
    {
        struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);

1714
        wined3d_views[i] = view ? view->wined3d_view : NULL;
1715
    }
1716 1717 1718 1719

    wined3d_mutex_lock();
    wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
            start_slot, view_count, wined3d_views, initial_counts);
1720
    wined3d_mutex_unlock();
1721 1722
}

1723
static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1724 1725
        ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
{
1726
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1727 1728 1729
    struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1730
            iface, shader, class_instances, class_instance_count);
1731 1732 1733 1734 1735

    if (class_instances)
        FIXME("Dynamic linking is not implemented yet.\n");

    wined3d_mutex_lock();
1736 1737
    wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
            cs ? cs->wined3d_shader : NULL);
1738
    wined3d_mutex_unlock();
1739 1740
}

1741
static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1742 1743
        UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
{
1744
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1745
            iface, start_slot, sampler_count, samplers);
1746

1747
    d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, sampler_count, samplers);
1748 1749
}

1750
static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1751 1752
        UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
{
1753
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1754
            iface, start_slot, buffer_count, buffers);
1755

1756
    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1757
            buffer_count, buffers, NULL, NULL);
1758 1759
}

1760
static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1761 1762
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
1763
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1764
            iface, start_slot, buffer_count, buffers);
1765

1766
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1767
            buffer_count, buffers, NULL, NULL);
1768 1769
}

1770
static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1771 1772
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
1773
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1774 1775 1776
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1777
            iface, start_slot, view_count, views);
1778 1779 1780 1781 1782 1783 1784

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

1785 1786
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        views[i] = &view_impl->ID3D11ShaderResourceView_iface;
        ID3D11ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
1797 1798
}

1799
static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1800 1801
        ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
1802
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1803 1804 1805 1806
    struct wined3d_shader *wined3d_shader;
    struct d3d_pixel_shader *shader_impl;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1807
            iface, shader, class_instances, class_instance_count);
1808 1809 1810

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
1811 1812
    if (class_instance_count)
        *class_instance_count = 0;
1813 1814

    wined3d_mutex_lock();
1815
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D11PixelShader_iface;
    ID3D11PixelShader_AddRef(*shader);
1826 1827
}

1828
static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1829 1830
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
1831
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1832 1833 1834
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1835
            iface, start_slot, sampler_count, samplers);
1836 1837 1838 1839 1840 1841 1842

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct wined3d_sampler *wined3d_sampler;
        struct d3d_sampler_state *sampler_impl;

1843 1844
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
        ID3D11SamplerState_AddRef(samplers[i]);
    }
    wined3d_mutex_unlock();
1855 1856
}

1857
static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1858 1859
        ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
1860
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1861 1862 1863 1864
    struct d3d_vertex_shader *shader_impl;
    struct wined3d_shader *wined3d_shader;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1865
            iface, shader, class_instances, class_instance_count);
1866 1867 1868

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
1869 1870
    if (class_instance_count)
        *class_instance_count = 0;
1871 1872

    wined3d_mutex_lock();
1873
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D11VertexShader_iface;
    ID3D11VertexShader_AddRef(*shader);
1884 1885
}

1886
static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1887 1888
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
1889
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1890
            iface, start_slot, buffer_count, buffers);
1891

1892
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1893
            buffer_count, buffers, NULL, NULL);
1894 1895
}

1896
static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1897 1898
        ID3D11InputLayout **input_layout)
{
1899
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1900 1901 1902 1903 1904 1905
    struct wined3d_vertex_declaration *wined3d_declaration;
    struct d3d_input_layout *input_layout_impl;

    TRACE("iface %p, input_layout %p.\n", iface, input_layout);

    wined3d_mutex_lock();
1906
    if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
    {
        wined3d_mutex_unlock();
        *input_layout = NULL;
        return;
    }

    input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
    wined3d_mutex_unlock();
    *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
    ID3D11InputLayout_AddRef(*input_layout);
1917 1918
}

1919
static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1920 1921
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
{
1922
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1923 1924 1925
    unsigned int i;

    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1926
            iface, start_slot, buffer_count, buffers, strides, offsets);
1927 1928 1929 1930

    wined3d_mutex_lock();
    for (i = 0; i < buffer_count; ++i)
    {
1931
        struct wined3d_buffer *wined3d_buffer = NULL;
1932 1933
        struct d3d_buffer *buffer_impl;

1934
        if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1935
                &wined3d_buffer, &offsets[i], &strides[i])))
1936 1937 1938 1939 1940 1941 1942
        {
            FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
            if (strides)
                strides[i] = 0;
            if (offsets)
                offsets[i] = 0;
        }
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953

        if (!wined3d_buffer)
        {
            buffers[i] = NULL;
            continue;
        }

        buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
        ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
    }
    wined3d_mutex_unlock();
1954 1955
}

1956
static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1957 1958
        ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
{
1959
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1960 1961 1962 1963 1964 1965 1966
    enum wined3d_format_id wined3d_format;
    struct wined3d_buffer *wined3d_buffer;
    struct d3d_buffer *buffer_impl;

    TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);

    wined3d_mutex_lock();
1967
    wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
    *format = dxgi_format_from_wined3dformat(wined3d_format);
    if (!wined3d_buffer)
    {
        wined3d_mutex_unlock();
        *buffer = NULL;
        return;
    }

    buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
    wined3d_mutex_unlock();
    ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1979 1980
}

1981
static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1982 1983
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
1984
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1985
            iface, start_slot, buffer_count, buffers);
1986

1987
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1988
            buffer_count, buffers, NULL, NULL);
1989 1990
}

1991
static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1992 1993
        ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
1994
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1995 1996 1997 1998
    struct d3d_geometry_shader *shader_impl;
    struct wined3d_shader *wined3d_shader;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1999
            iface, shader, class_instances, class_instance_count);
2000 2001 2002

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
2003 2004
    if (class_instance_count)
        *class_instance_count = 0;
2005 2006

    wined3d_mutex_lock();
2007
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D11GeometryShader_iface;
    ID3D11GeometryShader_AddRef(*shader);
2018 2019
}

2020
static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
2021 2022
        D3D11_PRIMITIVE_TOPOLOGY *topology)
{
2023
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2024 2025
    enum wined3d_primitive_type primitive_type;
    unsigned int patch_vertex_count;
2026 2027 2028 2029

    TRACE("iface %p, topology %p.\n", iface, topology);

    wined3d_mutex_lock();
2030
    wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
2031
    wined3d_mutex_unlock();
2032 2033

    d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
2034 2035
}

2036
static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
2037 2038
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
2039
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

2050 2051
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        views[i] = &view_impl->ID3D11ShaderResourceView_iface;
        ID3D11ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
2062 2063
}

2064
static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
2065 2066
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
2067
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2068 2069 2070
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2071
            iface, start_slot, sampler_count, samplers);
2072 2073 2074 2075 2076 2077 2078

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct wined3d_sampler *wined3d_sampler;
        struct d3d_sampler_state *sampler_impl;

2079 2080
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2081 2082 2083 2084 2085 2086 2087 2088 2089 2090
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
        ID3D11SamplerState_AddRef(samplers[i]);
    }
    wined3d_mutex_unlock();
2091 2092
}

2093
static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2094 2095
        ID3D11Predicate **predicate, BOOL *value)
{
2096
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2097 2098 2099 2100 2101 2102
    struct wined3d_query *wined3d_predicate;
    struct d3d_query *predicate_impl;

    TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);

    wined3d_mutex_lock();
2103
    if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
    {
        wined3d_mutex_unlock();
        *predicate = NULL;
        return;
    }

    predicate_impl = wined3d_query_get_parent(wined3d_predicate);
    wined3d_mutex_unlock();
    *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
    ID3D11Predicate_AddRef(*predicate);
2114 2115
}

2116
static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2117 2118
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
2119
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

2130 2131
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        views[i] = &view_impl->ID3D11ShaderResourceView_iface;
        ID3D11ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
2142 2143
}

2144
static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2145 2146
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
2147
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2148 2149 2150
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2151
            iface, start_slot, sampler_count, samplers);
2152 2153 2154 2155 2156 2157 2158

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct d3d_sampler_state *sampler_impl;
        struct wined3d_sampler *wined3d_sampler;

2159 2160
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
        ID3D11SamplerState_AddRef(samplers[i]);
    }
    wined3d_mutex_unlock();
2171 2172
}

2173
static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2174 2175 2176
        UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
        ID3D11DepthStencilView **depth_stencil_view)
{
2177
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2178 2179 2180
    struct wined3d_rendertarget_view *wined3d_view;

    TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2181
            iface, render_target_view_count, render_target_views, depth_stencil_view);
2182 2183 2184 2185 2186 2187 2188 2189 2190

    wined3d_mutex_lock();
    if (render_target_views)
    {
        struct d3d_rendertarget_view *view_impl;
        unsigned int i;

        for (i = 0; i < render_target_view_count; ++i)
        {
2191
            if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
                    || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
            {
                render_target_views[i] = NULL;
                continue;
            }

            render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
            ID3D11RenderTargetView_AddRef(render_target_views[i]);
        }
    }

    if (depth_stencil_view)
    {
        struct d3d_depthstencil_view *view_impl;

2207
        if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218
                || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
        {
            *depth_stencil_view = NULL;
        }
        else
        {
            *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
            ID3D11DepthStencilView_AddRef(*depth_stencil_view);
        }
    }
    wined3d_mutex_unlock();
2219 2220
}

2221
static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2222
        ID3D11DeviceContext1 *iface,
2223 2224 2225 2226 2227
        UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
        ID3D11DepthStencilView **depth_stencil_view,
        UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
        ID3D11UnorderedAccessView **unordered_access_views)
{
2228
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2229 2230 2231 2232 2233
    struct wined3d_unordered_access_view *wined3d_view;
    struct d3d11_unordered_access_view *view_impl;
    unsigned int i;

    TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2234
            "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2235
            "unordered_access_views %p.\n",
2236 2237
            iface, render_target_view_count, render_target_views, depth_stencil_view,
            unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2238 2239

    if (render_target_views || depth_stencil_view)
2240
        d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2241 2242 2243 2244 2245 2246 2247
                render_target_views, depth_stencil_view);

    if (unordered_access_views)
    {
        wined3d_mutex_lock();
        for (i = 0; i < unordered_access_view_count; ++i)
        {
2248 2249
            if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
                    WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260
            {
                unordered_access_views[i] = NULL;
                continue;
            }

            view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
            unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
            ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
        }
        wined3d_mutex_unlock();
    }
2261 2262
}

2263
static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2264 2265
        ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
{
2266
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2267 2268
    struct wined3d_blend_state *wined3d_state;
    struct d3d_blend_state *blend_state_impl;
2269 2270

    TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2271
            iface, blend_state, blend_factor, sample_mask);
2272 2273

    wined3d_mutex_lock();
2274
    if ((wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2275
            (struct wined3d_color *)blend_factor, sample_mask)))
2276 2277 2278 2279 2280 2281 2282 2283
    {
        blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
        ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
    }
    else
    {
        *blend_state = NULL;
    }
2284
    wined3d_mutex_unlock();
2285 2286
}

2287
static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2288 2289
        ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
{
2290
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2291 2292
    struct wined3d_depth_stencil_state *wined3d_state;
    struct d3d_depthstencil_state *state_impl;
2293 2294 2295 2296

    TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
            iface, depth_stencil_state, stencil_ref);

2297
    wined3d_mutex_lock();
2298
    if ((wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref)))
2299 2300 2301 2302 2303 2304 2305 2306 2307
    {
        state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
        ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
    }
    else
    {
        *depth_stencil_state = NULL;
    }
    wined3d_mutex_unlock();
2308 2309
}

2310
static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2311 2312
        UINT buffer_count, ID3D11Buffer **buffers)
{
2313
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2314 2315 2316 2317 2318 2319 2320 2321 2322
    unsigned int i;

    TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);

    wined3d_mutex_lock();
    for (i = 0; i < buffer_count; ++i)
    {
        struct wined3d_buffer *wined3d_buffer;
        struct d3d_buffer *buffer_impl;
2323

2324
        if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2325 2326 2327 2328 2329 2330 2331 2332 2333 2334
        {
            buffers[i] = NULL;
            continue;
        }

        buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
        buffers[i] = &buffer_impl->ID3D11Buffer_iface;
        ID3D11Buffer_AddRef(buffers[i]);
    }
    wined3d_mutex_unlock();
2335 2336
}

2337
static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2338 2339
        ID3D11RasterizerState **rasterizer_state)
{
2340
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2341 2342
    struct d3d_rasterizer_state *rasterizer_state_impl;
    struct wined3d_rasterizer_state *wined3d_state;
2343 2344 2345

    TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);

2346
    wined3d_mutex_lock();
2347
    if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2348 2349 2350 2351 2352 2353 2354 2355 2356
    {
        rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
        ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
    }
    else
    {
        *rasterizer_state = NULL;
    }
    wined3d_mutex_unlock();
2357 2358
}

2359
static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2360 2361
        UINT *viewport_count, D3D11_VIEWPORT *viewports)
{
2362
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2363 2364
    struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
    unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2365 2366 2367

    TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);

2368
    if (!viewport_count)
2369 2370 2371
        return;

    wined3d_mutex_lock();
2372
    wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2373 2374
    wined3d_mutex_unlock();

2375 2376 2377 2378 2379
    if (!viewports)
    {
        *viewport_count = actual_count;
        return;
    }
2380

2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
    if (*viewport_count > actual_count)
        memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));

    *viewport_count = min(actual_count, *viewport_count);
    for (i = 0; i < *viewport_count; ++i)
    {
        viewports[i].TopLeftX = wined3d_vp[i].x;
        viewports[i].TopLeftY = wined3d_vp[i].y;
        viewports[i].Width = wined3d_vp[i].width;
        viewports[i].Height = wined3d_vp[i].height;
        viewports[i].MinDepth = wined3d_vp[i].min_z;
        viewports[i].MaxDepth = wined3d_vp[i].max_z;
    }
2394 2395
}

2396
static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2397 2398
        UINT *rect_count, D3D11_RECT *rects)
{
2399
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2400
    unsigned int actual_count;
2401 2402 2403

    TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);

2404 2405 2406
    if (!rect_count)
        return;

2407 2408
    actual_count = *rect_count;

2409
    wined3d_mutex_lock();
2410
    wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2411 2412
    wined3d_mutex_unlock();

2413
    if (rects && *rect_count > actual_count)
2414
        memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2415
    *rect_count = actual_count;
2416 2417
}

2418
static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2419 2420
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
2421
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

2432 2433
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2434 2435 2436 2437 2438 2439 2440 2441 2442
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
    }
    wined3d_mutex_unlock();
2443 2444
}

2445
static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2446 2447
        ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
2448
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2449 2450 2451 2452
    struct d3d11_hull_shader *shader_impl;
    struct wined3d_shader *wined3d_shader;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2453
            iface, shader, class_instances, class_instance_count);
2454 2455 2456

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
2457 2458
    if (class_instance_count)
        *class_instance_count = 0;
2459 2460

    wined3d_mutex_lock();
2461
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2462 2463 2464 2465 2466 2467 2468 2469 2470
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2471 2472
}

2473
static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2474 2475
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
2476
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2477 2478 2479
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2480
            iface, start_slot, sampler_count, samplers);
2481 2482 2483 2484 2485 2486 2487

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct wined3d_sampler *wined3d_sampler;
        struct d3d_sampler_state *sampler_impl;

2488 2489
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2490 2491 2492 2493 2494 2495 2496 2497 2498
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
    }
    wined3d_mutex_unlock();
2499 2500
}

2501
static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2502 2503
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
2504
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2505
            iface, start_slot, buffer_count, buffers);
2506

2507
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2508
            buffer_count, buffers, NULL, NULL);
2509 2510
}

2511
static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2512 2513
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
2514
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2515 2516 2517
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2518
            iface, start_slot, view_count, views);
2519 2520 2521 2522 2523 2524 2525

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

2526 2527
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2528 2529 2530 2531 2532 2533 2534 2535 2536
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
    }
    wined3d_mutex_unlock();
2537 2538
}

2539
static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2540 2541
        ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
2542
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2543 2544 2545 2546
    struct d3d11_domain_shader *shader_impl;
    struct wined3d_shader *wined3d_shader;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2547
            iface, shader, class_instances, class_instance_count);
2548 2549 2550

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
2551 2552
    if (class_instance_count)
        *class_instance_count = 0;
2553 2554

    wined3d_mutex_lock();
2555
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2556 2557 2558 2559 2560 2561 2562 2563 2564
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2565 2566
}

2567
static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2568 2569
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
2570
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2571 2572 2573
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2574
            iface, start_slot, sampler_count, samplers);
2575 2576 2577 2578 2579 2580 2581

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct wined3d_sampler *wined3d_sampler;
        struct d3d_sampler_state *sampler_impl;

2582 2583
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2584 2585 2586 2587 2588 2589 2590 2591 2592
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
    }
    wined3d_mutex_unlock();
2593 2594
}

2595
static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2596 2597
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
2598
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2599
            iface, start_slot, buffer_count, buffers);
2600

2601
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2602
            buffer_count, buffers, NULL, NULL);
2603 2604
}

2605
static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2606 2607
        UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
{
2608
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
        struct d3d_shader_resource_view *view_impl;

2619 2620
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2621 2622 2623 2624 2625 2626 2627 2628 2629
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
        ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
    }
    wined3d_mutex_unlock();
2630 2631
}

2632
static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2633 2634
        UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
{
2635
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2636 2637 2638 2639 2640 2641 2642 2643 2644 2645
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_unordered_access_view *wined3d_view;
        struct d3d11_unordered_access_view *view_impl;

2646 2647
        if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
                context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2648 2649 2650 2651 2652 2653 2654 2655 2656
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
        ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
    }
    wined3d_mutex_unlock();
2657 2658
}

2659
static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2660 2661
        ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
{
2662
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2663 2664 2665 2666
    struct d3d11_compute_shader *shader_impl;
    struct wined3d_shader *wined3d_shader;

    TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2667
            iface, shader, class_instances, class_instance_count);
2668 2669 2670

    if (class_instances || class_instance_count)
        FIXME("Dynamic linking not implemented yet.\n");
2671 2672
    if (class_instance_count)
        *class_instance_count = 0;
2673 2674

    wined3d_mutex_lock();
2675
    if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2676 2677 2678 2679 2680 2681 2682 2683 2684
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }

    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2685 2686
}

2687
static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2688 2689
        UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
{
2690
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2691 2692 2693
    unsigned int i;

    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2694
            iface, start_slot, sampler_count, samplers);
2695 2696 2697 2698 2699 2700 2701

    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
    {
        struct wined3d_sampler *wined3d_sampler;
        struct d3d_sampler_state *sampler_impl;

2702 2703
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2704 2705 2706 2707 2708 2709 2710 2711 2712
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
    }
    wined3d_mutex_unlock();
2713 2714
}

2715
static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2716 2717
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
{
2718
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2719
            iface, start_slot, buffer_count, buffers);
2720

2721
    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2722
            buffer_count, buffers, NULL, NULL);
2723 2724
}

2725
static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2726
{
2727
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2728 2729 2730 2731

    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
2732
    wined3d_device_context_reset_state(context->wined3d_context);
2733
    wined3d_mutex_unlock();
2734 2735
}

2736
static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2737
{
2738
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2739 2740 2741 2742

    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
2743
    wined3d_device_context_flush(context->wined3d_context);
2744
    wined3d_mutex_unlock();
2745 2746
}

2747
static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2748
{
2749 2750
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);

2751 2752
    TRACE("iface %p.\n", iface);

2753
    return context->type;
2754 2755
}

2756
static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2757
{
2758
    TRACE("iface %p.\n", iface);
2759 2760 2761 2762

    return 0;
}

2763
static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2764 2765
        BOOL restore, ID3D11CommandList **command_list)
{
2766 2767 2768 2769
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
    struct d3d11_command_list *object;
    HRESULT hr;

2770
    TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2771

2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803
    if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
    {
        WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
        return DXGI_ERROR_INVALID_CALL;
    }

    if (!(object = heap_alloc_zero(sizeof(*object))))
        return E_OUTOFMEMORY;

    wined3d_mutex_lock();

    if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
            !!restore, &object->wined3d_list)))
    {
        WARN("Failed to record wined3d command list, hr %#x.\n", hr);
        heap_free(object);
        return hr;
    }

    wined3d_mutex_unlock();

    object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
    object->refcount = 1;
    object->device = &context->device->ID3D11Device2_iface;
    wined3d_private_store_init(&object->private_store);

    ID3D11Device2_AddRef(object->device);

    TRACE("Created command list %p.\n", object);
    *command_list = &object->ID3D11CommandList_iface;

    return S_OK;
2804 2805
}

2806
static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2807 2808
        ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
        ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2809
{
2810
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2811 2812 2813
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
    struct wined3d_box wined3d_src_box;

2814 2815 2816 2817 2818
    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
            "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
            iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
            src_resource, src_subresource_idx, src_box, flags);

2819 2820 2821
    if (!dst_resource || !src_resource)
        return;

2822 2823 2824
    if (src_box)
        wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
                src_box->right, src_box->bottom, src_box->front, src_box->back);
2825

2826 2827 2828
    wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
    wined3d_mutex_lock();
2829
    wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2830 2831
            dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
    wined3d_mutex_unlock();
2832 2833
}

2834
static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2835 2836
        ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
        UINT row_pitch, UINT depth_pitch, UINT flags)
2837
{
2838
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2839 2840 2841
    struct wined3d_resource *wined3d_resource;
    struct wined3d_box wined3d_box;

2842 2843 2844
    TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
            iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);

2845 2846 2847
    if (box)
        wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
                box->front, box->back);
2848

2849 2850
    wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
    wined3d_mutex_lock();
2851
    wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2852 2853
            box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
    wined3d_mutex_unlock();
2854 2855
}

2856
static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2857 2858 2859 2860 2861
        ID3D11Resource *resource)
{
    FIXME("iface %p, resource %p stub!\n", iface, resource);
}

2862
static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2863 2864 2865 2866
{
    FIXME("iface %p, view %p stub!\n", iface, view);
}

2867
static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2868 2869 2870
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2871
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2872
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2873 2874 2875

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2876 2877
}

2878
static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2879 2880 2881
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2882
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2883
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2884 2885 2886

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2887 2888
}

2889
static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2890 2891 2892
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2893
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2894
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2895 2896 2897

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2898 2899
}

2900
static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2901 2902 2903
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2904
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2905
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2906 2907 2908

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2909 2910
}

2911
static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2912 2913 2914
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2915
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2916
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2917 2918 2919

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2920 2921
}

2922
static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2923 2924 2925
        UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
        const UINT *num_constants)
{
2926
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2927
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2928 2929 2930

    d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2931 2932
}

2933
static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2934 2935
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2936
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2937
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2938 2939 2940

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2941 2942
}

2943
static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2944 2945
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2946
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2947
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2948 2949 2950

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2951 2952
}

2953
static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2954 2955
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2956
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2957
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2958 2959 2960

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2961 2962
}

2963
static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2964 2965
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2966
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2967
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2968 2969 2970

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2971 2972
}

2973
static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2974 2975
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2976
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2977
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2978 2979 2980

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2981 2982
}

2983
static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2984 2985
        UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
{
2986
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2987
            iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2988 2989 2990

    d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
            buffer_count, buffers, first_constant, num_constants);
2991 2992
}

2993
static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2994
        ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2995
{
2996
    struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2997
    struct d3d_device_context_state *state_impl, *prev_impl;
2998
    struct d3d_device *device = context->device;
2999
    struct wined3d_state *wined3d_state;
3000
    static unsigned int once;
3001

3002
    TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
3003

3004 3005 3006 3007
    if (prev)
        *prev = NULL;

    if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
3008
    {
3009
        WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
3010 3011
        return;
    }
3012

3013 3014 3015
    if (!state)
        return;

3016 3017
    wined3d_mutex_lock();

3018 3019 3020 3021
    prev_impl = device->state;
    state_impl = impl_from_ID3DDeviceContextState(state);
    if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
        ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
3022
    wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
3023

3024 3025
    if (prev)
        ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
3026

3027 3028 3029
    d3d_device_context_state_private_addref(state_impl);
    device->state = state_impl;
    d3d_device_context_state_private_release(prev_impl);
3030

3031
    if (d3d_device_is_d3d10_active(device) && !once++)
3032
        FIXME("D3D10 interface emulation not fully implemented yet!\n");
3033
    wined3d_mutex_unlock();
3034 3035
}

3036
static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
3037 3038 3039 3040 3041
        const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
{
    FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
}

3042
static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
3043 3044 3045 3046 3047
        const D3D11_RECT *rects, UINT num_rects)
{
    FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
}

3048
static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
3049 3050
{
    /* IUnknown methods */
3051 3052 3053
    d3d11_device_context_QueryInterface,
    d3d11_device_context_AddRef,
    d3d11_device_context_Release,
3054
    /* ID3D11DeviceChild methods */
3055 3056 3057 3058
    d3d11_device_context_GetDevice,
    d3d11_device_context_GetPrivateData,
    d3d11_device_context_SetPrivateData,
    d3d11_device_context_SetPrivateDataInterface,
3059
    /* ID3D11DeviceContext methods */
3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167
    d3d11_device_context_VSSetConstantBuffers,
    d3d11_device_context_PSSetShaderResources,
    d3d11_device_context_PSSetShader,
    d3d11_device_context_PSSetSamplers,
    d3d11_device_context_VSSetShader,
    d3d11_device_context_DrawIndexed,
    d3d11_device_context_Draw,
    d3d11_device_context_Map,
    d3d11_device_context_Unmap,
    d3d11_device_context_PSSetConstantBuffers,
    d3d11_device_context_IASetInputLayout,
    d3d11_device_context_IASetVertexBuffers,
    d3d11_device_context_IASetIndexBuffer,
    d3d11_device_context_DrawIndexedInstanced,
    d3d11_device_context_DrawInstanced,
    d3d11_device_context_GSSetConstantBuffers,
    d3d11_device_context_GSSetShader,
    d3d11_device_context_IASetPrimitiveTopology,
    d3d11_device_context_VSSetShaderResources,
    d3d11_device_context_VSSetSamplers,
    d3d11_device_context_Begin,
    d3d11_device_context_End,
    d3d11_device_context_GetData,
    d3d11_device_context_SetPredication,
    d3d11_device_context_GSSetShaderResources,
    d3d11_device_context_GSSetSamplers,
    d3d11_device_context_OMSetRenderTargets,
    d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
    d3d11_device_context_OMSetBlendState,
    d3d11_device_context_OMSetDepthStencilState,
    d3d11_device_context_SOSetTargets,
    d3d11_device_context_DrawAuto,
    d3d11_device_context_DrawIndexedInstancedIndirect,
    d3d11_device_context_DrawInstancedIndirect,
    d3d11_device_context_Dispatch,
    d3d11_device_context_DispatchIndirect,
    d3d11_device_context_RSSetState,
    d3d11_device_context_RSSetViewports,
    d3d11_device_context_RSSetScissorRects,
    d3d11_device_context_CopySubresourceRegion,
    d3d11_device_context_CopyResource,
    d3d11_device_context_UpdateSubresource,
    d3d11_device_context_CopyStructureCount,
    d3d11_device_context_ClearRenderTargetView,
    d3d11_device_context_ClearUnorderedAccessViewUint,
    d3d11_device_context_ClearUnorderedAccessViewFloat,
    d3d11_device_context_ClearDepthStencilView,
    d3d11_device_context_GenerateMips,
    d3d11_device_context_SetResourceMinLOD,
    d3d11_device_context_GetResourceMinLOD,
    d3d11_device_context_ResolveSubresource,
    d3d11_device_context_ExecuteCommandList,
    d3d11_device_context_HSSetShaderResources,
    d3d11_device_context_HSSetShader,
    d3d11_device_context_HSSetSamplers,
    d3d11_device_context_HSSetConstantBuffers,
    d3d11_device_context_DSSetShaderResources,
    d3d11_device_context_DSSetShader,
    d3d11_device_context_DSSetSamplers,
    d3d11_device_context_DSSetConstantBuffers,
    d3d11_device_context_CSSetShaderResources,
    d3d11_device_context_CSSetUnorderedAccessViews,
    d3d11_device_context_CSSetShader,
    d3d11_device_context_CSSetSamplers,
    d3d11_device_context_CSSetConstantBuffers,
    d3d11_device_context_VSGetConstantBuffers,
    d3d11_device_context_PSGetShaderResources,
    d3d11_device_context_PSGetShader,
    d3d11_device_context_PSGetSamplers,
    d3d11_device_context_VSGetShader,
    d3d11_device_context_PSGetConstantBuffers,
    d3d11_device_context_IAGetInputLayout,
    d3d11_device_context_IAGetVertexBuffers,
    d3d11_device_context_IAGetIndexBuffer,
    d3d11_device_context_GSGetConstantBuffers,
    d3d11_device_context_GSGetShader,
    d3d11_device_context_IAGetPrimitiveTopology,
    d3d11_device_context_VSGetShaderResources,
    d3d11_device_context_VSGetSamplers,
    d3d11_device_context_GetPredication,
    d3d11_device_context_GSGetShaderResources,
    d3d11_device_context_GSGetSamplers,
    d3d11_device_context_OMGetRenderTargets,
    d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
    d3d11_device_context_OMGetBlendState,
    d3d11_device_context_OMGetDepthStencilState,
    d3d11_device_context_SOGetTargets,
    d3d11_device_context_RSGetState,
    d3d11_device_context_RSGetViewports,
    d3d11_device_context_RSGetScissorRects,
    d3d11_device_context_HSGetShaderResources,
    d3d11_device_context_HSGetShader,
    d3d11_device_context_HSGetSamplers,
    d3d11_device_context_HSGetConstantBuffers,
    d3d11_device_context_DSGetShaderResources,
    d3d11_device_context_DSGetShader,
    d3d11_device_context_DSGetSamplers,
    d3d11_device_context_DSGetConstantBuffers,
    d3d11_device_context_CSGetShaderResources,
    d3d11_device_context_CSGetUnorderedAccessViews,
    d3d11_device_context_CSGetShader,
    d3d11_device_context_CSGetSamplers,
    d3d11_device_context_CSGetConstantBuffers,
    d3d11_device_context_ClearState,
    d3d11_device_context_Flush,
    d3d11_device_context_GetType,
    d3d11_device_context_GetContextFlags,
    d3d11_device_context_FinishCommandList,
3168
    /* ID3D11DeviceContext1 methods */
3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187
    d3d11_device_context_CopySubresourceRegion1,
    d3d11_device_context_UpdateSubresource1,
    d3d11_device_context_DiscardResource,
    d3d11_device_context_DiscardView,
    d3d11_device_context_VSSetConstantBuffers1,
    d3d11_device_context_HSSetConstantBuffers1,
    d3d11_device_context_DSSetConstantBuffers1,
    d3d11_device_context_GSSetConstantBuffers1,
    d3d11_device_context_PSSetConstantBuffers1,
    d3d11_device_context_CSSetConstantBuffers1,
    d3d11_device_context_VSGetConstantBuffers1,
    d3d11_device_context_HSGetConstantBuffers1,
    d3d11_device_context_DSGetConstantBuffers1,
    d3d11_device_context_GSGetConstantBuffers1,
    d3d11_device_context_PSGetConstantBuffers1,
    d3d11_device_context_CSGetConstantBuffers1,
    d3d11_device_context_SwapDeviceContextState,
    d3d11_device_context_ClearView,
    d3d11_device_context_DiscardView1,
3188 3189
};

3190 3191
/* ID3D11Multithread methods */

3192
static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3193
{
3194
    return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3195 3196 3197 3198 3199
}

static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
        REFIID iid, void **out)
{
3200
    struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3201 3202 3203

    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

3204
    return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3205 3206 3207 3208
}

static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
{
3209
    struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3210 3211 3212

    TRACE("iface %p.\n", iface);

3213
    return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3214 3215 3216 3217
}

static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
{
3218
    struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3219 3220 3221

    TRACE("iface %p.\n", iface);

3222
    return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264
}

static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
{
    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
}

static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
{
    TRACE("iface %p.\n", iface);

    wined3d_mutex_unlock();
}

static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
        ID3D11Multithread *iface, BOOL enable)
{
    FIXME("iface %p, enable %#x stub!\n", iface, enable);

    return TRUE;
}

static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
{
    FIXME("iface %p stub!\n", iface);

    return TRUE;
}

static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
{
    d3d11_multithread_QueryInterface,
    d3d11_multithread_AddRef,
    d3d11_multithread_Release,
    d3d11_multithread_Enter,
    d3d11_multithread_Leave,
    d3d11_multithread_SetMultithreadProtected,
    d3d11_multithread_GetMultithreadProtected,
};

3265 3266
static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
        D3D11_DEVICE_CONTEXT_TYPE type)
3267
{
3268
    context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3269
    context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3270
    context->refcount = 1;
3271
    context->type = type;
3272

3273
    context->device = device;
3274
    ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3275

3276 3277 3278
    wined3d_private_store_init(&context->private_store);
}

3279
/* ID3D11Device methods */
3280

3281
static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3282
{
3283
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3284
    return IUnknown_QueryInterface(device->outer_unk, iid, out);
3285
}
3286

3287
static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3288
{
3289
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3290
    return IUnknown_AddRef(device->outer_unk);
3291 3292
}

3293
static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3294
{
3295
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3296 3297
    return IUnknown_Release(device->outer_unk);
}
3298

3299
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3300 3301
        const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
{
3302
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3303 3304
    struct d3d_buffer *object;
    HRESULT hr;
3305

3306 3307 3308 3309 3310 3311 3312 3313
    TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);

    if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
        return hr;

    *buffer = &object->ID3D11Buffer_iface;

    return S_OK;
3314 3315
}

3316
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3317
        const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3318
{
3319
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3320 3321
    struct d3d_texture1d *object;
    HRESULT hr;
3322

3323 3324 3325 3326 3327 3328 3329 3330
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

    if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
        return hr;

    *texture = &object->ID3D11Texture1D_iface;

    return S_OK;
3331
}
3332

3333
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3334 3335
        const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
{
3336
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3337
    struct d3d_texture2d *object;
3338
    HRESULT hr;
3339

3340 3341 3342 3343 3344 3345 3346 3347
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

    if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
        return hr;

    *texture = &object->ID3D11Texture2D_iface;

    return S_OK;
3348 3349
}

3350
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3351
        const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3352
{
3353
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3354 3355
    struct d3d_texture3d *object;
    HRESULT hr;
3356

3357 3358 3359 3360 3361 3362 3363 3364
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

    if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
        return hr;

    *texture = &object->ID3D11Texture3D_iface;

    return S_OK;
3365 3366
}

3367
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3368
        ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3369
{
3370
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3371 3372
    struct d3d_shader_resource_view *object;
    HRESULT hr;
3373

3374 3375
    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

3376 3377 3378
    if (!resource)
        return E_INVALIDARG;

3379 3380 3381 3382 3383 3384
    if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
        return hr;

    *view = &object->ID3D11ShaderResourceView_iface;

    return S_OK;
3385 3386
}

3387
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3388
        ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3389
{
3390
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3391 3392
    struct d3d11_unordered_access_view *object;
    HRESULT hr;
3393

3394 3395 3396 3397 3398 3399 3400 3401
    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

    if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
        return hr;

    *view = &object->ID3D11UnorderedAccessView_iface;

    return S_OK;
3402
}
3403

3404
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3405
        ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3406
{
3407
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3408 3409 3410 3411 3412
    struct d3d_rendertarget_view *object;
    HRESULT hr;

    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

3413 3414 3415
    if (!resource)
        return E_INVALIDARG;

3416 3417 3418 3419 3420 3421
    if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
        return hr;

    *view = &object->ID3D11RenderTargetView_iface;

    return S_OK;
3422
}
3423

3424
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3425 3426
        ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
{
3427
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3428 3429
    struct d3d_depthstencil_view *object;
    HRESULT hr;
3430

3431 3432 3433 3434 3435 3436 3437 3438
    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

    if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
        return hr;

    *view = &object->ID3D11DepthStencilView_iface;

    return S_OK;
3439 3440
}

3441
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3442 3443
        const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
        SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3444
{
3445
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3446 3447 3448 3449 3450
    struct d3d_input_layout *object;
    HRESULT hr;

    TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
            "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3451
            shader_byte_code_length, input_layout);
3452

3453 3454 3455 3456 3457 3458 3459
    if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
            shader_byte_code, shader_byte_code_length, &object)))
        return hr;

    *input_layout = &object->ID3D11InputLayout_iface;

    return S_OK;
3460
}
3461

3462
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3463 3464
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
{
3465
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3466 3467 3468 3469
    struct d3d_vertex_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3470
            iface, byte_code, byte_code_length, class_linkage, shader);
3471

3472 3473 3474 3475 3476 3477 3478 3479 3480
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
        return hr;

    *shader = &object->ID3D11VertexShader_iface;

    return S_OK;
3481 3482
}

3483
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3484
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3485
{
3486
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3487 3488 3489 3490
    struct d3d_geometry_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3491
            iface, byte_code, byte_code_length, class_linkage, shader);
3492

3493 3494 3495
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

3496 3497
    if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
            NULL, 0, NULL, 0, 0, &object)))
3498 3499 3500 3501 3502
        return hr;

    *shader = &object->ID3D11GeometryShader_iface;

    return S_OK;
3503 3504
}

3505
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3506
        const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3507
        UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3508
        ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3509
{
3510
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3511 3512 3513 3514 3515
    struct d3d_geometry_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
            "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3516
            iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3517
            rasterizer_stream, class_linkage, shader);
3518

3519 3520 3521 3522 3523
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
            so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3524 3525
    {
        *shader = NULL;
3526
        return hr;
3527
    }
3528 3529 3530 3531

    *shader = &object->ID3D11GeometryShader_iface;

    return hr;
3532
}
3533

3534
static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3535 3536
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
{
3537
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3538 3539 3540 3541
    struct d3d_pixel_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3542
            iface, byte_code, byte_code_length, class_linkage, shader);
3543

3544 3545 3546 3547 3548 3549 3550 3551 3552
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
        return hr;

    *shader = &object->ID3D11PixelShader_iface;

    return S_OK;
3553 3554
}

3555
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3556
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3557
{
3558
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3559 3560 3561
    struct d3d11_hull_shader *object;
    HRESULT hr;

3562
    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3563
            iface, byte_code, byte_code_length, class_linkage, shader);
3564

3565 3566 3567 3568 3569 3570 3571 3572 3573
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
        return hr;

    *shader = &object->ID3D11HullShader_iface;

    return S_OK;
3574 3575
}

3576
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3577
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3578
{
3579
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3580 3581 3582 3583
    struct d3d11_domain_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3584
            iface, byte_code, byte_code_length, class_linkage, shader);
3585

3586 3587 3588 3589 3590 3591 3592 3593 3594
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
        return hr;

    *shader = &object->ID3D11DomainShader_iface;

    return S_OK;
3595 3596
}

3597
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3598
        SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3599
{
3600
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3601 3602 3603 3604
    struct d3d11_compute_shader *object;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3605
            iface, byte_code, byte_code_length, class_linkage, shader);
3606

3607 3608 3609 3610 3611 3612 3613 3614 3615
    if (class_linkage)
        FIXME("Class linkage is not implemented yet.\n");

    if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
        return hr;

    *shader = &object->ID3D11ComputeShader_iface;

    return S_OK;
3616 3617
}

3618
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3619
        ID3D11ClassLinkage **class_linkage)
3620
{
3621
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3622 3623
    struct d3d11_class_linkage *object;
    HRESULT hr;
3624

3625 3626 3627 3628 3629 3630 3631 3632
    TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);

    if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
        return hr;

    *class_linkage = &object->ID3D11ClassLinkage_iface;

    return S_OK;
3633
}
3634

3635
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3636 3637
        const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
{
3638
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3639 3640
    struct d3d_blend_state *object;
    HRESULT hr;
3641

3642 3643
    TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);

3644
    if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3645 3646 3647 3648 3649
        return hr;

    *blend_state = &object->ID3D11BlendState_iface;

    return S_OK;
3650 3651
}

3652
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3653
        const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3654
{
3655
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3656 3657
    struct d3d_depthstencil_state *object;
    HRESULT hr;
3658

3659 3660
    TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);

3661
    if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3662 3663 3664 3665 3666
        return hr;

    *depth_stencil_state = &object->ID3D11DepthStencilState_iface;

    return S_OK;
3667 3668
}

3669
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3670
        const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3671
{
3672
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3673 3674
    struct d3d_rasterizer_state *object;
    HRESULT hr;
3675

3676 3677
    TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);

3678
    if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3679 3680 3681 3682 3683
        return hr;

    *rasterizer_state = &object->ID3D11RasterizerState_iface;

    return S_OK;
3684
}
3685

3686
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3687 3688
        const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
{
3689
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3690 3691
    struct d3d_sampler_state *object;
    HRESULT hr;
3692

3693 3694
    TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);

3695
    if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3696 3697 3698 3699 3700
        return hr;

    *sampler_state = &object->ID3D11SamplerState_iface;

    return S_OK;
3701 3702
}

3703
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3704
        const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3705
{
3706
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3707 3708
    struct d3d_query *object;
    HRESULT hr;
3709

3710 3711 3712 3713 3714
    TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);

    if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
        return hr;

3715 3716 3717 3718 3719
    if (query)
    {
        *query = &object->ID3D11Query_iface;
        return S_OK;
    }
3720

3721 3722
    ID3D11Query_Release(&object->ID3D11Query_iface);
    return S_FALSE;
3723 3724
}

3725
static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3726
        ID3D11Predicate **predicate)
3727
{
3728
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3729 3730
    struct d3d_query *object;
    HRESULT hr;
3731

3732 3733 3734 3735 3736
    TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);

    if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
        return hr;

3737 3738 3739 3740 3741
    if (predicate)
    {
        *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
        return S_OK;
    }
3742

3743 3744
    ID3D11Query_Release(&object->ID3D11Query_iface);
    return S_FALSE;
3745 3746
}

3747
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3748
        ID3D11Counter **counter)
3749
{
3750
    FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3751

3752
    return E_NOTIMPL;
3753 3754
}

3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783
static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
        UINT flags, struct d3d11_device_context **context)
{
    struct d3d11_device_context *object;
    HRESULT hr;

    if (flags)
        FIXME("Ignoring flags %#x.\n", flags);

    if (!(object = heap_alloc_zero(sizeof(*object))))
        return E_OUTOFMEMORY;
    d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);

    wined3d_mutex_lock();
    if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
    {
        WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
        heap_free(object);
        wined3d_mutex_unlock();
        return hr;
    }
    wined3d_mutex_unlock();

    TRACE("Created deferred context %p.\n", object);
    *context = object;

    return S_OK;
}

3784
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3785
        ID3D11DeviceContext **context)
3786
{
3787 3788 3789
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
    struct d3d11_device_context *object;
    HRESULT hr;
3790

3791 3792 3793 3794 3795 3796 3797
    TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);

    if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
        return hr;

    *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
    return S_OK;
3798
}
3799

3800
static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3801 3802
        void **out)
{
3803
    FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3804

3805
    return E_NOTIMPL;
3806 3807
}

3808
static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3809
        UINT *format_support)
3810
{
3811
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3812
    struct wined3d_device_creation_parameters params;
3813
    struct wined3d_adapter *wined3d_adapter;
3814
    enum wined3d_format_id wined3d_format;
3815
    D3D_FEATURE_LEVEL feature_level;
3816 3817
    struct wined3d *wined3d;
    unsigned int i;
3818

3819
    static const struct
3820 3821
    {
        enum wined3d_resource_type rtype;
3822
        unsigned int bind_flags;
3823
        unsigned int usage;
3824 3825 3826 3827
        D3D11_FORMAT_SUPPORT flag;
    }
    flag_mapping[] =
    {
3828
        {WINED3D_RTYPE_BUFFER,     WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3829 3830 3831 3832 3833
        {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
        {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
        {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
        {WINED3D_RTYPE_NONE,       WINED3D_BIND_RENDER_TARGET,   0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
        {WINED3D_RTYPE_NONE,       WINED3D_BIND_DEPTH_STENCIL,   0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3834
        {WINED3D_RTYPE_NONE,       WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3835
        {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3836
        {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3837
        {WINED3D_RTYPE_NONE,       WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853
    };
    HRESULT hr;

    FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);

    wined3d_format = wined3dformat_from_dxgi_format(format);
    if (format && !wined3d_format)
    {
        WARN("Invalid format %#x.\n", format);
        *format_support = 0;
        return E_FAIL;
    }

    *format_support = 0;

    wined3d_mutex_lock();
3854
    feature_level = device->state->feature_level;
3855 3856
    wined3d = wined3d_device_get_wined3d(device->wined3d_device);
    wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3857
    wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3858 3859
    for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
    {
3860
        hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3861
                WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3862
        if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874
            continue;
        if (hr != WINED3D_OK)
        {
            WARN("Failed to check device format support, hr %#x.\n", hr);
            wined3d_mutex_unlock();
            return E_FAIL;
        }

        *format_support |= flag_mapping[i].flag;
    }
    wined3d_mutex_unlock();

3875 3876 3877
    if (feature_level < D3D_FEATURE_LEVEL_10_0)
        *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;

3878 3879 3880 3881 3882
    if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
            | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
    {
        *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
        *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3883
        *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3884 3885 3886

        if (feature_level >= D3D_FEATURE_LEVEL_10_1)
            *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3887 3888 3889

        if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
        {
3890 3891 3892 3893 3894
            if (feature_level >= D3D_FEATURE_LEVEL_10_0)
                *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;

            if (feature_level >= D3D_FEATURE_LEVEL_10_1)
                *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3895 3896 3897
        }
    }

3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909
    /* d3d11 requires 4 and 8 sample counts support for formats reported to
     * support multisample. */
    if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
            TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
            wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
            TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
    {
        *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
                | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
                | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
    }

3910
    return S_OK;
3911 3912
}

3913
static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3914
        DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3915
{
3916
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3917
    struct wined3d_device_creation_parameters params;
3918
    struct wined3d_adapter *wined3d_adapter;
3919 3920
    struct wined3d *wined3d;
    HRESULT hr;
3921

3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942
    TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
            iface, debug_dxgi_format(format), sample_count, quality_level_count);

    if (!quality_level_count)
        return E_INVALIDARG;

    *quality_level_count = 0;

    if (!sample_count)
        return E_FAIL;
    if (sample_count == 1)
    {
        *quality_level_count = 1;
        return S_OK;
    }
    if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
        return E_FAIL;

    wined3d_mutex_lock();
    wined3d = wined3d_device_get_wined3d(device->wined3d_device);
    wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3943 3944
    wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
    hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3945 3946 3947 3948 3949 3950 3951 3952
            wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
    wined3d_mutex_unlock();

    if (hr == WINED3DERR_INVALIDCALL)
        return E_INVALIDARG;
    if (hr == WINED3DERR_NOTAVAILABLE)
        return S_OK;
    return hr;
3953
}
3954

3955
static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3956 3957
{
    FIXME("iface %p, info %p stub!\n", iface, info);
3958 3959
}

3960
static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3961 3962
        D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
        char *units, UINT *units_length, char *description, UINT *description_length)
3963
{
3964 3965 3966 3967
    FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
            "units %p, units_length %p, description %p, description_length %p stub!\n",
            iface, desc, type, active_counter_count, name, name_length,
            units, units_length, description, description_length);
3968

3969 3970
    return E_NOTIMPL;
}
3971

3972
static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3973 3974
        void *feature_support_data, UINT feature_support_data_size)
{
3975
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
3976
    struct wined3d_caps wined3d_caps;
3977 3978
    HRESULT hr;

3979
    TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3980
            iface, feature, feature_support_data, feature_support_data_size);
3981

3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992
    switch (feature)
    {
        case D3D11_FEATURE_THREADING:
        {
            D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
            if (feature_support_data_size != sizeof(*threading_data))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

3993 3994 3995 3996 3997
            /* We lie about the threading support to make Tomb Raider 2013 and
             * Deus Ex: Human Revolution happy. */
            FIXME("Returning fake threading support data.\n");
            threading_data->DriverConcurrentCreates = TRUE;
            threading_data->DriverCommandLists = TRUE;
3998 3999
            return S_OK;
        }
4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022

        case D3D11_FEATURE_DOUBLES:
        {
            D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
            if (feature_support_data_size != sizeof(*doubles_data))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

            wined3d_mutex_lock();
            hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
            wined3d_mutex_unlock();
            if (FAILED(hr))
            {
                WARN("Failed to get device caps, hr %#x.\n", hr);
                return hr;
            }

            doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
            return S_OK;
        }

4023 4024 4025 4026 4027 4028 4029 4030 4031
        case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
        {
            D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
            if (feature_support_data_size != sizeof(*options))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042
            wined3d_mutex_lock();
            hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
            wined3d_mutex_unlock();
            if (FAILED(hr))
            {
                WARN("Failed to get device caps, hr %#x.\n", hr);
                return hr;
            }

            options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
                    = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4043 4044
            return S_OK;
        }
4045

4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062
        case D3D11_FEATURE_D3D11_OPTIONS:
        {
            D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
            if (feature_support_data_size != sizeof(*options))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

            FIXME("Returning fake Options support data.\n");
            options->OutputMergerLogicOp = FALSE;
            options->UAVOnlyRenderingForcedSampleCount = FALSE;
            options->DiscardAPIsSeenByDriver = FALSE;
            options->FlagsForUpdateAndCopySeenByDriver = FALSE;
            options->ClearView = FALSE;
            options->CopyWithOverlap = FALSE;
            options->ConstantBufferPartialUpdate = FALSE;
4063
            options->ConstantBufferOffsetting = TRUE;
4064 4065 4066 4067 4068 4069 4070 4071 4072
            options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
            options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
            options->MultisampleRTVWithForcedSampleCountOne = FALSE;
            options->SAD4ShaderInstructions = FALSE;
            options->ExtendedDoublesShaderInstructions = FALSE;
            options->ExtendedResourceSharing = FALSE;
            return S_OK;
        }

4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089
        case D3D11_FEATURE_D3D11_OPTIONS1:
        {
            D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
            if (feature_support_data_size != sizeof(*options))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

            FIXME("Returning fake Options1 support data.\n");
            options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
            options->MinMaxFiltering = FALSE;
            options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
            options->MapOnDefaultBuffers = FALSE;
            return S_OK;
        }

4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112
        case D3D11_FEATURE_D3D11_OPTIONS3:
        {
            D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
            if (feature_support_data_size != sizeof(*options))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

            wined3d_mutex_lock();
            hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
            wined3d_mutex_unlock();
            if (FAILED(hr))
            {
                WARN("Failed to get device caps, hr %#x.\n", hr);
                return hr;
            }

            options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
                    = wined3d_caps.viewport_array_index_any_shader;
            return S_OK;
        }

4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126
        case D3D11_FEATURE_ARCHITECTURE_INFO:
        {
            D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
            if (feature_support_data_size != sizeof(*options))
            {
                WARN("Invalid data size.\n");
                return E_INVALIDARG;
            }

            FIXME("Returning fake data architecture info.\n");
            options->TileBasedDeferredRenderer = FALSE;
            return S_OK;
        }

4127 4128 4129 4130
        default:
            FIXME("Unhandled feature %#x.\n", feature);
            return E_NOTIMPL;
    }
4131 4132
}

4133
static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4134
        UINT *data_size, void *data)
4135
{
4136 4137
    IDXGIDevice *dxgi_device;
    HRESULT hr;
4138

4139 4140
    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);

4141
    if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4142 4143 4144 4145 4146
        return hr;
    hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
    IDXGIDevice_Release(dxgi_device);

    return hr;
4147
}
4148

4149
static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4150 4151
        UINT data_size, const void *data)
{
4152 4153
    IDXGIDevice *dxgi_device;
    HRESULT hr;
4154

4155 4156
    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);

4157
    if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4158 4159 4160 4161 4162
        return hr;
    hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
    IDXGIDevice_Release(dxgi_device);

    return hr;
4163 4164
}

4165
static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4166
        const IUnknown *data)
4167
{
4168 4169
    IDXGIDevice *dxgi_device;
    HRESULT hr;
4170

4171 4172
    TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);

4173
    if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4174 4175 4176 4177 4178
        return hr;
    hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
    IDXGIDevice_Release(dxgi_device);

    return hr;
4179 4180
}

4181
static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4182
{
4183
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
4184 4185

    TRACE("iface %p.\n", iface);
4186

4187
    return device->state->feature_level;
4188
}
4189

4190
static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4191 4192
{
    FIXME("iface %p stub!\n", iface);
4193

4194
    return 0;
4195 4196
}

4197
static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4198
{
4199
    WARN("iface %p stub!\n", iface);
4200

4201 4202
    return S_OK;
}
4203

4204
static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4205 4206
        ID3D11DeviceContext **immediate_context)
{
4207
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
4208

4209 4210
    TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);

4211
    *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4212
    ID3D11DeviceContext_AddRef(*immediate_context);
4213
}
4214

4215
static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4216 4217 4218 4219
{
    FIXME("iface %p, flags %#x stub!\n", iface, flags);

    return E_NOTIMPL;
4220 4221
}

4222
static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4223
{
4224
    FIXME("iface %p stub!\n", iface);
4225

4226 4227
    return 0;
}
4228

4229 4230
static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
        ID3D11DeviceContext1 **immediate_context)
4231
{
4232 4233 4234 4235 4236 4237
    struct d3d_device *device = impl_from_ID3D11Device2(iface);

    TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);

    *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
    ID3D11DeviceContext1_AddRef(*immediate_context);
4238 4239
}

4240
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4241 4242
        ID3D11DeviceContext1 **context)
{
4243 4244 4245
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
    struct d3d11_device_context *object;
    HRESULT hr;
4246

4247 4248 4249 4250 4251 4252 4253
    TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);

    if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
        return hr;

    *context = &object->ID3D11DeviceContext1_iface;
    return S_OK;
4254 4255
}

4256
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4257 4258 4259 4260 4261 4262 4263
        const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
{
    FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);

    return E_NOTIMPL;
}

4264
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4265 4266 4267 4268 4269 4270 4271
        const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
{
    FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);

    return E_NOTIMPL;
}

4272
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4273
        const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4274 4275
        REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
{
4276 4277
    struct d3d_device *device = impl_from_ID3D11Device2(iface);
    struct d3d_device_context_state *state_impl;
4278
    struct wined3d_state *wined3d_state;
4279
    D3D_FEATURE_LEVEL feature_level;
4280
    HRESULT hr = E_INVALIDARG;
4281

4282 4283 4284 4285 4286 4287 4288 4289 4290
    TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
            "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
            iface, flags, feature_levels, feature_level_count,
            sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);

    if (flags)
        FIXME("Ignoring flags %#x.\n", flags);

    wined3d_mutex_lock();
4291 4292 4293

    if (!feature_level_count)
        goto fail;
4294

4295 4296 4297 4298 4299
    if (FAILED(hr = wined3d_state_create(device->wined3d_device,
            (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
        goto fail;
    feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));

4300
    if (chosen_feature_level)
4301
        *chosen_feature_level = feature_level;
4302

4303
    if (!state)
4304
    {
4305 4306 4307 4308
        wined3d_state_destroy(wined3d_state);
        wined3d_mutex_unlock();
        return S_FALSE;
    }
4309

4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323
    if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
    {
        wined3d_state_destroy(wined3d_state);
        hr = E_OUTOFMEMORY;
        goto fail;
    }

    d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
    if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
    {
        wined3d_state_destroy(wined3d_state);
        ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
        hr = E_FAIL;
        goto fail;
4324 4325
    }

4326
    *state = &state_impl->ID3DDeviceContextState_iface;
4327
    device->d3d11_only = FALSE;
4328 4329 4330
    wined3d_mutex_unlock();

    return S_OK;
4331 4332

fail:
4333
    wined3d_mutex_unlock();
4334 4335 4336 4337 4338
    if (chosen_feature_level)
        *chosen_feature_level = 0;
    if (state)
        *state = NULL;
    return hr;
4339 4340
}

4341
static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4342
        REFIID iid, void **resource)
4343
{
4344
    FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4345 4346 4347 4348

    return E_NOTIMPL;
}

4349
static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4350
        DWORD access, REFIID iid, void **resource)
4351
{
4352 4353
    FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
            debugstr_guid(iid), resource);
4354 4355 4356 4357

    return E_NOTIMPL;
}

4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392
static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
        ID3D11DeviceContext2 **context)
{
    FIXME("iface %p, context %p stub!\n", iface, context);
}

static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
        UINT flags, ID3D11DeviceContext2 **context)
{
    FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);

    return E_NOTIMPL;
}

static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
        ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
        D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
        D3D11_SUBRESOURCE_TILING *subresource_tiling)
{
    FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
            "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
            iface, resource, tile_count, mip_desc, tile_shape,
            subresource_tiling_count, first_subresource_tiling, subresource_tiling);
}

static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
        DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
{
    FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
            iface, format, sample_count, flags, quality_level_count);

    return E_NOTIMPL;
}

static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438
{
    /* IUnknown methods */
    d3d11_device_QueryInterface,
    d3d11_device_AddRef,
    d3d11_device_Release,
    /* ID3D11Device methods */
    d3d11_device_CreateBuffer,
    d3d11_device_CreateTexture1D,
    d3d11_device_CreateTexture2D,
    d3d11_device_CreateTexture3D,
    d3d11_device_CreateShaderResourceView,
    d3d11_device_CreateUnorderedAccessView,
    d3d11_device_CreateRenderTargetView,
    d3d11_device_CreateDepthStencilView,
    d3d11_device_CreateInputLayout,
    d3d11_device_CreateVertexShader,
    d3d11_device_CreateGeometryShader,
    d3d11_device_CreateGeometryShaderWithStreamOutput,
    d3d11_device_CreatePixelShader,
    d3d11_device_CreateHullShader,
    d3d11_device_CreateDomainShader,
    d3d11_device_CreateComputeShader,
    d3d11_device_CreateClassLinkage,
    d3d11_device_CreateBlendState,
    d3d11_device_CreateDepthStencilState,
    d3d11_device_CreateRasterizerState,
    d3d11_device_CreateSamplerState,
    d3d11_device_CreateQuery,
    d3d11_device_CreatePredicate,
    d3d11_device_CreateCounter,
    d3d11_device_CreateDeferredContext,
    d3d11_device_OpenSharedResource,
    d3d11_device_CheckFormatSupport,
    d3d11_device_CheckMultisampleQualityLevels,
    d3d11_device_CheckCounterInfo,
    d3d11_device_CheckCounter,
    d3d11_device_CheckFeatureSupport,
    d3d11_device_GetPrivateData,
    d3d11_device_SetPrivateData,
    d3d11_device_SetPrivateDataInterface,
    d3d11_device_GetFeatureLevel,
    d3d11_device_GetCreationFlags,
    d3d11_device_GetDeviceRemovedReason,
    d3d11_device_GetImmediateContext,
    d3d11_device_SetExceptionMode,
    d3d11_device_GetExceptionMode,
4439 4440 4441 4442 4443 4444 4445 4446
    /* ID3D11Device1 methods */
    d3d11_device_GetImmediateContext1,
    d3d11_device_CreateDeferredContext1,
    d3d11_device_CreateBlendState1,
    d3d11_device_CreateRasterizerState1,
    d3d11_device_CreateDeviceContextState,
    d3d11_device_OpenSharedResource1,
    d3d11_device_OpenSharedResourceByName,
4447 4448 4449 4450 4451
    /* ID3D11Device2 methods */
    d3d11_device_GetImmediateContext2,
    d3d11_device_CreateDeferredContext2,
    d3d11_device_GetResourceTiling,
    d3d11_device_CheckMultisampleQualityLevels1,
4452
};
4453

4454
/* Inner IUnknown methods */
4455

4456 4457 4458
static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
{
    return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4459 4460
}

4461
static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4462
{
4463
    struct d3d_device *device = impl_from_IUnknown(iface);
4464

4465
    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4466

4467 4468
    if (IsEqualGUID(riid, &IID_ID3D11Device2)
            || IsEqualGUID(riid, &IID_ID3D11Device1)
4469
            || IsEqualGUID(riid, &IID_ID3D11Device)
4470
            || IsEqualGUID(riid, &IID_IUnknown))
4471
    {
4472
        *out = &device->ID3D11Device2_iface;
4473
    }
4474 4475 4476
    else if (!device->d3d11_only
            && (IsEqualGUID(riid, &IID_ID3D10Device1)
            || IsEqualGUID(riid, &IID_ID3D10Device)))
4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492
    {
        *out = &device->ID3D10Device1_iface;
    }
    else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
    {
        *out = &device->ID3D10Multithread_iface;
    }
    else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
    {
        *out = &device->IWineDXGIDeviceParent_iface;
    }
    else
    {
        WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
        *out = NULL;
        return E_NOINTERFACE;
4493 4494
    }

4495 4496
    IUnknown_AddRef((IUnknown *)*out);
    return S_OK;
4497 4498
}

4499
static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4500
{
4501 4502
    struct d3d_device *device = impl_from_IUnknown(iface);
    ULONG refcount = InterlockedIncrement(&device->refcount);
4503

4504
    TRACE("%p increasing refcount to %u.\n", device, refcount);
4505

4506
    return refcount;
4507 4508
}

4509
static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4510
{
4511 4512
    struct d3d_device *device = impl_from_IUnknown(iface);
    ULONG refcount = InterlockedDecrement(&device->refcount);
4513
    unsigned int i;
4514

4515
    TRACE("%p decreasing refcount to %u.\n", device, refcount);
4516

4517
    if (!refcount)
4518
    {
4519 4520 4521 4522 4523 4524 4525
        if (device->state)
            d3d_device_context_state_private_release(device->state);
        for (i = 0; i < device->context_state_count; ++i)
        {
            d3d_device_context_state_remove_entry(device->context_states[i], device);
        }
        heap_free(device->context_states);
4526
        d3d11_device_context_cleanup(&device->immediate_context);
4527 4528 4529 4530 4531 4532 4533 4534 4535 4536
        if (device->wined3d_device)
        {
            wined3d_mutex_lock();
            wined3d_device_decref(device->wined3d_device);
            wined3d_mutex_unlock();
        }
        wine_rb_destroy(&device->sampler_states, NULL, NULL);
        wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
        wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
        wine_rb_destroy(&device->blend_states, NULL, NULL);
4537 4538
    }

4539
    return refcount;
4540 4541
}

4542 4543
/* IUnknown methods */

4544 4545
static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
        void **out)
4546
{
4547
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4548
    return IUnknown_QueryInterface(device->outer_unk, iid, out);
4549 4550
}

4551 4552
static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
{
4553 4554
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    return IUnknown_AddRef(device->outer_unk);
4555 4556 4557 4558
}

static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
{
4559 4560
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    return IUnknown_Release(device->outer_unk);
4561 4562 4563 4564
}

/* ID3D10Device methods */

4565 4566 4567 4568 4569 4570 4571 4572 4573
static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
        enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
{
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;

    wined3d_mutex_lock();
    for (i = 0; i < buffer_count; ++i)
    {
4574
        struct wined3d_constant_buffer_state state;
4575 4576
        struct d3d_buffer *buffer_impl;

4577 4578 4579 4580
        wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
                type, start_slot + i, &state);

        if (!state.buffer)
4581 4582 4583 4584 4585
        {
            buffers[i] = NULL;
            continue;
        }

4586
        buffer_impl = wined3d_buffer_get_parent(state.buffer);
4587 4588 4589 4590 4591 4592
        buffers[i] = &buffer_impl->ID3D10Buffer_iface;
        ID3D10Buffer_AddRef(buffers[i]);
    }
    wined3d_mutex_unlock();
}

4593 4594
static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int buffer_count, ID3D10Buffer *const *buffers)
4595
{
4596
    struct wined3d_constant_buffer_state wined3d_buffers[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4597
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4598
    unsigned int i;
4599

4600 4601 4602 4603 4604 4605
    if (buffer_count > ARRAY_SIZE(wined3d_buffers))
    {
        WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
        return;
    }

4606
    for (i = 0; i < buffer_count; ++i)
4607
    {
4608
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4609

4610 4611 4612
        wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        wined3d_buffers[i].offset = 0;
        wined3d_buffers[i].size = WINED3D_MAX_CONSTANT_BUFFER_SIZE * sizeof(struct wined3d_vec4);
4613
    }
4614 4615 4616 4617

    wined3d_mutex_lock();
    wined3d_device_context_set_constant_buffers(device->immediate_context.wined3d_context,
            type, start_slot, buffer_count, wined3d_buffers);
4618
    wined3d_mutex_unlock();
4619 4620
}

4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646
static void d3d10_device_set_shader_resource_views(ID3D10Device1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int count, ID3D10ShaderResourceView *const *views)
{
    struct wined3d_shader_resource_view *wined3d_views[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;

    if (count > ARRAY_SIZE(wined3d_views))
    {
        WARN("View count %u exceeds limit; ignoring call.\n", count);
        return;
    }

    for (i = 0; i < count; ++i)
    {
        struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);

        wined3d_views[i] = view ? view->wined3d_view : NULL;
    }

    wined3d_mutex_lock();
    wined3d_device_context_set_shader_resource_views(device->immediate_context.wined3d_context,
            type, start_slot, count, wined3d_views);
    wined3d_mutex_unlock();
}

4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672
static void d3d10_device_set_samplers(ID3D10Device1 *iface, enum wined3d_shader_type type,
        unsigned int start_slot, unsigned int count, ID3D10SamplerState *const *samplers)
{
    struct wined3d_sampler *wined3d_samplers[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;

    if (count > ARRAY_SIZE(wined3d_samplers))
    {
        WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
        return;
    }

    for (i = 0; i < count; ++i)
    {
        struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);

        wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
    }

    wined3d_mutex_lock();
    wined3d_device_context_set_samplers(device->immediate_context.wined3d_context,
            type, start_slot, count, wined3d_samplers);
    wined3d_mutex_unlock();
}

4673 4674 4675 4676 4677 4678 4679 4680 4681 4682
static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
{
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
            iface, start_slot, buffer_count, buffers);

    d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
            buffer_count, buffers);
}

4683 4684
static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4685
{
4686 4687
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
            iface, start_slot, view_count, views);
4688

4689
    d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
4690 4691
}

4692 4693
static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
        ID3D10PixelShader *shader)
4694
{
4695
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4696
    struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4697

4698
    TRACE("iface %p, shader %p\n", iface, shader);
4699

4700
    wined3d_mutex_lock();
4701 4702
    wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4703
    wined3d_mutex_unlock();
4704 4705
}

4706 4707
static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4708
{
4709 4710
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
            iface, start_slot, sampler_count, samplers);
4711

4712
    d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
4713 4714
}

4715 4716
static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
        ID3D10VertexShader *shader)
4717
{
4718
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4719
    struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4720

4721
    TRACE("iface %p, shader %p\n", iface, shader);
4722

4723
    wined3d_mutex_lock();
4724 4725
    wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4726
    wined3d_mutex_unlock();
4727 4728
}

4729 4730
static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
        UINT start_index_location, INT base_vertex_location)
4731
{
4732
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4733

4734 4735
    TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
            iface, index_count, start_index_location, base_vertex_location);
4736 4737

    wined3d_mutex_lock();
4738 4739
    wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
            base_vertex_location, start_index_location, index_count, 0, 0);
4740
    wined3d_mutex_unlock();
4741 4742
}

4743 4744
static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
        UINT start_vertex_location)
4745
{
4746
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4747

4748 4749
    TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
            iface, vertex_count, start_vertex_location);
4750

4751
    wined3d_mutex_lock();
4752
    wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4753
    wined3d_mutex_unlock();
4754 4755
}

4756 4757
static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4758
{
4759
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4760
            iface, start_slot, buffer_count, buffers);
4761

4762 4763
    d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
            buffer_count, buffers);
4764 4765
}

4766 4767
static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
        ID3D10InputLayout *input_layout)
4768
{
4769
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4770
    struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4771

4772
    TRACE("iface %p, input_layout %p\n", iface, input_layout);
4773

4774
    wined3d_mutex_lock();
4775
    wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4776
            layout ? layout->wined3d_decl : NULL);
4777
    wined3d_mutex_unlock();
4778 4779
}

4780 4781
static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
        UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4782
{
4783
    struct wined3d_stream_state streams[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4784
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4785
    unsigned int i;
4786

4787 4788
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
            iface, start_slot, buffer_count, buffers, strides, offsets);
4789

4790 4791 4792 4793 4794 4795
    if (buffer_count > ARRAY_SIZE(streams))
    {
        WARN("Buffer count %u exceeds limit.\n", buffer_count);
        buffer_count = ARRAY_SIZE(streams);
    }

4796
    for (i = 0; i < buffer_count; ++i)
4797
    {
4798
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4799

4800 4801 4802 4803 4804
        streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        streams[i].offset = offsets[i];
        streams[i].stride = strides[i];
        streams[i].frequency = 1;
        streams[i].flags = 0;
4805
    }
4806 4807 4808 4809

    wined3d_mutex_lock();
    wined3d_device_context_set_stream_sources(device->immediate_context.wined3d_context,
            start_slot, buffer_count, streams);
4810
    wined3d_mutex_unlock();
4811 4812
}

4813 4814
static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
        ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4815
{
4816
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4817
    struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4818

4819 4820
    TRACE("iface %p, buffer %p, format %s, offset %u.\n",
            iface, buffer, debug_dxgi_format(format), offset);
4821

4822
    wined3d_mutex_lock();
4823
    wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4824
            buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4825
            wined3dformat_from_dxgi_format(format), offset);
4826
    wined3d_mutex_unlock();
4827 4828
}

4829 4830 4831
static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
        UINT instance_index_count, UINT instance_count, UINT start_index_location,
        INT base_vertex_location, UINT start_instance_location)
4832
{
4833
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4834

4835 4836 4837 4838
    TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
            "base_vertex_location %d, start_instance_location %u.\n",
            iface, instance_index_count, instance_count, start_index_location,
            base_vertex_location, start_instance_location);
4839

4840
    wined3d_mutex_lock();
4841 4842
    wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
            start_index_location, instance_index_count, start_instance_location, instance_count);
4843
    wined3d_mutex_unlock();
4844 4845
}

4846 4847 4848
static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
        UINT instance_vertex_count, UINT instance_count,
        UINT start_vertex_location, UINT start_instance_location)
4849
{
4850
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4851

4852 4853 4854
    TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
            "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
            start_vertex_location, start_instance_location);
4855

4856
    wined3d_mutex_lock();
4857
    wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4858
            instance_vertex_count, start_instance_location, instance_count);
4859
    wined3d_mutex_unlock();
4860 4861
}

4862 4863
static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4864
{
4865 4866
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
            iface, start_slot, buffer_count, buffers);
4867

4868 4869
    d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
            buffer_count, buffers);
4870 4871
}

4872
static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4873
{
4874
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4875
    struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4876

4877
    TRACE("iface %p, shader %p.\n", iface, shader);
4878

4879
    wined3d_mutex_lock();
4880 4881
    wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4882
    wined3d_mutex_unlock();
4883 4884
}

4885 4886
static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
        D3D10_PRIMITIVE_TOPOLOGY topology)
4887
{
4888
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4889

4890
    TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4891

4892
    wined3d_mutex_lock();
4893 4894
    wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
            (enum wined3d_primitive_type)topology, 0);
4895
    wined3d_mutex_unlock();
4896 4897
}

4898 4899
static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4900
{
4901 4902
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
            iface, start_slot, view_count, views);
4903

4904
    d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
4905 4906
}

4907 4908
static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4909
{
4910 4911
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
            iface, start_slot, sampler_count, samplers);
4912

4913
    d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
4914 4915
}

4916
static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4917
{
4918
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4919
    struct d3d_query *query;
4920

4921
    TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4922

4923
    query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4924
    wined3d_mutex_lock();
4925 4926
    wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
            query ? query->wined3d_query : NULL, value);
4927
    wined3d_mutex_unlock();
4928 4929
}

4930 4931
static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4932
{
4933
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4934
            iface, start_slot, view_count, views);
4935

4936
    d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
4937 4938
}

4939 4940
static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4941
{
4942
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4943
            iface, start_slot, sampler_count, samplers);
4944

4945
    d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
4946 4947
}

4948
static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4949
        UINT rtv_count, ID3D10RenderTargetView *const *rtvs, ID3D10DepthStencilView *depth_stencil_view)
4950
{
4951
    struct wined3d_rendertarget_view *wined3d_rtvs[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
4952
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4953
    struct d3d_depthstencil_view *dsv;
4954
    unsigned int i;
4955

4956
    TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
4957

4958
    if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
4959
    {
4960 4961
        WARN("View count %u exceeds limit.\n", rtv_count);
        rtv_count = ARRAY_SIZE(wined3d_rtvs);
4962
    }
4963 4964

    for (i = 0; i < rtv_count; ++i)
4965
    {
4966 4967 4968
        struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(rtvs[i]);

        wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
4969 4970
    }

4971
    dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4972 4973 4974 4975

    wined3d_mutex_lock();
    wined3d_device_context_set_rendertarget_views(device->immediate_context.wined3d_context, 0,
            ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
4976
    wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4977
            dsv ? dsv->wined3d_view : NULL);
4978
    wined3d_mutex_unlock();
4979 4980
}

4981
static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4982
        ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4983
{
4984
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4985
    struct d3d_blend_state *blend_state_object;
4986

4987 4988
    TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
            iface, blend_state, debug_float4(blend_factor), sample_mask);
4989

4990
    blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4991
    d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4992
            blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4993 4994
}

4995 4996
static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
        ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4997
{
4998
    struct d3d_device *device = impl_from_ID3D10Device(iface);
4999
    struct d3d_depthstencil_state *ds_state_object;
5000

5001 5002
    TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
            iface, depth_stencil_state, stencil_ref);
5003

5004
    ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
5005
    d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5006
            ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
5007 5008
}

5009 5010
static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
        UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
5011
{
5012
    struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
5013
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5014
    unsigned int count, i;
5015

5016
    TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
5017

5018
    count = min(target_count, ARRAY_SIZE(outputs));
5019
    for (i = 0; i < count; ++i)
5020
    {
5021
        struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
5022

5023 5024
        outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
        outputs[i].offset = offsets ? offsets[i] : 0;
5025 5026
    }

5027 5028
    wined3d_mutex_lock();
    wined3d_device_context_set_stream_outputs(device->immediate_context.wined3d_context, outputs);
5029
    wined3d_mutex_unlock();
5030 5031
}

5032 5033 5034 5035 5036 5037
static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
{
    FIXME("iface %p stub!\n", iface);
}

static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
5038
{
5039
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5040
    struct d3d_rasterizer_state *rasterizer_state_object;
5041

5042
    TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5043

5044
    rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5045
    d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5046
            rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
5047 5048
}

5049 5050
static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
        UINT viewport_count, const D3D10_VIEWPORT *viewports)
5051
{
5052
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5053 5054
    struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
    unsigned int i;
5055

5056
    TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5057

5058
    if (viewport_count > ARRAY_SIZE(wined3d_vp))
5059
        return;
5060

5061 5062 5063 5064 5065 5066 5067 5068 5069
    for (i = 0; i < viewport_count; ++i)
    {
        wined3d_vp[i].x = viewports[i].TopLeftX;
        wined3d_vp[i].y = viewports[i].TopLeftY;
        wined3d_vp[i].width = viewports[i].Width;
        wined3d_vp[i].height = viewports[i].Height;
        wined3d_vp[i].min_z = viewports[i].MinDepth;
        wined3d_vp[i].max_z = viewports[i].MaxDepth;
    }
5070

5071
    wined3d_mutex_lock();
5072
    wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5073
    wined3d_mutex_unlock();
5074 5075
}

5076 5077
static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
        UINT rect_count, const D3D10_RECT *rects)
5078
{
5079
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5080

5081
    TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5082

5083
    if (rect_count > WINED3D_MAX_VIEWPORTS)
5084 5085 5086
        return;

    wined3d_mutex_lock();
5087
    wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5088
    wined3d_mutex_unlock();
5089 5090
}

5091 5092 5093
static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
        ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
        ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5094
{
5095
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5096
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5097
    struct wined3d_box wined3d_src_box;
5098

5099 5100 5101 5102
    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
            "src_resource %p, src_subresource_idx %u, src_box %p.\n",
            iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
            src_resource, src_subresource_idx, src_box);
5103

5104 5105 5106
    if (!dst_resource || !src_resource)
        return;

5107
    if (src_box)
5108 5109
        wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
                src_box->right, src_box->bottom, src_box->front, src_box->back);
5110

5111 5112
    wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5113
    wined3d_mutex_lock();
5114 5115 5116
    wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
            wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
            wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5117
    wined3d_mutex_unlock();
5118
}
5119

5120 5121 5122 5123 5124
static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
        ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
{
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5125

5126 5127
    TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);

5128 5129
    wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5130
    wined3d_mutex_lock();
5131 5132
    wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
            wined3d_dst_resource, wined3d_src_resource);
5133
    wined3d_mutex_unlock();
5134 5135
}

5136 5137 5138
static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
        ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
        const void *data, UINT row_pitch, UINT depth_pitch)
5139
{
5140
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5141
    ID3D11Resource *d3d11_resource;
5142

5143 5144
    TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
            iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5145

5146
    ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5147
    d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5148 5149
            d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
    ID3D11Resource_Release(d3d11_resource);
5150 5151
}

5152
static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5153
        ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5154
{
5155
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5156
    struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5157 5158
    const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
    HRESULT hr;
5159

5160 5161
    TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
            iface, render_target_view, debug_float4(color_rgba));
5162

5163 5164 5165
    if (!view)
        return;

5166
    wined3d_mutex_lock();
5167 5168
    if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
            view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5169 5170
        ERR("Failed to clear view, hr %#x.\n", hr);
    wined3d_mutex_unlock();
5171 5172
}

5173 5174
static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
        ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5175
{
5176 5177 5178 5179 5180 5181
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
    DWORD wined3d_flags;
    HRESULT hr;

    TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5182
            iface, depth_stencil_view, flags, depth, stencil);
5183

5184 5185 5186
    if (!view)
        return;

5187 5188 5189
    wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);

    wined3d_mutex_lock();
5190 5191
    if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
            view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5192 5193
        ERR("Failed to clear view, hr %#x.\n", hr);
    wined3d_mutex_unlock();
5194 5195
}

5196
static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5197
        ID3D10ShaderResourceView *view)
5198
{
5199
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5200 5201 5202 5203 5204
    struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);

    TRACE("iface %p, view %p.\n", iface, view);

    wined3d_mutex_lock();
5205
    wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5206
    wined3d_mutex_unlock();
5207
}
5208

5209 5210 5211 5212
static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
        ID3D10Resource *dst_resource, UINT dst_subresource_idx,
        ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
{
5213 5214 5215 5216 5217 5218
    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    enum wined3d_format_id wined3d_format;

    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
            "src_resource %p, src_subresource_idx %u, format %s.\n",
5219 5220
            iface, dst_resource, dst_subresource_idx,
            src_resource, src_subresource_idx, debug_dxgi_format(format));
5221 5222 5223 5224 5225

    wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
    wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
    wined3d_format = wined3dformat_from_dxgi_format(format);
    wined3d_mutex_lock();
5226
    wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5227 5228 5229
            wined3d_dst_resource, dst_subresource_idx,
            wined3d_src_resource, src_subresource_idx, wined3d_format);
    wined3d_mutex_unlock();
5230 5231
}

5232 5233
static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5234
{
5235 5236
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
            iface, start_slot, buffer_count, buffers);
5237

5238 5239
    d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
            buffers);
5240 5241
}

5242 5243
static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5244
{
5245 5246
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;
5247

5248 5249
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
            iface, start_slot, view_count, views);
5250

5251 5252 5253 5254
    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
    {
        struct wined3d_shader_resource_view *wined3d_view;
5255
        struct d3d_shader_resource_view *view_impl;
5256

5257 5258
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5259 5260 5261 5262 5263 5264
        {
            views[i] = NULL;
            continue;
        }

        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5265
        views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5266 5267 5268
        ID3D10ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
5269 5270
}

5271
static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5272
{
5273
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5274
    struct d3d_pixel_shader *shader_impl;
5275
    struct wined3d_shader *wined3d_shader;
5276

5277
    TRACE("iface %p, shader %p.\n", iface, shader);
5278

5279
    wined3d_mutex_lock();
5280 5281
    if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_PIXEL)))
5282 5283 5284 5285 5286
    {
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
    }
5287

5288 5289 5290 5291
    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D10PixelShader_iface;
    ID3D10PixelShader_AddRef(*shader);
5292 5293
}

5294 5295
static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5296
{
5297
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5298 5299
    unsigned int i;

5300 5301
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
            iface, start_slot, sampler_count, samplers);
5302

5303
    wined3d_mutex_lock();
5304
    for (i = 0; i < sampler_count; ++i)
5305
    {
5306
        struct d3d_sampler_state *sampler_impl;
5307 5308
        struct wined3d_sampler *wined3d_sampler;

5309 5310
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5311 5312 5313 5314 5315 5316 5317 5318
        {
            samplers[i] = NULL;
            continue;
        }

        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
        ID3D10SamplerState_AddRef(samplers[i]);
5319
    }
5320
    wined3d_mutex_unlock();
5321 5322
}

5323
static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5324
{
5325
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5326
    struct d3d_vertex_shader *shader_impl;
5327
    struct wined3d_shader *wined3d_shader;
5328

5329
    TRACE("iface %p, shader %p.\n", iface, shader);
5330

5331
    wined3d_mutex_lock();
5332 5333
    if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_VERTEX)))
5334
    {
5335 5336 5337
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
5338 5339
    }

5340 5341 5342 5343
    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D10VertexShader_iface;
    ID3D10VertexShader_AddRef(*shader);
5344 5345
}

5346 5347
static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5348
{
5349 5350
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
            iface, start_slot, buffer_count, buffers);
5351

5352 5353
    d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
            buffers);
5354 5355
}

5356
static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5357
{
5358
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5359
    struct wined3d_vertex_declaration *wined3d_declaration;
5360
    struct d3d_input_layout *input_layout_impl;
5361

5362
    TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5363

5364
    wined3d_mutex_lock();
5365 5366
    if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
            device->immediate_context.wined3d_context)))
5367
    {
5368 5369 5370
        wined3d_mutex_unlock();
        *input_layout = NULL;
        return;
5371 5372
    }

5373 5374 5375 5376
    input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
    wined3d_mutex_unlock();
    *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
    ID3D10InputLayout_AddRef(*input_layout);
5377 5378
}

5379 5380
static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5381
{
5382
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5383
    unsigned int i;
5384

5385 5386
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
            iface, start_slot, buffer_count, buffers, strides, offsets);
5387

5388 5389
    wined3d_mutex_lock();
    for (i = 0; i < buffer_count; ++i)
5390
    {
5391
        struct wined3d_buffer *wined3d_buffer = NULL;
5392
        struct d3d_buffer *buffer_impl;
5393

5394
        if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5395 5396
                &wined3d_buffer, &offsets[i], &strides[i])))
            ERR("Failed to get vertex buffer.\n");
5397

5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408
        if (!wined3d_buffer)
        {
            buffers[i] = NULL;
            continue;
        }

        buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
        buffers[i] = &buffer_impl->ID3D10Buffer_iface;
        ID3D10Buffer_AddRef(buffers[i]);
    }
    wined3d_mutex_unlock();
5409 5410
}

5411 5412
static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
        ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5413
{
5414
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5415 5416
    enum wined3d_format_id wined3d_format;
    struct wined3d_buffer *wined3d_buffer;
5417
    struct d3d_buffer *buffer_impl;
5418

5419
    TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5420

5421
    wined3d_mutex_lock();
5422 5423
    wined3d_buffer = wined3d_device_context_get_index_buffer(
            device->immediate_context.wined3d_context, &wined3d_format, offset);
5424 5425
    *format = dxgi_format_from_wined3dformat(wined3d_format);
    if (!wined3d_buffer)
5426
    {
5427 5428 5429
        wined3d_mutex_unlock();
        *buffer = NULL;
        return;
5430
    }
5431

5432 5433 5434 5435
    buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
    wined3d_mutex_unlock();
    *buffer = &buffer_impl->ID3D10Buffer_iface;
    ID3D10Buffer_AddRef(*buffer);
5436 5437
}

5438 5439
static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
        UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5440
{
5441 5442
    TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
            iface, start_slot, buffer_count, buffers);
5443

5444 5445
    d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
            buffers);
5446 5447
}

5448
static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5449
{
5450
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5451
    struct d3d_geometry_shader *shader_impl;
5452
    struct wined3d_shader *wined3d_shader;
5453

5454
    TRACE("iface %p, shader %p.\n", iface, shader);
5455

5456
    wined3d_mutex_lock();
5457 5458
    if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
            WINED3D_SHADER_TYPE_GEOMETRY)))
5459
    {
5460 5461 5462
        wined3d_mutex_unlock();
        *shader = NULL;
        return;
5463 5464
    }

5465 5466 5467 5468
    shader_impl = wined3d_shader_get_parent(wined3d_shader);
    wined3d_mutex_unlock();
    *shader = &shader_impl->ID3D10GeometryShader_iface;
    ID3D10GeometryShader_AddRef(*shader);
5469 5470
}

5471 5472
static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
        D3D10_PRIMITIVE_TOPOLOGY *topology)
5473
{
5474
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5475

5476
    TRACE("iface %p, topology %p.\n", iface, topology);
5477

5478
    wined3d_mutex_lock();
5479 5480
    wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
            (enum wined3d_primitive_type *)topology, NULL);
5481 5482
    wined3d_mutex_unlock();
}
5483

5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494
static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
{
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;

    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
            iface, start_slot, view_count, views);

    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
5495
    {
5496
        struct wined3d_shader_resource_view *wined3d_view;
5497
        struct d3d_shader_resource_view *view_impl;
5498

5499 5500
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5501 5502 5503 5504
        {
            views[i] = NULL;
            continue;
        }
5505

5506
        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5507
        views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5508 5509 5510
        ID3D10ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
5511 5512
}

5513 5514
static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5515
{
5516 5517
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;
5518

5519 5520
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
            iface, start_slot, sampler_count, samplers);
5521

5522 5523
    wined3d_mutex_lock();
    for (i = 0; i < sampler_count; ++i)
5524
    {
5525
        struct d3d_sampler_state *sampler_impl;
5526
        struct wined3d_sampler *wined3d_sampler;
5527

5528 5529
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5530 5531 5532 5533
        {
            samplers[i] = NULL;
            continue;
        }
5534

5535 5536 5537 5538 5539
        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
        ID3D10SamplerState_AddRef(samplers[i]);
    }
    wined3d_mutex_unlock();
5540 5541
}

5542 5543
static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
        ID3D10Predicate **predicate, BOOL *value)
5544
{
5545 5546
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    struct wined3d_query *wined3d_predicate;
5547
    struct d3d_query *predicate_impl;
5548

5549 5550 5551
    TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);

    wined3d_mutex_lock();
5552
    if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5553 5554 5555 5556 5557 5558 5559 5560 5561 5562
    {
        wined3d_mutex_unlock();
        *predicate = NULL;
        return;
    }

    predicate_impl = wined3d_query_get_parent(wined3d_predicate);
    wined3d_mutex_unlock();
    *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
    ID3D10Predicate_AddRef(*predicate);
5563 5564
}

5565 5566
static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
        UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5567
{
5568 5569
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    unsigned int i;
5570

5571 5572
    TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
            iface, start_slot, view_count, views);
5573

5574 5575
    wined3d_mutex_lock();
    for (i = 0; i < view_count; ++i)
5576
    {
5577
        struct wined3d_shader_resource_view *wined3d_view;
5578
        struct d3d_shader_resource_view *view_impl;
5579

5580 5581
        if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5582 5583 5584 5585
        {
            views[i] = NULL;
            continue;
        }
5586

5587
        view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5588
        views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5589 5590 5591
        ID3D10ShaderResourceView_AddRef(views[i]);
    }
    wined3d_mutex_unlock();
5592 5593
}

5594 5595
static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
        UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5596
{
5597
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5598
    unsigned int i;
5599

5600 5601
    TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
            iface, start_slot, sampler_count, samplers);
5602

5603
    wined3d_mutex_lock();
5604
    for (i = 0; i < sampler_count; ++i)
5605
    {
5606
        struct d3d_sampler_state *sampler_impl;
5607
        struct wined3d_sampler *wined3d_sampler;
5608

5609 5610
        if (!(wined3d_sampler = wined3d_device_context_get_sampler(
                device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5611 5612 5613 5614
        {
            samplers[i] = NULL;
            continue;
        }
5615

5616 5617 5618
        sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
        samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
        ID3D10SamplerState_AddRef(samplers[i]);
5619
    }
5620
    wined3d_mutex_unlock();
5621
}
5622

5623 5624
static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
        UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5625
{
5626
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5627
    struct wined3d_rendertarget_view *wined3d_view;
5628

5629 5630
    TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
            iface, view_count, render_target_views, depth_stencil_view);
5631

5632
    wined3d_mutex_lock();
5633
    if (render_target_views)
5634
    {
5635
        struct d3d_rendertarget_view *view_impl;
5636
        unsigned int i;
5637

5638 5639
        for (i = 0; i < view_count; ++i)
        {
5640 5641
            if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
                    device->immediate_context.wined3d_context, i))
5642 5643 5644 5645 5646
                    || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
            {
                render_target_views[i] = NULL;
                continue;
            }
5647

5648 5649 5650
            render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
            ID3D10RenderTargetView_AddRef(render_target_views[i]);
        }
5651
    }
5652

5653
    if (depth_stencil_view)
5654
    {
5655
        struct d3d_depthstencil_view *view_impl;
5656

5657
        if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668
                || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
        {
            *depth_stencil_view = NULL;
        }
        else
        {
            *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
            ID3D10DepthStencilView_AddRef(*depth_stencil_view);
        }
    }
    wined3d_mutex_unlock();
5669 5670
}

5671 5672
static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
        ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5673
{
5674
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5675
    ID3D11BlendState *d3d11_blend_state;
5676

5677 5678
    TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
            iface, blend_state, blend_factor, sample_mask);
5679

5680
    d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5681 5682 5683 5684 5685 5686
            &d3d11_blend_state, blend_factor, sample_mask);

    if (d3d11_blend_state)
        *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
    else
        *blend_state = NULL;
5687
}
5688

5689 5690 5691 5692
static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
        ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
{
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5693
    ID3D11DepthStencilState *d3d11_iface;
5694

5695 5696
    TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
            iface, depth_stencil_state, stencil_ref);
5697

5698
    d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5699 5700 5701 5702 5703 5704
            &d3d11_iface, stencil_ref);

    if (d3d11_iface)
        *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
    else
        *depth_stencil_state = NULL;
5705 5706
}

5707 5708
static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
        UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5709
{
5710
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5711
    unsigned int i;
5712

5713 5714
    TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
            iface, buffer_count, buffers, offsets);
5715

5716
    wined3d_mutex_lock();
5717
    for (i = 0; i < buffer_count; ++i)
5718
    {
5719
        struct wined3d_buffer *wined3d_buffer;
5720
        struct d3d_buffer *buffer_impl;
5721

5722 5723
        if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
                device->immediate_context.wined3d_context, i, &offsets[i])))
5724 5725 5726 5727
        {
            buffers[i] = NULL;
            continue;
        }
5728

5729 5730 5731
        buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
        buffers[i] = &buffer_impl->ID3D10Buffer_iface;
        ID3D10Buffer_AddRef(buffers[i]);
5732
    }
5733
    wined3d_mutex_unlock();
5734
}
5735

5736 5737 5738
static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
{
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5739 5740
    struct d3d_rasterizer_state *rasterizer_state_impl;
    struct wined3d_rasterizer_state *wined3d_state;
5741

5742
    TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5743

5744
    wined3d_mutex_lock();
5745
    if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5746 5747 5748 5749 5750 5751 5752 5753 5754
    {
        rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
        ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
    }
    else
    {
        *rasterizer_state = NULL;
    }
    wined3d_mutex_unlock();
5755 5756
}

5757 5758
static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
        UINT *viewport_count, D3D10_VIEWPORT *viewports)
5759
{
5760
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5761 5762
    struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
    unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5763

5764
    TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5765

5766
    if (!viewport_count)
5767
        return;
5768

5769
    wined3d_mutex_lock();
5770 5771
    wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
            &actual_count, viewports ? wined3d_vp : NULL);
5772 5773
    wined3d_mutex_unlock();

5774 5775 5776 5777 5778
    if (!viewports)
    {
        *viewport_count = actual_count;
        return;
    }
5779

5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792
    if (*viewport_count > actual_count)
        memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));

    *viewport_count = min(actual_count, *viewport_count);
    for (i = 0; i < *viewport_count; ++i)
    {
        viewports[i].TopLeftX = wined3d_vp[i].x;
        viewports[i].TopLeftY = wined3d_vp[i].y;
        viewports[i].Width = wined3d_vp[i].width;
        viewports[i].Height = wined3d_vp[i].height;
        viewports[i].MinDepth = wined3d_vp[i].min_z;
        viewports[i].MaxDepth = wined3d_vp[i].max_z;
    }
5793 5794
}

5795
static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5796
{
5797
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5798
    unsigned int actual_count;
5799

5800
    TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5801

5802 5803 5804
    if (!rect_count)
        return;

5805 5806
    actual_count = *rect_count;

5807
    wined3d_mutex_lock();
5808
    wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5809 5810
    wined3d_mutex_unlock();

5811
    if (!rects)
5812
    {
5813
        *rect_count = actual_count;
5814
        return;
5815 5816
    }

5817 5818
    if (*rect_count > actual_count)
        memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5819
}
5820

5821 5822 5823 5824 5825 5826
static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
{
    TRACE("iface %p.\n", iface);

    /* In the current implementation the device is never removed, so we can
     * just return S_OK here. */
5827 5828

    return S_OK;
5829 5830
}

5831
static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5832
{
5833
    FIXME("iface %p, flags %#x stub!\n", iface, flags);
5834 5835 5836 5837

    return E_NOTIMPL;
}

5838
static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5839
{
5840
    FIXME("iface %p stub!\n", iface);
5841

5842
    return 0;
5843 5844
}

5845 5846
static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
        REFGUID guid, UINT *data_size, void *data)
5847
{
5848
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5849

5850
    TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5851

5852
    return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5853 5854
}

5855 5856
static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
        REFGUID guid, UINT data_size, const void *data)
5857
{
5858
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5859

5860
    TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5861

5862
    return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5863 5864
}

5865 5866
static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
        REFGUID guid, const IUnknown *data)
5867
{
5868
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5869

5870 5871
    TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);

5872
    return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5873 5874
}

5875
static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5876
{
5877 5878 5879 5880
    struct d3d_device *device = impl_from_ID3D10Device(iface);

    TRACE("iface %p.\n", iface);

5881
    d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5882 5883
}

5884
static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5885
{
5886 5887 5888 5889 5890
    struct d3d_device *device = impl_from_ID3D10Device(iface);

    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
5891
    wined3d_device_context_flush(device->immediate_context.wined3d_context);
5892
    wined3d_mutex_unlock();
5893 5894
}

5895 5896
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
        const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5897
{
5898
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5899
    D3D11_BUFFER_DESC d3d11_desc;
5900
    struct d3d_buffer *object;
5901
    HRESULT hr;
5902

5903 5904
    TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);

5905 5906 5907 5908 5909 5910 5911
    d3d11_desc.ByteWidth = desc->ByteWidth;
    d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
    d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
    d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
    d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
    d3d11_desc.StructureByteStride = 0;

5912
    if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5913 5914 5915 5916 5917
        return hr;

    *buffer = &object->ID3D10Buffer_iface;

    return S_OK;
5918 5919
}

5920 5921
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
        const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5922
{
5923 5924 5925 5926
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    D3D11_TEXTURE1D_DESC d3d11_desc;
    struct d3d_texture1d *object;
    HRESULT hr;
5927

5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

    d3d11_desc.Width = desc->Width;
    d3d11_desc.MipLevels = desc->MipLevels;
    d3d11_desc.ArraySize = desc->ArraySize;
    d3d11_desc.Format = desc->Format;
    d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
    d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
    d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
    d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);

    if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
        return hr;

    *texture = &object->ID3D10Texture1D_iface;

    return S_OK;
5945 5946
}

5947 5948 5949
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
        const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
        ID3D10Texture2D **texture)
5950
{
5951 5952
    struct d3d_device *device = impl_from_ID3D10Device(iface);
    D3D11_TEXTURE2D_DESC d3d11_desc;
5953
    struct d3d_texture2d *object;
5954
    HRESULT hr;
5955

5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

    d3d11_desc.Width = desc->Width;
    d3d11_desc.Height = desc->Height;
    d3d11_desc.MipLevels = desc->MipLevels;
    d3d11_desc.ArraySize = desc->ArraySize;
    d3d11_desc.Format = desc->Format;
    d3d11_desc.SampleDesc = desc->SampleDesc;
    d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
    d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
    d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
    d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);

5969
    if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5970 5971 5972 5973 5974
        return hr;

    *texture = &object->ID3D10Texture2D_iface;

    return S_OK;
5975 5976
}

5977 5978 5979
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
        const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
        ID3D10Texture3D **texture)
5980
{
5981
    struct d3d_device *device = impl_from_ID3D10Device(iface);
5982
    D3D11_TEXTURE3D_DESC d3d11_desc;
5983
    struct d3d_texture3d *object;
5984
    HRESULT hr;
5985

5986 5987
    TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);

5988 5989 5990 5991 5992 5993 5994 5995 5996 5997
    d3d11_desc.Width = desc->Width;
    d3d11_desc.Height = desc->Height;
    d3d11_desc.Depth = desc->Depth;
    d3d11_desc.MipLevels = desc->MipLevels;
    d3d11_desc.Format = desc->Format;
    d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
    d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
    d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
    d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);

5998
    if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5999 6000 6001 6002 6003 6004 6005
        return hr;

    *texture = &object->ID3D10Texture3D_iface;

    return S_OK;
}

6006 6007
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
        ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
6008
{
6009
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6010
    struct d3d_shader_resource_view *object;
6011
    ID3D11Resource *d3d11_resource;
6012
    HRESULT hr;
6013

6014
    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6015

6016 6017 6018
    if (!resource)
        return E_INVALIDARG;

6019 6020 6021 6022 6023 6024
    if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
    {
        ERR("Resource does not implement ID3D11Resource.\n");
        return E_FAIL;
    }

6025 6026
    hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
            &object);
6027
    ID3D11Resource_Release(d3d11_resource);
6028 6029
    if (FAILED(hr))
        return hr;
6030

6031
    *view = &object->ID3D10ShaderResourceView1_iface;
6032 6033 6034 6035

    return S_OK;
}

6036 6037 6038 6039 6040 6041 6042 6043 6044
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
        ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
{
    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

    return d3d10_device_CreateShaderResourceView1(iface, resource,
            (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
}

6045 6046
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
        ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6047
{
6048
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6049
    struct d3d_rendertarget_view *object;
6050
    ID3D11Resource *d3d11_resource;
6051 6052 6053 6054
    HRESULT hr;

    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

6055 6056 6057
    if (!resource)
        return E_INVALIDARG;

6058 6059 6060 6061 6062 6063
    if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
    {
        ERR("Resource does not implement ID3D11Resource.\n");
        return E_FAIL;
    }

6064
    hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6065
    ID3D11Resource_Release(d3d11_resource);
6066 6067
    if (FAILED(hr))
        return hr;
6068

6069 6070 6071
    *view = &object->ID3D10RenderTargetView_iface;

    return S_OK;
6072 6073
}

6074 6075 6076 6077 6078
static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
{
    return (D3D11_DSV_DIMENSION)dim;
}

6079 6080
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
        ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6081
{
6082
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6083
    D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6084
    struct d3d_depthstencil_view *object;
6085
    ID3D11Resource *d3d11_resource;
6086 6087 6088 6089
    HRESULT hr;

    TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);

6090 6091 6092
    if (desc)
    {
        d3d11_desc.Format = desc->Format;
6093
        d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6094 6095 6096 6097
        d3d11_desc.Flags = 0;
        memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
    }

6098 6099 6100 6101 6102 6103
    if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
    {
        ERR("Resource does not implement ID3D11Resource.\n");
        return E_FAIL;
    }

6104
    hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6105
    ID3D11Resource_Release(d3d11_resource);
6106 6107
    if (FAILED(hr))
        return hr;
6108

6109 6110 6111
    *view = &object->ID3D10DepthStencilView_iface;

    return S_OK;
6112 6113
}

6114 6115 6116 6117
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
        const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
        const void *shader_byte_code, SIZE_T shader_byte_code_length,
        ID3D10InputLayout **input_layout)
6118
{
6119
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6120
    struct d3d_input_layout *object;
6121 6122 6123 6124 6125 6126 6127
    HRESULT hr;

    TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
            "shader_byte_code_length %lu, input_layout %p\n",
            iface, element_descs, element_count, shader_byte_code,
            shader_byte_code_length, input_layout);

6128 6129
    if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
            shader_byte_code, shader_byte_code_length, &object)))
6130 6131 6132 6133 6134
        return hr;

    *input_layout = &object->ID3D10InputLayout_iface;

    return S_OK;
6135 6136
}

6137 6138
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
        const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6139
{
6140
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6141
    struct d3d_vertex_shader *object;
6142 6143
    HRESULT hr;

6144
    TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6145 6146
            iface, byte_code, byte_code_length, shader);

6147
    if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6148 6149 6150 6151 6152
        return hr;

    *shader = &object->ID3D10VertexShader_iface;

    return S_OK;
6153 6154
}

6155 6156
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
        const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6157
{
6158
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6159
    struct d3d_geometry_shader *object;
6160
    HRESULT hr;
6161

6162 6163 6164
    TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
            iface, byte_code, byte_code_length, shader);

6165 6166
    if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
            NULL, 0, NULL, 0, 0, &object)))
6167 6168 6169 6170 6171
        return hr;

    *shader = &object->ID3D10GeometryShader_iface;

    return S_OK;
6172 6173
}

6174 6175 6176
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
        const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
        UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6177
{
6178
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6179
    D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6180 6181 6182 6183 6184 6185
    struct d3d_geometry_shader *object;
    unsigned int i, stride_count = 1;
    HRESULT hr;

    TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
            "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6186 6187
            iface, byte_code, byte_code_length, output_stream_decls,
            output_stream_decl_count, output_stream_stride, shader);
6188

6189 6190 6191 6192 6193 6194 6195 6196
    if (!output_stream_decl_count && output_stream_stride)
    {
        WARN("Stride must be 0 when declaration entry count is 0.\n");
        *shader = NULL;
        return E_INVALIDARG;
    }

    if (output_stream_decl_count
6197
            && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6198 6199
    {
        ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6200
        *shader = NULL;
6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213
        return E_OUTOFMEMORY;
    }

    for (i = 0; i < output_stream_decl_count; ++i)
    {
        so_entries[i].Stream = 0;
        so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
        so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
        so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
        so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
        so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;

        if (output_stream_decls[i].OutputSlot)
6214 6215 6216 6217 6218
        {
            stride_count = 0;
            if (output_stream_stride)
            {
                WARN("Stride must be 0 when multiple output slots are used.\n");
6219
                heap_free(so_entries);
6220 6221 6222 6223
                *shader = NULL;
                return E_INVALIDARG;
            }
        }
6224 6225 6226 6227
    }

    hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
            so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6228
    heap_free(so_entries);
6229
    if (FAILED(hr))
6230 6231
    {
        *shader = NULL;
6232
        return hr;
6233
    }
6234 6235 6236 6237

    *shader = &object->ID3D10GeometryShader_iface;

    return hr;
6238 6239
}

6240 6241
static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
        const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6242
{
6243
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6244
    struct d3d_pixel_shader *object;
6245
    HRESULT hr;
6246

6247
    TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6248 6249
            iface, byte_code, byte_code_length, shader);

6250
    if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6251 6252 6253 6254 6255
        return hr;

    *shader = &object->ID3D10PixelShader_iface;

    return S_OK;
6256 6257
}

6258 6259
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
        const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6260
{
6261
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6262
    struct d3d_blend_state *object;
6263
    HRESULT hr;
6264

6265 6266
    TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);

6267
    if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6268 6269
        return hr;

6270 6271 6272
    *blend_state = &object->ID3D10BlendState1_iface;

    return S_OK;
6273 6274 6275 6276 6277 6278 6279 6280 6281 6282
}

static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
        const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
{
    D3D10_BLEND_DESC1 d3d10_1_desc;
    unsigned int i;

    TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);

6283 6284 6285
    if (!desc)
        return E_INVALIDARG;

6286 6287
    d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
    d3d10_1_desc.IndependentBlendEnable = FALSE;
6288
    for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6289
    {
6290 6291
        if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
                || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6292
            d3d10_1_desc.IndependentBlendEnable = TRUE;
6293 6294
    }

6295
    for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6296
    {
6297 6298 6299 6300 6301 6302 6303 6304
        d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
        d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
        d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
        d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
        d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
        d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
        d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
        d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6305 6306
    }

6307
    return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6308 6309
}

6310 6311
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
        const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6312
{
6313
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6314
    struct d3d_depthstencil_state *object;
6315 6316 6317 6318
    HRESULT hr;

    TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);

6319
    if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6320
        return hr;
6321

6322 6323 6324
    *depth_stencil_state = &object->ID3D10DepthStencilState_iface;

    return S_OK;
6325 6326
}

6327 6328
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
        const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6329
{
6330
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6331
    struct d3d_rasterizer_state *object;
6332
    HRESULT hr;
6333

6334
    TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6335

6336
    if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6337
        return hr;
6338

6339 6340 6341
    *rasterizer_state = &object->ID3D10RasterizerState_iface;

    return S_OK;
6342 6343
}

6344 6345
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
        const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6346
{
6347
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6348
    struct d3d_sampler_state *object;
6349
    HRESULT hr;
6350

6351
    TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6352

6353
    if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6354
        return hr;
6355

6356 6357 6358
    *sampler_state = &object->ID3D10SamplerState_iface;

    return S_OK;
6359 6360
}

6361 6362
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
        const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6363
{
6364
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6365
    struct d3d_query *object;
6366
    HRESULT hr;
6367

6368
    TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6369

6370
    if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6371
        return hr;
6372

6373 6374 6375 6376 6377
    if (query)
    {
        *query = &object->ID3D10Query_iface;
        return S_OK;
    }
6378

6379 6380
    ID3D10Query_Release(&object->ID3D10Query_iface);
    return S_FALSE;
6381 6382
}

6383 6384
static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
        const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6385
{
6386
    struct d3d_device *device = impl_from_ID3D10Device(iface);
6387
    struct d3d_query *object;
6388
    HRESULT hr;
6389

6390
    TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6391

6392
    if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6393
        return hr;
6394

6395 6396 6397 6398 6399
    if (predicate)
    {
        *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
        return S_OK;
    }
6400

6401 6402
    ID3D10Query_Release(&object->ID3D10Query_iface);
    return S_FALSE;
6403 6404
}

6405 6406
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
        const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6407
{
6408
    FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6409 6410 6411 6412

    return E_NOTIMPL;
}

6413 6414
static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
        DXGI_FORMAT format, UINT *format_support)
6415
{
6416 6417 6418
    struct d3d_device *device = impl_from_ID3D10Device(iface);

    TRACE("iface %p, format %s, format_support %p.\n",
6419
            iface, debug_dxgi_format(format), format_support);
6420

6421
    return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6422 6423
}

6424
static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6425 6426
        DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
{
6427 6428 6429
    struct d3d_device *device = impl_from_ID3D10Device(iface);

    TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6430
            iface, debug_dxgi_format(format), sample_count, quality_level_count);
6431

6432
    return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6433
            sample_count, quality_level_count);
6434 6435
}

6436
static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6437
{
6438
    FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6439 6440
}

6441 6442 6443
static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
        const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
        UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6444
{
6445
    FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6446
            "units %p, units_length %p, description %p, description_length %p stub!\n",
6447
            iface, desc, type, active_counters, name, name_length,
6448 6449 6450 6451 6452
            units, units_length, description, description_length);

    return E_NOTIMPL;
}

6453
static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6454
{
6455
    FIXME("iface %p stub!\n", iface);
6456

6457
    return 0;
6458 6459
}

6460 6461
static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
        HANDLE resource_handle, REFIID guid, void **resource)
6462
{
6463 6464
    FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
            iface, resource_handle, debugstr_guid(guid), resource);
6465 6466 6467 6468

    return E_NOTIMPL;
}

6469
static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6470
{
6471
    FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6472 6473
}

6474
static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6475
{
6476
    FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6477 6478
}

6479 6480 6481 6482 6483
static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
{
    return (D3D10_FEATURE_LEVEL1)level;
}

6484
static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6485
{
6486 6487 6488
    struct d3d_device *device = impl_from_ID3D10Device(iface);

    TRACE("iface %p.\n", iface);
6489

6490
    return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6491 6492
}

6493
static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6494
{
6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598
    /* IUnknown methods */
    d3d10_device_QueryInterface,
    d3d10_device_AddRef,
    d3d10_device_Release,
    /* ID3D10Device methods */
    d3d10_device_VSSetConstantBuffers,
    d3d10_device_PSSetShaderResources,
    d3d10_device_PSSetShader,
    d3d10_device_PSSetSamplers,
    d3d10_device_VSSetShader,
    d3d10_device_DrawIndexed,
    d3d10_device_Draw,
    d3d10_device_PSSetConstantBuffers,
    d3d10_device_IASetInputLayout,
    d3d10_device_IASetVertexBuffers,
    d3d10_device_IASetIndexBuffer,
    d3d10_device_DrawIndexedInstanced,
    d3d10_device_DrawInstanced,
    d3d10_device_GSSetConstantBuffers,
    d3d10_device_GSSetShader,
    d3d10_device_IASetPrimitiveTopology,
    d3d10_device_VSSetShaderResources,
    d3d10_device_VSSetSamplers,
    d3d10_device_SetPredication,
    d3d10_device_GSSetShaderResources,
    d3d10_device_GSSetSamplers,
    d3d10_device_OMSetRenderTargets,
    d3d10_device_OMSetBlendState,
    d3d10_device_OMSetDepthStencilState,
    d3d10_device_SOSetTargets,
    d3d10_device_DrawAuto,
    d3d10_device_RSSetState,
    d3d10_device_RSSetViewports,
    d3d10_device_RSSetScissorRects,
    d3d10_device_CopySubresourceRegion,
    d3d10_device_CopyResource,
    d3d10_device_UpdateSubresource,
    d3d10_device_ClearRenderTargetView,
    d3d10_device_ClearDepthStencilView,
    d3d10_device_GenerateMips,
    d3d10_device_ResolveSubresource,
    d3d10_device_VSGetConstantBuffers,
    d3d10_device_PSGetShaderResources,
    d3d10_device_PSGetShader,
    d3d10_device_PSGetSamplers,
    d3d10_device_VSGetShader,
    d3d10_device_PSGetConstantBuffers,
    d3d10_device_IAGetInputLayout,
    d3d10_device_IAGetVertexBuffers,
    d3d10_device_IAGetIndexBuffer,
    d3d10_device_GSGetConstantBuffers,
    d3d10_device_GSGetShader,
    d3d10_device_IAGetPrimitiveTopology,
    d3d10_device_VSGetShaderResources,
    d3d10_device_VSGetSamplers,
    d3d10_device_GetPredication,
    d3d10_device_GSGetShaderResources,
    d3d10_device_GSGetSamplers,
    d3d10_device_OMGetRenderTargets,
    d3d10_device_OMGetBlendState,
    d3d10_device_OMGetDepthStencilState,
    d3d10_device_SOGetTargets,
    d3d10_device_RSGetState,
    d3d10_device_RSGetViewports,
    d3d10_device_RSGetScissorRects,
    d3d10_device_GetDeviceRemovedReason,
    d3d10_device_SetExceptionMode,
    d3d10_device_GetExceptionMode,
    d3d10_device_GetPrivateData,
    d3d10_device_SetPrivateData,
    d3d10_device_SetPrivateDataInterface,
    d3d10_device_ClearState,
    d3d10_device_Flush,
    d3d10_device_CreateBuffer,
    d3d10_device_CreateTexture1D,
    d3d10_device_CreateTexture2D,
    d3d10_device_CreateTexture3D,
    d3d10_device_CreateShaderResourceView,
    d3d10_device_CreateRenderTargetView,
    d3d10_device_CreateDepthStencilView,
    d3d10_device_CreateInputLayout,
    d3d10_device_CreateVertexShader,
    d3d10_device_CreateGeometryShader,
    d3d10_device_CreateGeometryShaderWithStreamOutput,
    d3d10_device_CreatePixelShader,
    d3d10_device_CreateBlendState,
    d3d10_device_CreateDepthStencilState,
    d3d10_device_CreateRasterizerState,
    d3d10_device_CreateSamplerState,
    d3d10_device_CreateQuery,
    d3d10_device_CreatePredicate,
    d3d10_device_CreateCounter,
    d3d10_device_CheckFormatSupport,
    d3d10_device_CheckMultisampleQualityLevels,
    d3d10_device_CheckCounterInfo,
    d3d10_device_CheckCounter,
    d3d10_device_GetCreationFlags,
    d3d10_device_OpenSharedResource,
    d3d10_device_SetTextFilterSize,
    d3d10_device_GetTextFilterSize,
    d3d10_device_CreateShaderResourceView1,
    d3d10_device_CreateBlendState1,
    d3d10_device_GetFeatureLevel,
};
6599

6600
static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6601 6602
{
    /* IUnknown methods */
6603 6604 6605
    d3d_device_inner_QueryInterface,
    d3d_device_inner_AddRef,
    d3d_device_inner_Release,
6606 6607 6608 6609
};

/* ID3D10Multithread methods */

6610
static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6611
{
6612
    return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6613 6614 6615 6616
}

static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
{
6617
    struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6618 6619 6620 6621 6622 6623 6624 6625

    TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);

    return IUnknown_QueryInterface(device->outer_unk, iid, out);
}

static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
{
6626
    struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6627 6628 6629 6630 6631 6632 6633 6634

    TRACE("iface %p.\n", iface);

    return IUnknown_AddRef(device->outer_unk);
}

static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
{
6635
    struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655

    TRACE("iface %p.\n", iface);

    return IUnknown_Release(device->outer_unk);
}

static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
{
    TRACE("iface %p.\n", iface);

    wined3d_mutex_lock();
}

static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
{
    TRACE("iface %p.\n", iface);

    wined3d_mutex_unlock();
}

6656
static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6657
{
6658
    FIXME("iface %p, enable %#x stub!\n", iface, enable);
6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680

    return TRUE;
}

static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
{
    FIXME("iface %p stub!\n", iface);

    return TRUE;
}

static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
{
    d3d10_multithread_QueryInterface,
    d3d10_multithread_AddRef,
    d3d10_multithread_Release,
    d3d10_multithread_Enter,
    d3d10_multithread_Leave,
    d3d10_multithread_SetMultithreadProtected,
    d3d10_multithread_GetMultithreadProtected,
};

6681
/* IWineDXGIDeviceParent IUnknown methods */
6682

6683
static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6684
{
6685
    return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6686 6687
}

6688
static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6689
        REFIID iid, void **out)
6690
{
6691
    struct d3d_device *device = device_from_dxgi_device_parent(iface);
6692
    return IUnknown_QueryInterface(device->outer_unk, iid, out);
6693 6694
}

6695
static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6696
{
6697
    struct d3d_device *device = device_from_dxgi_device_parent(iface);
6698
    return IUnknown_AddRef(device->outer_unk);
6699 6700
}

6701
static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6702
{
6703
    struct d3d_device *device = device_from_dxgi_device_parent(iface);
6704
    return IUnknown_Release(device->outer_unk);
6705 6706
}

6707 6708 6709
static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
        IWineDXGIDeviceParent *iface)
{
6710
    struct d3d_device *device = device_from_dxgi_device_parent(iface);
6711 6712 6713
    return &device->device_parent;
}

6714
static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6715 6716 6717 6718 6719 6720 6721 6722
{
    /* IUnknown methods */
    dxgi_device_parent_QueryInterface,
    dxgi_device_parent_AddRef,
    dxgi_device_parent_Release,
    /* IWineDXGIDeviceParent methods */
    dxgi_device_parent_get_wined3d_device_parent,
};
6723

6724
static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6725
{
6726
    return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6727
}
6728

6729 6730 6731
static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
        struct wined3d_device *wined3d_device)
{
6732
    struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6733
    struct d3d_device_context_state *state;
6734
    struct wined3d_state *wined3d_state;
6735
    D3D_FEATURE_LEVEL feature_level;
6736

6737 6738 6739 6740
    TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);

    wined3d_device_incref(wined3d_device);
    device->wined3d_device = wined3d_device;
6741
    device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6742

6743
    wined3d_state = wined3d_device_get_state(device->wined3d_device);
6744
    feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6745

6746
    if (!(state = heap_alloc_zero(sizeof(*state))))
6747
    {
6748
        ERR("Failed to create the initial device context state.\n");
6749
        return;
6750
    }
6751

6752 6753 6754 6755 6756
    d3d_device_context_state_init(state, device, feature_level,
            device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);

    device->state = state;
    if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6757 6758
        ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);

6759 6760
    d3d_device_context_state_private_addref(state);
    ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6761 6762
}

6763 6764 6765 6766 6767
static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
{
    TRACE("device_parent %p.\n", device_parent);
}

6768 6769 6770 6771 6772
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
    TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
}

6773 6774 6775
static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
        enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
        void **parent, const struct wined3d_parent_ops **parent_ops)
6776
{
6777 6778
    TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
            device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6779

6780
    *parent = NULL;
6781
    *parent_ops = &d3d_null_wined3d_parent_ops;
6782 6783 6784 6785

    return S_OK;
}

6786
static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6787
        void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6788
        struct wined3d_texture **wined3d_texture)
6789
{
6790
    struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6791
    struct d3d_texture2d *texture;
6792 6793
    ID3D11Texture2D *texture_iface;
    D3D11_TEXTURE2D_DESC desc;
6794 6795
    HRESULT hr;

6796 6797
    TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
            device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6798

6799 6800
    desc.Width = wined3d_desc->width;
    desc.Height = wined3d_desc->height;
6801 6802
    desc.MipLevels = 1;
    desc.ArraySize = 1;
6803 6804 6805
    desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
    desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
    desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6806
    desc.Usage = D3D11_USAGE_DEFAULT;
6807
    desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6808 6809 6810
    desc.CPUAccessFlags = 0;
    desc.MiscFlags = 0;

6811 6812
    if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
    {
6813
        desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6814 6815 6816 6817 6818 6819
        texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
    }

    if (texture_flags)
        FIXME("Unhandled flags %#x.\n", texture_flags);

6820
    if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6821
            &desc, NULL, &texture_iface)))
6822
    {
6823
        WARN("Failed to create 2D texture, hr %#x.\n", hr);
6824 6825 6826
        return hr;
    }

6827
    texture = impl_from_ID3D11Texture2D(texture_iface);
6828

6829 6830
    *wined3d_texture = texture->wined3d_texture;
    wined3d_texture_incref(*wined3d_texture);
6831
    ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6832 6833

    return S_OK;
6834 6835
}

6836
static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6837
{
6838
    device_parent_wined3d_device_created,
6839
    device_parent_mode_changed,
6840
    device_parent_activate,
6841
    device_parent_texture_sub_resource_created,
6842
    device_parent_create_swapchain_texture,
6843
};
6844

6845
static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6846
{
6847 6848
    const D3D11_SAMPLER_DESC *ka = key;
    const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6849 6850 6851 6852

    return memcmp(ka, kb, sizeof(*ka));
}

6853
static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6854
{
6855 6856
    const D3D11_BLEND_DESC *ka = key;
    const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6857 6858 6859 6860

    return memcmp(ka, kb, sizeof(*ka));
}

6861
static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6862
{
6863 6864
    const D3D11_DEPTH_STENCIL_DESC *ka = key;
    const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6865
            const struct d3d_depthstencil_state, entry)->desc;
6866 6867 6868 6869

    return memcmp(ka, kb, sizeof(*ka));
}

6870
static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6871
{
6872 6873
    const D3D11_RASTERIZER_DESC *ka = key;
    const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6874 6875 6876 6877

    return memcmp(ka, kb, sizeof(*ka));
}

6878
void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6879
{
6880
    device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6881
    device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6882 6883
    device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
    device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6884
    device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6885
    device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6886
    device->refcount = 1;
6887 6888
    /* COM aggregation always takes place */
    device->outer_unk = outer_unknown;
6889
    device->d3d11_only = FALSE;
6890
    device->state = NULL;
6891

6892
    d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6893
    ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6894

6895 6896 6897 6898
    wine_rb_init(&device->blend_states, d3d_blend_state_compare);
    wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
    wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
    wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);
6899
}