mirror of
https://github.com/Ishan09811/pine.git
synced 2025-04-24 08:55:10 +00:00
shader_manager: Use multithreading to load the replacement shader files concurrently (#41)
This commit is contained in:
parent
55efa7dc96
commit
4fc489c62a
@ -33,21 +33,28 @@ namespace skyline::gpu {
|
||||
void ShaderManager::LoadShaderReplacements(std::string_view replacementDir) {
|
||||
std::filesystem::path replacementDirPath{replacementDir};
|
||||
if (std::filesystem::exists(replacementDirPath)) {
|
||||
std::vector<std::future<void>> tasks;
|
||||
for (const auto &entry : std::filesystem::directory_iterator{replacementDirPath}) {
|
||||
if (entry.is_regular_file()) {
|
||||
// Parse hash from filename
|
||||
auto path{entry.path()};
|
||||
auto &replacementMap{path.extension().string() == ".spv" ? hostShaderReplacements : guestShaderReplacements};
|
||||
u64 hash{std::stoull(path.stem().string(), nullptr, 16)};
|
||||
auto it{replacementMap.insert({hash, {}})};
|
||||
tasks.emplace_back(std::async(std::launch::async, [this, path = entry.path()]() {
|
||||
// Parse hash from filename
|
||||
auto &replacementMap{path.extension().string() == ".spv" ? hostShaderReplacements : guestShaderReplacements};
|
||||
u64 hash{std::stoull(path.stem().string(), nullptr, 16)};
|
||||
|
||||
// Read file into map entry
|
||||
std::ifstream file{entry.path(), std::ios::binary | std::ios::ate};
|
||||
it.first->second.resize(static_cast<size_t>(file.tellg()));
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(reinterpret_cast<char *>(it.first->second.data()), static_cast<std::streamsize>(it.first->second.size()));
|
||||
std::ifstream file{path, std::ios::binary | std::ios::ate};
|
||||
std::vector<u8> data(static_cast<size_t>(file.tellg()));
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(reinterpret_cast<char *>(data.data()), static_cast<std::streamsize>(data.size()));
|
||||
|
||||
std::scoped_lock lock{replacementMapMutex};
|
||||
replacementMap[hash] = std::move(data);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &task : tasks) {
|
||||
task.get(); // Wait for all tasks to complete
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ namespace skyline::gpu {
|
||||
std::mutex poolMutex;
|
||||
std::filesystem::path dumpPath;
|
||||
std::mutex dumpMutex;
|
||||
std::mutex replacementMapMutex;
|
||||
|
||||
/**
|
||||
* @brief Called at init time to populate the shader replacements map from the input directory
|
||||
|
Loading…
x
Reference in New Issue
Block a user