Needed by Orbiter Space Flight Simulator and Train Simulator Classic.
-- v13: d3d9/tests: Add Direct3DCreate9On12() tests. d3d9: Implement Direct3DCreate9On12(). include: Add d3d9on12.idl file.
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- include/Makefile.in | 1 + include/d3d9on12.idl | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 include/d3d9on12.idl
diff --git a/include/Makefile.in b/include/Makefile.in index d52afd06926..3f81dd6bf0e 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -139,6 +139,7 @@ SOURCES = \ d3d8types.h \ d3d9.h \ d3d9caps.h \ + d3d9on12.idl \ d3d9types.h \ d3dcaps.h \ d3dcommon.idl \ diff --git a/include/d3d9on12.idl b/include/d3d9on12.idl new file mode 100644 index 00000000000..9eec402a711 --- /dev/null +++ b/include/d3d9on12.idl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2024 Mohamad Al-Jaf + * + * 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 + */ + +cpp_quote("#include <d3d9.h>") +import "d3d12.idl"; + +interface IDirect3D9; +interface IDirect3DResource9; + +#define MAX_D3D9ON12_QUEUES 2 + +typedef struct D3D9ON12_ARGS +{ + BOOL Enable9On12; + IUnknown *pD3D12Device; + IUnknown *ppD3D12Queues[MAX_D3D9ON12_QUEUES]; + UINT NumQueues; + UINT NodeMask; +} D3D9ON12_ARGS; + +typedef IDirect3D9 * (__stdcall *PFN_Direct3DCreate9On12)(UINT sdk_version, D3D9ON12_ARGS *override_list, UINT override_entries); +IDirect3D9 * __stdcall Direct3DCreate9On12(UINT,D3D9ON12_ARGS *,UINT); + +typedef struct IDirect3DDevice9On12 *LPDIRECT3DDEVICE9ON12, *PDIRECT3DDEVICE9ON12; + +[ + local, + uuid(e7fda234-b589-4049-940d-8878977531c8) +] +interface IDirect3DDevice9On12 : IUnknown +{ + HRESULT GetD3D12Device (REFIID riid, void **out); + HRESULT UnwrapUnderlyingResource (IDirect3DResource9 *resource, ID3D12CommandQueue *queue, REFIID riid, void **out); + HRESULT ReturnUnderlyingResource (IDirect3DResource9 *resource, UINT num_sync, UINT64 *signal_values, ID3D12Fence **fences); +}
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by Orbiter Space Flight Simulator and Train Simulator Classic. --- dlls/d3d9/d3d9.spec | 1 + dlls/d3d9/d3d9_main.c | 22 +++++++ dlls/d3d9/d3d9_private.h | 6 ++ dlls/d3d9/device.c | 123 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+)
diff --git a/dlls/d3d9/d3d9.spec b/dlls/d3d9/d3d9.spec index a33cba51e77..11ad26b64c6 100644 --- a/dlls/d3d9/d3d9.spec +++ b/dlls/d3d9/d3d9.spec @@ -12,3 +12,4 @@ @ stdcall DebugSetMute() @ stdcall Direct3DCreate9(long) @ stdcall Direct3DCreate9Ex(long ptr) +@ stdcall Direct3DCreate9On12(long ptr long) diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c index 5bdf05409aa..c393ca738ea 100644 --- a/dlls/d3d9/d3d9_main.c +++ b/dlls/d3d9/d3d9_main.c @@ -75,6 +75,28 @@ HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT sdk_version, IDirect3D9E return D3D_OK; }
+IDirect3D9 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate9On12(UINT sdk_version, D3D9ON12_ARGS *d3d9on12_args, UINT override_entries) +{ + struct d3d9 *object; + + TRACE("sdk_version %#x, d3d9on12_args %p, override_entries %#x.\n", sdk_version, d3d9on12_args, override_entries); + + if (!(object = calloc(1, sizeof(*object)))) + return NULL; + + if (!d3d9_init(object, TRUE)) + { + WARN("Failed to initialize d3d9.\n"); + free(object); + return NULL; + } + + d3d9on12_init(object, d3d9on12_args, override_entries); + + TRACE("Created d3d9 object %p.\n", object); + return (IDirect3D9 *)&object->IDirect3D9Ex_iface; +} + /* The callback is called on any error encountered during validation, including * improper IDirect3DShaderValidator9 method calls. * - "file" and "line" are passed through directly from Instruction(). "line" diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index a5f059c5aef..279c2bfbea6 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -34,6 +34,7 @@ #include "wine/debug.h"
#include "d3d9.h" +#include "d3d9on12.h" #include "wine/wined3d.h"
#define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256 @@ -65,11 +66,15 @@ struct d3d9 struct wined3d_output **wined3d_outputs; unsigned int wined3d_output_count; BOOL extended; + BOOL d3d9on12; + struct D3D9ON12_ARGS *d3d9on12_args; + UINT override_entries; };
void d3d9_caps_from_wined3dcaps(const struct d3d9 *d3d9, unsigned int adapter_ordinal, D3DCAPS9 *caps, const struct wined3d_caps *wined3d_caps); BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended); +void d3d9on12_init(struct d3d9 *d3d9, D3D9ON12_ARGS *d3d9on12_args, UINT override_entries);
struct fvf_declaration { @@ -87,6 +92,7 @@ enum d3d9_device_state struct d3d9_device { IDirect3DDevice9Ex IDirect3DDevice9Ex_iface; + IDirect3DDevice9On12 IDirect3DDevice9On12_iface; struct wined3d_device_parent device_parent; LONG refcount; struct wined3d_device *wined3d_device; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 408dace48ad..86415509467 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -593,6 +593,111 @@ static void device_reset_viewport_state(struct d3d9_device *device) wined3d_stateblock_set_scissor_rect(device->state, &rect); }
+static inline struct d3d9_device *impl_from_IDirect3DDevice9On12( IDirect3DDevice9On12 *iface ) +{ + return CONTAINING_RECORD( iface, struct d3d9_device, IDirect3DDevice9On12_iface ); +} + +static HRESULT WINAPI d3d9on12_QueryInterface( IDirect3DDevice9On12 *iface, REFIID iid, void **out ) +{ + struct d3d9_device *device = impl_from_IDirect3DDevice9On12(iface); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IDirect3DDevice9On12 )) + { + IDirect3DDevice9On12_AddRef( &device->IDirect3DDevice9On12_iface ); + *out = &device->IDirect3DDevice9On12_iface; + return S_OK; + } + + WARN( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid) ); + + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI d3d9on12_AddRef( IDirect3DDevice9On12 *iface ) +{ + struct d3d9_device *device = impl_from_IDirect3DDevice9On12(iface); + ULONG refcount = InterlockedIncrement(&device->refcount); + TRACE( "%p increasing refcount to %lu.\n", iface, refcount ); + return refcount; +} + +static ULONG WINAPI d3d9on12_Release( IDirect3DDevice9On12 *iface ) +{ + struct d3d9_device *device = impl_from_IDirect3DDevice9On12(iface); + ULONG refcount = InterlockedDecrement(&device->refcount); + + TRACE( "%p decreasing refcount to %lu.\n", iface, refcount ); + + if (!refcount) + { + if (device->d3d_parent->d3d9on12_args) + { + if (device->d3d_parent->d3d9on12_args->pD3D12Device) + ID3D12Device_Release( (ID3D12Device *)device->d3d_parent->d3d9on12_args->pD3D12Device ); + + for ( int i = 0; i < device->d3d_parent->d3d9on12_args->NumQueues; i++ ) + { + if (device->d3d_parent->d3d9on12_args->ppD3D12Queues[i]) + ID3D12CommandQueue_Release( (ID3D12CommandQueue *)device->d3d_parent->d3d9on12_args->ppD3D12Queues[i] ); + } + + free( device->d3d_parent->d3d9on12_args ); + } + } + + return refcount; +} + +static HRESULT WINAPI d3d9on12_GetD3D12Device( IDirect3DDevice9On12 *iface, REFIID iid, void **out ) +{ + FIXME( "iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out ); + + if (!out) return E_INVALIDARG; + + *out = NULL; + return E_NOINTERFACE; +} + +static HRESULT WINAPI d3d9on12_UnwrapUnderlyingResource( IDirect3DDevice9On12 *iface, IDirect3DResource9 *resource, ID3D12CommandQueue *queue, REFIID iid, void **out ) +{ + FIXME( "iface %p, resource %p, queue %p, iid %s, out %p stub!\n", iface, resource, queue, debugstr_guid(iid), out ); + return E_NOTIMPL; +} + +static HRESULT WINAPI d3d9on12_ReturnUnderlyingResource( IDirect3DDevice9On12 *iface, IDirect3DResource9 *resource, UINT num_sync, UINT64 *signal_values, ID3D12Fence **fences ) +{ + FIXME( "iface %p, resource %p, num_sync %#x, signal_values %p, fences %p stub!\n", iface, resource, num_sync, signal_values, fences ); + return E_NOTIMPL; +} + +static const struct IDirect3DDevice9On12Vtbl d3d9on12_vtbl = +{ + /* IUnknown */ + d3d9on12_QueryInterface, + d3d9on12_AddRef, + d3d9on12_Release, + /* IDirect3DDevice9On12 */ + d3d9on12_GetD3D12Device, + d3d9on12_UnwrapUnderlyingResource, + d3d9on12_ReturnUnderlyingResource, +}; + +void d3d9on12_init( struct d3d9 *d3d9, D3D9ON12_ARGS *d3d9on12_args, UINT override_entries ) +{ + if (!override_entries || !d3d9on12_args || !d3d9on12_args->Enable9On12) return; + + FIXME( "ignoring d3d9on12_args %p\n", d3d9on12_args ); + + d3d9->d3d9on12 = TRUE; + d3d9->d3d9on12_args = NULL; + d3d9->override_entries = override_entries; +} + static HRESULT WINAPI d3d9_device_QueryInterface(IDirect3DDevice9Ex *iface, REFIID riid, void **out) { TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out); @@ -623,6 +728,24 @@ static HRESULT WINAPI d3d9_device_QueryInterface(IDirect3DDevice9Ex *iface, REFI return S_OK; }
+ if (IsEqualGUID(riid, &IID_IDirect3DDevice9On12)) + { + struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); + + if (!device->d3d_parent->d3d9on12) + { + WARN("IDirect3D9 instance wasn't created with D3D9On12 enabled, returning E_NOINTERFACE.\n"); + *out = NULL; + return E_NOINTERFACE; + } + + FIXME("pD3D12Device value is not being checked if it matches the d3d9 device\n"); + + device->IDirect3DDevice9On12_iface.lpVtbl = &d3d9on12_vtbl; + IDirect3DDevice9On12_QueryInterface(&device->IDirect3DDevice9On12_iface, riid, out); + return S_OK; + } + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
*out = NULL;
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/d3d9/tests/device.c | 275 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+)
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 53dc9ee55ed..4c90b0effa2 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -25,6 +25,19 @@ #define COBJMACROS #include <d3d9.h> #include "utils.h" +#include <initguid.h> +#include <d3d9on12.h> +#include <dxgi1_4.h> + +static HMODULE d3d9_handle = 0; +static HMODULE d3d12_handle = 0; +static HMODULE dxgi_handle = 0; + +static IDirect3D9 * (WINAPI *pDirect3DCreate9On12)(UINT sdk_version, D3D9ON12_ARGS *override_list, UINT override_entries); +static HRESULT (WINAPI *pCreateDXGIFactory2)(UINT flags, REFIID iid, void **factory); +static HRESULT (WINAPI *pD3D12CreateDevice)(IUnknown *adapter, D3D_FEATURE_LEVEL feature_level, REFIID iid, void **device); + +DEFINE_GUID(IID_IDeadbeef, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xee, 0xee, 0xee, 0xee, 0xef);
struct vec3 { @@ -15031,6 +15044,267 @@ static void test_window_position(void) IDirect3D9_Release(d3d); }
+static BOOL init_d3d9on12_modules(void) +{ + d3d9_handle = LoadLibraryA("d3d9.dll"); + if (!d3d9_handle) + { + skip("Could not load d3d9.dll\n"); + return FALSE; + } + dxgi_handle = LoadLibraryA("dxgi.dll"); + if (!dxgi_handle) + { + skip("Could not load dxgi.dll\n"); + return FALSE; + } + d3d12_handle = LoadLibraryA("d3d12.dll"); + if (!d3d12_handle) + { + skip("Could not load d3d12.dll\n"); + return FALSE; + } + + pDirect3DCreate9On12 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9On12"); + if (!pDirect3DCreate9On12) + { + win_skip("Direct3DCreate9On12 is not supported, skipping d3d9on12 tests\n"); + return FALSE; + } + pCreateDXGIFactory2 = (void *)GetProcAddress(dxgi_handle, "CreateDXGIFactory2"); + if (!pCreateDXGIFactory2) + { + win_skip("CreateDXGIFactory2 is not supported, skipping d3d9on12 tests\n"); + return FALSE; + } + pD3D12CreateDevice = (void *)GetProcAddress(d3d12_handle, "D3D12CreateDevice"); + if (!pD3D12CreateDevice) + { + win_skip("D3D12CreateDevice is not supported, skipping d3d9on12 tests\n"); + return FALSE; + } + + return TRUE; +} + +#define create_d3d9on12_device(out_d3d9, window, override_list, override_entries, out_device, success) \ + create_d3d9on12_device_(__LINE__, out_d3d9, window, override_list, override_entries, out_device, success) +static HRESULT create_d3d9on12_device_(unsigned int line, IDirect3D9 **out_d3d9, HWND window, D3D9ON12_ARGS *override_list, + UINT override_entries, IDirect3DDevice9 **out_device, BOOLEAN success) +{ + IDirect3DDevice9On12 *d3d9on12 = (void *)0xdeadbeef; + IDirect3DDevice9 *device = (void *)0xdeadbeef; + IDirect3D9 *d3d9 = (void *)0xdeadbeef; + D3DPRESENT_PARAMETERS present_parameters; + HRESULT hr; + + memset(&present_parameters, 0, sizeof(present_parameters)); + present_parameters.Windowed = TRUE; + present_parameters.hDeviceWindow = window; + present_parameters.SwapEffect = D3DSWAPEFFECT_COPY; + present_parameters.BackBufferWidth = 640; + present_parameters.BackBufferHeight = 480; + present_parameters.EnableAutoDepthStencil = FALSE; + present_parameters.AutoDepthStencilFormat = D3DFMT_D16; + + SetLastError(0xdeadbeef); + d3d9 = pDirect3DCreate9On12(D3D_SDK_VERSION, override_list, override_entries); + ok_(__FILE__, line)(d3d9 != NULL, "got NULL d3d9 object\n"); + + hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok_(__FILE__, line)(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr); + ok_(__FILE__, line)(d3d9on12 == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9on12); + + hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, + D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device); + + *out_d3d9 = d3d9; + *out_device = device; + + return hr; +} + +static void test_d3d9on12(void) +{ + IDirect3DDevice9On12 *d3d9on12_2 = (void *)0xdeadbeef; + IDirect3DDevice9On12 *d3d9on12 = (void *)0xdeadbeef; + IDirect3DDevice9 *device = (void *)0xdeadbeef; + IDirect3D9 *d3d9 = (void *)0xdeadbeef; + IDXGIAdapter *adapter = (void *)0xdeadbeef; + IDXGIFactory4 *factory = (void *)0xdeadbeef; + ID3D12Device *d3d12device = (void *)0xdeadbeef; + ID3D12Device *d3d12device_2 = (void *)0xdeadbeef; + D3D9ON12_ARGS override_list; + UINT override_entries = 0; + ULONG ref; + HRESULT hr; + HWND window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, + 0, 0, 640, 480, 0, 0, 0, 0); + + if(!init_d3d9on12_modules()) + { + skip("Failed to load d3d9on12 modules, skipping d3d9on12 tests.\n"); + return; + } + + SetLastError(0xdeadbeef); + d3d9 = pDirect3DCreate9On12(D3D_SDK_VERSION, NULL, override_entries); + ok(d3d9 != NULL, "got NULL d3d9 object\n"); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, FALSE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr); + ok(d3d9on12 == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9on12); + IDirect3DDevice9_Release(device); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + override_list.Enable9On12 = TRUE; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, FALSE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr); + ok(d3d9on12 == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9on12); + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Got refcount %lu.\n", ref); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + override_entries = 1; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, FALSE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr); + ok(d3d9on12 == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9on12); + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Got refcount %lu.\n", ref); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + override_list.Enable9On12 = TRUE; + override_list.NodeMask = 0xdeadbeef; + override_entries = 1; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9On12_QueryInterface(d3d9on12, &IID_IDirect3DDevice9On12, (void **)&d3d9on12_2); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + ref = IDirect3DDevice9On12_Release(d3d9on12_2); + todo_wine + ok(ref == 1, "Got refcount %lu.\n", ref); + ref = IDirect3DDevice9On12_Release(d3d9on12); + todo_wine + ok(ref == 0, "Got refcount %lu.\n", ref); + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Got refcount %lu.\n", ref); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + override_list.Enable9On12 = TRUE; + override_entries = 1; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9On12_GetD3D12Device(d3d9on12, NULL, NULL); + ok(hr == E_INVALIDARG, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9On12_GetD3D12Device(d3d9on12, &IID_IDeadbeef, NULL); + ok(hr == E_INVALIDARG, "Got hr %#lx.\n", hr); + IDirect3DDevice9On12_Release(d3d9on12); + IDirect3DDevice9_Release(device); + IDirect3D9_Release(d3d9); + + memset(&override_list, 0, sizeof(override_list)); + override_list.Enable9On12 = TRUE; + override_entries = 0xdeadbeef; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + ref = IDirect3DDevice9On12_Release(d3d9on12); + todo_wine + ok(ref == 0, "Got refcount %lu.\n", ref); + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Got refcount %lu.\n", ref); + IDirect3D9_Release(d3d9); + + hr = pCreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDXGIFactory4_EnumAdapters(factory, 0, &adapter); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + IDXGIFactory4_Release(factory); + + hr = pD3D12CreateDevice((IUnknown *)adapter, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&d3d12device); + IDXGIAdapter_Release(adapter); + + memset(&override_list, 0, sizeof(override_list)); + override_list.Enable9On12 = TRUE; + override_list.pD3D12Device = (IUnknown *)d3d12device; + override_entries = 1; + d3d9on12 = (void *)0xdeadbeef; + hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE); + if (FAILED(hr)) + { + skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n"); + goto out; + } + + hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + hr = IDirect3DDevice9On12_GetD3D12Device(d3d9on12, &IID_ID3D12Device, (void **)&d3d12device_2); + todo_wine + ok(hr == S_OK, "Got hr %#lx.\n", hr); + todo_wine + ok(override_list.pD3D12Device == (IUnknown *)d3d12device_2, "GetD3D12Device returned device %p, expected %p\n", d3d12device_2, override_list.pD3D12Device); + d3d12device_2 = (void *)0xdeadbeef; + hr = IDirect3DDevice9On12_GetD3D12Device(d3d9on12, &IID_IDeadbeef, (void **)&d3d12device_2); + ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr); + ok(d3d12device_2 == NULL, "GetD3D12Device returned device %p, expected NULL\n", d3d12device_2); + + ref = IDirect3DDevice9On12_Release(d3d9on12); + todo_wine + ok(ref == 0, "Got refcount %lu.\n", ref); + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Got refcount %lu.\n", ref); +out: + IDirect3D9_Release(d3d9); + DestroyWindow(window); +} + START_TEST(device) { HMODULE d3d9_handle = GetModuleHandleA("d3d9.dll"); @@ -15167,6 +15441,7 @@ START_TEST(device) test_creation_parameters(); test_cursor_clipping(); test_window_position(); + test_d3d9on12();
UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL)); }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=146807
Your paranoid android.
=== w10pro64 (32 bit report) ===
d3d9: device.c:4192: Test failed: Expected message 0x46 for window 0x1, but didn't receive it, i=0. device.c:4236: Test failed: Expected message 0x7e for window 0, but didn't receive it, i=0. device.c:4240: Test failed: The device window is active, i=0. device.c:4245: Test failed: Got unexpected hr 0x88760869. device.c:4249: Test failed: Got unexpected screen size 800x600. device.c:4281: Test failed: Expected message 0x46 for window 0, but didn't receive it, i=0. device.c:4290: Test failed: Got unexpected screen size 800x600. device.c:4307: Test failed: Expected message 0x7e for window 0, but didn't receive it, i=0. device.c:4316: Test failed: Got unexpected width 640. device.c:4317: Test failed: Got unexpected height 480. device.c:4398: Test failed: Expected message 0x7e for window 0x1, but didn't receive it, i=0. device.c:4408: Test failed: Expected IsIconic 1, got 0, i=0. device.c:4412: Test failed: Got unexpected hr 0. device.c:4420: Test failed: Expected message 0x46 for window 0x1, but didn't receive it, i=0. device.c:4458: Test failed: Expected message 0x1c for window 0x1, but didn't receive it, i=0. device.c:4468: Test failed: Got unexpected hr 0.
=== debian11b (64 bit WoW report) ===
comctl32: button.c:801: Test failed: [0] expected uItemState 16, got 80 button.c:801: Test failed: [0] expected uItemState 16, got 80 button.c:810: Test failed: [0] expected uItemState 0, got 64 button.c:810: Test failed: [0] expected uItemState 0, got 64 button.c:819: Test failed: [0] expected uItemState 0, got 64 button.c:819: Test failed: [0] expected uItemState 0, got 64 button.c:834: Test failed: expected state 0, got 0200 button.c:838: Test failed: [0] expected uItemState 1, got 65 button.c:838: Test failed: [0] expected uItemState 1, got 65 button.c:847: Test failed: expected state 0x0004, got 0204 button.c:854: Test failed: [0] expected uItemState 0, got 64 button.c:854: Test failed: [0] expected uItemState 0, got 64 button.c:859: Test failed: BM_SETSTATE/FALSE on a button: the msg sequence is not complete: expected 0000 - actual 0084 button.c:863: Test failed: expected state 0, got 0200 button.c:898: Test failed: [0] expected uItemState 0, got 64 button.c:898: Test failed: [0] expected uItemState 0, got 64 button.c:898: Test failed: [0] expected uItemState 0, got 64 button.c:898: Test failed: [0] expected uItemState 0, got 64
kernel32: comm.c:1574: Test failed: AbortWaitCts hComPortEvent failed comm.c:1586: Test failed: Unexpected time 1001, expected around 500
On Thu May 30 00:17:58 2024 +0000, Elizabeth Figura wrote:
The flag is no problem, but the arguments won't be passed into the
d3d9 device. d3d9_device holds a pointer to the d3d object. Again, this is exactly the way things work for d3d9ex. You should be able to follow *exactly* the same model, and refer to that when confused.
Where would you store D3D9ON12_ARGS *override_list and UINT
override_entries? UINT sdk_version doesn't seem to be used anyway so that's not a problem. In the d3d9 object. I'm also inclined to recommend a better name than "override_list". Yes, the Microsoft headers use it, but the Microsoft headers make a lot of poor choices.
What would you do in Direct3DCreate9On12?
You can implement a separate refcount without needing a separate
object (just use a separate refcount field), although it's not clear we need to care.
This doesn't make sense to me. Are there examples of objects with more
than one refcount? Yes, but I don't think it's worth implementing unless we find an application that needs it.
D3D9on12 is only created if the right arguments are passed to
Direct3DCreate9On12. And it can be released independently of IDirect3DDevice9 so it should have its own refcount. Also, wouldn't it be better from a memory management perspective to handle it as a separate object? QueryInterface() is supposed to be symmetric. That means that neither "object" can be destroyed until the other is, which means that they're really just one object. From a memory management perspective, that implies one allocation.
I hope this latest revision is what you had in mind. I also changed `override_list` to `d3d9on12_args`.
Elizabeth Figura (@zfigura) commented about include/d3d9on12.idl:
+{
- BOOL Enable9On12;
- IUnknown *pD3D12Device;
- IUnknown *ppD3D12Queues[MAX_D3D9ON12_QUEUES];
- UINT NumQueues;
- UINT NodeMask;
+} D3D9ON12_ARGS;
+typedef IDirect3D9 * (__stdcall *PFN_Direct3DCreate9On12)(UINT sdk_version, D3D9ON12_ARGS *override_list, UINT override_entries); +IDirect3D9 * __stdcall Direct3DCreate9On12(UINT,D3D9ON12_ARGS *,UINT);
+typedef struct IDirect3DDevice9On12 *LPDIRECT3DDEVICE9ON12, *PDIRECT3DDEVICE9ON12;
+[
- local,
- uuid(e7fda234-b589-4049-940d-8878977531c8)
I think this needs [object] as well.
Elizabeth Figura (@zfigura) commented about include/d3d9on12.idl:
+} D3D9ON12_ARGS;
+typedef IDirect3D9 * (__stdcall *PFN_Direct3DCreate9On12)(UINT sdk_version, D3D9ON12_ARGS *override_list, UINT override_entries); +IDirect3D9 * __stdcall Direct3DCreate9On12(UINT,D3D9ON12_ARGS *,UINT);
+typedef struct IDirect3DDevice9On12 *LPDIRECT3DDEVICE9ON12, *PDIRECT3DDEVICE9ON12;
+[
- local,
- uuid(e7fda234-b589-4049-940d-8878977531c8)
+] +interface IDirect3DDevice9On12 : IUnknown +{
- HRESULT GetD3D12Device (REFIID riid, void **out);
- HRESULT UnwrapUnderlyingResource (IDirect3DResource9 *resource, ID3D12CommandQueue *queue, REFIID riid, void **out);
- HRESULT ReturnUnderlyingResource (IDirect3DResource9 *resource, UINT num_sync, UINT64 *signal_values, ID3D12Fence **fences);
As long as we're here, can you please remove the space between the function name and opening parenthesis?
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- IDirect3DDevice9On12 *d3d9on12_2 = (void *)0xdeadbeef;
- IDirect3DDevice9On12 *d3d9on12 = (void *)0xdeadbeef;
- IDirect3DDevice9 *device = (void *)0xdeadbeef;
- IDirect3D9 *d3d9 = (void *)0xdeadbeef;
- IDXGIAdapter *adapter = (void *)0xdeadbeef;
- IDXGIFactory4 *factory = (void *)0xdeadbeef;
- ID3D12Device *d3d12device = (void *)0xdeadbeef;
- ID3D12Device *d3d12device_2 = (void *)0xdeadbeef;
- D3D9ON12_ARGS override_list;
- UINT override_entries = 0;
- ULONG ref;
- HRESULT hr;
- HWND window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION,
0, 0, 640, 480, 0, 0, 0, 0);
- if(!init_d3d9on12_modules())
Needs a space here.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- return hr;
+}
+static void test_d3d9on12(void) +{
- IDirect3DDevice9On12 *d3d9on12_2 = (void *)0xdeadbeef;
- IDirect3DDevice9On12 *d3d9on12 = (void *)0xdeadbeef;
- IDirect3DDevice9 *device = (void *)0xdeadbeef;
- IDirect3D9 *d3d9 = (void *)0xdeadbeef;
- IDXGIAdapter *adapter = (void *)0xdeadbeef;
- IDXGIFactory4 *factory = (void *)0xdeadbeef;
- ID3D12Device *d3d12device = (void *)0xdeadbeef;
- ID3D12Device *d3d12device_2 = (void *)0xdeadbeef;
- D3D9ON12_ARGS override_list;
- UINT override_entries = 0;
I don't think this needs to be a variable, does it?
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
+static void test_d3d9on12(void) +{
- IDirect3DDevice9On12 *d3d9on12_2 = (void *)0xdeadbeef;
- IDirect3DDevice9On12 *d3d9on12 = (void *)0xdeadbeef;
- IDirect3DDevice9 *device = (void *)0xdeadbeef;
- IDirect3D9 *d3d9 = (void *)0xdeadbeef;
- IDXGIAdapter *adapter = (void *)0xdeadbeef;
- IDXGIFactory4 *factory = (void *)0xdeadbeef;
- ID3D12Device *d3d12device = (void *)0xdeadbeef;
- ID3D12Device *d3d12device_2 = (void *)0xdeadbeef;
- D3D9ON12_ARGS override_list;
- UINT override_entries = 0;
- ULONG ref;
- HRESULT hr;
- HWND window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION,
0, 0, 640, 480, 0, 0, 0, 0);
You can use create_window() here.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- IDirect3DDevice9 *device = (void *)0xdeadbeef;
- IDirect3D9 *d3d9 = (void *)0xdeadbeef;
- IDXGIAdapter *adapter = (void *)0xdeadbeef;
- IDXGIFactory4 *factory = (void *)0xdeadbeef;
- ID3D12Device *d3d12device = (void *)0xdeadbeef;
- ID3D12Device *d3d12device_2 = (void *)0xdeadbeef;
- D3D9ON12_ARGS override_list;
- UINT override_entries = 0;
- ULONG ref;
- HRESULT hr;
- HWND window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION,
0, 0, 640, 480, 0, 0, 0, 0);
- if(!init_d3d9on12_modules())
- {
skip("Failed to load d3d9on12 modules, skipping d3d9on12 tests.\n");
This should be win_skip.
You also leak the window here.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- todo_wine
- ok(ref == 0, "Got refcount %lu.\n", ref);
- ref = IDirect3DDevice9_Release(device);
- ok(ref == 0, "Got refcount %lu.\n", ref);
- IDirect3D9_Release(d3d9);
- memset(&override_list, 0, sizeof(override_list));
- override_list.Enable9On12 = TRUE;
- override_entries = 1;
- d3d9on12 = (void *)0xdeadbeef;
- hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE);
- if (FAILED(hr))
- {
skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n");
goto out;
- }
Do we need this check more than once? I think it's fair to assume that if it worked the first time it'll continue to work.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12);
- ok(hr == S_OK, "Got hr %#lx.\n", hr);
- ref = IDirect3DDevice9On12_Release(d3d9on12);
- todo_wine
- ok(ref == 0, "Got refcount %lu.\n", ref);
- ref = IDirect3DDevice9_Release(device);
- ok(ref == 0, "Got refcount %lu.\n", ref);
- IDirect3D9_Release(d3d9);
- hr = pCreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory);
- ok(hr == S_OK, "Got hr %#lx.\n", hr);
- hr = IDXGIFactory4_EnumAdapters(factory, 0, &adapter);
- ok(hr == S_OK, "Got hr %#lx.\n", hr);
- IDXGIFactory4_Release(factory);
- hr = pD3D12CreateDevice((IUnknown *)adapter, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&d3d12device);
This is missing an ok(). We also never release this device.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/tests/device.c:
- d3d9on12 = (void *)0xdeadbeef;
- hr = create_d3d9on12_device(&d3d9, window, &override_list, override_entries, &device, TRUE);
- if (FAILED(hr))
- {
skip("Failed to create a regular Direct3DDevice9, skipping d3d9on12 tests\n");
goto out;
- }
- hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9On12, (void **)&d3d9on12);
- ok(hr == S_OK, "Got hr %#lx.\n", hr);
- hr = IDirect3DDevice9On12_GetD3D12Device(d3d9on12, &IID_ID3D12Device, (void **)&d3d12device_2);
- todo_wine
- ok(hr == S_OK, "Got hr %#lx.\n", hr);
- todo_wine
- ok(override_list.pD3D12Device == (IUnknown *)d3d12device_2, "GetD3D12Device returned device %p, expected %p\n", d3d12device_2, override_list.pD3D12Device);
Should GetD3D12Device() reference the returned device? If so we should release it.
The documentation doesn't say, but you can probably test by making sure to release the device at the end of the function, and checking if its refcount reaches zero.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/d3d9_private.h:
struct wined3d_output **wined3d_outputs; unsigned int wined3d_output_count; BOOL extended;
- BOOL d3d9on12;
- struct D3D9ON12_ARGS *d3d9on12_args;
- UINT override_entries;
Let's not store these here as long as they're unused.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/device.c:
free( device->d3d_parent->d3d9on12_args );
}
- }
- return refcount;
+}
+static HRESULT WINAPI d3d9on12_GetD3D12Device( IDirect3DDevice9On12 *iface, REFIID iid, void **out ) +{
- FIXME( "iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out );
- if (!out) return E_INVALIDARG;
- *out = NULL;
- return E_NOINTERFACE;
+}
Let's follow the existing d3d coding style, please. No spaces inside of parentheses; always put if bodies on a new line. See https://wiki.winehq.org/Wine_Developer's_Guide/Coding_Practice.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/device.c:
- return CONTAINING_RECORD( iface, struct d3d9_device, IDirect3DDevice9On12_iface );
+}
+static HRESULT WINAPI d3d9on12_QueryInterface( IDirect3DDevice9On12 *iface, REFIID iid, void **out ) +{
- struct d3d9_device *device = impl_from_IDirect3DDevice9On12(iface);
- TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out );
- if (IsEqualGUID( iid, &IID_IUnknown ) ||
IsEqualGUID( iid, &IID_IDirect3DDevice9On12 ))
- {
IDirect3DDevice9On12_AddRef( &device->IDirect3DDevice9On12_iface );
*out = &device->IDirect3DDevice9On12_iface;
return S_OK;
- }
Again, QueryInterface() is symmetric. You should be forwarding to d3d9_device_QueryInterface(). Same for AddRef() and Release().
Elizabeth Figura (@zfigura) commented about dlls/d3d9/d3d9_main.c:
+{
- struct d3d9 *object;
- TRACE("sdk_version %#x, d3d9on12_args %p, override_entries %#x.\n", sdk_version, d3d9on12_args, override_entries);
- if (!(object = calloc(1, sizeof(*object))))
return NULL;
- if (!d3d9_init(object, TRUE))
- {
WARN("Failed to initialize d3d9.\n");
free(object);
return NULL;
- }
- d3d9on12_init(object, d3d9on12_args, override_entries);
No need for a separate function here just to set the d3d9on12 field to TRUE; instead please pass a separate argument to d3d9_init().
Elizabeth Figura (@zfigura) commented about dlls/d3d9/device.c:
}
- if (IsEqualGUID(riid, &IID_IDirect3DDevice9On12))
- {
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
if (!device->d3d_parent->d3d9on12)
{
WARN("IDirect3D9 instance wasn't created with D3D9On12 enabled, returning E_NOINTERFACE.\n");
*out = NULL;
return E_NOINTERFACE;
}
FIXME("pD3D12Device value is not being checked if it matches the d3d9 device\n");
device->IDirect3DDevice9On12_iface.lpVtbl = &d3d9on12_vtbl;
Please initialize it on creation, like all other vtbls.
Elizabeth Figura (@zfigura) commented about dlls/d3d9/device.c:
return S_OK; }
- if (IsEqualGUID(riid, &IID_IDirect3DDevice9On12))
- {
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
if (!device->d3d_parent->d3d9on12)
{
WARN("IDirect3D9 instance wasn't created with D3D9On12 enabled, returning E_NOINTERFACE.\n");
*out = NULL;
return E_NOINTERFACE;
}
FIXME("pD3D12Device value is not being checked if it matches the d3d9 device\n");
What does this mean?
Elizabeth Figura (@zfigura) commented about dlls/d3d9/device.c:
- if (IsEqualGUID(riid, &IID_IDirect3DDevice9On12))
- {
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
if (!device->d3d_parent->d3d9on12)
{
WARN("IDirect3D9 instance wasn't created with D3D9On12 enabled, returning E_NOINTERFACE.\n");
*out = NULL;
return E_NOINTERFACE;
}
FIXME("pD3D12Device value is not being checked if it matches the d3d9 device\n");
device->IDirect3DDevice9On12_iface.lpVtbl = &d3d9on12_vtbl;
IDirect3DDevice9On12_QueryInterface(&device->IDirect3DDevice9On12_iface, riid, out);
And you can just directly return &device->IDirect3DDevice9On12_iface here.
On Wed May 29 07:07:22 2024 +0000, Mohamad Al-Jaf wrote:
@Mystral Do you have any input on this matter? Should the FIXME stay or be removed?
Ah, sorry, somehow I didn't notice these replies until now :/
I'm not sure I recall what I meant at the time :rolling_eyes: I suspect I was trying to say that this currently doesn't check the "override list" at all, so we might want a FIXME calling that out.