diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a04c771..5fdc359a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,6 +201,8 @@ endif() if (ENABLE_METAL) include_directories(${CMAKE_SOURCE_DIR}/dependencies/metal-cpp) + + add_definitions(-DENABLE_METAL=1) endif() if (ENABLE_DISCORD_RPC) diff --git a/src/Cafe/CMakeLists.txt b/src/Cafe/CMakeLists.txt index b30f8efe..5b1e6fde 100644 --- a/src/Cafe/CMakeLists.txt +++ b/src/Cafe/CMakeLists.txt @@ -151,9 +151,6 @@ add_library(CemuCafe HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLAttrDecoder.cpp HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLHeader.hpp - HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLAttrDecoder.cpp - HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp - HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp HW/Latte/LegacyShaderDecompiler/LatteDecompiler.h HW/Latte/LegacyShaderDecompiler/LatteDecompilerInstructions.h HW/Latte/LegacyShaderDecompiler/LatteDecompilerInternal.h @@ -579,6 +576,12 @@ if(ENABLE_METAL) HW/Latte/Renderer/Metal/UtilityShaderSource.h ) + target_sources(CemuCafe PRIVATE + HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLAttrDecoder.cpp + HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp + HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp + ) + #target_link_libraries(CemuCafe PRIVATE # "-framework Metal" # "-framework QuartzCore" diff --git a/src/Cafe/HW/Latte/Core/FetchShader.cpp b/src/Cafe/HW/Latte/Core/FetchShader.cpp index 6da6100b..d50447b3 100644 --- a/src/Cafe/HW/Latte/Core/FetchShader.cpp +++ b/src/Cafe/HW/Latte/Core/FetchShader.cpp @@ -11,7 +11,7 @@ #include "HW/Latte/Renderer/Renderer.h" #include "util/containers/LookupTableL3.h" #include "util/helpers/fspinlock.h" -#if BOOST_OS_MACOS +#if ENABLE_METAL #include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h" #endif #include /* SHA1_DIGEST_LENGTH */ @@ -166,6 +166,7 @@ void LatteFetchShader::CalculateFetchShaderVkHash() void LatteFetchShader::CheckIfVerticesNeedManualFetchMtl(uint32* contextRegister) { +#if ENABLE_METAL for (sint32 g = 0; g < bufferGroups.size(); g++) { LatteParsedFetchShaderBufferGroup_t& group = bufferGroups[g]; @@ -183,6 +184,7 @@ void LatteFetchShader::CheckIfVerticesNeedManualFetchMtl(uint32* contextRegister mtlFetchVertexManually = true; } } +#endif } void _fetchShaderDecompiler_parseInstruction_VTX_SEMANTIC(LatteFetchShader* parsedFetchShader, uint32* contextRegister, const LatteClauseInstruction_VTX* instr) diff --git a/src/Cafe/HW/Latte/Core/LatteShader.cpp b/src/Cafe/HW/Latte/Core/LatteShader.cpp index 9e3e6b1f..504bddcc 100644 --- a/src/Cafe/HW/Latte/Core/LatteShader.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShader.cpp @@ -14,7 +14,7 @@ #include "config/ActiveSettings.h" #include "Cafe/GameProfile/GameProfile.h" #include "util/containers/flat_hash_map.hpp" -#if BOOST_OS_MACOS +#if ENABLE_METAL #include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h" #endif #include @@ -591,7 +591,7 @@ void LatteSHRC_UpdatePSBaseHash(uint8* pixelShaderPtr, uint32 pixelShaderSize, b // get vertex shader uint64 psHash = psHash1 + psHash2 + _activePSImportTable.key + (usesGeometryShader ? hashCacheGS.prevHash1 : 0ULL); -#if BOOST_OS_MACOS +#if ENABLE_METAL if (g_renderer->GetType() == RendererAPI::Metal) { for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++) diff --git a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp index 126dcc50..ed9dc467 100644 --- a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp @@ -11,8 +11,10 @@ #include "Cafe/HW/Latte/Renderer/Renderer.h" #include "Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h" #include "Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h" +#if ENABLE_METAL #include "Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.h" +#endif #include "Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.h" #include @@ -163,8 +165,10 @@ void LatteShaderCache_finish() RendererShaderVk::ShaderCacheLoading_end(); else if (g_renderer->GetType() == RendererAPI::OpenGL) RendererShaderGL::ShaderCacheLoading_end(); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) RendererShaderMtl::ShaderCacheLoading_end(); +#endif } uint32 LatteShaderCache_getShaderCacheExtraVersion(uint64 titleId) @@ -247,8 +251,11 @@ void LatteShaderCache_Load() RendererShaderVk::ShaderCacheLoading_begin(cacheTitleId); else if (g_renderer->GetType() == RendererAPI::OpenGL) RendererShaderGL::ShaderCacheLoading_begin(cacheTitleId); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) RendererShaderMtl::ShaderCacheLoading_begin(cacheTitleId); +#endif + // get cache file name const auto pathGeneric = ActiveSettings::GetCachePath("shaderCache/transferable/{:016x}_shaders.bin", cacheTitleId); const auto pathGenericPre1_25_0 = ActiveSettings::GetCachePath("shaderCache/transferable/{:016x}.bin", cacheTitleId); // before 1.25.0 @@ -508,14 +515,18 @@ void LatteShaderCache_LoadPipelineCache(uint64 cacheTitleId) { if (g_renderer->GetType() == RendererAPI::Vulkan) g_shaderCacheLoaderState.pipelineFileCount = VulkanPipelineStableCache::GetInstance().BeginLoading(cacheTitleId); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) g_shaderCacheLoaderState.pipelineFileCount = MetalPipelineCache::GetInstance().BeginLoading(cacheTitleId); +#endif g_shaderCacheLoaderState.loadedPipelines = 0; LatteShaderCache_ShowProgress(LatteShaderCache_updatePipelineLoadingProgress, true); if (g_renderer->GetType() == RendererAPI::Vulkan) VulkanPipelineStableCache::GetInstance().EndLoading(); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) MetalPipelineCache::GetInstance().EndLoading(); +#endif if(Latte_GetStopSignal()) LatteThread_Exit(); } @@ -525,8 +536,10 @@ bool LatteShaderCache_updatePipelineLoadingProgress() uint32 pipelinesMissingShaders = 0; if (g_renderer->GetType() == RendererAPI::Vulkan) return VulkanPipelineStableCache::GetInstance().UpdateLoading(g_shaderCacheLoaderState.loadedPipelines, pipelinesMissingShaders); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) return MetalPipelineCache::GetInstance().UpdateLoading(g_shaderCacheLoaderState.loadedPipelines, pipelinesMissingShaders); +#endif return false; } @@ -790,14 +803,18 @@ void LatteShaderCache_Close() RendererShaderVk::ShaderCacheLoading_Close(); else if (g_renderer->GetType() == RendererAPI::OpenGL) RendererShaderGL::ShaderCacheLoading_Close(); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) RendererShaderMtl::ShaderCacheLoading_Close(); +#endif // if Vulkan or Metal then also close pipeline cache if (g_renderer->GetType() == RendererAPI::Vulkan) VulkanPipelineStableCache::GetInstance().Close(); +#if ENABLE_METAL else if (g_renderer->GetType() == RendererAPI::Metal) MetalPipelineCache::GetInstance().Close(); +#endif } #include diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompiler.cpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompiler.cpp index c2051090..7359a1ff 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompiler.cpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompiler.cpp @@ -1067,10 +1067,12 @@ void _LatteDecompiler_Process(LatteDecompilerShaderContext* shaderContext, uint8 // emit code if (shaderContext->shader->hasError == false) { - if (g_renderer->GetType() == RendererAPI::Metal) - LatteDecompiler_emitMSLShader(shaderContext, shaderContext->shader); + if (g_renderer->GetType() == RendererAPI::OpenGL || g_renderer->GetType() == RendererAPI::Vulkan) + LatteDecompiler_emitGLSLShader(shaderContext, shaderContext->shader); +#if ENABLE_METAL else - LatteDecompiler_emitGLSLShader(shaderContext, shaderContext->shader); + LatteDecompiler_emitMSLShader(shaderContext, shaderContext->shader); +#endif } LatteDecompiler_cleanup(shaderContext); // fast access diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index df98c1f1..f12f120e 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -4,8 +4,6 @@ add_library(CemuGui canvas/OpenGLCanvas.h canvas/VulkanCanvas.cpp canvas/VulkanCanvas.h - canvas/MetalCanvas.cpp - canvas/MetalCanvas.h CemuApp.cpp CemuApp.h CemuUpdateWindow.cpp @@ -131,6 +129,13 @@ add_library(CemuGui wxHelper.h ) +if(ENABLE_METAL) + target_sources(CemuGui PRIVATE + canvas/MetalCanvas.cpp + canvas/MetalCanvas.h + ) +endif() + set_property(TARGET CemuGui PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") diff --git a/src/gui/GameProfileWindow.cpp b/src/gui/GameProfileWindow.cpp index fe332702..76b8801c 100644 --- a/src/gui/GameProfileWindow.cpp +++ b/src/gui/GameProfileWindow.cpp @@ -113,7 +113,7 @@ GameProfileWindow::GameProfileWindow(wxWindow* parent, uint64_t title_id) first_row->Add(new wxStaticText(panel, wxID_ANY, _("Graphics API")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); wxString gapi_values[] = { "", "OpenGL", "Vulkan", -#ifdef __APPLE__ +#if ENABLE_METAL "Metal" #endif }; @@ -271,7 +271,7 @@ void GameProfileWindow::ApplyProfile() if (!m_game_profile.m_graphics_api.has_value()) m_graphic_api->SetSelection(0); // selecting "" else - m_graphic_api->SetSelection(1 + m_game_profile.m_graphics_api.value()); // "", OpenGL, Vulkan + 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); //// audio @@ -338,7 +338,7 @@ void GameProfileWindow::SaveProfile() if (m_graphic_api->GetSelection() == 0) m_game_profile.m_graphics_api = {}; else - m_game_profile.m_graphics_api = (GraphicAPI)(m_graphic_api->GetSelection() - 1); // "", OpenGL, Vulkan + m_game_profile.m_graphics_api = (GraphicAPI)(m_graphic_api->GetSelection() - 1); // "", OpenGL, Vulkan, Metal // controller for (int i = 0; i < 8; ++i) diff --git a/src/gui/GeneralSettings2.cpp b/src/gui/GeneralSettings2.cpp index 4cd0be9a..4812a884 100644 --- a/src/gui/GeneralSettings2.cpp +++ b/src/gui/GeneralSettings2.cpp @@ -314,7 +314,7 @@ wxPanel* GeneralSettings2::AddGraphicsPage(wxNotebook* notebook) { choices[api_size++] = "Vulkan"; } -#ifdef __APPLE__ +#if ENABLE_METAL choices[api_size++] = "Metal"; #endif diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7f738c2e..2e44a4c7 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1570,8 +1570,10 @@ void MainWindow::CreateCanvas() m_render_canvas = new VulkanCanvas(m_game_panel, wxSize(1280, 720), true); else if (ActiveSettings::GetGraphicsAPI() == kOpenGL) m_render_canvas = GLCanvas_Create(m_game_panel, wxSize(1280, 720), true); +#if ENABLE_METAL else m_render_canvas = new MetalCanvas(m_game_panel, wxSize(1280, 720), true); +#endif // mouse events m_render_canvas->Bind(wxEVT_MOTION, &MainWindow::OnMouseMove, this); diff --git a/src/gui/PadViewFrame.cpp b/src/gui/PadViewFrame.cpp index 6d1ec7d6..94319299 100644 --- a/src/gui/PadViewFrame.cpp +++ b/src/gui/PadViewFrame.cpp @@ -77,8 +77,10 @@ void PadViewFrame::InitializeRenderCanvas() m_render_canvas = new VulkanCanvas(this, wxSize(854, 480), false); else if (ActiveSettings::GetGraphicsAPI() == kOpenGL) m_render_canvas = GLCanvas_Create(this, wxSize(854, 480), false); +#if ENABLE_METAL else m_render_canvas = new MetalCanvas(this, wxSize(854, 480), false); +#endif sizer->Add(m_render_canvas, 1, wxEXPAND, 0, nullptr); } SetSizer(sizer);