mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 13:54:16 +01:00
[dxvk] Open state cache file only when necessary
Fixes an issue with Shadow of the Tomb Raider randomly nuking its cache when it creates not one but *two* D3D11 devices.
This commit is contained in:
parent
8054e4a772
commit
f5b21d42fc
@ -35,36 +35,26 @@ namespace dxvk {
|
|||||||
m_passManager(passManager) {
|
m_passManager(passManager) {
|
||||||
bool newFile = !readCacheFile();
|
bool newFile = !readCacheFile();
|
||||||
|
|
||||||
// Open cache file for writing
|
if (newFile) {
|
||||||
std::ios_base::openmode mode = std::ios_base::binary;
|
|
||||||
|
|
||||||
mode |= newFile
|
|
||||||
? std::ios_base::trunc
|
|
||||||
: std::ios_base::app;
|
|
||||||
|
|
||||||
m_writerFile = std::ofstream(getCacheFileName(), mode);
|
|
||||||
|
|
||||||
if (!m_writerFile) {
|
|
||||||
// We can't write to the file, but we might still
|
|
||||||
// use cache entries previously read from the file
|
|
||||||
Logger::warn("DXVK: Failed to open state cache file");
|
|
||||||
} else if (newFile) {
|
|
||||||
Logger::warn("DXVK: Creating new state cache file");
|
Logger::warn("DXVK: Creating new state cache file");
|
||||||
|
|
||||||
|
// Start with an empty file
|
||||||
|
std::ofstream file(getCacheFileName(),
|
||||||
|
std::ios_base::binary |
|
||||||
|
std::ios_base::trunc);
|
||||||
|
|
||||||
// Write header with the current version number
|
// Write header with the current version number
|
||||||
DxvkStateCacheHeader header;
|
DxvkStateCacheHeader header;
|
||||||
|
|
||||||
auto data = reinterpret_cast<const char*>(&header);
|
auto data = reinterpret_cast<const char*>(&header);
|
||||||
auto size = sizeof(header);
|
auto size = sizeof(header);
|
||||||
|
|
||||||
m_writerFile.write(data, size);
|
file.write(data, size);
|
||||||
|
|
||||||
// Write all valid entries to the cache file in
|
// Write all valid entries to the cache file in
|
||||||
// case we're recovering a corrupted cache file
|
// case we're recovering a corrupted cache file
|
||||||
for (auto& e : m_entries)
|
for (auto& e : m_entries)
|
||||||
writeCacheEntry(m_writerFile, e);
|
writeCacheEntry(file, e);
|
||||||
|
|
||||||
m_writerFile.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use half the available CPU cores for pipeline compilation
|
// Use half the available CPU cores for pipeline compilation
|
||||||
@ -390,6 +380,8 @@ namespace dxvk {
|
|||||||
void DxvkStateCache::writerFunc() {
|
void DxvkStateCache::writerFunc() {
|
||||||
env::setThreadName(L"dxvk-writer");
|
env::setThreadName(L"dxvk-writer");
|
||||||
|
|
||||||
|
std::ofstream file;
|
||||||
|
|
||||||
while (!m_stopThreads.load()) {
|
while (!m_stopThreads.load()) {
|
||||||
DxvkStateCacheEntry entry;
|
DxvkStateCacheEntry entry;
|
||||||
|
|
||||||
@ -407,7 +399,13 @@ namespace dxvk {
|
|||||||
m_writerQueue.pop();
|
m_writerQueue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
writeCacheEntry(m_writerFile, entry);
|
if (!file) {
|
||||||
|
file = std::ofstream(getCacheFileName(),
|
||||||
|
std::ios_base::binary |
|
||||||
|
std::ios_base::app);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeCacheEntry(file, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,6 @@ namespace dxvk {
|
|||||||
std::mutex m_writerLock;
|
std::mutex m_writerLock;
|
||||||
std::condition_variable m_writerCond;
|
std::condition_variable m_writerCond;
|
||||||
std::queue<WriterItem> m_writerQueue;
|
std::queue<WriterItem> m_writerQueue;
|
||||||
std::ofstream m_writerFile;
|
|
||||||
dxvk::thread m_writerThread;
|
dxvk::thread m_writerThread;
|
||||||
|
|
||||||
DxvkShaderKey getShaderKey(
|
DxvkShaderKey getShaderKey(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user