Skip to content

Commit

Permalink
add an option to use the host memory instead of buffer cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SamoZ256 committed Nov 3, 2024
1 parent ab41de4 commit 03d4e86
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Cafe/CafeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ void InfoLog_PrintActiveSettings()
{
cemuLog_log(LogType::Force, "Async compile: {}", GetConfig().async_compile.GetValue() ? "true" : "false");
cemuLog_log(LogType::Force, "Fast math: {}", GetConfig().fast_math.GetValue() ? "true" : "false");
cemuLog_log(LogType::Force, "Use host memory for cache: {}", g_current_game_profile->UseHostMemForCache() ? "true" : "false");
if (!GetConfig().vk_accurate_barriers.GetValue())
cemuLog_log(LogType::Force, "Accurate barriers are disabled!");
}
Expand Down
14 changes: 9 additions & 5 deletions src/Cafe/GameProfile/GameProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool gameProfile_loadIntegerOption(IniParser& iniParser, const char* optionName,
{
cemuLog_log(LogType::Force, "Value '{}' is out of range for option '{}' in game profile", *option_value, optionName);
return false;
}
}
}

template<typename T>
Expand Down Expand Up @@ -224,8 +224,9 @@ bool GameProfile::Load(uint64_t title_id)
gameProfile_loadIntegerOption(&iniParser, "graphics_api", &graphicsApi, -1, 0, 1);
if (graphicsApi.value != -1)
m_graphics_api = (GraphicAPI)graphicsApi.value;

gameProfile_loadEnumOption(iniParser, "accurateShaderMul", m_accurateShaderMul);
gameProfile_loadBooleanOption2(iniParser, "useHostMemForCache", m_useHostMemForCache);

// legacy support
auto option_precompiledShaders = iniParser.FindOption("precompiledShaders");
Expand Down Expand Up @@ -277,7 +278,7 @@ bool GameProfile::Load(uint64_t title_id)
void GameProfile::Save(uint64_t title_id)
{
auto gameProfileDir = ActiveSettings::GetConfigPath("gameProfiles");
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec))
if (std::error_code ex_ec; !fs::exists(gameProfileDir, ex_ec))
fs::create_directories(gameProfileDir, ex_ec);
auto gameProfilePath = gameProfileDir / fmt::format("{:016x}.ini", title_id);
FileStream* fs = FileStream::createFile2(gameProfilePath);
Expand Down Expand Up @@ -308,6 +309,7 @@ void GameProfile::Save(uint64_t title_id)

fs->writeLine("[Graphics]");
WRITE_ENTRY(accurateShaderMul);
WRITE_ENTRY(useHostMemForCache);
WRITE_OPTIONAL_ENTRY(precompiledShaders);
WRITE_OPTIONAL_ENTRY(graphics_api);
fs->writeLine("");
Expand Down Expand Up @@ -337,6 +339,7 @@ void GameProfile::ResetOptional()

// graphic settings
m_accurateShaderMul = AccurateShaderMulOption::True;
m_useHostMemForCache = false;
// cpu settings
m_threadQuantum = kThreadQuantumDefault;
m_cpuMode.reset(); // CPUModeOption::kSingleCoreRecompiler;
Expand All @@ -354,9 +357,10 @@ void GameProfile::Reset()
// general settings
m_loadSharedLibraries = true;
m_startWithPadView = false;

// graphic settings
m_accurateShaderMul = AccurateShaderMulOption::True;
m_useHostMemForCache = false;
m_precompiledShaders = PrecompiledShaderOption::Auto;
// cpu settings
m_threadQuantum = kThreadQuantumDefault;
Expand All @@ -366,4 +370,4 @@ void GameProfile::Reset()
// controller settings
for (auto& profile : m_controllerProfile)
profile.reset();
}
}
2 changes: 2 additions & 0 deletions src/Cafe/GameProfile/GameProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GameProfile

[[nodiscard]] const std::optional<GraphicAPI>& GetGraphicsAPI() const { return m_graphics_api; }
[[nodiscard]] const AccurateShaderMulOption& GetAccurateShaderMul() const { return m_accurateShaderMul; }
[[nodiscard]] bool UseHostMemForCache() const { return m_useHostMemForCache; }
[[nodiscard]] const std::optional<PrecompiledShaderOption>& GetPrecompiledShadersState() const { return m_precompiledShaders; }

[[nodiscard]] uint32 GetThreadQuantum() const { return m_threadQuantum; }
Expand All @@ -54,6 +55,7 @@ class GameProfile
// graphic settings
std::optional<GraphicAPI> m_graphics_api{};
AccurateShaderMulOption m_accurateShaderMul = AccurateShaderMulOption::True;
bool m_useHostMemForCache = false;
std::optional<PrecompiledShaderOption> m_precompiledShaders{};
// cpu settings
uint32 m_threadQuantum = kThreadQuantumDefault; // values: 20000 45000 60000 80000 100000
Expand Down
6 changes: 3 additions & 3 deletions src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalVoidVertexPipeline.h"

#include "Cemu/Logging/CemuLogging.h"
#include "Common/precompiled.h"
#include "GameProfile/GameProfile.h"

/*
MetalVertexBufferCache::~MetalVertexBufferCache()
Expand Down Expand Up @@ -117,8 +119,7 @@ void MetalMemoryManager::InitBufferCache(size_t size)
cemu_assert_debug(!m_bufferCache);

// First, try to import the host memory as a buffer
// TODO: only import if the option is ticked in game profile
if (m_mtlr->IsAppleGPU())
if (g_current_game_profile->UseHostMemForCache() && m_mtlr->IsAppleGPU())
{
m_importedMemBaseAddress = 0x10000000;
size_t hostAllocationSize = 0x40000000ull;
Expand Down Expand Up @@ -165,7 +166,6 @@ void MetalMemoryManager::UploadToBufferCache(const void* data, size_t offset, si

void MetalMemoryManager::CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size)
{
cemu_assert_debug(!m_useHostMemoryForCache);
cemu_assert_debug(m_bufferCache);

m_mtlr->CopyBufferToBuffer(m_bufferCache, srcOffset, m_bufferCache, dstOffset, size, ALL_MTL_RENDER_STAGES, ALL_MTL_RENDER_STAGES);
Expand Down
9 changes: 9 additions & 0 deletions src/gui/GameProfileWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ GameProfileWindow::GameProfileWindow(wxWindow* parent, uint64_t title_id)
m_shader_mul_accuracy->SetToolTip(_("EXPERT OPTION\nControls the accuracy of floating point multiplication in shaders.\n\nRecommended: true"));
first_row->Add(m_shader_mul_accuracy, 0, wxALL, 5);

first_row->Add(new wxStaticText(panel, wxID_ANY, _("Use host memory for cache")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);

wxString mem_values[] = { _("false"), _("true")};
m_use_host_mem_for_cache = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(mem_values), mem_values);
m_use_host_mem_for_cache->SetToolTip(_("EXPERT OPTION\nAllows the GPU to access data directly without the need for an intermediate cache. May increase performance and reduce memory usage, but can also cause flickering.\n\nMetal only\n\nRecommended: false"));
first_row->Add(m_use_host_mem_for_cache, 0, wxALL, 5);

/*first_row->Add(new wxStaticText(panel, wxID_ANY, _("GPU buffer cache accuracy")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString accuarcy_values[] = { _("high"), _("medium"), _("low") };
m_cache_accuracy = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(accuarcy_values), accuarcy_values);
Expand Down Expand Up @@ -273,6 +280,7 @@ void GameProfileWindow::ApplyProfile()
else
m_graphic_api->SetSelection(1 + m_game_profile.m_graphics_api.value()); // "", OpenGL, Vulkan, Metal
m_shader_mul_accuracy->SetSelection((int)m_game_profile.m_accurateShaderMul);
m_use_host_mem_for_cache->SetSelection((int)m_game_profile.m_useHostMemForCache);

//// audio
//m_disable_audio->Set3StateValue(GetCheckboxState(m_game_profile.disableAudio));
Expand Down Expand Up @@ -332,6 +340,7 @@ void GameProfileWindow::SaveProfile()

// gpu
m_game_profile.m_accurateShaderMul = (AccurateShaderMulOption)m_shader_mul_accuracy->GetSelection();
m_game_profile.m_useHostMemForCache = (bool)m_use_host_mem_for_cache->GetSelection();
if (m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::False && m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::True)
m_game_profile.m_accurateShaderMul = AccurateShaderMulOption::True; // force a legal value

Expand Down
3 changes: 2 additions & 1 deletion src/gui/GameProfileWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ class GameProfileWindow : public wxFrame
wxChoice* m_graphic_api;

wxChoice* m_shader_mul_accuracy;
wxChoice* m_use_host_mem_for_cache;
//wxChoice* m_cache_accuracy;

// audio
//wxCheckBox* m_disable_audio;

// controller
wxComboBox* m_controller_profile[8];
};
};

0 comments on commit 03d4e86

Please sign in to comment.