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

@@ -658,6 +658,65 @@ struct SimTurfTally {
std::unordered_set<uint64_t> ever[2];
};
SimTurfTally sim_turf_tally;
// ---- ((Triforce, 11-29) a list some program reads through the GAME'S OWN descriptor: one the IR pass left as it is (the
// pool producer 3de6d86ec7e6720e on his PC: "pools 0 made, N absent" all session). Such a program indexes the blade list
// with the game's cap (record = 143359 - i for a reverse list) but takes its count from the header, which a grown private
// list fills past that cap: i past 143359 reads far outside the buffer, the blade records it then follows are garbage, and
// the dispatch never ends. 11-29 his crash: device lost (Windows TDR, LiveKernelEvent 141) in that dispatch, the frame
// after both blade lists grew 143360 -> 165056. So a list read so is held at the game's size: the grow is refused, a list
// already grown is made the game's size again at its producer's next dispatch. A patched program reads a list's header
// through the game's descriptor by design (headers stay in the game's buffers): only a stage with no turf descriptor of its
// own counts. Exact address: the pass's private descriptor and the game's are read from the same constant-bank words ----
constexpr size_t kSimTurfLiveSlots = 2 * kSimTurfPrivateMax;
std::atomic<uint64_t> sim_turf_live_addr[kSimTurfLiveSlots]{}; // (the private lists' addresses, 0 = none; lock-free reads)
std::atomic<bool> sim_turf_live_held[kSimTurfLiveSlots]{}; // (that address already held at the game's size)
std::atomic<uint32_t> sim_turf_live_n{0};
std::unordered_set<uint64_t> sim_turf_game_read; // (addresses an unpatched program read: under sim_turf_mu, whole run)
/// RX_VK_SIM_TURF_HOLD=0: no hold (the lists grow whoever reads them: the 11-29 hang back; an A/B only)
bool sim_turf_hold_on() {
static const bool on = [] {
const char* e = getenv("RX_VK_SIM_TURF_HOLD");
return !(e && e[0] == '0');
}();
return on;
}
/// The lock-free copy of the private lists' addresses, after any change (under sim_turf_mu)
void sim_turf_publish() {
size_t n = 0;
for (int kind = 0; kind < 2; kind++)
for (const SimTurfPrivate& g : sim_turf_private[kind])
if (n < kSimTurfLiveSlots) {
sim_turf_live_held[n].store(sim_turf_game_read.count(g.addr) != 0, std::memory_order_relaxed);
sim_turf_live_addr[n++].store(g.addr, std::memory_order_relaxed);
}
const size_t live = n;
while (n < kSimTurfLiveSlots) sim_turf_live_addr[n++].store(0, std::memory_order_relaxed);
sim_turf_live_n.store((uint32_t)live, std::memory_order_release);
}
/// A list held at the game's size (above): its policy may not pass the game's cap
void sim_turf_hold(SimTurfPrivate& g, bool pool) {
g.policy.limit(pool ? Shader::Optimization::kSimTurfPoolCap : Shader::Optimization::kSimTurfBladeCap);
}
/// An unpatched stage binds the game's descriptor at addr: hold the private list there, if any, at the game's size
void sim_turf_game_reader(uint64_t addr, uint64_t prog) {
if (!addr || !sim_turf_live_n.load(std::memory_order_acquire)) return;
size_t slot = kSimTurfLiveSlots;
for (size_t i = 0; i < kSimTurfLiveSlots; i++)
if (sim_turf_live_addr[i].load(std::memory_order_relaxed) == addr) { slot = i; break; }
if (slot == kSimTurfLiveSlots || sim_turf_live_held[slot].load(std::memory_order_relaxed)) return;
std::lock_guard lk(sim_turf_mu);
sim_turf_game_read.insert(addr);
for (int kind = 0; kind < 2; kind++)
for (SimTurfPrivate& g : sim_turf_private[kind])
if (g.addr == addr) {
const uint32_t before = g.policy.capacity();
sim_turf_hold(g, kind == 1);
logf("vk: simulated turf: prog %016llx reads the %s at %#llx through the game's own descriptor (a variant the "
"pass left as it is): the list held at the game's %u records (now %u)", (unsigned long long)prog,
kind ? "pool" : "blade list", (unsigned long long)addr, g.policy.maximum(), before);
}
sim_turf_publish();
}
/// The most records a list may hold. A list's reader runs a workgroup for every `group` records, in one indirect command the
/// game's program writes from the list's length: a pool's mesh draw, a blade list's dispatch. Past what the device takes in
/// one the command is invalid (AMD's 65535 mesh groups are 2,097,120 pool records, and a longer pool's turf flickered all over).
@@ -787,6 +846,7 @@ VkDescriptorBufferInfo sim_turf_private_binding(uint64_t addr, uint32_t enc, uin
v.emplace_back(pool, sim_turf_max_records(pool, salign));
SimTurfPrivate& n = v.back();
n.addr = addr, n.used = frame;
if (sim_turf_game_read.count(addr)) sim_turf_hold(n, pool); // ((Triforce, 11-29) sim_turf_game_reader)
if (!sim_turf_resize(n, pool, salign)) {
v.pop_back();
static std::atomic<int> failed{0};
@@ -807,8 +867,10 @@ VkDescriptorBufferInfo sim_turf_private_binding(uint64_t addr, uint32_t enc, uin
v.emplace_back(pool, sim_turf_max_records(pool, salign));
SimTurfPrivate& replacement = v.back();
replacement.addr = addr, replacement.used = frame;
if (sim_turf_game_read.count(addr)) sim_turf_hold(replacement, pool); // ((Triforce, 11-29) sim_turf_game_reader)
if (!sim_turf_resize(replacement, pool, salign)) {
v.pop_back();
sim_turf_publish();
return none;
}
g = &replacement;
@@ -819,6 +881,7 @@ VkDescriptorBufferInfo sim_turf_private_binding(uint64_t addr, uint32_t enc, uin
}
g->addr = addr, g->used = frame;
sim_turf_tally.ever[pool].insert(addr);
sim_turf_publish(); // ((Triforce, 11-29) the lock-free addresses sim_turf_game_reader checks)
return sim_turf_bound_result(*g, addr, enc, pool, creator);
}
@@ -6662,6 +6725,10 @@ void build_descriptors(const NvnState& s, const Program& p, bool keep = false, b
w.pBufferInfo = &dwr.bufs[first];
dwr.writes.push_back(w);
}
// ((Triforce, 11-29) sim_turf_game_reader: a stage with no turf descriptor of its own, while private lists exist)
const bool turf_unpatched = sim_turf_live_n.load(std::memory_order_relaxed) && sim_turf_hold_on() &&
std::none_of(info.storage_buffers_descriptors.begin(), info.storage_buffers_descriptors.end(),
[](const auto& x) { return Shader::IsSimTurfStorage(x); });
for (const auto& d : info.storage_buffers_descriptors) {
FINE_SCOPE(FT_STORAGE);
FINE_N(FC_SSBO_DESCS, d.count);
@@ -6701,6 +6768,7 @@ void build_descriptors(const NvnState& s, const Program& p, bool keep = false, b
const uint64_t addr = stage_cbuf_word(s, st, d.cbuf_index, off) |
(uint64_t)stage_cbuf_word(s, st, d.cbuf_index, off + 4) << 32;
uint64_t size = stage_cbuf_word(s, st, d.cbuf_index, off + 8);
if (turf_unpatched) sim_turf_game_reader(addr, p.key); // ((Triforce, 11-29) a turf list read the game's way)
// ((Triforce) desc_keep.h: a single storage buffer the program only reads, kept with its address and size. The
// rest of what follows is for tables, written buffers, the bare and wide ones and the diagnostics, none of them kept)
desc_keep::Elem* const ke = kp && d.count == 1 && !d.is_written && !info.native_global_bounds && !sim_turf ? &kp->e[jb + k] : nullptr;
@@ -11522,6 +11590,7 @@ static void push_capture(VkCommandBuffer cmd, const Program& p, const NvnState&
CaptureDraw k;
k.depth = at.depth, k.vbuf = s.vbuf[0].address, k.program = p.key, k.count = d.count;
k.camera = s.ubo[0][0].addr, k.camera_size = s.ubo[0][0].size;
k.object = s.ubo[0][1].addr, k.object_size = s.ubo[0][1].size; // (Triforce: a copy's place, for temporal_capture_draw)
if (d.indexed) k.ibuf = d.ibuf, k.itype = d.itype, k.base_vertex = d.base_vertex;
else k.ibuf = 0, k.itype = dlss_actor::kNoIndices, k.base_vertex = d.first; // (vertex i: first + i)
// (as the draw's dynamic state has it: dyn_state)
@@ -14850,13 +14919,13 @@ bool precompile_keeps_all() {
const bool discrete = dev.props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
const bool query_on =
mem_parts::query_used_on(getenv("HOS_MEM_QUERY_USED"), getenv("HOS_MEM_CENSUS"), getenv("HOS_MEM_GIVE_BACK"));
if (!e && mem_parts::keep_all_small_pc(discrete, ms.ullTotalPhys, query_on)) {
const bool amd = dev.props.vendorID == 0x1002; // ((Triforce, 11-30) not the small PC's rule on AMD's driver: mem_parts.h
if (!e && mem_parts::keep_all_small_pc(discrete, ms.ullTotalPhys, query_on, amd)) {
logf("vk: precompile: the pipelines it builds are kept for the session: a discrete GPU in a PC of %llu MB (under 20 GB), "
"the game told its mapped pages are used (RX_VK_PRECOMPILE_KEEP=auto: by the RAM available, =0: never)",
(unsigned long long)(ms.ullTotalPhys >> 20));
return true;
}
const bool amd = dev.props.vendorID == 0x1002;
const uint64_t cache_read = pcache_read_ws.load(), own = mem_parts::own_for_keep(ws, cache_read, amd);
const bool keep = mem_parts::keep_all_pipelines(ms.ullTotalPhys, ms.ullAvailPhys, own);
logf("vk: precompile: %s: %llu MB of RAM available and %llu MB held by the game already (%llu MB in all, %llu MB of it "