latte: rename metal specific options

This commit is contained in:
Samuliak 2025-05-20 18:26:52 +02:00
parent feba1aa7ba
commit 4311a41f34
No known key found for this signature in database
11 changed files with 57 additions and 53 deletions

View file

@ -259,7 +259,7 @@ void InfoLog_PrintActiveSettings()
{
cemuLog_log(LogType::Force, "Async compile: {}", GetConfig().async_compile.GetValue() ? "true" : "false");
cemuLog_log(LogType::Force, "Force mesh shaders: {}", GetConfig().force_mesh_shaders.GetValue() ? "true" : "false");
cemuLog_log(LogType::Force, "Fast math: {}", g_current_game_profile->GetFastMath() ? "true" : "false");
cemuLog_log(LogType::Force, "Fast math: {}", g_current_game_profile->GetShaderFastMath() ? "true" : "false");
cemuLog_log(LogType::Force, "Buffer cache type: {}", g_current_game_profile->GetBufferCacheMode());
cemuLog_log(LogType::Force, "Position invariance: {}", g_current_game_profile->GetPositionInvariance());
if (!GetConfig().vk_accurate_barriers.GetValue())

View file

@ -226,8 +226,8 @@ bool GameProfile::Load(uint64_t title_id)
m_graphics_api = (GraphicAPI)graphicsApi.value;
gameProfile_loadEnumOption(iniParser, "accurateShaderMul", m_accurateShaderMul);
gameProfile_loadBooleanOption2(iniParser, "fastMath", m_fastMath);
gameProfile_loadEnumOption(iniParser, "bufferCacheMode2", m_bufferCacheMode);
gameProfile_loadBooleanOption2(iniParser, "shaderFastMath", m_shaderFastMath);
gameProfile_loadEnumOption(iniParser, "metalBufferCacheMode2", m_metalBufferCacheMode);
gameProfile_loadEnumOption(iniParser, "positionInvariance2", m_positionInvariance);
// legacy support
@ -309,8 +309,8 @@ void GameProfile::Save(uint64_t title_id)
fs->writeLine("[Graphics]");
WRITE_ENTRY(accurateShaderMul);
WRITE_ENTRY(fastMath);
WRITE_ENTRY_NUMBERED(bufferCacheMode, 2);
WRITE_ENTRY(shaderFastMath);
WRITE_ENTRY_NUMBERED(metalBufferCacheMode, 2);
WRITE_ENTRY_NUMBERED(positionInvariance, 2);
WRITE_OPTIONAL_ENTRY(precompiledShaders);
WRITE_OPTIONAL_ENTRY(graphics_api);
@ -342,8 +342,8 @@ void GameProfile::ResetOptional()
// graphic settings
m_accurateShaderMul = AccurateShaderMulOption::True;
m_fastMath = true;
m_bufferCacheMode = BufferCacheMode::Auto;
m_shaderFastMath = true;
m_metalBufferCacheMode = MetalBufferCacheMode::Auto;
m_positionInvariance = PositionInvariance::Auto;
// cpu settings
m_threadQuantum = kThreadQuantumDefault;
@ -365,8 +365,8 @@ void GameProfile::Reset()
// graphic settings
m_accurateShaderMul = AccurateShaderMulOption::True;
m_fastMath = true;
m_bufferCacheMode = BufferCacheMode::Auto;
m_shaderFastMath = true;
m_metalBufferCacheMode = MetalBufferCacheMode::Auto;
m_positionInvariance = PositionInvariance::Auto;
m_precompiledShaders = PrecompiledShaderOption::Auto;
// cpu settings

View file

@ -31,8 +31,8 @@ public:
[[nodiscard]] const std::optional<GraphicAPI>& GetGraphicsAPI() const { return m_graphics_api; }
[[nodiscard]] const AccurateShaderMulOption& GetAccurateShaderMul() const { return m_accurateShaderMul; }
[[nodiscard]] bool GetFastMath() const { return m_fastMath; }
[[nodiscard]] BufferCacheMode GetBufferCacheMode() const { return m_bufferCacheMode; }
[[nodiscard]] bool GetShaderFastMath() const { return m_shaderFastMath; }
[[nodiscard]] MetalBufferCacheMode GetBufferCacheMode() const { return m_metalBufferCacheMode; }
[[nodiscard]] PositionInvariance GetPositionInvariance() const { return m_positionInvariance; }
[[nodiscard]] const std::optional<PrecompiledShaderOption>& GetPrecompiledShadersState() const { return m_precompiledShaders; }
@ -57,8 +57,8 @@ private:
// graphic settings
std::optional<GraphicAPI> m_graphics_api{};
AccurateShaderMulOption m_accurateShaderMul = AccurateShaderMulOption::True;
bool m_fastMath = true;
BufferCacheMode m_bufferCacheMode = BufferCacheMode::Auto;
bool m_shaderFastMath = true;
MetalBufferCacheMode m_metalBufferCacheMode = MetalBufferCacheMode::Auto;
PositionInvariance m_positionInvariance = PositionInvariance::Auto;
std::optional<PrecompiledShaderOption> m_precompiledShaders{};
// cpu settings

View file

@ -559,6 +559,7 @@ namespace LatteDecompiler
{
decompilerContext->hasUniformVarBlock = true; // uf_verticesPerInstance and uf_streamoutBufferBase*
}
#if ENABLE_METAL
if (g_renderer->GetType() == RendererAPI::Metal)
{
bool usesGeometryShader = UseGeometryShader(*decompilerContext->contextRegistersNew, decompilerContext->options->usesGeometryShader);
@ -566,6 +567,7 @@ namespace LatteDecompiler
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex && usesGeometryShader)
decompilerContext->hasUniformVarBlock = true; // uf_verticesPerInstance
}
#endif
}
void _initUniformBindingPoints(LatteDecompilerShaderContext* decompilerContext)

View file

@ -36,9 +36,9 @@ void MetalMemoryManager::InitBufferCache(size_t size)
{
cemu_assert_debug(!m_bufferCache);
m_bufferCacheMode = g_current_game_profile->GetBufferCacheMode();
m_metalBufferCacheMode = g_current_game_profile->GetBufferCacheMode();
if (m_bufferCacheMode == BufferCacheMode::Auto)
if (m_metalBufferCacheMode == MetalBufferCacheMode::Auto)
{
// TODO: do this for all unified memory systems?
if (m_mtlr->IsAppleGPU())
@ -50,21 +50,21 @@ void MetalMemoryManager::InitBufferCache(size_t size)
case 0x0005000010143500: // USA
case 0x0005000010143400: // JPN
// TODO: use host instead?
m_bufferCacheMode = BufferCacheMode::DeviceShared;
m_metalBufferCacheMode = MetalBufferCacheMode::DeviceShared;
break;
default:
m_bufferCacheMode = BufferCacheMode::DevicePrivate;
m_metalBufferCacheMode = MetalBufferCacheMode::DevicePrivate;
break;
}
}
else
{
m_bufferCacheMode = BufferCacheMode::DevicePrivate;
m_metalBufferCacheMode = MetalBufferCacheMode::DevicePrivate;
}
}
// First, try to import the host memory as a buffer
if (m_bufferCacheMode == BufferCacheMode::Host)
if (m_metalBufferCacheMode == MetalBufferCacheMode::Host)
{
if (m_mtlr->HasUnifiedMemory())
{
@ -74,18 +74,18 @@ void MetalMemoryManager::InitBufferCache(size_t size)
if (!m_bufferCache)
{
cemuLog_log(LogType::Force, "Failed to import host memory as a buffer, using device shared mode instead");
m_bufferCacheMode = BufferCacheMode::DeviceShared;
m_metalBufferCacheMode = MetalBufferCacheMode::DeviceShared;
}
}
else
{
cemuLog_log(LogType::Force, "Host buffer cache mode is only available on unified memory systems, using device shared mode instead");
m_bufferCacheMode = BufferCacheMode::DeviceShared;
m_metalBufferCacheMode = MetalBufferCacheMode::DeviceShared;
}
}
if (!m_bufferCache)
m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, (m_bufferCacheMode == BufferCacheMode::DevicePrivate ? MTL::ResourceStorageModePrivate : MTL::ResourceStorageModeShared));
m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, (m_metalBufferCacheMode == MetalBufferCacheMode::DevicePrivate ? MTL::ResourceStorageModePrivate : MTL::ResourceStorageModeShared));
#ifdef CEMU_DEBUG_ASSERT
m_bufferCache->setLabel(GetLabel("Buffer cache", m_bufferCache));
@ -94,11 +94,11 @@ void MetalMemoryManager::InitBufferCache(size_t size)
void MetalMemoryManager::UploadToBufferCache(const void* data, size_t offset, size_t size)
{
cemu_assert_debug(m_bufferCacheMode != BufferCacheMode::Host);
cemu_assert_debug(m_metalBufferCacheMode != MetalBufferCacheMode::Host);
cemu_assert_debug(m_bufferCache);
cemu_assert_debug((offset + size) <= m_bufferCache->length());
if (m_bufferCacheMode == BufferCacheMode::DevicePrivate)
if (m_metalBufferCacheMode == MetalBufferCacheMode::DevicePrivate)
{
auto blitCommandEncoder = m_mtlr->GetBlitCommandEncoder();
@ -118,10 +118,10 @@ 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_bufferCacheMode != BufferCacheMode::Host);
cemu_assert_debug(m_metalBufferCacheMode != MetalBufferCacheMode::Host);
cemu_assert_debug(m_bufferCache);
if (m_bufferCacheMode == BufferCacheMode::DevicePrivate)
if (m_metalBufferCacheMode == MetalBufferCacheMode::DevicePrivate)
m_mtlr->CopyBufferToBuffer(m_bufferCache, srcOffset, m_bufferCache, dstOffset, size, ALL_MTL_RENDER_STAGES, ALL_MTL_RENDER_STAGES);
else
memcpy((uint8*)m_bufferCache->contents() + dstOffset, (uint8*)m_bufferCache->contents() + srcOffset, size);

View file

@ -43,12 +43,12 @@ public:
// Getters
bool UseHostMemoryForCache() const
{
return (m_bufferCacheMode == BufferCacheMode::Host);
return (m_metalBufferCacheMode == MetalBufferCacheMode::Host);
}
bool NeedsReducedLatency() const
{
return (m_bufferCacheMode == BufferCacheMode::DeviceShared || m_bufferCacheMode == BufferCacheMode::Host);
return (m_metalBufferCacheMode == MetalBufferCacheMode::DeviceShared || m_metalBufferCacheMode == MetalBufferCacheMode::Host);
}
MPTR GetImportedMemBaseAddress() const
@ -70,7 +70,7 @@ private:
MetalSynchronizedHeapAllocator m_indexAllocator;
MTL::Buffer* m_bufferCache = nullptr;
BufferCacheMode m_bufferCacheMode;
MetalBufferCacheMode m_metalBufferCacheMode;
MPTR m_importedMemBaseAddress;
size_t m_hostAllocationSize = 0;
};

View file

@ -277,7 +277,7 @@ MTL::Library* RendererShaderMtl::LibraryFromSource()
{
// Compile from source
NS_STACK_SCOPED MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
if (g_current_game_profile->GetFastMath())
if (g_current_game_profile->GetShaderFastMath())
options->setFastMathEnabled(true);
if (m_mtlr->GetPositionInvariance())

View file

@ -124,14 +124,14 @@ enum class AccurateShaderMulOption
};
ENABLE_ENUM_ITERATORS(AccurateShaderMulOption, AccurateShaderMulOption::False, AccurateShaderMulOption::True);
enum class BufferCacheMode
enum class MetalBufferCacheMode
{
Auto,
DevicePrivate,
DeviceShared,
Host,
};
ENABLE_ENUM_ITERATORS(BufferCacheMode, BufferCacheMode::Auto, BufferCacheMode::Host);
ENABLE_ENUM_ITERATORS(MetalBufferCacheMode, MetalBufferCacheMode::Auto, MetalBufferCacheMode::Host);
enum class PositionInvariance
{
@ -239,16 +239,16 @@ struct fmt::formatter<AccurateShaderMulOption> : formatter<string_view> {
}
};
template <>
struct fmt::formatter<BufferCacheMode> : formatter<string_view> {
struct fmt::formatter<MetalBufferCacheMode> : formatter<string_view> {
template <typename FormatContext>
auto format(const BufferCacheMode c, FormatContext &ctx) const {
auto format(const MetalBufferCacheMode c, FormatContext &ctx) const {
string_view name;
switch (c)
{
case BufferCacheMode::Auto: name = "auto"; break;
case BufferCacheMode::DevicePrivate: name = "device private"; break;
case BufferCacheMode::DeviceShared: name = "device shared"; break;
case BufferCacheMode::Host: name = "host"; break;
case MetalBufferCacheMode::Auto: name = "auto"; break;
case MetalBufferCacheMode::DevicePrivate: name = "device private"; break;
case MetalBufferCacheMode::DeviceShared: name = "device shared"; break;
case MetalBufferCacheMode::Host: name = "host"; break;
default: name = "unknown"; break;
}
return formatter<string_view>::format(name, ctx);

View file

@ -128,19 +128,19 @@ 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, _("Fast math")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Shader fast math")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString math_values[] = { _("false"), _("true") };
m_fast_math = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(math_values), math_values);
m_fast_math->SetToolTip(_("EXPERT OPTION\nEnables fast math for all shaders. May (rarely) cause graphical bugs.\n\nMetal only\n\nRecommended: true"));
first_row->Add(m_fast_math, 0, wxALL, 5);
m_shader_fast_math = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(math_values), math_values);
m_shader_fast_math->SetToolTip(_("EXPERT OPTION\nEnables fast math for all shaders. May (rarely) cause graphical bugs.\n\nMetal only\n\nRecommended: true"));
first_row->Add(m_shader_fast_math, 0, wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Buffer cache mode")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Metal buffer cache mode")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString cache_values[] = { _("auto"), _("device private"), _("device shared"), _("host") };
m_buffer_cache_mode = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(cache_values), cache_values);
m_buffer_cache_mode->SetToolTip(_("EXPERT OPTION\nDecides how the buffer cache memory will be managed.\n\nMetal only\n\nRecommended: auto"));
first_row->Add(m_buffer_cache_mode, 0, wxALL, 5);
m_metal_buffer_cache_mode = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(cache_values), cache_values);
m_metal_buffer_cache_mode->SetToolTip(_("EXPERT OPTION\nDecides how the buffer cache memory will be managed.\n\nMetal only\n\nRecommended: auto"));
first_row->Add(m_metal_buffer_cache_mode, 0, wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Position invariance")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
@ -295,8 +295,8 @@ 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_fast_math->SetSelection((int)m_game_profile.m_fastMath);
m_buffer_cache_mode->SetSelection((int)m_game_profile.m_bufferCacheMode);
m_shader_fast_math->SetSelection((int)m_game_profile.m_shaderFastMath);
m_metal_buffer_cache_mode->SetSelection((int)m_game_profile.m_metalBufferCacheMode);
m_position_invariance->SetSelection((int)m_game_profile.m_positionInvariance);
//// audio
@ -359,8 +359,8 @@ void GameProfileWindow::SaveProfile()
m_game_profile.m_accurateShaderMul = (AccurateShaderMulOption)m_shader_mul_accuracy->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
m_game_profile.m_fastMath = (bool)m_fast_math->GetSelection();
m_game_profile.m_bufferCacheMode = (BufferCacheMode)m_buffer_cache_mode->GetSelection();
m_game_profile.m_shaderFastMath = (bool)m_shader_fast_math->GetSelection();
m_game_profile.m_metalBufferCacheMode = (MetalBufferCacheMode)m_metal_buffer_cache_mode->GetSelection();
m_game_profile.m_positionInvariance = (PositionInvariance)m_position_invariance->GetSelection();
if (m_graphic_api->GetSelection() == 0)

View file

@ -40,8 +40,8 @@ private:
wxChoice* m_graphic_api;
wxChoice* m_shader_mul_accuracy;
wxChoice* m_fast_math;
wxChoice* m_buffer_cache_mode;
wxChoice* m_shader_fast_math;
wxChoice* m_metal_buffer_cache_mode;
wxChoice* m_position_invariance;
//wxChoice* m_cache_accuracy;

View file

@ -1091,11 +1091,13 @@ void GeneralSettings2::StoreConfig()
{
if (selection != wxNOT_FOUND)
{
#if ENABLE_METAL
const auto* info = (wxMetalUUID*)m_graphic_device->GetClientObject(selection);
if (info)
config.mtl_graphic_device_uuid = info->GetDeviceInfo().uuid;
else
config.mtl_graphic_device_uuid = {};
#endif
}
else
config.mtl_graphic_device_uuid = {};
@ -1638,9 +1640,9 @@ void GeneralSettings2::HandleGraphicsApiSelection()
m_vsync->Select(selection);
m_graphic_device->Enable();
auto devices = MetalRenderer::GetDevices();
m_graphic_device->Clear();
#if ENABLE_METAL
auto devices = MetalRenderer::GetDevices();
if(!devices.empty())
{
for (const auto& device : devices)