From f494a2bd75c41daccb9af8053e91fb2cfbc79fe0 Mon Sep 17 00:00:00 2001 From: Aemony <10578344+Aemony@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:25:53 +0200 Subject: [PATCH] Added temp parameters for toggled render APIs (#99) * Added temp parameters for toggled render APIs This allows enabling and disabling render APIs in the compatibility section without affecting the current behaviour of Special K. Co-authored-by: Andon M. Coleman --- include/SpecialK/config.h | 11 ++- src/config.cpp | 20 +++-- src/control_panel/cfg_compatibility.cpp | 100 +++++++++++++++--------- 3 files changed, 84 insertions(+), 47 deletions(-) diff --git a/include/SpecialK/config.h b/include/SpecialK/config.h index 8b6c353b7..bdb6fd292 100644 --- a/include/SpecialK/config.h +++ b/include/SpecialK/config.h @@ -1002,19 +1002,22 @@ struct sk_config_t bool hook = true; bool translated = false; int native_dxvk = SK_NoPreference; + bool hook_next = true; } d3d9, d3d9ex; struct dxgi_s { struct d3d11or12_s{ - bool hook = true; + bool hook = true; + bool hook_next = true; } d3d12, d3d11; } dxgi; struct khronos_s { - bool hook = true; - bool translate = true; + bool hook = true; + bool translate = true; + bool hook_next = true; } Vulkan, OpenGL; @@ -1431,4 +1434,4 @@ extern SK_LazyGlobal > virtKey extern SK_LazyGlobal > virtKeyCodeToFullyLocalizedKeyName; extern SK_LazyGlobal > SK_KeyboardMacros; -#endif /* __SK__CONFIG_H__ */ \ No newline at end of file +#endif /* __SK__CONFIG_H__ */ diff --git a/src/config.cpp b/src/config.cpp index dfe6671f1..69db8691c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -3209,6 +3209,14 @@ auto DeclKeybind = #ifdef _M_AMD64 apis.Vulkan.hook->load (config.apis.Vulkan.hook); #endif + + // Variables used to indicate changes for next launch + config.apis.d3d9.hook_next = config.apis.d3d9.hook; + config.apis.d3d9ex.hook_next = config.apis.d3d9ex.hook; + config.apis.dxgi.d3d11.hook_next = config.apis.dxgi.d3d11.hook; + config.apis.dxgi.d3d12.hook_next = config.apis.dxgi.d3d12.hook; + config.apis.OpenGL.hook_next = config.apis.OpenGL.hook; + config.apis.Vulkan.hook_next = config.apis.Vulkan.hook; init = TRUE; } @@ -4891,14 +4899,14 @@ SK_SaveConfig ( std::wstring name, apis.ddraw.hook->store (config.apis.ddraw.hook); apis.d3d8.hook->store (config.apis.d3d8.hook); #endif - apis.d3d9.hook->store (config.apis.d3d9.hook); - apis.d3d9ex.hook->store (config.apis.d3d9ex.hook); + apis.d3d9.hook->store (config.apis.d3d9.hook_next); + apis.d3d9ex.hook->store (config.apis.d3d9ex.hook_next); apis.dxvk9.enable->store (config.apis.d3d9.native_dxvk); - apis.d3d11.hook->store (config.apis.dxgi.d3d11.hook); - apis.d3d12.hook->store (config.apis.dxgi.d3d12.hook); - apis.OpenGL.hook->store (config.apis.OpenGL.hook); + apis.d3d11.hook->store (config.apis.dxgi.d3d11.hook_next); + apis.d3d12.hook->store (config.apis.dxgi.d3d12.hook_next); + apis.OpenGL.hook->store (config.apis.OpenGL.hook_next); #ifdef _M_AMD64 - apis.Vulkan.hook->store (config.apis.Vulkan.hook); + apis.Vulkan.hook->store (config.apis.Vulkan.hook_next); #endif nvidia.api.disable_hdr->store (config.apis.NvAPI.disable_hdr); diff --git a/src/control_panel/cfg_compatibility.cpp b/src/control_panel/cfg_compatibility.cpp index 019cd8695..9fdea7263 100644 --- a/src/control_panel/cfg_compatibility.cpp +++ b/src/control_panel/cfg_compatibility.cpp @@ -59,45 +59,52 @@ SK::ControlPanel::Compatibility::Draw (void) switch (api) { case SK_RenderAPI::D3D9Ex: - config.apis.d3d9ex.hook = true; // Fallthrough, D3D9Ex - case SK_RenderAPI::D3D9: // implies D3D9! - config.apis.d3d9.hook = true; + config.apis.d3d9ex.hook_next = true; // Fallthrough, D3D9Ex + case SK_RenderAPI::D3D9: // implies D3D9! + config.apis.d3d9.hook_next = true; break; case SK_RenderAPI::D3D12: - config.apis.dxgi.d3d12.hook = true; + config.apis.dxgi.d3d12.hook_next = true; case SK_RenderAPI::D3D11: - config.apis.dxgi.d3d11.hook = true; // Shared logic, both are needed + config.apis.dxgi.d3d11.hook_next = true; // Shared logic, both are needed break; #ifdef _M_IX86 case SK_RenderAPI::DDrawOn12: - config.apis.dxgi.d3d12.hook = true; + config.apis.dxgi.d3d12.hook = true; case SK_RenderAPI::DDrawOn11: - config.apis.dxgi.d3d11.hook = true; // Shared logic, both are needed - config.apis.ddraw.hook = true; + config.apis.dxgi.d3d11.hook = true; // Shared logic, both are needed + config.apis.ddraw.hook = true; break; case SK_RenderAPI::D3D8On12: - config.apis.dxgi.d3d12.hook = true; + config.apis.dxgi.d3d12.hook = true; case SK_RenderAPI::D3D8On11: - config.apis.dxgi.d3d11.hook = true; // Shared logic, both are needed - config.apis.d3d8.hook = true; + config.apis.dxgi.d3d11.hook = true; // Shared logic, both are needed + config.apis.d3d8.hook = true; break; #endif case SK_RenderAPI::OpenGL: - config.apis.OpenGL.hook = true; + config.apis.OpenGL.hook_next = true; break; #ifdef _M_AMD64 case SK_RenderAPI::Vulkan: - config.apis.Vulkan.hook = true; + config.apis.Vulkan.hook_next = true; break; #endif default: break; } + + if (SK_GL_OnD3D11) + { + config.apis.dxgi.d3d11.hook_next = true; + config.apis.OpenGL.hook_next = true; + config.apis.OpenGL.translate = true; + } }; using Tooltip_pfn = void (*)(void); @@ -130,23 +137,23 @@ SK::ControlPanel::Compatibility::Draw (void) }; #ifdef _M_AMD64 - constexpr float num_lines = 4.0f; // Basic set of APIs + constexpr float num_lines = 4.5f; // Basic set of APIs #else - constexpr float num_lines = 5.0f; // + DirectDraw / Direct3D 8 + constexpr float num_lines = 5.5f; // + DirectDraw / Direct3D 8 #endif ImGui::PushStyleVar (ImGuiStyleVar_ChildRounding, 10.0f); - ImGui::BeginChild ("", ImVec2 (font.size * 39.0f, font.size_multiline * num_lines * 1.1f), true, ImGuiWindowFlags_NavFlattened); + ImGui::BeginChild ("", ImVec2 (font.size * 39.0f, font.size_multiline * num_lines * 1.1f), true, ImGuiWindowFlags_NavFlattened | ImGuiWindowFlags_NoScrollWithMouse); ImGui::Columns ( 2 ); - ImGui_CheckboxEx ("Direct3D 9", &config.apis.d3d9.hook); - ImGui_CheckboxEx ("Direct3D 9Ex", &config.apis.d3d9ex.hook, config.apis.d3d9.hook); + ImGui_CheckboxEx ("Direct3D 9", &config.apis.d3d9.hook_next); + ImGui_CheckboxEx ("Direct3D 9Ex", &config.apis.d3d9ex.hook_next, config.apis.d3d9.hook_next); ImGui::NextColumn ( ); - ImGui_CheckboxEx ("Direct3D 11", &config.apis.dxgi.d3d11.hook); - ImGui_CheckboxEx ("Direct3D 12", &config.apis.dxgi.d3d12.hook, config.apis.dxgi.d3d11.hook); + ImGui_CheckboxEx ("Direct3D 11", &config.apis.dxgi.d3d11.hook_next); + ImGui_CheckboxEx ("Direct3D 12", &config.apis.dxgi.d3d12.hook_next, config.apis.dxgi.d3d11.hook_next); ImGui::Columns ( 1 ); ImGui::Separator ( ); @@ -191,32 +198,25 @@ SK::ControlPanel::Compatibility::Draw (void) ImGui::Columns ( 2 ); - ImGui::Checkbox ("OpenGL ", &config.apis.OpenGL.hook); ImGui::SameLine (); + ImGui::Checkbox ("OpenGL ", &config.apis.OpenGL.hook_next); ImGui::SameLine (); #ifdef _M_AMD64 - ImGui::Checkbox ("Vulkan ", &config.apis.Vulkan.hook); + ImGui::Checkbox ("Vulkan ", &config.apis.Vulkan.hook_next); #endif ImGui::NextColumn ( ); + // The active API will be re-enabled immediately if (ImGui::Button (" Disable All But the Active API ")) { - config.apis.d3d9ex.hook = false; config.apis.d3d9.hook = false; - config.apis.dxgi.d3d11.hook = false; config.apis.dxgi.d3d12.hook = false; - config.apis.OpenGL.hook = false; + config.apis.d3d9ex.hook_next = false; config.apis.d3d9.hook_next = false; + config.apis.dxgi.d3d11.hook_next = false; config.apis.dxgi.d3d12.hook_next = false; + config.apis.OpenGL.hook_next = false; #ifdef _M_AMD64 - config.apis.Vulkan.hook = false; + config.apis.Vulkan.hook_next = false; #else - config.apis.d3d8.hook = false; config.apis.ddraw.hook = false; + config.apis.d3d8.hook = false; config.apis.ddraw.hook = false; #endif - // The active API will be re-enabled immediately - - // ... except for Indirect K, these presentation redirects need extra attention - if (SK_GL_OnD3D11) - { // TODO: Add an actual way of opting-in/out of OpenGL-IK to control panel - config.apis.dxgi.d3d11.hook = true; - config.apis.OpenGL.hook = true; - config.apis.OpenGL.translate = true; - } + EnableActiveAPI (render_api); } if (ImGui::IsItemHovered ()) @@ -224,10 +224,36 @@ SK::ControlPanel::Compatibility::Draw (void) ImGui::Columns ( 1 ); + // Show a warning to the user about the possible consequences if the current active render API is being disabled + if ((render_api == SK_RenderAPI::D3D9Ex && !config.apis.d3d9ex.hook_next ) || + (render_api == SK_RenderAPI::D3D9 && !config.apis.d3d9.hook_next ) || + (render_api == SK_RenderAPI::D3D11 && !config.apis.dxgi.d3d11.hook_next ) || + (render_api == SK_RenderAPI::D3D12 && !config.apis.dxgi.d3d12.hook_next ) || + (render_api == SK_RenderAPI::OpenGL && !config.apis.OpenGL.hook_next ) || + (render_api == SK_RenderAPI::Vulkan && !config.apis.Vulkan.hook_next ) || + ( SK_GL_OnD3D11 && !config.apis.OpenGL.hook_next )) + { + ImGui::PushStyleColor (ImGuiCol_Text, ImColor (1.0f, .7f, .3f)); + ImGui::BulletText ("The current configuration may prevent Special K from working properly!"); + ImGui::PopStyleColor (); + + if (ImGui::IsItemHovered ()) + { + if (SK_GL_OnD3D11 && !config.apis.OpenGL.hook_next) + ImGui::SetTooltip ("OpenGL-IK is currently being used, but OpenGL has been disabled for future launches!\n" + "This may prevent Special K from working properly on the next launch."); + else if (SK_GL_OnD3D11 && !config.apis.dxgi.d3d11.hook_next) + ImGui::SetTooltip ("OpenGL-IK is currently being used, but Direct3D 11 has been disabled for future launches!\n" + "This may cause Special K to fall back on OpenGL on the next launch."); + else + ImGui::SetTooltip ("The render API that is currently being used by the game has been disabled!\n" + "This may prevent Special K from working properly on the next launch."); + } + } + ImGui::EndChild ( ); ImGui::PopStyleVar ( ); - EnableActiveAPI (render_api); ImGui::TreePop (); }