mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5.2
Hotfix: the brightness flashes fixed without the fps cost (the readback wait only for ranges the CPU resets), and the Discord status names where Link is by default.
This commit is contained in:
@@ -144,6 +144,8 @@ bool mesh_ahead_enabled(); // (Triforce, vk_draw.cpp: RX_VK_MESH_AHEAD, mesh_a
|
||||
struct CondNote { int64_t present; uint64_t addr, x, y; int mode; bool on; }; // (the last render conditions, for a dark frame)
|
||||
CondNote cond_ring[1 << 15];
|
||||
uint32_t cond_ring_at = 0;
|
||||
void memory_part_submitted(uint64_t seq); // ((Triforce, 11-28) vk_memory.cpp: a part's batch of write-backs by its number
|
||||
uint64_t memory_wb_part_seq(uint64_t guest, uint64_t size, uint64_t value); // (and the part that wrote a range back)
|
||||
namespace {
|
||||
|
||||
// ---- submissions: a timeline semaphore; value n = the n-th submit done ----
|
||||
@@ -167,6 +169,22 @@ std::map<uint64_t, uint64_t> value_rec; // submission value (or a recording'
|
||||
// ((Triforce, 11-27) the recordings by their own value, the value their write-backs are noted under: the newest part submitted and
|
||||
// whether it ended the recording, for a readback's wait (readback_rec_wait; wb_rec_wait.h Parts). rec_map_mu)
|
||||
::mkwvk::wb_rec_wait::Parts rec_parts_by_value;
|
||||
/// ((Triforce, 11-28) the early tail's two notes for the readbacks (wb_rec_wait.h Parts::Entry scene_seq): passed false, the tail
|
||||
/// began after the part just submitted (tail_begin); true, it passed its verdict (tail_end). RX_VK_RB_TAIL=0: not noted, the
|
||||
/// readbacks wait for the tail's end as 0.8.5 did
|
||||
void rb_tail_note(uint64_t value, bool passed) {
|
||||
static const bool on = [] {
|
||||
const char* e = getenv("RX_VK_RB_TAIL");
|
||||
const bool v = !(e && *e && atoi(e) == 0);
|
||||
logf("vk: a readback after an early tail that passed waits for %s (RX_VK_RB_TAIL%s)",
|
||||
v ? "the scene's part, not the tail's end" : "the tail's end", v ? "=0: the tail's end" : "=0");
|
||||
return v;
|
||||
}();
|
||||
if (!on || !value) return;
|
||||
std::lock_guard mk(rec_map_mu);
|
||||
if (passed) rec_parts_by_value.tail_passed(value);
|
||||
else rec_parts_by_value.tail_began(value);
|
||||
}
|
||||
std::unordered_map<uint64_t, uint64_t> q_last; // queue -> its last submission's value (sync_order_mu)
|
||||
std::map<uint64_t, uint64_t> value_queue; // a submission's value -> its queue (sync_order_mu)
|
||||
std::atomic<uint64_t> pushed{0};
|
||||
@@ -1852,6 +1870,7 @@ void submit_recording(Recording& r, bool signal_value = true, uint64_t signal_at
|
||||
// queue. rec_map_mu takes no other lock inside it)
|
||||
const auto register_recording = [&] {
|
||||
if (!seq) return;
|
||||
memory_part_submitted(seq); // ((Triforce, 11-28) this part's batch of write-backs, by its number: before rec_map_mu)
|
||||
std::lock_guard mk(rec_map_mu);
|
||||
// (upstream #2419, behind RX_VK_REC_LAST: a submission recorded in parts maps its value to its LAST part. emplace keeps
|
||||
// the first, and a wait for the submission through wait_recorded comes back after its first part)
|
||||
@@ -3802,7 +3821,9 @@ void tail_begin(VkCommandBuffer& cmd) {
|
||||
texture_end_recording(cmd);
|
||||
memory_end_submission(cmd);
|
||||
full_barrier(cmd, "barrier (recording end)");
|
||||
const uint64_t scene_value = rec_cur->value;
|
||||
submit_recording(*rec_cur, false, 0, true); // (a part)
|
||||
rb_tail_note(scene_value, false); // ((Triforce, 11-28) the scene's part, for the readbacks: wb_rec_wait.h scene_seq)
|
||||
ub_first_of_recording = ub_here;
|
||||
Recording& r = begin_recording(rec_cur_value);
|
||||
memory_begin_submission();
|
||||
@@ -3892,6 +3913,7 @@ void tail_end(Recording& r, const tail_early::Seen& seen, bool baked) {
|
||||
tail_stats();
|
||||
if (why == tail_early::EARLY) {
|
||||
tl.early = true;
|
||||
rb_tail_note(r.value, true); // ((Triforce, 11-28) it wrote nothing the game reads: readbacks stop at the scene's part)
|
||||
return;
|
||||
}
|
||||
tl.words.clear();
|
||||
@@ -6194,23 +6216,47 @@ bool wait_recorded(uint64_t f, uint64_t timeout_ns, int* ok) {
|
||||
/// ((Triforce, 11-27) RX_VK_RB_REC_END: a readback's wait for its write-back ends at the LAST part of the recording that writes it
|
||||
/// back, not the first (wb_rec_wait.h readback_wait: the exposure meter read as 0 between a recording's parts, the brightness
|
||||
/// flashes). On unless =0, read once
|
||||
bool rb_rec_end_on() {
|
||||
static const bool v = [] {
|
||||
const bool on = ::mkwvk::wb_rec_wait::rec_end_on(getenv("RX_VK_RB_REC_END"));
|
||||
logf("vk: a readback waits for %s (RX_VK_RB_REC_END%s)",
|
||||
on ? "the last part of the recording that writes it back" : "the first part of the recording that writes it back, as before",
|
||||
on ? "=0 or unset: the first part, as before" : "=1: the last part; 0.8.5.1: off by default, its ~5 ms reads");
|
||||
return on;
|
||||
int rb_rec_end_mode() {
|
||||
static const int v = [] {
|
||||
namespace wr = ::mkwvk::wb_rec_wait;
|
||||
const int m = wr::rec_end_mode(getenv("RX_VK_RB_REC_END"));
|
||||
logf("vk: a readback waits for %s (RX_VK_RB_REC_END=%d; =0: the first part, as before; =1: the last part, every readback, "
|
||||
"as 0.8.5; =2, the default: the last part where the CPU writes the range after reading it)",
|
||||
m == wr::kRecEndAll ? "the last part of the recording that writes it back"
|
||||
: m == wr::kRecEndCpuWritten ? "the last part of the recording that writes it back where the CPU writes the range, else the first part"
|
||||
: "the first part of the recording that writes it back, as before",
|
||||
m);
|
||||
return m;
|
||||
}();
|
||||
return v;
|
||||
}
|
||||
bool rb_rec_end_on() { return rb_rec_end_mode() != ::mkwvk::wb_rec_wait::kRecEndOff; }
|
||||
std::atomic<int64_t> st_rb_cpu_ranges{0}; // ((Triforce, 11-28) readbacks the last-part rule took, the CPU writing their range)
|
||||
/// ((Triforce, 11-28) whether this readback takes the last-part rule (wb_rec_wait.h rec_end_applies)
|
||||
bool rb_rec_end_for(uint64_t guest, uint64_t size) {
|
||||
namespace wr = ::mkwvk::wb_rec_wait;
|
||||
const int m = rb_rec_end_mode();
|
||||
const bool cpu = m == wr::kRecEndCpuWritten && memory_rb_cpu_written(guest, size);
|
||||
if (cpu) {
|
||||
st_rb_cpu_ranges.fetch_add(1, std::memory_order_relaxed);
|
||||
static std::mutex lm;
|
||||
static std::unordered_set<uint64_t> told; // (the first 24 ranges that took it, once each)
|
||||
std::lock_guard lk(lm);
|
||||
if (told.size() < 24 && told.insert(guest).second)
|
||||
logf("vk: readback %#llx +%#llx: the CPU writes it after reading it: it waits for its writer's last part (RX_VK_RB_REC_END=2)",
|
||||
(unsigned long long)guest, (unsigned long long)size);
|
||||
}
|
||||
return wr::rec_end_applies(m, cpu);
|
||||
}
|
||||
std::atomic<int64_t> st_rb_went_on{0}, st_rb_went_on_ns{0}; // ((Triforce, 11-27) readbacks whose writer's recording went on past a part)
|
||||
/// ((Triforce, 11-27) A readback's wait for write-back value v on the recordings' timeline, by the rule (rb_rec_end_on): true when
|
||||
/// the writer's recording is known (the result in *ok, as wait_recorded), false when it is not (the caller's fallback)
|
||||
bool readback_rec_wait(uint64_t v, int* ok) {
|
||||
bool readback_rec_wait(uint64_t v, uint64_t guest, uint64_t size, int* ok) {
|
||||
if (!rec_timeline || per_queue_fences_off()) return false;
|
||||
struct Calls {
|
||||
uint64_t v;
|
||||
uint64_t v, guest, size;
|
||||
// ((Triforce, 11-28) the part whose write-back last covered the read's range (vk_memory.cpp), for an early tail's reads
|
||||
uint64_t range_seq() { return memory_wb_part_seq(guest, size, v); }
|
||||
uint64_t first_part() {
|
||||
std::lock_guard mk(rec_map_mu);
|
||||
const auto it = value_rec.find(v);
|
||||
@@ -6245,10 +6291,28 @@ bool readback_rec_wait(uint64_t v, int* ok) {
|
||||
const VkResult res = vkWaitSemaphores(dev.device, &wi, ::mkwvk::wb_rec_wait::kSliceNs);
|
||||
return res == VK_SUCCESS ? 0 : res == VK_TIMEOUT ? 1 : 2;
|
||||
}
|
||||
} calls{v};
|
||||
} calls{v, guest, size};
|
||||
GpuWaitTimer gwt("readback_rec_wait", v);
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
// ((Triforce, 11-28, diagnostic) RX_VK_LOG_RB_RANGE=1: the first 60 waits past a part, with the recording's entry and the
|
||||
// range's part before and after, and what ended them)
|
||||
static const bool rb_log = getenv("RX_VK_LOG_RB_RANGE") != nullptr;
|
||||
const ::mkwvk::wb_rec_wait::Parts::Entry e0 = rb_log ? calls.look() : ::mkwvk::wb_rec_wait::Parts::Entry{};
|
||||
const uint64_t rs0 = rb_log ? calls.range_seq() : 0;
|
||||
const ::mkwvk::wb_rec_wait::ReadbackWait r = ::mkwvk::wb_rec_wait::readback_wait(rb_rec_end_on(), calls);
|
||||
if (rb_log && r.went_on) {
|
||||
static std::atomic<int> told{0};
|
||||
if (told.fetch_add(1) < 60) {
|
||||
const ::mkwvk::wb_rec_wait::Parts::Entry e1 = calls.look();
|
||||
logf("vk: rb range: v %llu %#llx +%#llx: at the read part %llu ended %d scene_part %llu scene_seq %llu range %llu; "
|
||||
"after %.2f ms part %llu ended %d scene_part %llu scene_seq %llu range %llu, slices %lld",
|
||||
(unsigned long long)v, (unsigned long long)guest, (unsigned long long)size, (unsigned long long)e0.seq,
|
||||
(int)e0.ended, (unsigned long long)e0.scene_part, (unsigned long long)e0.scene_seq, (unsigned long long)rs0,
|
||||
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count(), (unsigned long long)e1.seq,
|
||||
(int)e1.ended, (unsigned long long)e1.scene_part, (unsigned long long)e1.scene_seq,
|
||||
(unsigned long long)calls.range_seq(), (long long)r.slices);
|
||||
}
|
||||
}
|
||||
if (!r.known) return false;
|
||||
*ok = r.ok ? 1 : 0;
|
||||
if (r.went_on)
|
||||
@@ -6261,8 +6325,8 @@ bool readback_rec_wait(uint64_t v, int* ok) {
|
||||
// by a hash of its control flow (if, ?:, !, &&, ||), and an `if` or `?:` added in invalidate (or `!` in submit_recording's
|
||||
// note) left both at plain -O2, invalidate's ~460,000 calls a benchmark run among them. A call in place of a call keeps it.
|
||||
/// A readback's wait on the recordings' timeline: by the rule (readback_rec_wait), or the first part as before (wait_recorded)
|
||||
bool readback_recorded_wait(uint64_t v, int* ok) {
|
||||
return rb_rec_end_on() ? readback_rec_wait(v, ok) : wait_recorded(v, UINT64_MAX, ok);
|
||||
bool readback_recorded_wait(uint64_t v, uint64_t guest, uint64_t size, int* ok) {
|
||||
return rb_rec_end_for(guest, size) ? readback_rec_wait(v, guest, size, ok) : wait_recorded(v, UINT64_MAX, ok);
|
||||
}
|
||||
/// RX_VK_LOG_READBACK_ZERO's line, with the writer's recording now: its first part (the old wait's), its newest part and
|
||||
/// whether that ended it, and the recordings' timeline (a read between the parts waited for the first alone)
|
||||
@@ -6285,10 +6349,13 @@ void readback_zero_line(long long presents, uint64_t gpu, uint64_t size, uint64_
|
||||
/// The 3000-readback line's count of the readbacks whose writer's recording went on past the part first found (the old wait
|
||||
/// ended there)
|
||||
void readback_went_on_line() {
|
||||
const int64_t cpu = st_rb_cpu_ranges.exchange(0);
|
||||
if (const int64_t on = st_rb_went_on.exchange(0))
|
||||
logf("vk: readbacks of GPU results: %lld of them found their writer's recording going on past a part and waited for "
|
||||
"its last part, %.2f ms each (RX_VK_RB_REC_END=0: the first part, as before)",
|
||||
(long long)on, st_rb_went_on_ns.exchange(0) / (double)on / 1e6);
|
||||
"its last part, %.2f ms each; %lld took the rule, the CPU writing their range (RX_VK_RB_REC_END=0: the first part, as before)",
|
||||
(long long)on, st_rb_went_on_ns.exchange(0) / (double)on / 1e6, (long long)cpu);
|
||||
else if (cpu)
|
||||
logf("vk: readbacks of GPU results: %lld took the last-part rule, the CPU writing their range; none waited past a part", (long long)cpu);
|
||||
}
|
||||
// ((Triforce, 11-22, the performance audit's SYNC-122, after Source B's) A readback whose write-back is not recorded yet
|
||||
// (wait_recorded said so: its writer is still being recorded, or stopped at an event wait). It waited on the submissions'
|
||||
@@ -6798,10 +6865,10 @@ void invalidate(uint64_t gpu, uint64_t size) {
|
||||
} else if (!is_late && v > completed()) {
|
||||
int ok = 0;
|
||||
// ((Triforce, 11-27) RX_VK_RB_REC_END, on: the last part of the writer's recording, not its first (readback_recorded_wait)
|
||||
if (!(unforced && readback_recorded_wait(v, &ok))) {
|
||||
if (!(unforced && readback_recorded_wait(v, host->gpu_guest(gpu), size, &ok))) {
|
||||
if (unforced && !async_on() && replay_behind()) wait_queue_empty(); // (not recorded whole: as before)
|
||||
if (async_unforced()) { // (its recording is being made: when the replay thread has it, on its timeline)
|
||||
while (completed() < v && !readback_recorded_wait(v, &ok) && async_wait_step(v)) {}
|
||||
while (completed() < v && !readback_recorded_wait(v, host->gpu_guest(gpu), size, &ok) && async_wait_step(v)) {}
|
||||
if (completed() < v && !ok) wait_value(v);
|
||||
} else {
|
||||
// ((Triforce, 11-22, SYNC-122) the fallback: counted; in slices that look the recording up under
|
||||
|
||||
Reference in New Issue
Block a user