To support ID3D10Device interface activation on D3D11 devices.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
The idea here is only to have a minimal implementation of SwapDeviceContextState, to fix the D2D1 over D3D11 regression. What's missing is the actual state change, as well as the enabling / disabling or the D3D10 / D3D11 interface methods when state is changed to another version, as described in [1].
I didn't really investigate what the full device context state implementation would require, but I suspect it to be much bigger scope. This could possibly serve as an initial work for it as well.
[1] https://docs.microsoft.com/en-us/windows/win32/api/d3d11_1/nf-d3d11_1-id3d11...
dlls/d3d11/d3d11_main.c | 1 + dlls/d3d11/d3d11_private.h | 13 +++ dlls/d3d11/device.c | 187 ++++++++++++++++++++++++++++++++++++- dlls/d3d11/tests/d3d11.c | 38 +++++--- 4 files changed, 223 insertions(+), 16 deletions(-)
diff --git a/dlls/d3d11/d3d11_main.c b/dlls/d3d11/d3d11_main.c index dac59d09999..6666876049d 100644 --- a/dlls/d3d11/d3d11_main.c +++ b/dlls/d3d11/d3d11_main.c @@ -137,6 +137,7 @@ HRESULT WINAPI D3D11CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapte return E_FAIL; } d3d_device->d3d11_only = TRUE; + d3d_device->emulated_interface = IID_ID3D11Device2;
return S_OK; } diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h index 3248285fcda..2effe3a8242 100644 --- a/dlls/d3d11/d3d11_private.h +++ b/dlls/d3d11/d3d11_private.h @@ -516,6 +516,18 @@ 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;
+/* ID3DDeviceContextState */ +struct d3d_device_context_state +{ + ID3DDeviceContextState ID3DDeviceContextState_iface; + LONG refcount; + + struct wined3d_private_store private_store; + + ID3D11Device2 *device; + GUID emulated_interface; +}; + /* ID3D11DeviceContext - immediate context */ struct d3d11_immediate_context { @@ -539,6 +551,7 @@ struct d3d_device
D3D_FEATURE_LEVEL feature_level; BOOL d3d11_only; + GUID emulated_interface;
struct d3d11_immediate_context immediate_context;
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index 50e8cd58fe2..dac31913340 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -29,6 +29,140 @@ static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops = d3d_null_wined3d_object_destroyed, };
+/* 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 inline struct d3d_device *device_from_ID3DDeviceContextState(ID3DDeviceContextState *iface) +{ + struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface); + return impl_from_ID3D11Device2(state->device); +} + +static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface, + REFIID iid, void **out) +{ + struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface); + + 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)) + { + *out = &state->ID3DDeviceContextState_iface; + } + else + { + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; + } + + ID3DDeviceContextState_AddRef(iface); + return S_OK; +} + +static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface) +{ + struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface); + struct d3d_device *device = device_from_ID3DDeviceContextState(iface); + ULONG refcount = InterlockedIncrement(&state->refcount); + + TRACE("%p increasing refcount to %u.\n", state, refcount); + + if (refcount == 1) + { + ID3D11Device2_AddRef(&device->ID3D11Device2_iface); + } + + return refcount; +} + +static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface) +{ + struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface); + struct d3d_device *device = device_from_ID3DDeviceContextState(iface); + ULONG refcount = InterlockedDecrement(&state->refcount); + + TRACE("%p decreasing refcount to %u.\n", state, refcount); + + if (!refcount) + { + wined3d_private_store_cleanup(&state->private_store); + ID3D11Device2_Release(&device->ID3D11Device2_iface); + } + + return refcount; +} + +static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device) +{ + struct d3d_device *device_object = device_from_ID3DDeviceContextState(iface); + + TRACE("iface %p, device %p.\n", iface, device); + + *device = (ID3D11Device *)&device_object->ID3D11Device2_iface; + 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, +}; + +static void d3d_device_context_state_init(struct d3d_device_context_state *context, struct d3d_device *device, + REFIID emulated_interface) +{ + context->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl; + context->refcount = 1; + context->emulated_interface = *emulated_interface; + ID3D11Device2_AddRef(context->device = &device->ID3D11Device2_iface); + + wined3d_private_store_init(&context->private_store); +} + /* ID3D11DeviceContext - immediate context methods */
static inline struct d3d11_immediate_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface) @@ -2551,7 +2685,33 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers1(ID3D static void STDMETHODCALLTYPE d3d11_immediate_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface, ID3DDeviceContextState *state, ID3DDeviceContextState **prev_state) { - FIXME("iface %p, state %p, prev_state %p stub!\n", iface, state, prev_state); + static int once; + struct d3d_device_context_state *d3d_dc_state; + struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface); + + if (!once++) FIXME("iface %p, state %p, prev_state %p semi-stub!\n", iface, state, prev_state); + + if (prev_state) + { + *prev_state = NULL; + if ((d3d_dc_state = heap_alloc(sizeof(*d3d_dc_state)))) + { + d3d_device_context_state_init(d3d_dc_state, device, &device->emulated_interface); + *prev_state = &d3d_dc_state->ID3DDeviceContextState_iface; + } + } + + if (!(d3d_dc_state = impl_from_ID3DDeviceContextState(state))) + return; + + if (device->d3d11_only && + (IsEqualGUID(&d3d_dc_state->emulated_interface, &IID_ID3D10Device1) + || IsEqualGUID(&d3d_dc_state->emulated_interface, &IID_ID3D10Device))) + device->d3d11_only = FALSE; + + device->emulated_interface = d3d_dc_state->emulated_interface; + + /* FIXME: Apply device context state */ }
static void STDMETHODCALLTYPE d3d11_immediate_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view, @@ -3738,11 +3898,31 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Dev const D3D_FEATURE_LEVEL *feature_levels, UINT feature_levels_count, UINT sdk_version, REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state) { + struct d3d_device *device = impl_from_ID3D11Device2(iface); + struct d3d_device_context_state *d3d_device_context_state; + FIXME("iface %p, flags %#x, feature_levels %p, feature_level_count %u, sdk_version %u, " - "emulated_interface %s, chosen_feature_level %p, state %p stub!\n", iface, flags, feature_levels, + "emulated_interface %s, chosen_feature_level %p, state %p semi-stub!\n", iface, flags, feature_levels, feature_levels_count, sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
- return E_NOTIMPL; + if (chosen_feature_level) + *chosen_feature_level = 0; + + if (state) + { + *state = NULL; + if (!(d3d_device_context_state = heap_alloc(sizeof(*d3d_device_context_state)))) + return E_OUTOFMEMORY; + d3d_device_context_state_init(d3d_device_context_state, device, emulated_interface); + *state = &d3d_device_context_state->ID3DDeviceContextState_iface; + } + + /* FIXME: Return actual chosen feature level for the device context state */ + + if (chosen_feature_level) + *chosen_feature_level = ID3D11Device2_GetFeatureLevel(iface); + + return state ? S_OK : S_FALSE; }
static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle, @@ -6235,6 +6415,7 @@ void d3d_device_init(struct d3d_device *device, void *outer_unknown) /* COM aggregation always takes place */ device->outer_unk = outer_unknown; device->d3d11_only = FALSE; + device->emulated_interface = GUID_NULL;
d3d11_immediate_context_init(&device->immediate_context, device); ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface); diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 9fc09a5ec83..134902e000a 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -6686,7 +6686,6 @@ static void test_device_context_state(void) feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1); hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION, &IID_ID3D10Device, NULL, &context_state); -todo_wine ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr); if (FAILED(hr)) { @@ -6747,61 +6746,74 @@ todo_wine ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler); - ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) + ID3D11SamplerState_Release(tmp_sampler); if (!enable_debug_layer) ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler); - ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler); - ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler); - ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler); - ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler); tmp_sampler = (ID3D11SamplerState *)0xdeadbeef; ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler); - ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler); + if (tmp_sampler) ID3D11SamplerState_Release(tmp_sampler);
context_type = ID3D11DeviceContext1_GetType(context); ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
tmp_cb = (ID3D11Buffer *)0xdeadbeef; ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb); - ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb); + if (tmp_cb) ID3D11Buffer_Release(tmp_cb);
check_interface(device, &IID_ID3D10Device, TRUE, FALSE); check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);