Skip to content

Commit

Permalink
Added temp parameters for toggled render APIs (#99)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Aemony and Kaldaien authored Oct 4, 2023
1 parent 3d5eae8 commit f494a2b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 47 deletions.
11 changes: 7 additions & 4 deletions include/SpecialK/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1431,4 +1434,4 @@ extern SK_LazyGlobal <std::unordered_map <BYTE, wchar_t [32]>> virtKey
extern SK_LazyGlobal <std::unordered_map <BYTE, wchar_t [32]>> virtKeyCodeToFullyLocalizedKeyName;
extern SK_LazyGlobal <std::unordered_multimap <uint32_t, SK_KeyCommand>> SK_KeyboardMacros;

#endif /* __SK__CONFIG_H__ */
#endif /* __SK__CONFIG_H__ */
20 changes: 14 additions & 6 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
100 changes: 63 additions & 37 deletions src/control_panel/cfg_compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ( );
Expand Down Expand Up @@ -191,43 +198,62 @@ 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 ())
ImGui::SetTooltip ("Application start time and negative interactions with third-party software can be reduced by turning off APIs that are not needed...");

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));

Check failure on line 236 in src/control_panel/cfg_compatibility.cpp

View workflow job for this annotation

GitHub Actions / Build (Release, Win32)

ImGui::PushStyleColor (ImGuiCol_Text, ImColor (1.0f, .7f, .3f)); [D:\a\SpecialK\SpecialK\SpecialK.vcxproj]

Check failure on line 236 in src/control_panel/cfg_compatibility.cpp

View workflow job for this annotation

GitHub Actions / Build (Release, Win32)

^ [D:\a\SpecialK\SpecialK\SpecialK.vcxproj]

Check failure on line 236 in src/control_panel/cfg_compatibility.cpp

View workflow job for this annotation

GitHub Actions / Build (Release, x64)

ImGui::PushStyleColor (ImGuiCol_Text, ImColor (1.0f, .7f, .3f)); [D:\a\SpecialK\SpecialK\SpecialK.vcxproj]

Check failure on line 236 in src/control_panel/cfg_compatibility.cpp

View workflow job for this annotation

GitHub Actions / Build (Release, x64)

^ [D:\a\SpecialK\SpecialK\SpecialK.vcxproj]
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 ();
}

Expand Down

0 comments on commit f494a2b

Please sign in to comment.