mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-25 18:48:51 -04:00
Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
This commit is contained in:
77
gpu/vk/reshade/fx_pipeline_cache.cpp
Normal file
77
gpu/vk/reshade/fx_pipeline_cache.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "fx_pipeline_cache.h"
|
||||
#include "vk_paths.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
namespace mkwvk::reshade {
|
||||
namespace {
|
||||
|
||||
constexpr size_t file_limit = 16 * 1024 * 1024;
|
||||
|
||||
bool matches_device(const std::vector<char>& bytes) {
|
||||
VkPipelineCacheHeaderVersionOne header{};
|
||||
if (bytes.size() < sizeof(header)) return false;
|
||||
std::memcpy(&header, bytes.data(), sizeof(header));
|
||||
return header.headerSize >= sizeof(header) && header.headerSize <= bytes.size() &&
|
||||
header.headerVersion == VK_PIPELINE_CACHE_HEADER_VERSION_ONE && header.vendorID == dev.props.vendorID &&
|
||||
header.deviceID == dev.props.deviceID && std::memcmp(header.pipelineCacheUUID, dev.props.pipelineCacheUUID, VK_UUID_SIZE) == 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::filesystem::path game_dir() {
|
||||
char exe[MAX_PATH];
|
||||
const DWORD n = game_module_path(exe, MAX_PATH);
|
||||
if (!n || n >= MAX_PATH) return {};
|
||||
return std::filesystem::u8path(std::string(exe, n)).parent_path();
|
||||
}
|
||||
|
||||
PipelineCache::PipelineCache() {
|
||||
// ((Triforce) beside the game's own pipeline caches, triforce_pipelines.bin and the rest: the game folder)
|
||||
const auto root = game_dir();
|
||||
if (!root.empty()) path_ = root / "triforce_reshade_pipelines.bin";
|
||||
std::vector<char> bytes;
|
||||
if (!path_.empty()) {
|
||||
std::ifstream file(path_, std::ios::binary | std::ios::ate);
|
||||
const auto size = file.tellg();
|
||||
if (size > 0 && static_cast<std::streamoff>(size) <= file_limit) {
|
||||
bytes.resize(static_cast<size_t>(size));
|
||||
if (!file.seekg(0).read(bytes.data(), bytes.size()) || !matches_device(bytes)) bytes.clear();
|
||||
}
|
||||
}
|
||||
VkPipelineCacheCreateInfo ci{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO};
|
||||
ci.initialDataSize = bytes.size();
|
||||
ci.pInitialData = bytes.data();
|
||||
if (vkCreatePipelineCache(dev.device, &ci, nullptr, &cache_) != VK_SUCCESS && !bytes.empty()) {
|
||||
ci.initialDataSize = 0;
|
||||
ci.pInitialData = nullptr;
|
||||
(void)vkCreatePipelineCache(dev.device, &ci, nullptr, &cache_);
|
||||
}
|
||||
}
|
||||
|
||||
PipelineCache::~PipelineCache() { if (cache_) vkDestroyPipelineCache(dev.device, cache_, nullptr); }
|
||||
|
||||
void PipelineCache::save() const {
|
||||
if (!cache_ || path_.empty()) return;
|
||||
size_t size = 0;
|
||||
if (vkGetPipelineCacheData(dev.device, cache_, &size, nullptr) != VK_SUCCESS || !size || size > file_limit) return;
|
||||
std::vector<char> bytes(size);
|
||||
if (vkGetPipelineCacheData(dev.device, cache_, &size, bytes.data()) != VK_SUCCESS) return;
|
||||
std::error_code error;
|
||||
std::filesystem::create_directories(path_.parent_path(), error);
|
||||
if (error) return;
|
||||
auto temporary = path_;
|
||||
temporary += "." + std::to_string(GetCurrentProcessId()) + ".tmp";
|
||||
std::ofstream out(temporary, std::ios::binary | std::ios::trunc);
|
||||
out.write(bytes.data(), size);
|
||||
out.close();
|
||||
if (out) {
|
||||
std::filesystem::rename(temporary, path_, error);
|
||||
if (!error) return;
|
||||
}
|
||||
std::filesystem::remove(temporary, error);
|
||||
}
|
||||
|
||||
} // namespace mkwvk::reshade
|
||||
Reference in New Issue
Block a user