diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h index 28d92225..2543a9fc 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalCommon.h @@ -123,14 +123,27 @@ public: } // Get the file size + // Use a loop to handle the case where the file size is 0 (more of a safety net) struct stat fileStat; - if (fstat(m_fd, &fileStat) == -1) + while (true) { - close(m_fd); - cemuLog_log(LogType::Force, "failed to get file size: {}", filePath); - return; + if (fstat(m_fd, &fileStat) == -1) + { + close(m_fd); + cemuLog_log(LogType::Force, "failed to get file size: {}", filePath); + return; + } + m_fileSize = fileStat.st_size; + + if (m_fileSize == 0) + { + cemuLog_logOnce(LogType::Force, "file size is 0: {}", filePath); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + continue; + } + + break; } - m_fileSize = fileStat.st_size; // Memory map the file m_data = mmap(nullptr, m_fileSize, PROT_READ, MAP_PRIVATE, m_fd, 0); diff --git a/src/Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.cpp b/src/Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.cpp index e6aa0cab..303ba1e9 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.cpp @@ -29,7 +29,7 @@ public: if (m_threadsActive.exchange(true)) return; // create thread pool - const uint32 threadCount = 2; + const uint32 threadCount = 8; for (uint32 i = 0; i < threadCount; ++i) s_threads.emplace_back(&ShaderMtlThreadPool::CompilerThreadFunc, this); } @@ -128,7 +128,7 @@ void RendererShaderMtl::ShaderCacheLoading_end() // Close RAM filesystem if (s_hasRAMFilesystem) { - //executeCommand("diskutil eject {}", METAL_AIR_CACHE_PATH); + executeCommand("diskutil eject {}", METAL_AIR_CACHE_PATH); s_hasRAMFilesystem = false; } @@ -241,7 +241,6 @@ MTL::Library* RendererShaderMtl::LibraryFromAIR(std::span data) NS::Error* error = nullptr; MTL::Library* library = m_mtlr->GetDevice()->newLibrary(dispatchData, &error); FinishCompilation(); - printf("AIR size: %zu\n", data.size()); if (error) { cemuLog_log(LogType::Force, "failed to create library from AIR: {}", error->localizedDescription()->utf8String()); @@ -296,17 +295,17 @@ void RendererShaderMtl::CompileInternal() mslFile.close(); // Compile - executeCommand("xcrun -sdk macosx metal -o {}.ir -c {}.metal -Wno-unused-variable -Wno-sign-compare", baseFilename, baseFilename); + executeCommand("xcrun -sdk macosx metal -o {}.ir -c {}.metal -w", baseFilename, baseFilename); executeCommand("xcrun -sdk macosx metallib -o {}.metallib {}.ir", baseFilename, baseFilename); // Clean up executeCommand("rm {}.metal", baseFilename); executeCommand("rm {}.ir", baseFilename); - // Load from the newly Generated AIR + // Load from the newly generated AIR MemoryMappedFile airFile(fmt::format("{}.metallib", baseFilename)); std::span airData = std::span(airFile.data(), airFile.size()); - library = LibraryFromAIR(std::span(cacheFileData.data(), cacheFileData.size())); + library = LibraryFromAIR(std::span(airData.data(), airData.size())); // Store in the cache uint64 h1, h2;