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:
@@ -10,12 +10,21 @@
|
||||
A knob named d_<site> is a delay: a busy wait of <value> microseconds at that site, at most once a frame (delay(), below):
|
||||
what the frame's time answers to a part of it taking longer, which is whether that part is on the frame's critical path
|
||||
(1 ms in for 1 ms of delay) or has slack (nothing). Any other name is a switch the code reads with on("<name>").
|
||||
(Triforce, 11-22, the performance audit's REPLAY-51, after Source B's) A knob named e_<event> is a delay at every
|
||||
occurrence of an event, not once a frame: a busy wait of <value> NANOseconds at each draw (e_draw) or dispatch
|
||||
(e_dispatch), first in vk_draw.cpp's draw() and dispatch() so that the profiles leave it out, on whichever thread
|
||||
records, counted (each(), below). The frame's change against the time spun says how much of that path is on the frame's
|
||||
critical path: 200 ns at ~3,050 draws a frame is 0.6 ms of work. One line a phase gives each knob's spins and ms a second
|
||||
(each_report). d_present_after is d_present's after: the same wait just after the present's drain(0), where d_present is
|
||||
just before it. Pin RX_VK_PARALLEL for e_ knobs: Automatic moves draws between threads (the replay warns).
|
||||
Not for players: nothing reads these without the variable. */
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
@@ -32,6 +41,17 @@ inline std::atomic<uint64_t> frame_no{0}; // (presents counted here)
|
||||
inline std::atomic<uint64_t> fired[16]; // (the frame each delay last waited in)
|
||||
inline std::atomic<uint32_t> pres_thread{0}; // (the thread that presents: the game's Presentation thread, in the plain mode)
|
||||
inline int64_t phase_frames = 300, skip_frames = 30;
|
||||
// ((Triforce, 11-22, REPLAY-51) the e_ knobs: each event's wait in this phase (ns, 0: none), and what was spun)
|
||||
enum Each { E_DRAW = 0, E_DISPATCH = 1, E_COUNT = 2 };
|
||||
inline const char* const each_names[E_COUNT] = {"e_draw", "e_dispatch"};
|
||||
inline std::atomic<int64_t> each_ns[E_COUNT];
|
||||
inline std::atomic<uint64_t> each_spins[E_COUNT], each_spun_ns[E_COUNT];
|
||||
struct EachPhase { // (the presenting thread's: the phase being counted)
|
||||
int knob = 0;
|
||||
std::chrono::steady_clock::time_point since{};
|
||||
};
|
||||
inline EachPhase each_phase;
|
||||
inline char each_line[256]; // (the line of a phase just over, for the replay to log; empty: none)
|
||||
|
||||
inline void init() {
|
||||
if (n_knobs >= 0) return;
|
||||
@@ -53,6 +73,53 @@ inline void init() {
|
||||
if (const char* s = getenv("RX_VK_LAB_AB_SKIP")) skip_frames = atoll(s);
|
||||
n_knobs = n;
|
||||
}
|
||||
/// ((Triforce, 11-22, REPLAY-51) Whether any knob is an e_ one (the replay warns once unless RX_VK_PARALLEL is pinned)
|
||||
inline bool any_each() {
|
||||
for (int i = 0; i < n_knobs; i++)
|
||||
for (const char* name : each_names)
|
||||
if (!strcmp(knobs[i].name, name)) return true;
|
||||
return false;
|
||||
}
|
||||
/// (phase_tick, the presenting thread) The phase is knob k (0: none): at a change, the line of the phase that ended (each_line,
|
||||
/// when it had an e_ knob: its spins and ms a second), and the events' waits for this one
|
||||
inline void each_tick(int k) {
|
||||
if (k == each_phase.knob && each_phase.since.time_since_epoch().count()) return;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
each_line[0] = 0;
|
||||
const int was = each_phase.knob;
|
||||
if (was > 0 && each_phase.since.time_since_epoch().count()) {
|
||||
const double s = std::chrono::duration<double>(now - each_phase.since).count();
|
||||
for (int e = 0; e < E_COUNT; e++) {
|
||||
if (strcmp(knobs[was - 1].name, each_names[e])) continue;
|
||||
const uint64_t spins = each_spins[e].exchange(0, std::memory_order_relaxed);
|
||||
const uint64_t ns = each_spun_ns[e].exchange(0, std::memory_order_relaxed);
|
||||
snprintf(each_line, sizeof each_line, "vk: lab A/B: phase %s:%lld over: %.0f waits a second, %.2f ms a second spun "
|
||||
"(%llu waits in %.1f s)", each_names[e], (long long)knobs[was - 1].value, s > 0 ? spins / s : 0.0,
|
||||
s > 0 ? ns / 1e6 / s : 0.0, (unsigned long long)spins, s);
|
||||
}
|
||||
}
|
||||
for (int e = 0; e < E_COUNT; e++)
|
||||
each_ns[e].store(k > 0 && !strcmp(knobs[k - 1].name, each_names[e]) ? std::max<int64_t>(0, knobs[k - 1].value) : 0,
|
||||
std::memory_order_relaxed);
|
||||
each_phase.knob = k, each_phase.since = now;
|
||||
}
|
||||
/// At every occurrence of an event (first in draw() and dispatch()): one relaxed load without its knob; with it, a busy wait
|
||||
/// of the knob's nanoseconds, counted
|
||||
inline void each(int event) {
|
||||
const int64_t ns = each_ns[event].load(std::memory_order_relaxed);
|
||||
if (!ns) return;
|
||||
const auto t0 = std::chrono::steady_clock::now(), until = t0 + std::chrono::nanoseconds(ns);
|
||||
auto now = t0;
|
||||
while (now < until) {
|
||||
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
|
||||
__builtin_ia32_pause();
|
||||
#endif
|
||||
now = std::chrono::steady_clock::now();
|
||||
}
|
||||
each_spins[event].fetch_add(1, std::memory_order_relaxed);
|
||||
each_spun_ns[event].fetch_add((uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now - t0).count(),
|
||||
std::memory_order_relaxed);
|
||||
}
|
||||
/// Once a present, on the presenting thread: the phase this frame belongs to (the trace's column)
|
||||
inline int phase_tick() {
|
||||
init();
|
||||
@@ -61,6 +128,7 @@ inline int phase_tick() {
|
||||
const uint64_t phase = f / (uint64_t)phase_frames; // (0 none, 1 knob 1, 2 none, 3 knob 2, ...)
|
||||
const int k = (phase & 1) ? (int)((phase / 2) % (uint64_t)n_knobs) + 1 : 0;
|
||||
active.store(k, std::memory_order_relaxed);
|
||||
each_tick(k); // ((Triforce, 11-22, REPLAY-51) the e_ knobs' waits for this phase, and the line of the one before)
|
||||
const bool settling = (int64_t)(f % (uint64_t)phase_frames) < skip_frames;
|
||||
return settling ? -(k + 1) : k; // (-1: none, settling; -(k + 1): knob k, settling)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user