Skip to content

Commit c667888

Browse files
committed
Rewrite ImGuiScene using TerraFX + Add DX12 backend
1 parent d52118b commit c667888

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+8916
-397
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "lib/ImGuiScene"]
2-
path = lib/ImGuiScene
3-
url = https://github.com/goatcorp/ImGuiScene
41
[submodule "lib/FFXIVClientStructs"]
52
path = lib/FFXIVClientStructs
63
url = https://github.com/aers/FFXIVClientStructs.git
@@ -10,3 +7,6 @@
107
[submodule "lib/TsudaKageyu-minhook"]
118
path = lib/TsudaKageyu-minhook
129
url = https://github.com/TsudaKageyu/minhook.git
10+
[submodule "lib/ImGui.NET"]
11+
path = lib/ImGui.NET
12+
url = https://github.com/goatcorp/ImGui.NET

Dalamud.CorePlugin/Dalamud.CorePlugin.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@
4040
<ProjectReference Include="..\Dalamud\Dalamud.csproj">
4141
<Private>false</Private>
4242
</ProjectReference>
43-
<ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj">
44-
<Private>false</Private>
45-
</ProjectReference>
46-
<ProjectReference Include="..\lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj">
47-
<Private>false</Private>
48-
</ProjectReference>
49-
<ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj">
43+
<ProjectReference Include="..\lib\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj">
5044
<Private>false</Private>
5145
</ProjectReference>
5246
</ItemGroup>

Dalamud.sln

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
66
ProjectSection(SolutionItems) = preProject
77
.editorconfig = .editorconfig
88
.gitignore = .gitignore
9-
targets\Dalamud.Plugin.targets = targets\Dalamud.Plugin.targets
109
targets\Dalamud.Plugin.Bootstrap.targets = targets\Dalamud.Plugin.Bootstrap.targets
10+
targets\Dalamud.Plugin.targets = targets\Dalamud.Plugin.targets
1111
EndProjectSection
1212
EndProject
1313
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "build", "build\build.csproj", "{94E5B016-02B1-459B-97D9-E783F28764B2}"
@@ -24,11 +24,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dalamud.Test", "Dalamud.Tes
2424
EndProject
2525
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interface", "Interface", "{E15BDA6D-E881-4482-94BA-BE5527E917FF}"
2626
EndProject
27-
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}"
28-
EndProject
29-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImGuiScene", "lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj", "{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}"
30-
EndProject
31-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2-CS", "lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj", "{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}"
27+
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}"
3228
EndProject
3329
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dalamud.CorePlugin", "Dalamud.CorePlugin\Dalamud.CorePlugin.csproj", "{4AFDB34A-7467-4D41-B067-53BC4101D9D0}"
3430
EndProject
@@ -38,7 +34,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFXIVClientStructs.InteropS
3834
EndProject
3935
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DalamudCrashHandler", "DalamudCrashHandler\DalamudCrashHandler.vcxproj", "{317A264C-920B-44A1-8A34-F3A6827B0705}"
4036
EndProject
41-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dalamud.Common", "Dalamud.Common\Dalamud.Common.csproj", "{F21B13D2-D7D0-4456-B70F-3F8D695064E2}"
37+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dalamud.Common", "Dalamud.Common\Dalamud.Common.csproj", "{F21B13D2-D7D0-4456-B70F-3F8D695064E2}"
4238
EndProject
4339
Global
4440
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -132,30 +128,6 @@ Global
132128
{0483026E-C6CE-4B1A-AA68-46544C08140B}.Release|x64.Build.0 = Release|x64
133129
{0483026E-C6CE-4B1A-AA68-46544C08140B}.Release|x86.ActiveCfg = Release|x64
134130
{0483026E-C6CE-4B1A-AA68-46544C08140B}.Release|x86.Build.0 = Release|x64
135-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|Any CPU.ActiveCfg = Debug|x64
136-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|Any CPU.Build.0 = Debug|x64
137-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|x64.ActiveCfg = Debug|x64
138-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|x64.Build.0 = Debug|x64
139-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|x86.ActiveCfg = Debug|x64
140-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Debug|x86.Build.0 = Debug|x64
141-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|Any CPU.ActiveCfg = Release|x64
142-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|Any CPU.Build.0 = Release|x64
143-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|x64.ActiveCfg = Release|x64
144-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|x64.Build.0 = Release|x64
145-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|x86.ActiveCfg = Release|x64
146-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A}.Release|x86.Build.0 = Release|x64
147-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|Any CPU.ActiveCfg = Debug|x64
148-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|Any CPU.Build.0 = Debug|x64
149-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|x64.ActiveCfg = Debug|x64
150-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|x64.Build.0 = Debug|x64
151-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|x86.ActiveCfg = Debug|x64
152-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Debug|x86.Build.0 = Debug|x64
153-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|Any CPU.ActiveCfg = Release|x64
154-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|Any CPU.Build.0 = Release|x64
155-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|x64.ActiveCfg = Release|x64
156-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|x64.Build.0 = Release|x64
157-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|x86.ActiveCfg = Release|x64
158-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8}.Release|x86.Build.0 = Release|x64
159131
{4AFDB34A-7467-4D41-B067-53BC4101D9D0}.Debug|Any CPU.ActiveCfg = Debug|x64
160132
{4AFDB34A-7467-4D41-B067-53BC4101D9D0}.Debug|Any CPU.Build.0 = Debug|x64
161133
{4AFDB34A-7467-4D41-B067-53BC4101D9D0}.Debug|x64.ActiveCfg = Debug|x64
@@ -222,8 +194,6 @@ Global
222194
EndGlobalSection
223195
GlobalSection(NestedProjects) = preSolution
224196
{0483026E-C6CE-4B1A-AA68-46544C08140B} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
225-
{C0E7E797-4FBF-4F46-BC57-463F3719BA7A} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
226-
{2F7FF0A8-B619-4572-86C7-71E46FE22FB8} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
227197
{C9B87BD7-AF49-41C3-91F1-D550ADEB7833} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
228198
{05AB2F46-268B-4915-806F-DDF813E2D59D} = {E15BDA6D-E881-4482-94BA-BE5527E917FF}
229199
EndGlobalSection

Dalamud/Configuration/Internal/DalamudConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ public string EffectiveLanguage
434434
/// </summary>
435435
public double UiBuilderHitch { get; set; } = 100;
436436

437+
/// <summary>
438+
/// Gets or sets a value indicating whether to use the DX12 renderer for testing purposes.
439+
/// </summary>
440+
public bool UseDx12Preview { get; set; }
441+
437442
/// <summary>
438443
/// Gets or sets the page of the plugin installer that is shown by default when opened.
439444
/// </summary>

Dalamud/Dalamud.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@
7676
<PackageReference Include="MinSharp" Version="1.0.4" />
7777
<PackageReference Include="MonoModReorg.RuntimeDetour" Version="23.1.2-prerelease.1" />
7878
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
79+
<PackageReference Include="PInvoke.Kernel32" Version="0.7.124" />
80+
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
7981
<PackageReference Include="Serilog" Version="2.11.0" />
8082
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
8183
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
8284
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
85+
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
86+
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
8387
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
8488
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
8589
<PrivateAssets>all</PrivateAssets>
@@ -90,19 +94,23 @@
9094
<PackageReference Include="System.Reactive" Version="5.0.0" />
9195
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="7.0.0" />
9296
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
97+
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.22621.2" />
9398
</ItemGroup>
9499
<ItemGroup>
95100
<ProjectReference Include="..\Dalamud.Common\Dalamud.Common.csproj" />
96101
<ProjectReference Include="..\lib\FFXIVClientStructs\FFXIVClientStructs\FFXIVClientStructs.csproj" />
97-
<ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
98-
<ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj" />
99-
<ProjectReference Include="..\lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj" />
102+
<ProjectReference Include="..\lib\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
100103
</ItemGroup>
101104

102105
<ItemGroup>
103106
<AdditionalFiles Include="..\stylecop.json" />
104107
</ItemGroup>
105108

109+
<ItemGroup>
110+
<EmbeddedResource Include="ImGuiScene\Shaders\imgui-frag.hlsl.bytes" LogicalName="imgui-frag.hlsl.bytes" />
111+
<EmbeddedResource Include="ImGuiScene\Shaders\imgui-vertex.hlsl.bytes" LogicalName="imgui-vertex.hlsl.bytes" />
112+
</ItemGroup>
113+
106114
<ItemGroup>
107115
<None Remove="licenses.txt" />
108116
<Content Include="licenses.txt">

Dalamud/DalamudAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum DalamudAsset
1919
/// <see cref="DalamudAssetPurpose.TextureFromRaw"/>: The fallback empty texture.
2020
/// </summary>
2121
[DalamudAsset(DalamudAssetPurpose.TextureFromRaw, data: new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })]
22-
[DalamudAssetRawTexture(4, 8, 4, SharpDX.DXGI.Format.BC1_UNorm)]
22+
[DalamudAssetRawTexture(4, 8, 4, TerraFX.Interop.DirectX.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM)]
2323
Empty4X4 = 1000,
2424

2525
/// <summary>

Dalamud/Game/Gui/GameGui.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using FFXIVClientStructs.FFXIV.Common.Component.BGCollision;
1616
using FFXIVClientStructs.FFXIV.Component.GUI;
1717
using ImGuiNET;
18-
using SharpDX;
1918

2019
using Vector2 = System.Numerics.Vector2;
2120
using Vector3 = System.Numerics.Vector3;
@@ -212,32 +211,28 @@ public bool ScreenToWorld(Vector2 screenPos, out Vector3 worldPos, float rayDist
212211
var matrixSingleton = this.getMatrixSingleton();
213212

214213
// Read current ViewProjectionMatrix plus game window size
215-
var viewProjectionMatrix = default(Matrix);
216-
var rawMatrix = (float*)(matrixSingleton + 0x1b4).ToPointer();
214+
var rawMatrix = (float*)(matrixSingleton + 0x1b4);
215+
var inverseViewProjectionMatrix = *(Matrix4x4*)rawMatrix;
216+
var width = *(rawMatrix + 16);
217+
var height = *(rawMatrix + 17);
217218

218-
for (var i = 0; i < 16; i++, rawMatrix++)
219-
viewProjectionMatrix[i] = *rawMatrix;
219+
if (!Matrix4x4.Invert(inverseViewProjectionMatrix, out var viewProjectionMatrix))
220+
viewProjectionMatrix = Matrix4x4.Identity;
220221

221-
var width = *rawMatrix;
222-
var height = *(rawMatrix + 1);
223-
224-
viewProjectionMatrix.Invert();
225-
226-
var localScreenPos = new SharpDX.Vector2(screenPos.X - windowPos.X, screenPos.Y - windowPos.Y);
227-
var screenPos3D = new SharpDX.Vector3
222+
var localScreenPos = new Vector2(screenPos.X - windowPos.X, screenPos.Y - windowPos.Y);
223+
var screenPos3D = new Vector3
228224
{
229225
X = (localScreenPos.X / width * 2.0f) - 1.0f,
230226
Y = -((localScreenPos.Y / height * 2.0f) - 1.0f),
231227
Z = 0,
232228
};
233229

234-
SharpDX.Vector3.TransformCoordinate(ref screenPos3D, ref viewProjectionMatrix, out var camPos);
230+
var camPos = Vector3.Transform(screenPos3D, viewProjectionMatrix);
235231

236232
screenPos3D.Z = 1;
237-
SharpDX.Vector3.TransformCoordinate(ref screenPos3D, ref viewProjectionMatrix, out var camPosOne);
233+
var camPosOne = Vector3.Transform(screenPos3D, viewProjectionMatrix);
238234

239-
var clipPos = camPosOne - camPos;
240-
clipPos.Normalize();
235+
var clipPos = Vector3.Normalize(camPosOne - camPos);
241236

242237
// This array is larger than necessary because it contains more info than we currently use
243238
var worldPosArray = default(RaycastHit);
@@ -250,7 +245,7 @@ public bool ScreenToWorld(Vector2 screenPos, out Vector3 worldPos, float rayDist
250245
0x0,
251246
};
252247

253-
var isSuccess = BGCollisionModule.Raycast2(camPos.ToSystem(), clipPos.ToSystem(), rayDistance, &worldPosArray, unknown);
248+
var isSuccess = BGCollisionModule.Raycast2(camPos, clipPos, rayDistance, &worldPosArray, unknown);
254249
worldPos = worldPosArray.Point;
255250

256251
return isSuccess;

0 commit comments

Comments
 (0)