Triforce v0.9.0

Character tab, faster renderer defaults, HD rumble shipped, and the 11-30 bug pass: ending softlock below 60 fps, adult first-night lock, Intel Arc robust buffers, adult map, randomizer load order.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-30 20:55:14 -06:00
parent 8cb23131f9
commit 822ee913bc
86 changed files with 8128 additions and 438 deletions

View File

@@ -54,6 +54,7 @@
#include <mutex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "capture_tables.h" // ((Triforce, the upscaler audit's UPS-02) the stored draws' tables, kept from frame to frame)
@@ -384,6 +385,8 @@ struct State {
bool own = false;
bool placed = false; // ((Triforce) a skinned draw's place, read at its draw (note_skinned_place): pair_copies)
float place[3]{};
bool origin_ok = false; // ((Triforce) not skinned: its object's origin as read at the draw, its place if its model has copies)
float origin[3]{};
};
// (the camera read last for a stored draw, most draws of a frame having the same one)
uint64_t capture_camera = 0, capture_camera_view = 0;
@@ -397,6 +400,10 @@ struct State {
const bool capture_tables_kept = capture_tables::kept(getenv("RX_VK_CAPTURE_TABLES"));
capture_tables::Nth captured_models{capture_tables_kept}; // (by model: its draws so far this frame, for the key's nth)
capture_tables::Before<Captured> captured_before{capture_tables_kept};
// ((Triforce) the models drawn 2+ times this frame and the frame before (copies: their object's origin is read at the draw),
// and where in `captured` each model's first draw is (read once its second shows up))
std::unordered_set<uint64_t> multi_now, multi_before;
std::unordered_map<uint64_t, size_t> capture_first;
uint64_t captured_frame = 0;
struct CaptureBuffer {
VkBuffer buffer = VK_NULL_HANDLE;
@@ -756,6 +763,19 @@ bool place_pairing() {
return on;
}
/// (Triforce) Copies without a place (not skinned: trees, rocks, pieces of ground) of a model drawn more than once get the
/// camera's motion (capture_motion, dlss_actor::unsure_copies): by their n-th draw, one took its neighbour's positions as its
/// own frame before whenever the game drew them in another order, and frame generation drew it part way to the neighbour.
/// RX_VK_DLSS_COPY_ORDER=1: by their n-th draw, as before
bool copy_order() {
static const bool on = [] {
const bool v = env_switch("RX_VK_DLSS_COPY_ORDER") > 0;
if (v) logf("vk: actor motion: copies without a place pair by draw order (RX_VK_DLSS_COPY_ORDER=1)");
return v;
}();
return on;
}
/// This upscale's reach (dlss_actor::place_reach), the time since the last one's taken
float pairs_reach(State& s) {
static const float speed = [] {
@@ -777,13 +797,17 @@ float pairs_reach(State& s) {
/// Which of the frame before's draws each of this frame's pairs with. keys[i]: this frame's draw's key (dlss_actor::key),
/// placed[i] and places[i * 3]: its place when it has one (left out: not of the scene's depth, so not paired); then: the
/// frame before's draws with a place. Out: look[i], the frame before's key to take (has[i] 0: none, the camera's motion)
/// frame before's draws with a place. Out: look[i], the frame before's key to take (has[i] 0: none, the camera's motion).
/// by_origin[i]: its place is its object's origin (not skinned): unsure[i] is then set when its pair is not a sure one
/// (dlss_actor::ambiguous_by_place), or its model had no copy with a place the frame before (nothing to pair by): the camera's
/// motion for it, as for any copy without a place of a model with copies
void pair_copies(const std::vector<uint64_t>& keys, const std::vector<char>& placed, const std::vector<float>& places,
const std::vector<State::PlacedBefore>& then, float reach, std::vector<uint64_t>& look,
std::vector<char>& has) {
const std::vector<char>& by_origin, const std::vector<State::PlacedBefore>& then, float reach,
std::vector<uint64_t>& look, std::vector<char>& has, std::vector<char>& unsure) {
const size_t n = keys.size();
look.assign(keys.begin(), keys.end());
has.assign(n, 1);
unsure.assign(n, 0);
if (!place_pairing()) return;
struct Copies {
std::vector<dlss_actor::Placed> now, then;
@@ -796,7 +820,10 @@ void pair_copies(const std::vector<uint64_t>& keys, const std::vector<char>& pla
c.then.push_back({{p.place[0], p.place[1], p.place[2]}, (int)(p.key & 0xff)});
c.key.push_back(p.key);
}
if (models.empty()) return; // (none had a place the frame before: by draw order, as before)
if (models.empty()) { // (none had a place the frame before: by draw order, as before)
for (size_t i = 0; i < n; i++) unsure[i] = placed[i] && by_origin[i];
return;
}
std::vector<char> decided(n, 0);
std::vector<uint64_t> by_place(n, 0);
std::vector<char> paired(n, 0);
@@ -804,7 +831,10 @@ void pair_copies(const std::vector<uint64_t>& keys, const std::vector<char>& pla
for (size_t i = 0; i < n; i++) {
if (!placed[i]) continue;
const auto m = models.find(keys[i] >> 8);
if (m == models.end()) continue; // (its model had no copy with a place the frame before: by its n-th)
if (m == models.end()) { // (its model had no copy with a place the frame before: by its n-th, a guess for a copy by origin)
unsure[i] = by_origin[i];
continue;
}
m->second.now.push_back({{places[i * 3], places[i * 3 + 1], places[i * 3 + 2]}, (int)(keys[i] & 0xff)});
m->second.draw.push_back(i);
decided[i] = 1;
@@ -812,6 +842,9 @@ void pair_copies(const std::vector<uint64_t>& keys, const std::vector<char>& pla
for (const auto& [model, c] : models) {
if (c.now.empty()) continue;
const std::vector<int> pairs = dlss_actor::pair_by_place(c.now, c.then, reach);
const std::vector<char> doubtful = dlss_actor::ambiguous_by_place(c.now, c.then, pairs);
for (size_t a = 0; a < pairs.size(); a++)
if (by_origin[c.draw[a]] && doubtful[a]) unsure[c.draw[a]] = 1;
for (size_t a = 0; a < pairs.size(); a++)
if (pairs[a] >= 0) by_place[c.draw[a]] = c.key[pairs[a]], paired[c.draw[a]] = 1, taken[c.key[pairs[a]]] = 1;
}
@@ -1062,7 +1095,8 @@ int actor_motion(VkCommandBuffer cmd, const Camera& cam, const float* before, co
dlss_actor::place_of(k.pose.data(), k.pose.data() + dlss_actor::kPoseHead, k.nbones, &places[i * 3]);
placed[i] = 1;
}
pair_copies(keys, placed, places, then, pairs_reach(s), look, has);
std::vector<char> no_origin(skins.size(), 0), no_unsure; // (skinned: every place is a pose's, never unsure)
pair_copies(keys, placed, places, no_origin, then, pairs_reach(s), look, has, no_unsure);
for (size_t i = 0; i < skins.size(); i++) {
const State::Skin& k = skins[i];
if (k.k.depth != cam.depth) {
@@ -1163,7 +1197,8 @@ constexpr uint32_t kCaptureMostSlots = 1u << 20; // (a draw's)
std::vector<State::Captured> take_captures() {
State& s = st();
std::vector<State::Captured> c = std::move(s.captured);
s.captured.clear(), s.captured_models.clear();
s.captured.clear(), s.captured_models.clear(), s.capture_first.clear();
s.multi_before.swap(s.multi_now), s.multi_now.clear();
// ((Triforce, UPS-02) the next frame's list at this frame's size from its start: moved from, it grew from nothing again
// every frame, a dozen times over)
s.captured.reserve(capture_tables::room(c.size(), s.capture_tables_kept));
@@ -1209,20 +1244,60 @@ int capture_motion(VkCommandBuffer cmd, const Camera& cam, const float* before,
if (c.k.depth == cam.depth) s.captured_before.put(c.key, c);
// ((Triforce) which of the frame before's each pairs with: copies of a skinned model by place, pair_copies)
std::vector<uint64_t> keys(caps.size()), look;
std::vector<char> placed(caps.size(), 0), has;
std::vector<char> placed(caps.size(), 0), has, by_origin(caps.size(), 0), origin_unsure;
std::vector<float> places(caps.size() * 3, 0.0f);
std::vector<State::PlacedBefore> then;
if (old_ok) then = std::move(s.placed_before);
s.placed_before.clear();
// ((Triforce) the copies without a skin, of a model with copies (drawn 2+ times this frame, or its 2nd the frame before),
// whose object's origin was read are placed by it. A model drawn once keeps its own pairing: it may move fast)
const bool by_place = !copy_order(); // (recorded also without history: the next frame pairs by it)
std::vector<char> origin_set(caps.size(), 0);
if (by_place) {
std::vector<uint64_t> scene_keys;
std::vector<char> readable;
std::vector<size_t> scene_at;
for (size_t i = 0; i < caps.size(); i++)
if (caps[i].k.depth == cam.depth && !caps[i].placed)
scene_keys.push_back(caps[i].key), readable.push_back(caps[i].origin_ok), scene_at.push_back(i);
const std::vector<char> w = dlss_actor::place_by_origin(
scene_keys, readable, [&](uint64_t k) { return s.captured_before.before(k) != nullptr; });
for (size_t j = 0; j < w.size(); j++) origin_set[scene_at[j]] = w[j];
}
for (size_t i = 0; i < caps.size(); i++) {
const State::Captured& c = caps[i];
keys[i] = c.key;
if (c.k.depth != cam.depth || !c.placed) continue;
placed[i] = 1;
for (int a = 0; a < 3; a++) places[i * 3 + a] = c.place[a];
s.placed_before.push_back({c.key, {c.place[0], c.place[1], c.place[2]}});
if (c.k.depth != cam.depth) continue;
if (c.placed) {
placed[i] = 1;
for (int a = 0; a < 3; a++) places[i * 3 + a] = c.place[a];
} else if (origin_set[i]) {
placed[i] = by_origin[i] = 1;
for (int a = 0; a < 3; a++) places[i * 3 + a] = c.origin[a];
}
if (placed[i]) s.placed_before.push_back({c.key, {places[i * 3], places[i * 3 + 1], places[i * 3 + 2]}});
}
pair_copies(keys, placed, places, by_origin, then, pairs_reach(s), look, has, origin_unsure);
// ((Triforce) a copy without a place of a model drawn more than once: its n-th the frame before is a guess, the camera's
// motion instead. dlss_actor::unsure_copies)
std::vector<char> unsure(caps.size(), 0);
if (old_ok && !copy_order()) {
std::vector<uint64_t> scene_keys;
std::vector<char> scene_placed;
std::vector<size_t> scene_at;
for (size_t i = 0; i < caps.size(); i++)
if (caps[i].k.depth == cam.depth)
scene_keys.push_back(keys[i]), scene_placed.push_back(placed[i]), scene_at.push_back(i);
const std::vector<char> u = dlss_actor::unsure_copies(
scene_keys, scene_placed, [&](uint64_t k) { return s.captured_before.before(k) != nullptr; });
for (size_t j = 0; j < u.size(); j++) unsure[scene_at[j]] = u[j];
std::unordered_set<uint64_t> then_keys;
for (const auto& p : then) then_keys.insert(p.key);
const std::vector<char> lost = dlss_actor::lost_second_copy(
keys, by_origin, [&](uint64_t k) { return s.captured_before.before(k) != nullptr; },
[&](uint64_t k) { return then_keys.count(k) != 0; });
for (size_t i = 0; i < caps.size(); i++) unsure[i] = unsure[i] || origin_unsure[i] || lost[i];
}
pair_copies(keys, placed, places, then, pairs_reach(s), look, has);
// (RX_VK_DLSS_TRACE=<frames>: on vk_draw.cpp's traced frames, each stored draw left out here and why)
static const int trace_every = env_switch("RX_VK_DLSS_TRACE");
const uint64_t now = texture_frame_no();
@@ -1231,6 +1306,37 @@ int capture_motion(VkCommandBuffer cmd, const Camera& cam, const float* before,
if (trace) logf("vk: dlss-trace capture left out: prog %016llx vb %llx ib %llx n%d: %s", (unsigned long long)c.k.program,
(unsigned long long)c.k.vbuf, (unsigned long long)c.k.ibuf, c.k.count, why);
};
// (RX_VK_DLSS_TRACE: the 8 models with most copies placed by their object's origin: whether that origin is a place. key>>8,
// copies, how many differ, how many are flagged (unsure), the least and greatest distance between two of them)
if (trace && by_place) {
struct Group {
uint64_t model;
std::vector<dlss_actor::Placed> at;
int flagged = 0;
};
std::unordered_map<uint64_t, size_t> index;
std::vector<Group> groups;
for (size_t i = 0; i < caps.size(); i++) {
if (caps[i].k.depth != cam.depth || caps[i].placed || !caps[i].origin_ok) continue; // (by origin, or over the cap)
const auto it = index.emplace(keys[i] >> 8, groups.size());
if (it.second) groups.push_back({keys[i] >> 8, {}, 0});
Group& g = groups[it.first->second];
g.at.push_back({{caps[i].origin[0], caps[i].origin[1], caps[i].origin[2]}, (int)(keys[i] & 0xff)});
g.flagged += old_ok && unsure[i];
}
std::sort(groups.begin(), groups.end(), [](const Group& a, const Group& b) { return a.at.size() > b.at.size(); });
for (size_t g = 0; g < groups.size() && g < 8; g++) {
const bool over = groups[g].at.size() > dlss_actor::kCopyCap; // (not paired by place: all flagged, nothing measured)
const dlss_actor::Spread sp = over ? dlss_actor::Spread{} : dlss_actor::origin_spread(groups[g].at);
if (over)
logf("vk: dlss-trace f%llu copy origins: model %llx copies %zu over cap (camera motion for all)%s", (unsigned long long)now,
(unsigned long long)groups[g].model, groups[g].at.size(), old_ok ? "" : " (no history)");
else
logf("vk: dlss-trace f%llu copy origins: model %llx copies %zu distinct %d flagged %d gap min %g max %g%s",
(unsigned long long)now, (unsigned long long)groups[g].model, groups[g].at.size(), sp.distinct, groups[g].flagged,
(double)sp.min_gap, (double)sp.max_gap, old_ok ? "" : " (no history)");
}
}
if (caps.empty() || !make_capture_pipeline()) return 0;
struct Redraw {
dlss_actor::CapturePush push;
@@ -1245,6 +1351,11 @@ int capture_motion(VkCommandBuffer cmd, const Camera& cam, const float* before,
left(c, "another depth target than the scene's");
continue;
}
if (unsure[i]) {
s.actor_skipped++;
left(c, "a copy of a model drawn more than once, with no place to pair by");
continue;
}
const State::Captured* const was = old_ok && has[i] ? s.captured_before.before(look[i]) : nullptr;
if (!was) {
s.actor_skipped++;
@@ -1450,6 +1561,7 @@ void drop_all() {
}
s.poses.clear(), s.skins.clear(), s.model_bones.clear();
s.captured.clear(), s.captured_models.clear(), s.captured_before.clear(), s.index_ranges.clear();
s.capture_first.clear(), s.multi_now.clear(), s.multi_before.clear();
s.capture_used = 0, s.captured_frame = 0;
if (!s.depth_views.empty()) {
auto old = std::move(s.depth_views);
@@ -1827,7 +1939,7 @@ void temporal_capture_draw(const CaptureDraw& k, CaptureSlot* out) {
// buffer given out again. Left to pile up, the buffer ran out there, and was made twice as large for nothing)
const uint64_t frame = texture_frame_no();
if (frame > s.capture_frame + 1 || s.captured.size() >= 32768) {
s.captured.clear(), s.captured_models.clear();
s.captured.clear(), s.captured_models.clear(), s.capture_first.clear(), s.multi_now.clear(), s.multi_before.clear();
s.capture_used = 0, s.capture_full = false;
}
if (s.captured.empty()) s.capture_frame = frame;
@@ -1888,6 +2000,34 @@ void temporal_capture_draw(const CaptureDraw& k, CaptureSlot* out) {
c.placed = true;
for (int a = 0; a < 3; a++) c.place[a] = skin_place.place[a];
}
// ((Triforce) a draw without a skin: its object's place (buffer 4: a 3x4 row-major world matrix, the translation at +0x0c,
// +0x1c, +0x2c; dlss_actor::object_place; the skinned draws' origin at 0x40 is not it), the place of one of the
// copies of its model (capture_motion decides which are). Read only for a model that has copies: its 2nd or later draw, or
// its 1st when it had a 2nd the frame before; its 1st otherwise is read when its 2nd shows up. Read as submitted; not
// readable or not a world matrix: none, and its copies then go by unsure_copies as before)
if (!placed && place_pairing() && !copy_order()) {
const auto read_origin = [](State::Captured& d) {
float m[12], o[3];
if (d.k.object && d.k.object_size >= 0x30 && memory_read_as_submitted(d.k.object, m, sizeof m) &&
dlss_actor::object_place(m, o)) {
d.origin_ok = true;
for (int a = 0; a < 3; a++) d.origin[a] = o[a];
}
};
const uint64_t group = c.key >> 8;
if (nth == 0) {
s.capture_first[group] = s.captured.size(); // (c's place in captured, pushed below)
if (s.multi_before.count(group)) read_origin(c);
} else {
s.multi_now.insert(group);
read_origin(c);
const auto first = nth == 1 ? s.capture_first.find(group) : s.capture_first.end();
if (first != s.capture_first.end() && first->second < s.captured.size()) {
State::Captured& f = s.captured[first->second];
if (f.key >> 8 == group && !f.placed && !f.origin_ok) read_origin(f);
}
}
}
// (the jitter of the camera it is drawn with, as submitted: read again when the address or the captures' view changes)
if (k.camera && k.camera_size >= 0xb0) {
const uint64_t view = memory_capture_view();