Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite ImGuiScene using TerraFX + Add DX12 backend #1542

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/ImGuiScene"]
path = lib/ImGuiScene
url = https://github.com/goatcorp/ImGuiScene
[submodule "lib/FFXIVClientStructs"]
path = lib/FFXIVClientStructs
url = https://github.com/aers/FFXIVClientStructs
Expand All @@ -10,3 +7,6 @@
[submodule "lib/TsudaKageyu-minhook"]
path = lib/TsudaKageyu-minhook
url = https://github.com/TsudaKageyu/minhook.git
[submodule "lib/ImGui.NET"]
path = lib/ImGui.NET
url = https://github.com/goatcorp/ImGui.NET
1 change: 1 addition & 0 deletions Dalamud.Boot/DalamudStartInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void from_json(const nlohmann::json& json, DalamudStartInfo& config) {
config.NoLoadThirdPartyPlugins = json.value("NoLoadThirdPartyPlugins", config.NoLoadThirdPartyPlugins);

config.BootLogPath = json.value("BootLogPath", config.BootLogPath);
config.BootDebugDirectX = json.value("BootDebugDirectX", config.BootDebugDirectX);
config.BootShowConsole = json.value("BootShowConsole", config.BootShowConsole);
config.BootDisableFallbackConsole = json.value("BootDisableFallbackConsole", config.BootDisableFallbackConsole);
config.BootWaitMessageBox = json.value("BootWaitMessageBox", config.BootWaitMessageBox);
Expand Down
1 change: 1 addition & 0 deletions Dalamud.Boot/DalamudStartInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct DalamudStartInfo {
bool NoLoadThirdPartyPlugins;

std::string BootLogPath;
bool BootDebugDirectX = false;
bool BootShowConsole = false;
bool BootDisableFallbackConsole = false;
WaitMessageboxFlags BootWaitMessageBox = WaitMessageboxFlags::None;
Expand Down
68 changes: 68 additions & 0 deletions Dalamud.Boot/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "pch.h"

#include <d3d11.h>
#include <d3d12.h>
#include <dxgi1_3.h>

#include "DalamudStartInfo.h"
#include "hooks.h"
#include "logging.h"
#include "utils.h"
#include "veh.h"
Expand Down Expand Up @@ -98,6 +103,69 @@ HRESULT WINAPI InitializeImpl(LPVOID lpParam, HANDLE hMainThreadContinue) {
logging::W("Skipping fixes, as MinHook has failed to load.");
}

if (g_startInfo.BootDebugDirectX) {
logging::I("Enabling DirectX Debugging.");

const auto hD3D11 = GetModuleHandleW(L"d3d11.dll");
const auto hDXGI = GetModuleHandleW(L"dxgi.dll");
const auto pfnD3D11CreateDevice = static_cast<decltype(&D3D11CreateDevice)>(
hD3D11 ? static_cast<void*>(GetProcAddress(hD3D11, "D3D11CreateDevice")) : nullptr);
if (pfnD3D11CreateDevice) {
static hooks::direct_hook<decltype(D3D11CreateDevice)> s_hookD3D11CreateDevice(
"d3d11.dll!D3D11CreateDevice",
pfnD3D11CreateDevice);
s_hookD3D11CreateDevice.set_detour([](
IDXGIAdapter* pAdapter,
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
const D3D_FEATURE_LEVEL* pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
ID3D11Device** ppDevice,
D3D_FEATURE_LEVEL* pFeatureLevel,
ID3D11DeviceContext** ppImmediateContext
) -> HRESULT {
return s_hookD3D11CreateDevice.call_original(
pAdapter,
DriverType,
Software,
Flags | D3D11_CREATE_DEVICE_DEBUG,
pFeatureLevels,
FeatureLevels,
SDKVersion,
ppDevice,
pFeatureLevel,
ppImmediateContext);
});
} else {
logging::W("Could not find d3d11!D3D11CreateDevice.");
}

const auto pfnCreateDXGIFactory = static_cast<decltype(&CreateDXGIFactory)>(
hDXGI ? static_cast<void*>(GetProcAddress(hDXGI, "CreateDXGIFactory")) : nullptr);
const auto pfnCreateDXGIFactory1 = static_cast<decltype(&CreateDXGIFactory1)>(
hDXGI ? static_cast<void*>(GetProcAddress(hDXGI, "CreateDXGIFactory1")) : nullptr);
static const auto pfnCreateDXGIFactory2 = static_cast<decltype(&CreateDXGIFactory2)>(
hDXGI ? static_cast<void*>(GetProcAddress(hDXGI, "CreateDXGIFactory2")) : nullptr);
if (pfnCreateDXGIFactory2) {
static hooks::direct_hook<decltype(CreateDXGIFactory)> s_hookCreateDXGIFactory(
"dxgi.dll!CreateDXGIFactory",
pfnCreateDXGIFactory);
static hooks::direct_hook<decltype(CreateDXGIFactory1)> s_hookCreateDXGIFactory1(
"dxgi.dll!CreateDXGIFactory1",
pfnCreateDXGIFactory1);
s_hookCreateDXGIFactory.set_detour([](REFIID riid, _COM_Outptr_ void **ppFactory) -> HRESULT {
return pfnCreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, riid, ppFactory);
});
s_hookCreateDXGIFactory1.set_detour([](REFIID riid, _COM_Outptr_ void **ppFactory) -> HRESULT {
return pfnCreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, riid, ppFactory);
});
} else {
logging::W("Could not find dxgi!CreateDXGIFactory2.");
}
}

if (g_startInfo.BootWaitDebugger) {
logging::I("Waiting for debugger to attach...");
while (!IsDebuggerPresent())
Expand Down
5 changes: 5 additions & 0 deletions Dalamud.Common/DalamudStartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public DalamudStartInfo()
/// </summary>
public string? BootLogPath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable D3D11 and DXGI debugging if possible.
/// </summary>
public bool BootDebugDirectX { get; set; }

/// <summary>
/// Gets or sets a value indicating whether a Boot console should be shown.
/// </summary>
Expand Down
8 changes: 1 addition & 7 deletions Dalamud.CorePlugin/Dalamud.CorePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@
<ProjectReference Include="..\Dalamud\Dalamud.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj">
<ProjectReference Include="..\lib\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Dalamud.Injector/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static int Main(int argc, IntPtr argvPtr)

startInfo = ExtractAndInitializeStartInfoFromArguments(startInfo, args);
// Remove already handled arguments
args.Remove("--debug-directx");
args.Remove("--console");
args.Remove("--msgbox1");
args.Remove("--msgbox2");
Expand Down Expand Up @@ -396,6 +397,7 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam
startInfo.LogName ??= string.Empty;

// Set boot defaults
startInfo.BootDebugDirectX = args.Contains("--debug-directx");
startInfo.BootShowConsole = args.Contains("--console");
startInfo.BootEnableEtw = args.Contains("--etw");
startInfo.BootLogPath = GetLogPath(startInfo.LogPath, "dalamud.boot", startInfo.LogName);
Expand Down
8 changes: 1 addition & 7 deletions Dalamud.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dalamud.Test", "Dalamud.Tes
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interface", "Interface", "{E15BDA6D-E881-4482-94BA-BE5527E917FF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImGui.NET-472", "lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj", "{0483026E-C6CE-4B1A-AA68-46544C08140B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImGuiScene", "lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj", "{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2-CS", "lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj", "{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImGui.NET-472", "lib\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj", "{0483026E-C6CE-4B1A-AA68-46544C08140B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dalamud.CorePlugin", "Dalamud.CorePlugin\Dalamud.CorePlugin.csproj", "{4AFDB34A-7467-4D41-B067-53BC4101D9D0}"
EndProject
Expand Down Expand Up @@ -127,8 +123,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0483026E-C6CE-4B1A-AA68-46544C08140B} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
{C9B87BD7-AF49-41C3-91F1-D550ADEB7833} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
{3620414C-7DFC-423E-929F-310E19F5D930} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
{A6AA1C3F-9470-4922-9D3F-D4549657AB22} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
Expand Down
5 changes: 5 additions & 0 deletions Dalamud/Configuration/Internal/DalamudConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ public string EffectiveLanguage
/// <summary>Gets or sets a value indicating whether to track texture allocation by plugins.</summary>
public bool UseTexturePluginTracking { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to use the DX12 renderer for testing purposes.
/// </summary>
public bool UseDx12Preview { get; set; }

/// <summary>
/// Gets or sets the page of the plugin installer that is shown by default when opened.
/// </summary>
Expand Down
14 changes: 11 additions & 3 deletions Dalamud/Dalamud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Platforms>x64;AnyCPU</Platforms>
<LangVersion>12.0</LangVersion>
<EnableWindowsTargeting>True</EnableWindowsTargeting>
<EnableWindowsTargeting>True</EnableWindowsTargeting>
</PropertyGroup>

<PropertyGroup Label="Feature">
Expand Down Expand Up @@ -79,10 +80,14 @@
</PackageReference>
<PackageReference Include="MinSharp" Version="1.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.124" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -98,15 +103,18 @@
<ItemGroup>
<ProjectReference Include="..\Dalamud.Common\Dalamud.Common.csproj" />
<ProjectReference Include="..\lib\FFXIVClientStructs\FFXIVClientStructs\FFXIVClientStructs.csproj" />
<ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
<ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj" />
<ProjectReference Include="..\lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj" />
<ProjectReference Include="..\lib\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="ImGuiScene\Shaders\imgui-frag.hlsl.bytes" LogicalName="imgui-frag.hlsl.bytes" />
<EmbeddedResource Include="ImGuiScene\Shaders\imgui-vertex.hlsl.bytes" LogicalName="imgui-vertex.hlsl.bytes" />
</ItemGroup>

<ItemGroup>
<None Remove="licenses.txt" />
<Content Include="licenses.txt">
Expand Down
Loading
Loading