add back DXGISwapChain::on_present hook as default for now

This commit is contained in:
Soreepeong 2024-07-25 18:05:21 +09:00
parent bd170ee74a
commit ebee2f151e
7 changed files with 379 additions and 172 deletions

View file

@ -11,9 +11,9 @@ namespace Dalamud.Interface.Internal;
/// <summary>
/// This class manages interaction with the ImGui interface.
/// </summary>
internal partial class InterfaceManager
internal unsafe partial class InterfaceManager
{
private unsafe void ReShadeAddonInterfaceOnDestroySwapChain(ref ReShadeAddonInterface.ApiObject swapChain)
private void ReShadeAddonInterfaceOnDestroySwapChain(ref ReShadeAddonInterface.ApiObject swapChain)
{
var swapChainNative = swapChain.GetNative<IDXGISwapChain>();
if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative)
@ -22,7 +22,7 @@ internal partial class InterfaceManager
this.scene?.OnPreResize();
}
private unsafe void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeAddonInterface.ApiObject swapChain)
private void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeAddonInterface.ApiObject swapChain)
{
var swapChainNative = swapChain.GetNative<IDXGISwapChain>();
if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative)
@ -42,52 +42,25 @@ internal partial class InterfaceManager
ReadOnlySpan<RECT> destRect,
ReadOnlySpan<RECT> dirtyRects)
{
var swapChainNative = swapChain.GetNative();
var swapChainNative = swapChain.GetNative<IDXGISwapChain>();
if (this.scene == null)
this.InitScene(swapChainNative);
if (this.scene?.SwapChain.NativePointer != swapChainNative)
return;
Debug.Assert(this.dalamudAtlas is not null, "this.dalamudAtlas is not null");
if (!this.dalamudAtlas!.HasBuiltAtlas)
{
if (this.dalamudAtlas.BuildTask.Exception != null)
{
// TODO: Can we do something more user-friendly here? Unload instead?
Log.Error(this.dalamudAtlas.BuildTask.Exception, "Failed to initialize Dalamud base fonts");
Util.Fatal("Failed to initialize Dalamud base fonts.\nPlease report this error.", "Dalamud");
}
return;
}
this.CumulativePresentCalls++;
this.IsMainThreadInPresent = true;
while (this.runBeforeImGuiRender.TryDequeue(out var action))
action.InvokeSafely();
RenderImGui(this.scene!);
this.PostImGuiRender();
this.IsMainThreadInPresent = false;
if (this.RenderDalamudCheckAndInitialize(swapChainNative) is { } activeScene)
this.RenderDalamudDraw(activeScene);
}
private nint AsReShadeAddonResizeBuffersDetour(
nint swapChain,
private int AsReShadeAddonDxgiSwapChainResizeBuffersDetour(
IDXGISwapChain* swapChain,
uint bufferCount,
uint width,
uint height,
uint newFormat,
DXGI_FORMAT newFormat,
uint swapChainFlags)
{
// Hooked vtbl instead of registering ReShade event. This check is correct.
if (!SwapChainHelper.IsGameDeviceSwapChain(swapChain))
return this.resizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
return this.dxgiSwapChainResizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
this.ResizeBuffers?.InvokeSafely();
return this.resizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
return this.dxgiSwapChainResizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
}
}