mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-01 05:18:50 -04:00
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:
@@ -3672,6 +3672,11 @@ std::atomic<uint64_t> wb_batch_now{0};
|
||||
std::map<uint64_t, uint64_t> wb_batch_seq; // batch -> its part's number on the recordings' timeline
|
||||
std::vector<WbRun> wb_runs_recent; // (wb_pages_mu held)
|
||||
uint64_t wb_runs_lost = 0; // (the ranges of submissions up to this value were dropped unseen)
|
||||
// ((Triforce, 11-29, the performance session) a write-back queued in this part covers a page the CPU reads back (rb_watch, below):
|
||||
// the part may end sooner (vk_replay.cpp part_min_now: RX_VK_PART_RB, the lab knob partrb), so that its copy reaches the reader
|
||||
// sooner. Set at the written binding that queues it (the mirrors' writebacks), cleared at the part's end (memory_end_submission)
|
||||
std::atomic<bool> part_rb_write{false};
|
||||
bool rb_watched(uint64_t lo, uint64_t hi);
|
||||
void wb_pages_note(uint64_t guest_lo, uint64_t guest_hi, uint64_t value) {
|
||||
static const bool off = getenv("RX_VK_NO_READBACK_WAIT") != nullptr;
|
||||
if (off || !value || guest_hi <= guest_lo) return;
|
||||
@@ -4499,7 +4504,41 @@ struct LateFix {
|
||||
VmaAllocation alloc = nullptr;
|
||||
size_t nbytes = 0;
|
||||
std::vector<std::pair<uint32_t, uint32_t>> slots; // (slot, guest page), by slot
|
||||
uint64_t part = 0; // ((Triforce, 11-29) RX_VK_LATE_PART: the part that wrote the pages back last (late_pages_part); 0 not known
|
||||
};
|
||||
/// ((Triforce, 11-29, the performance session) RX_VK_LATE_PART=1, or the lab knob latepart: a late fix waits for the part that
|
||||
/// wrote its pages back last (vk_replay.cpp late_fix_part_wait), not for its value. Off unset
|
||||
bool memory_late_part_on() {
|
||||
static const bool env = [] {
|
||||
const char* e = getenv("RX_VK_LATE_PART");
|
||||
const bool on = e && *e && atoi(e) != 0;
|
||||
if (on) logf("vk: the late pages' fixes wait for the part that wrote their pages back last (RX_VK_LATE_PART=1; unset: their value)");
|
||||
return on;
|
||||
}();
|
||||
return env || lab_ab::on("latepart");
|
||||
}
|
||||
/// ((Triforce, 11-29) The part (its number on the recordings' timeline) after which every write-back still in flight over the
|
||||
/// fix's pages is done: the newest part among the recent runs past done that cover one of them. 0 when one is not known (its
|
||||
/// part not submitted, or the list was cut while it was on the GPU) or none is found: the fix waits for its value, as before.
|
||||
/// One pass over the runs, the pages sorted (wb_pages_mu: taken here; the take's pools_mu held, the order of its other takes)
|
||||
uint64_t late_pages_part(const std::vector<std::pair<uint32_t, uint32_t>>& slots, uint64_t done) {
|
||||
static thread_local std::vector<uint32_t> pages;
|
||||
pages.clear();
|
||||
for (const auto& s : slots) pages.push_back(s.second);
|
||||
std::sort(pages.begin(), pages.end());
|
||||
std::lock_guard lk(wb_pages_mu);
|
||||
if (wb_runs_lost > done) return 0;
|
||||
uint64_t part = 0;
|
||||
for (const WbRun& r : wb_runs_recent) {
|
||||
if (r.value <= done || r.hi <= r.lo) continue;
|
||||
const auto it = std::lower_bound(pages.begin(), pages.end(), (uint32_t)(r.lo >> kPageShift));
|
||||
if (it == pages.end() || (uint64_t)*it > (r.hi - 1) >> kPageShift) continue;
|
||||
const auto b = wb_batch_seq.find(r.batch);
|
||||
if (b == wb_batch_seq.end()) return 0;
|
||||
part = std::max(part, b->second);
|
||||
}
|
||||
return part;
|
||||
}
|
||||
std::mutex late_fix_mu;
|
||||
std::deque<LateFix> late_fixes; // (late_fix_mu; in take order, values rising)
|
||||
std::atomic<uint64_t> late_fix_top{0}; // (the highest value a pending fix waits for; 0: none)
|
||||
@@ -4524,6 +4563,16 @@ bool late_fix_slot_pending(WriteGen gen, uint32_t slot, uint64_t* value) {
|
||||
return false;
|
||||
}
|
||||
uint64_t memory_late_fix_pending() { return late_fix_top.load(std::memory_order_acquire); }
|
||||
/// ((Triforce, 11-29) RX_VK_LATE_PART: the newest of the pending fixes' parts; 0 when one of them is not known
|
||||
uint64_t memory_late_fix_part() {
|
||||
std::lock_guard lk(late_fix_mu);
|
||||
uint64_t part = 0;
|
||||
for (const LateFix& f : late_fixes) {
|
||||
if (!f.part) return 0;
|
||||
part = std::max(part, f.part);
|
||||
}
|
||||
return part;
|
||||
}
|
||||
/// the pending fixes whose value done has reached: their late pages copied again from guest memory into their slots (as the take
|
||||
/// did after its wait). The queue's lock held (vk_replay.cpp), before anything goes to the queue
|
||||
void memory_late_fix_apply(uint64_t done) {
|
||||
@@ -5264,6 +5313,7 @@ bool take_capture(std::unique_ptr<Capture> c, uint64_t value, uint64_t completed
|
||||
f.value = lq_value, f.gen = g, f.map = (uint8_t*)c->map, f.alloc = c->alloc, f.nbytes = c->nbytes;
|
||||
f.slots = std::move(lq_slots);
|
||||
std::sort(f.slots.begin(), f.slots.end());
|
||||
if (memory_late_part_on()) f.part = late_pages_part(f.slots, vk_timeline_completed()); // ((11-29) RX_VK_LATE_PART)
|
||||
std::lock_guard fl(late_fix_mu);
|
||||
late_fixes.push_back(std::move(f));
|
||||
late_fix_top.store(late_fixes.back().value, std::memory_order_release);
|
||||
@@ -5349,6 +5399,11 @@ bool take_capture(std::unique_ptr<Capture> c, uint64_t value, uint64_t completed
|
||||
(long long)st_lq_deferred.exchange(0), (long long)st_lq_tex.exchange(0), (long long)st_lq_unsent.exchange(0),
|
||||
(long long)st_lq_full.exchange(0), (long long)st_lq_reads.exchange(0), (long long)st_lq_applied.exchange(0),
|
||||
(long long)qw, qns / 1e6 / 600, (long long)qto);
|
||||
int64_t pw, pns, pun; // ((Triforce, 11-29) RX_VK_LATE_PART's waits at the pages' part, and the fixes whose part was not known
|
||||
vk_late_part_stats(&pw, &pns, &pun);
|
||||
if (pw || pun)
|
||||
logf("vk: RX_VK_LATE_PART (600 takes): %lld queue waits at the part that wrote the late pages back (%.3f ms a take), "
|
||||
"%lld at their value, the part not known", (long long)pw, pns / 1e6 / 600, (long long)pun);
|
||||
}
|
||||
st_tk_all = st_tk_stamp = st_tk_copy = st_tk_late = st_tk_lock = 0, st_tk_late_n = 0;
|
||||
st_late_needed = st_late_skipped = st_late_same = st_late_part = 0;
|
||||
@@ -6852,6 +6907,28 @@ std::atomic<uint64_t> rb_collections{0};
|
||||
std::atomic<bool> rb_watch_any{false};
|
||||
constexpr uint64_t kRbCpuRecent = 4096; // (collections, a few seconds of play: a page the CPU stopped writing goes back)
|
||||
constexpr uint64_t kRbWatchMax = 0x10000; // (the largest range watched: results, not textures)
|
||||
// ((Triforce, 11-29) the watched pages' bounds for wb_pages_note's question without the lock, and the question: does
|
||||
// [lo, hi) cover a read-back page (wb_pages_mu held there; rb_cpu_mu is still a leaf: nothing is taken under it)
|
||||
std::atomic<uint32_t> rb_watch_lo_a{~0u}, rb_watch_hi_a{0};
|
||||
bool rb_watched(uint64_t lo, uint64_t hi) {
|
||||
if (hi <= lo || !rb_watch_any.load(std::memory_order_relaxed)) return false;
|
||||
const uint64_t p0 = lo >> kPageShift, p1 = (hi - 1) >> kPageShift;
|
||||
if (p1 < rb_watch_lo_a.load(std::memory_order_relaxed) || p0 > rb_watch_hi_a.load(std::memory_order_relaxed)) return false;
|
||||
std::lock_guard lk(rb_cpu_mu);
|
||||
if (p1 - p0 < rb_watch.size()) {
|
||||
for (uint64_t p = p0; p <= p1; p++)
|
||||
if (rb_watch.count((uint32_t)p)) return true;
|
||||
return false;
|
||||
}
|
||||
for (const auto& [p, at] : rb_watch)
|
||||
if (p >= p0 && p <= p1) return true;
|
||||
return false;
|
||||
}
|
||||
/// The written binding's write-back [lo, hi) queued in this part: part_rb_write once it covers a read-back page. Its branches
|
||||
/// here, not in the binding: the renderer's play profile matches the binding by a hash of its control flow (a call keeps it)
|
||||
void rb_write_note(uint64_t lo, uint64_t hi) {
|
||||
if (!part_rb_write.load(std::memory_order_relaxed) && rb_watched(lo, hi)) part_rb_write.store(true, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
void memory_rb_watch(uint64_t guest, uint64_t size) {
|
||||
if (!size || size > kRbWatchMax) return;
|
||||
@@ -6871,6 +6948,7 @@ void memory_rb_watch(uint64_t guest, uint64_t size) {
|
||||
if (rb_watch.size() > 4096 || rb_ranges_seen.size() > 16384) { // (a safety net: a game that reads back very many ranges starts over)
|
||||
rb_watch.clear(), rb_watch_lo = ~0u, rb_watch_hi = 0, rb_ranges_seen.clear();
|
||||
}
|
||||
rb_watch_lo_a.store(rb_watch_lo, std::memory_order_relaxed), rb_watch_hi_a.store(rb_watch_hi, std::memory_order_relaxed);
|
||||
rb_watch_any.store(!rb_watch.empty(), std::memory_order_relaxed);
|
||||
}
|
||||
/// A collection's pages, the ones the CPU wrote since the one before: the read-back pages among them noted
|
||||
@@ -7731,6 +7809,7 @@ BufferRef gpu_buffer_bind(uint64_t gpu, uint64_t size, bool written) {
|
||||
} else {
|
||||
writebacks.push_back({p, off, wb_end, tl_event_write, early_wb_segment(p->lo + off, p->lo + wb_end, tl_event_write)});
|
||||
}
|
||||
rb_write_note(p->lo + off, p->lo + wb_end); // ((Triforce, 11-29) a read-back page's write-back in this part, above
|
||||
}
|
||||
rb_hazard_locked(p->lo + off, p->lo + std::min(off + size, p->hi - p->lo)); // (memory_rb_refresh)
|
||||
const uint64_t np = (p->hi - p->lo + 4095) >> 12;
|
||||
@@ -9606,6 +9685,7 @@ void msync_pass_report() {
|
||||
|
||||
void memory_end_submission(VkCommandBuffer cmd) {
|
||||
std::lock_guard lk(pools_mu);
|
||||
part_rb_write.store(false, std::memory_order_relaxed); // ((Triforce, 11-29) the next part's own, rb_write_note
|
||||
wb_batch_now.fetch_add(1, std::memory_order_relaxed); // ((Triforce, 11-28) this part's batch of write-backs: WbRun.batch
|
||||
{ // (every 600 submissions: how the mirror syncs' dirty pages were read)
|
||||
static int64_t n, l_live, l_cap;
|
||||
@@ -10406,6 +10486,8 @@ void memory_part_submitted(uint64_t seq) {
|
||||
wb_batch_seq[wb_batch_now.load(std::memory_order_relaxed)] = seq;
|
||||
while (wb_batch_seq.size() > 8192) wb_batch_seq.erase(wb_batch_seq.begin());
|
||||
}
|
||||
/// ((Triforce, 11-29) whether a write-back queued in the part being recorded covers a page the CPU reads back (rb_write_note)
|
||||
bool memory_part_rb_write() { return part_rb_write.load(std::memory_order_relaxed); }
|
||||
/// ((Triforce, 11-28) The part (its number on the recordings' timeline) whose write-back last covered any of [guest, guest + size)
|
||||
/// among submission value's, 0 when none is known (the range not written back under value yet, or its part not submitted)
|
||||
uint64_t memory_wb_part_seq(uint64_t guest, uint64_t size, uint64_t value) {
|
||||
|
||||
Reference in New Issue
Block a user