fix: AIR shaders not getting loaded properly

This commit is contained in:
Samuliak 2025-01-15 19:25:29 +01:00
parent a8da524dd4
commit 371c089923
No known key found for this signature in database
2 changed files with 23 additions and 11 deletions

View file

@ -123,7 +123,10 @@ public:
} }
// Get the file size // 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; struct stat fileStat;
while (true)
{
if (fstat(m_fd, &fileStat) == -1) if (fstat(m_fd, &fileStat) == -1)
{ {
close(m_fd); close(m_fd);
@ -132,6 +135,16 @@ public:
} }
m_fileSize = fileStat.st_size; 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;
}
// Memory map the file // Memory map the file
m_data = mmap(nullptr, m_fileSize, PROT_READ, MAP_PRIVATE, m_fd, 0); m_data = mmap(nullptr, m_fileSize, PROT_READ, MAP_PRIVATE, m_fd, 0);
if (m_data == MAP_FAILED) if (m_data == MAP_FAILED)

View file

@ -29,7 +29,7 @@ public:
if (m_threadsActive.exchange(true)) if (m_threadsActive.exchange(true))
return; return;
// create thread pool // create thread pool
const uint32 threadCount = 2; const uint32 threadCount = 8;
for (uint32 i = 0; i < threadCount; ++i) for (uint32 i = 0; i < threadCount; ++i)
s_threads.emplace_back(&ShaderMtlThreadPool::CompilerThreadFunc, this); s_threads.emplace_back(&ShaderMtlThreadPool::CompilerThreadFunc, this);
} }
@ -128,7 +128,7 @@ void RendererShaderMtl::ShaderCacheLoading_end()
// Close RAM filesystem // Close RAM filesystem
if (s_hasRAMFilesystem) if (s_hasRAMFilesystem)
{ {
//executeCommand("diskutil eject {}", METAL_AIR_CACHE_PATH); executeCommand("diskutil eject {}", METAL_AIR_CACHE_PATH);
s_hasRAMFilesystem = false; s_hasRAMFilesystem = false;
} }
@ -241,7 +241,6 @@ MTL::Library* RendererShaderMtl::LibraryFromAIR(std::span<uint8> data)
NS::Error* error = nullptr; NS::Error* error = nullptr;
MTL::Library* library = m_mtlr->GetDevice()->newLibrary(dispatchData, &error); MTL::Library* library = m_mtlr->GetDevice()->newLibrary(dispatchData, &error);
FinishCompilation(); FinishCompilation();
printf("AIR size: %zu\n", data.size());
if (error) if (error)
{ {
cemuLog_log(LogType::Force, "failed to create library from AIR: {}", error->localizedDescription()->utf8String()); cemuLog_log(LogType::Force, "failed to create library from AIR: {}", error->localizedDescription()->utf8String());
@ -296,17 +295,17 @@ void RendererShaderMtl::CompileInternal()
mslFile.close(); mslFile.close();
// Compile // 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); executeCommand("xcrun -sdk macosx metallib -o {}.metallib {}.ir", baseFilename, baseFilename);
// Clean up // Clean up
executeCommand("rm {}.metal", baseFilename); executeCommand("rm {}.metal", baseFilename);
executeCommand("rm {}.ir", baseFilename); executeCommand("rm {}.ir", baseFilename);
// Load from the newly Generated AIR // Load from the newly generated AIR
MemoryMappedFile airFile(fmt::format("{}.metallib", baseFilename)); MemoryMappedFile airFile(fmt::format("{}.metallib", baseFilename));
std::span<uint8> airData = std::span<uint8>(airFile.data(), airFile.size()); std::span<uint8> airData = std::span<uint8>(airFile.data(), airFile.size());
library = LibraryFromAIR(std::span<uint8>(cacheFileData.data(), cacheFileData.size())); library = LibraryFromAIR(std::span<uint8>(airData.data(), airData.size()));
// Store in the cache // Store in the cache
uint64 h1, h2; uint64 h1, h2;