d3d11: Implement d3d11_immediate_context_SwapDeviceContextState() on top of wined3d_device_set_state().

Based on a patch by Rémi Bernon.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2021-02-23 19:50:46 +01:00 committed by Alexandre Julliard
parent 80e1eb87ad
commit 7b487c38d0
3 changed files with 251 additions and 220 deletions

View file

@ -516,6 +516,12 @@ struct d3d_query *unsafe_impl_from_ID3D11Query(ID3D11Query *iface) DECLSPEC_HIDD
struct d3d_query *unsafe_impl_from_ID3D10Query(ID3D10Query *iface) DECLSPEC_HIDDEN;
struct d3d_query *unsafe_impl_from_ID3D11Asynchronous(ID3D11Asynchronous *iface) DECLSPEC_HIDDEN;
struct d3d_device_context_state_entry
{
struct d3d_device *device;
struct wined3d_state *wined3d_state;
};
/* ID3DDeviceContextState */
struct d3d_device_context_state
{
@ -523,30 +529,12 @@ struct d3d_device_context_state
LONG refcount, private_refcount;
struct wined3d_private_store private_store;
struct
{
ID3D11VertexShader *shader;
ID3D11SamplerState *samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
ID3D11ShaderResourceView *srvs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
ID3D11Buffer *cbs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
} vs;
struct
{
ID3D11GeometryShader *shader;
ID3D11SamplerState *samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
ID3D11ShaderResourceView *srvs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
ID3D11Buffer *cbs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
} gs;
struct
{
ID3D11PixelShader *shader;
ID3D11SamplerState *samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
ID3D11ShaderResourceView *srvs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
ID3D11Buffer *cbs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
} ps;
GUID emulated_interface;
struct d3d_device_context_state_entry *entries;
SIZE_T entries_size;
SIZE_T entry_count;
struct wined3d_device *wined3d_device;
ID3D11Device2 *device;
};
@ -585,6 +573,10 @@ struct d3d_device
struct wine_rb_tree depthstencil_states;
struct wine_rb_tree rasterizer_states;
struct wine_rb_tree sampler_states;
struct d3d_device_context_state **context_states;
SIZE_T context_states_size;
SIZE_T context_state_count;
};
static inline struct d3d_device *impl_from_ID3D11Device(ID3D11Device *iface)

View file

@ -22,6 +22,32 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
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;
}
static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
@ -88,9 +114,27 @@ static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContext
return refcount;
}
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;
}
}
static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
{
ULONG refcount = InterlockedDecrement(&state->private_refcount);
struct d3d_device_context_state_entry *entry;
struct d3d_device *device;
unsigned int i;
TRACE("%p decreasing private refcount to %u.\n", state, refcount);
@ -98,27 +142,17 @@ static void d3d_device_context_state_private_release(struct d3d_device_context_s
if (!refcount)
{
wined3d_private_store_cleanup(&state->private_store);
if (state->vs.shader) ID3D11VertexShader_Release(state->vs.shader);
if (state->gs.shader) ID3D11GeometryShader_Release(state->gs.shader);
if (state->ps.shader) ID3D11PixelShader_Release(state->ps.shader);
for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
for (i = 0; i < state->entry_count; ++i)
{
if (state->vs.samplers[i]) ID3D11SamplerState_Release(state->vs.samplers[i]);
if (state->gs.samplers[i]) ID3D11SamplerState_Release(state->gs.samplers[i]);
if (state->ps.samplers[i]) ID3D11SamplerState_Release(state->ps.samplers[i]);
}
for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
{
if (state->vs.srvs[i]) ID3D11ShaderResourceView_Release(state->vs.srvs[i]);
if (state->gs.srvs[i]) ID3D11ShaderResourceView_Release(state->gs.srvs[i]);
if (state->ps.srvs[i]) ID3D11ShaderResourceView_Release(state->ps.srvs[i]);
}
for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
{
if (state->vs.cbs[i]) ID3D11Buffer_Release(state->vs.cbs[i]);
if (state->gs.cbs[i]) ID3D11Buffer_Release(state->gs.cbs[i]);
if (state->ps.cbs[i]) ID3D11Buffer_Release(state->ps.cbs[i]);
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);
}
heap_free(state->entries);
wined3d_device_decref(state->wined3d_device);
heap_free(state);
}
@ -194,6 +228,85 @@ static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
/* ID3DDeviceContextState methods */
};
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;
if (FAILED(wined3d_state_create(device->wined3d_device, &wined3d_state)))
return NULL;
if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
{
wined3d_state_destroy(wined3d_state);
return NULL;
}
return wined3d_state;
}
static void d3d_device_context_state_init(struct d3d_device_context_state *state, struct d3d_device *device,
REFIID emulated_interface)
{
@ -201,9 +314,6 @@ static void d3d_device_context_state_init(struct d3d_device_context_state *state
state->refcount = state->private_refcount = 0;
wined3d_private_store_init(&state->private_store);
memset(&state->vs, 0, sizeof(state->vs));
memset(&state->gs, 0, sizeof(state->gs));
memset(&state->ps, 0, sizeof(state->ps));
state->emulated_interface = *emulated_interface;
wined3d_device_incref(state->wined3d_device = device->wined3d_device);
@ -2722,98 +2832,39 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers1(ID3D
iface, start_slot, buffer_count, buffers, first_constant, num_constants);
}
static void d3d11_immediate_context_capture_state(ID3D11DeviceContext1 *iface, struct d3d_device_context_state *state)
{
wined3d_mutex_lock();
d3d11_immediate_context_VSGetShader(iface, &state->vs.shader, NULL, 0);
d3d11_immediate_context_VSGetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->vs.samplers);
d3d11_immediate_context_VSGetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->vs.srvs);
d3d11_immediate_context_VSGetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->vs.cbs);
d3d11_immediate_context_GSGetShader(iface, &state->gs.shader, NULL, 0);
d3d11_immediate_context_GSGetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->gs.samplers);
d3d11_immediate_context_GSGetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->gs.srvs);
d3d11_immediate_context_GSGetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->gs.cbs);
d3d11_immediate_context_PSGetShader(iface, &state->ps.shader, NULL, 0);
d3d11_immediate_context_PSGetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->ps.samplers);
d3d11_immediate_context_PSGetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->ps.srvs);
d3d11_immediate_context_PSGetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->ps.cbs);
wined3d_mutex_unlock();
}
static void d3d11_immediate_context_restore_state(ID3D11DeviceContext1 *iface, struct d3d_device_context_state *state)
{
wined3d_mutex_lock();
d3d11_immediate_context_VSSetShader(iface, state->vs.shader, NULL, 0);
d3d11_immediate_context_VSSetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->vs.samplers);
d3d11_immediate_context_VSSetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->vs.srvs);
d3d11_immediate_context_VSSetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->vs.cbs);
d3d11_immediate_context_GSSetShader(iface, state->gs.shader, NULL, 0);
d3d11_immediate_context_GSSetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->gs.samplers);
d3d11_immediate_context_GSSetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->gs.srvs);
d3d11_immediate_context_GSSetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->gs.cbs);
d3d11_immediate_context_PSSetShader(iface, state->ps.shader, NULL, 0);
d3d11_immediate_context_PSSetSamplers(iface, 0,
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, state->ps.samplers);
d3d11_immediate_context_PSSetShaderResources(iface, 0,
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, state->ps.srvs);
d3d11_immediate_context_PSSetConstantBuffers(iface, 0,
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, state->ps.cbs);
wined3d_mutex_unlock();
}
static void STDMETHODCALLTYPE d3d11_immediate_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
ID3DDeviceContextState *state, ID3DDeviceContextState **prev_state)
ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
{
struct d3d_device_context_state *state_impl;
struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
struct d3d_device_context_state *state_impl, *prev_impl;
struct wined3d_state *wined3d_state;
FIXME("iface %p, state %p, prev_state %p semi-stub!\n", iface, state, prev_state);
FIXME("iface %p, state %p, prev %p semi-stub!\n", iface, state, prev);
if (prev_state) *prev_state = NULL;
if (!state) return;
if (!state)
{
if (prev)
*prev = NULL;
return;
}
wined3d_mutex_lock();
if (prev_state)
{
*prev_state = NULL;
if ((state_impl = heap_alloc(sizeof(*state_impl))))
{
d3d_device_context_state_init(state_impl, device, &device->state->emulated_interface);
d3d11_immediate_context_capture_state(iface, state_impl);
*prev_state = &state_impl->ID3DDeviceContextState_iface;
}
}
if ((state_impl = impl_from_ID3DDeviceContextState(state)))
{
d3d11_immediate_context_restore_state(iface, state_impl);
device->state->emulated_interface = state_impl->emulated_interface;
if (d3d_device_is_d3d10_active(device))
FIXME("D3D10 interface emulation not fully implemented yet!\n");
}
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);
wined3d_device_set_state(device->wined3d_device, wined3d_state);
if (prev)
ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
d3d_device_context_state_private_addref(state_impl);
device->state = state_impl;
d3d_device_context_state_private_release(prev_impl);
if (d3d_device_is_d3d10_active(device))
FIXME("D3D10 interface emulation not fully implemented yet!\n");
wined3d_mutex_unlock();
}
@ -4027,9 +4078,12 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Dev
if (state)
{
*state = NULL;
if (!(state_impl = heap_alloc(sizeof(*state_impl))))
if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
{
*state = NULL;
return E_OUTOFMEMORY;
}
d3d_device_context_state_init(state_impl, device, emulated_interface);
*state = &state_impl->ID3DDeviceContextState_iface;
}
@ -4211,12 +4265,19 @@ static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
{
struct d3d_device *device = impl_from_IUnknown(iface);
ULONG refcount = InterlockedDecrement(&device->refcount);
unsigned int i;
TRACE("%p decreasing refcount to %u.\n", device, refcount);
if (!refcount)
{
if (device->state) d3d_device_context_state_private_release(device->state);
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);
d3d11_immediate_context_destroy(&device->immediate_context);
if (device->wined3d_device)
{
@ -6394,6 +6455,7 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par
struct wined3d_device *wined3d_device)
{
struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
struct wined3d_state *wined3d_state;
ID3DDeviceContextState *state;
HRESULT hr;
@ -6407,13 +6469,18 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par
if (FAILED(hr = d3d11_device_CreateDeviceContextState(&device->ID3D11Device2_iface, 0, &device->feature_level,
1, D3D11_SDK_VERSION, device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1, NULL,
&state)))
ERR("Failed to create the initial device context state, hr %#x.\n", hr);
else
{
device->state = impl_from_ID3DDeviceContextState(state);
d3d_device_context_state_private_addref(device->state);
ID3DDeviceContextState_Release(state);
ERR("Failed to create the initial device context state, hr %#x.\n", hr);
return;
}
device->state = impl_from_ID3DDeviceContextState(state);
wined3d_state = wined3d_device_get_state(device->wined3d_device);
if (!d3d_device_context_state_add_entry(device->state, device, wined3d_state))
ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
d3d_device_context_state_private_addref(device->state);
ID3DDeviceContextState_Release(state);
}
static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)

View file

@ -7083,7 +7083,7 @@ static void test_device_context_state(void)
ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
ok(previous_context_state != NULL, "Failed to get previous context state\n");
refcount = get_refcount(vs);
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
hr = ID3DDeviceContextState_SetPrivateData(context_state, &test_guid, sizeof(constant), &constant);
ok(hr == S_OK, "Failed to set private data, hr %#x.\n", hr);
@ -7093,9 +7093,9 @@ static void test_device_context_state(void)
data_size = sizeof(data);
memset(data, 0xa5, sizeof(data));
hr = ID3DDeviceContextState_GetPrivateData(context_state, &test_guid, &data_size, data);
todo_wine ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
todo_wine ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
todo_wine ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, NULL);
context_type = ID3D11DeviceContext1_GetType(context);
@ -7142,118 +7142,96 @@ static void test_device_context_state(void)
tmp_cb = (ID3D11Buffer *)0xdeadbeef;
ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
tmp_hs = (ID3D11HullShader *)0xdeadbeef;
ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
if (hs) todo_wine ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
if (tmp_hs) ID3D11HullShader_Release(tmp_hs);
if (hs) ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
if (tmp_srv) ID3D11ShaderResourceView_Release(tmp_srv);
ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
tmp_cb = (ID3D11Buffer *)0xdeadbeef;
ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
if (ds) todo_wine ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
if (tmp_ds) ID3D11DomainShader_Release(tmp_ds);
if (ds) ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
if (tmp_srv) ID3D11ShaderResourceView_Release(tmp_srv);
ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
tmp_cb = (ID3D11Buffer *)0xdeadbeef;
ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
if (cs) todo_wine ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
if (tmp_cs) ID3D11ComputeShader_Release(tmp_cs);
if (cs) ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
if (tmp_srv) ID3D11ShaderResourceView_Release(tmp_srv);
ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
todo_wine ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
topo = 0xdeadbeef;
ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
todo_wine ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
tmp_il = (ID3D11InputLayout *)0xdeadbeef;
ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
todo_wine ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
if (tmp_il) ID3D11InputLayout_Release(tmp_il);
ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
tmp_ib = (ID3D11Buffer *)0xdeadbeef;
format = 0xdeadbeef;
offset = 0xdeadbeef;
ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
todo_wine ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
if (tmp_ib) ID3D11Buffer_Release(tmp_ib);
todo_wine ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
todo_wine ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
tmp_vb = (ID3D11Buffer *)0xdeadbeef;
stride = 0xdeadbeef;
offset = 0xdeadbeef;
ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
todo_wine ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
if (tmp_vb) ID3D11Buffer_Release(tmp_vb);
todo_wine ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
todo_wine ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
todo_wine ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
if (tmp_rtv) ID3D11RenderTargetView_Release(tmp_rtv);
todo_wine ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
if (tmp_dsv) ID3D11DepthStencilView_Release(tmp_dsv);
todo_wine ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
tmp_bs = (ID3D11BlendState *)0xdeadbeef;
memset(blend_factor, 0xcd, sizeof(blend_factor));
sample_mask = 0xdeadbeef;
ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
todo_wine ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
if (tmp_bs) ID3D11BlendState_Release(tmp_bs);
todo_wine ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
"Got unexpected blend factor %f,%f,%f,%f.\n",
blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
todo_wine ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
stencil_ref = 0xdeadbeef;
ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
todo_wine ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
if (tmp_dss) ID3D11DepthStencilState_Release(tmp_dss);
todo_wine ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
todo_wine ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
if (tmp_rs) ID3D11RasterizerState_Release(tmp_rs);
ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
memset(tmp_vp, 0xa5, sizeof(tmp_vp));
count = 2;
ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
todo_wine ok(count == 0, "Got unexpected viewport count %u.\n", count);
ok(count == 0, "Got unexpected viewport count %u.\n", count);
memset(tmp_rect, 0xa5, sizeof(tmp_rect));
count = 2;
ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
@ -7261,15 +7239,13 @@ static void test_device_context_state(void)
tmp_sob = (ID3D11Buffer *)0xdeadbeef;
ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
todo_wine ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
if (tmp_sob) ID3D11Buffer_Release(tmp_sob);
ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
tmp_pred = (ID3D11Predicate *)0xdeadbeef;
pred_value = 0xdeadbeef;
ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
todo_wine ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
if (tmp_pred) ID3D11Predicate_Release(tmp_pred);
todo_wine ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
/* updating the device context should also update the device context state */
hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs2);
@ -7277,14 +7253,13 @@ static void test_device_context_state(void)
ID3D11DeviceContext1_VSSetShader(context, vs2, NULL, 0);
ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &tmp_context_state);
refcount = ID3DDeviceContextState_Release(tmp_context_state);
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
todo_wine ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
todo_wine ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
if (tmp_vs) refcount = ID3D11VertexShader_Release(tmp_vs);
else refcount = 0;
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
refcount = ID3D11VertexShader_Release(tmp_vs);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
/* context states may be used with other devices instances too */
d3d11_device2 = create_device(NULL);
@ -7305,17 +7280,16 @@ static void test_device_context_state(void)
/* updating context2 vertex shader doesn't update other contexts using the same state */
ID3D11DeviceContext1_VSSetShader(context2, vs, NULL, 0);
ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
todo_wine ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
if (tmp_vs) refcount = ID3D11VertexShader_Release(tmp_vs);
else refcount = 0;
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
refcount = ID3D11VertexShader_Release(tmp_vs);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ID3D11DeviceContext1_SwapDeviceContextState(context2, tmp_context_state, &context_state2);
refcount = ID3DDeviceContextState_Release(tmp_context_state);
ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
refcount = ID3DDeviceContextState_Release(context_state2);
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
todo_wine ok(context_state2 == context_state, "Got unexpected state pointer.\n");
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(context_state2 == context_state, "Got unexpected state pointer.\n");
/* swapping the default state on context2 effectively clears the vertex shader */
tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
@ -7333,19 +7307,17 @@ static void test_device_context_state(void)
ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
todo_wine ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
if (tmp_vs) refcount = ID3D11VertexShader_Release(tmp_vs);
else refcount = 0;
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
refcount = ID3D11VertexShader_Release(tmp_vs);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
/* even after swapping it again */
ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, NULL);
tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
todo_wine ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
if (tmp_vs) refcount = ID3D11VertexShader_Release(tmp_vs);
else refcount = 0;
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
refcount = ID3D11VertexShader_Release(tmp_vs);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
/* swapping the initial state on context2 doesn't have side effect on context either */
ID3D11DeviceContext1_SwapDeviceContextState(context2, previous_context_state, NULL);
@ -7362,10 +7334,10 @@ static void test_device_context_state(void)
refcount = ID3DDeviceContextState_Release(previous_context_state);
ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
refcount = ID3DDeviceContextState_Release(tmp_context_state);
todo_wine ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
refcount = ID3DDeviceContextState_Release(context_state);
ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
todo_wine ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
refcount = get_refcount(vs);
ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);