mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-22 17:19:58 -04:00
Triforce v0.7.0 "Sage Of Courage"
The 0.6 crashes after warps and area changes fixed (no write-back into memory the capture leaves out), invisible objects fixed (occlusion gate), DLSS frame generation flicker fixed, achievements, the renderer built with a play profile, faster translated game code, helper threads judged on settled scenes, memory, shader preparation, audio effects, launcher, controls and Linux fixes.
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace tex_warm {
|
||||
|
||||
@@ -49,4 +52,109 @@ inline bool ripe(uint64_t noted, uint64_t frame) { return frame >= noted + kAgeF
|
||||
/// Whether the look goes on after a texture: neither the time spent nor the frame's uploads took the budget
|
||||
inline bool goes_on(int64_t spent_ns, int64_t frame_upload_ns) { return spent_ns < kBudgetNs && frame_upload_ns < kBudgetNs; }
|
||||
|
||||
// ---- (Triforce, 11-22, the performance audit's TEX-23, after Source A's) The list of what was drawn ----
|
||||
// Every registered slot made ahead needs the 40% rule above, and on a card of 8 GB that rule stops the warming at once (40% is
|
||||
// about 2.8 GB, below the 4 GB a stand in the lab drew from). Source A keeps a list of the textures a draw used within 90 s of
|
||||
// the game making them, between runs, and makes those ahead with a room of their own: while the textures and 256 MB more fit
|
||||
// their budget. A texture is named in the list by its place: its shape and eight 64-byte samples of its bytes (the signature),
|
||||
// mixed with its storage's address, so that a texture at a new address is not taken for one the list has (it is made at its
|
||||
// draw as before, and learnt then). RX_VK_TEX_WARM_LIST=1: the listed slots first, the others after them while the 40% rule
|
||||
// allows; 2: the listed slots alone; unset or 0: every slot as above. The list is learnt only while it is on. The file is
|
||||
// triforce_textures_drawn.bin beside the game, its own magic and version; one cut short or of another version is not read.
|
||||
inline int list_mode_of(const char* env) {
|
||||
if (!env || !*env) return 0;
|
||||
const int v = std::atoi(env);
|
||||
return v == 1 || v == 2 ? v : 0;
|
||||
}
|
||||
|
||||
inline constexpr int64_t kLearnNs = 90'000'000'000; // (a texture drawn within this of the game making it is learnt)
|
||||
inline constexpr size_t kListMost = 32768; // (places in the list: past it the list starts again)
|
||||
inline constexpr uint64_t kListRoom = 256ull << 20; // (listed textures are made while the textures and this fit their budget)
|
||||
inline constexpr uint64_t kSaveEvery = 300; // (presents between saves of a list that changed)
|
||||
inline constexpr int kSamples = 8;
|
||||
inline constexpr uint64_t kSampleBytes = 64;
|
||||
inline constexpr char kListMagic[8] = {'T', 'F', 'D', 'R', 'A', 'W', 'N', 0};
|
||||
inline constexpr uint32_t kListVersion = 1;
|
||||
|
||||
/// What a texture's signature takes of its shape (its descriptor and its storage's size)
|
||||
struct Shape {
|
||||
uint32_t width, height, depth, levels, format, target, layers;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
/// Whether a texture the game made at born_ns (0: not known) and drawn at now_ns is learnt: within kLearnNs of it
|
||||
inline bool learnable(int64_t born_ns, int64_t now_ns) { return born_ns > 0 && now_ns >= born_ns && now_ns - born_ns <= kLearnNs; }
|
||||
|
||||
/// Where sample i (0 to kSamples - 1) of a storage of `size` bytes starts: spread from its start to its end, 64-byte aligned
|
||||
inline uint64_t sample_at(uint64_t size, int i) {
|
||||
if (size <= kSampleBytes) return 0;
|
||||
return ((size - kSampleBytes) * (uint64_t)i / (kSamples - 1)) & ~(kSampleBytes - 1);
|
||||
}
|
||||
/// How many bytes each sample reads: kSampleBytes, or the whole of a smaller storage
|
||||
inline uint64_t sample_len(uint64_t size) { return size < kSampleBytes ? size : kSampleBytes; }
|
||||
|
||||
/// The signature: the shape and the samples (kSamples * kSampleBytes bytes, sample i at i * kSampleBytes), FNV-1a
|
||||
inline uint64_t signature(const Shape& s, const uint8_t* samples) {
|
||||
uint64_t h = 0xCBF29CE484222325ull;
|
||||
const auto add = [&h](uint64_t v) {
|
||||
for (int i = 0; i < 8; i++) h = (h ^ ((v >> (8 * i)) & 0xFF)) * 1099511628211ull;
|
||||
};
|
||||
add(s.width), add(s.height), add(s.depth), add(s.levels), add(s.format), add(s.target), add(s.layers), add(s.size);
|
||||
for (uint64_t i = 0; i < kSamples * kSampleBytes; i++) h = (h ^ samples[i]) * 1099511628211ull;
|
||||
return h;
|
||||
}
|
||||
/// A signature at a storage address: what the list holds (never 0)
|
||||
inline uint64_t place(uint64_t sig, uint64_t gpu) {
|
||||
uint64_t h = sig ^ (gpu * 0x9E3779B97F4A7C15ull);
|
||||
h ^= h >> 31, h *= 0xBF58476D1CE4E5B9ull, h ^= h >> 29, h *= 0x94D049BB133111EBull, h ^= h >> 32;
|
||||
return h | 1;
|
||||
}
|
||||
/// A place learnt: true when the list changed. A full list (kListMost) starts again, so that it follows what the game draws now
|
||||
inline bool remember(std::unordered_set<uint64_t>& list, uint64_t p) {
|
||||
if (!p || list.count(p)) return false;
|
||||
if (list.size() >= kListMost) list.clear();
|
||||
list.insert(p);
|
||||
return true;
|
||||
}
|
||||
/// Whether a listed texture may be made: the target pool is not being given back (VRAM near the allowance), and the textures
|
||||
/// with kListRoom more fit their budget (0 or all ones: none is set, no room is known)
|
||||
inline bool listed_room(bool pressed, uint64_t texture_bytes, uint64_t budget) {
|
||||
if (pressed || !budget || budget == ~0ull) return false;
|
||||
return texture_bytes <= budget && budget - texture_bytes >= kListRoom;
|
||||
}
|
||||
|
||||
inline uint64_t list_check(const uint8_t* b, size_t n) {
|
||||
uint64_t h = 0xCBF29CE484222325ull;
|
||||
for (size_t i = 0; i < n; i++) h = (h ^ b[i]) * 1099511628211ull;
|
||||
return h;
|
||||
}
|
||||
/// The file's bytes: the magic, the version, the count, the places, and a check of the places
|
||||
inline std::vector<uint8_t> encode(const std::unordered_set<uint64_t>& list) {
|
||||
std::vector<uint8_t> o(16 + list.size() * 8 + 8);
|
||||
const uint32_t head[2] = {kListVersion, (uint32_t)list.size()};
|
||||
std::memcpy(o.data(), kListMagic, 8), std::memcpy(o.data() + 8, head, 8);
|
||||
size_t at = 16;
|
||||
for (const uint64_t p : list) std::memcpy(o.data() + at, &p, 8), at += 8;
|
||||
const uint64_t check = list_check(o.data() + 16, list.size() * 8);
|
||||
std::memcpy(o.data() + at, &check, 8);
|
||||
return o;
|
||||
}
|
||||
/// The places of a file's bytes into `out`; false, and `out` left empty, for anything that is not a whole file of this version
|
||||
inline bool decode(const uint8_t* b, size_t n, std::unordered_set<uint64_t>& out) {
|
||||
out.clear();
|
||||
if (!b || n < 24 || std::memcmp(b, kListMagic, 8)) return false;
|
||||
uint32_t head[2];
|
||||
std::memcpy(head, b + 8, 8);
|
||||
if (head[0] != kListVersion || head[1] > kListMost || n != 16 + (size_t)head[1] * 8 + 8) return false;
|
||||
uint64_t check;
|
||||
std::memcpy(&check, b + n - 8, 8);
|
||||
if (check != list_check(b + 16, (size_t)head[1] * 8)) return false;
|
||||
for (uint32_t i = 0; i < head[1]; i++) {
|
||||
uint64_t p;
|
||||
std::memcpy(&p, b + 16 + (size_t)i * 8, 8);
|
||||
if (p) out.insert(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace tex_warm
|
||||
|
||||
Reference in New Issue
Block a user