1- // The loader resolves each export to the System32 dxgi.dll, so Luma doesn't need its own stubs.
2- // "dxgi.X" would resolve to Luma itself, hence the full path.
3- #define LUMA_DXGI_EXPORT (name, ordinal ) \
4- __pragma (comment(linker, " /EXPORT:" #name " =\\\\ .\\ GLOBALROOT\\ SystemRoot\\ System32\\ dxgi.dll." #name " ,@" #ordinal))
1+ #include < Windows.h>
2+
3+ #include < dxgi1_6.h>
4+
5+ #include " System/Modules.hpp"
6+
7+ // Most exports are forwarders the loader resolves to the system dxgi.dll, so Luma doesn't need its own stubs.
8+ // "dxgi.X" would resolve to Luma itself, hence the full path. 32 bit processes get SysWOW64, the loader doesn't redirect NT paths.
9+ // Wine can't open that path: the exports Wine's or DXVK's dxgi.dll have are Luma's own functions, calling the system dxgi.dll.
10+ // The others only exist on Windows.
11+ // On 32 bit, a pragma's export doesn't find a decorated symbol ("_Name@ArgumentsSize") by itself.
12+ #ifdef _WIN64
13+ #define LUMA_DXGI_PATH " \\\\ .\\ GLOBALROOT\\ SystemRoot\\ System32\\ dxgi.dll."
14+ #define LUMA_DXGI_FUNCTION (name, ordinal, arguments_size ) __pragma(comment(linker, " /EXPORT:" #name " ,@" #ordinal))
15+ #else
16+ #define LUMA_DXGI_PATH " \\\\ .\\ GLOBALROOT\\ SystemRoot\\ SysWOW64\\ dxgi.dll."
17+ #define LUMA_DXGI_FUNCTION (name, ordinal, arguments_size ) __pragma(comment(linker, " /EXPORT:" #name " =_" #name " @" #arguments_size " ,@" #ordinal))
18+ #endif
19+ #define LUMA_DXGI_EXPORT (name, ordinal ) __pragma(comment(linker, " /EXPORT:" #name " =" LUMA_DXGI_PATH #name " ,@" #ordinal))
520
621// The names and ordinals of the System32 dxgi.dll ("dumpbin /exports C:\Windows\System32\dxgi.dll")
722LUMA_DXGI_EXPORT (ApplyCompatResolutionQuirking, 1 )
@@ -13,14 +28,86 @@ LUMA_DXGI_EXPORT(PIXEndCapture, 6)
1328LUMA_DXGI_EXPORT (PIXGetCaptureState, 7 )
1429LUMA_DXGI_EXPORT (SetAppCompatStringPointer, 8 )
1530LUMA_DXGI_EXPORT (UpdateHMDEmulationStatus, 9 )
16- LUMA_DXGI_EXPORT (CreateDXGIFactory, 10 )
17- LUMA_DXGI_EXPORT (CreateDXGIFactory1, 11 )
18- LUMA_DXGI_EXPORT (CreateDXGIFactory2, 12 )
19- LUMA_DXGI_EXPORT (DXGID3D10CreateDevice, 13 )
31+ LUMA_DXGI_FUNCTION (CreateDXGIFactory, 10 , 8 )
32+ LUMA_DXGI_FUNCTION (CreateDXGIFactory1, 11 , 8 )
33+ LUMA_DXGI_FUNCTION (CreateDXGIFactory2, 12 , 12 )
34+ LUMA_DXGI_FUNCTION (DXGID3D10CreateDevice, 13 , 28 )
2035LUMA_DXGI_EXPORT (DXGID3D10CreateLayeredDevice, 14 )
2136LUMA_DXGI_EXPORT (DXGID3D10GetLayeredDeviceSize, 15 )
22- LUMA_DXGI_EXPORT (DXGID3D10RegisterLayers, 16 )
23- LUMA_DXGI_EXPORT (DXGIDeclareAdapterRemovalSupport, 17 )
37+ LUMA_DXGI_FUNCTION (DXGID3D10RegisterLayers, 16 , 8 )
38+ LUMA_DXGI_FUNCTION (DXGIDeclareAdapterRemovalSupport, 17 , 0 )
2439LUMA_DXGI_EXPORT (DXGIDisableVBlankVirtualization, 18 )
25- LUMA_DXGI_EXPORT (DXGIGetDebugInterface1, 19 )
40+ LUMA_DXGI_FUNCTION (DXGIGetDebugInterface1, 19 , 12 )
2641LUMA_DXGI_EXPORT (DXGIReportAdapterConfiguration, 20 )
42+
43+ namespace
44+ {
45+ // Loads the system dxgi.dll if it isn't loaded yet. Not GetProcAddress (see FindExport).
46+ void * FindSystemExport (const char * name)
47+ {
48+ HMODULE module = Luma::System::Modules::FindSystemModule (L" dxgi.dll" );
49+ if (!module )
50+ module = LoadLibraryW (Luma::System::Modules::SystemPath (L" dxgi.dll" ).c_str ());
51+ if (!module || module == Luma::System::Modules::GetSelf ())
52+ return nullptr ;
53+ return Luma::System::Modules::FindExport (module , name);
54+ }
55+ } // namespace
56+
57+ extern " C" HRESULT WINAPI CreateDXGIFactory (REFIID riid, void ** factory)
58+ {
59+ const auto function = reinterpret_cast <decltype (&CreateDXGIFactory)>(FindSystemExport (" CreateDXGIFactory" ));
60+ if (!function)
61+ return E_FAIL ;
62+ return function (riid, factory);
63+ }
64+
65+ extern " C" HRESULT WINAPI CreateDXGIFactory1 (REFIID riid, void ** factory)
66+ {
67+ const auto function = reinterpret_cast <decltype (&CreateDXGIFactory1)>(FindSystemExport (" CreateDXGIFactory1" ));
68+ if (!function)
69+ return E_FAIL ;
70+ return function (riid, factory);
71+ }
72+
73+ extern " C" HRESULT WINAPI CreateDXGIFactory2 (UINT flags, REFIID riid, void ** factory)
74+ {
75+ const auto function = reinterpret_cast <decltype (&CreateDXGIFactory2)>(FindSystemExport (" CreateDXGIFactory2" ));
76+ if (!function)
77+ return E_FAIL ;
78+ return function (flags, riid, factory);
79+ }
80+
81+ // Not in the Windows SDK: Wine's own d3d11.dll and d3d10core.dll import them (Wine without DXVK). The signatures are Wine's and
82+ // ReShade's.
83+ extern " C" HRESULT WINAPI DXGID3D10CreateDevice (HMODULE module , IDXGIFactory* factory, IDXGIAdapter* adapter, UINT flags, const void * feature_levels, UINT feature_level_count, void ** device)
84+ {
85+ const auto function = reinterpret_cast <decltype (&DXGID3D10CreateDevice)>(FindSystemExport (" DXGID3D10CreateDevice" ));
86+ if (!function)
87+ return E_FAIL ;
88+ return function (module , factory, adapter, flags, feature_levels, feature_level_count, device);
89+ }
90+
91+ extern " C" HRESULT WINAPI DXGID3D10RegisterLayers (const void * layers, UINT layer_count)
92+ {
93+ const auto function = reinterpret_cast <decltype (&DXGID3D10RegisterLayers)>(FindSystemExport (" DXGID3D10RegisterLayers" ));
94+ if (!function)
95+ return E_FAIL ;
96+ return function (layers, layer_count);
97+ }
98+
99+ extern " C" HRESULT WINAPI DXGIDeclareAdapterRemovalSupport ()
100+ {
101+ const auto function = reinterpret_cast <decltype (&DXGIDeclareAdapterRemovalSupport)>(FindSystemExport (" DXGIDeclareAdapterRemovalSupport" ));
102+ if (!function)
103+ return E_FAIL ;
104+ return function ();
105+ }
106+
107+ extern " C" HRESULT WINAPI DXGIGetDebugInterface1 (UINT flags, REFIID riid, void ** debug)
108+ {
109+ const auto function = reinterpret_cast <decltype (&DXGIGetDebugInterface1)>(FindSystemExport (" DXGIGetDebugInterface1" ));
110+ if (!function)
111+ return E_FAIL ;
112+ return function (flags, riid, debug);
113+ }
0 commit comments