Triforce v0.8.5

A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-28 10:54:41 -06:00
parent 2df08c751e
commit b527e29adb
203 changed files with 18821 additions and 2051 deletions

View File

@@ -82,6 +82,7 @@
#include "warm_computes.h" // ((Triforce) the compute pipelines the translation pass builds: only play's on Intel, prepare_run)
#include "compile_level.h" // ((Triforce, 11-24) Compile shaders, All or Most: compile_level_now)
#include "index_rebase.h" // ((Triforce, 11-21, DESC-12) an indexed draw's buffer bound at 0, its offset the first index)
#include "capturepushkeep.h" // ((Triforce, 11-26, C15) a plain draw's capture push left out while zeros are held)
#include "predict_stream.h" // ((Triforce, 11-21, PIPE-83) the predicted builder's plan as record numbers)
#include "pcache_bound.h"
#include "pcache_carry.h" // ((Triforce) the file carried over a stamp change at an update's preparation, capped)
@@ -116,6 +117,8 @@
#include "desc_sig.h" // (Triforce: the whole-draw skip by the signature of a draw's descriptor inputs, draw)
#include "desc_pool_grow.h" // ((Triforce, 11-22, DESC-33) a slot's descriptor pool at half, whole once a recording runs out)
#include "desc_counts.h" // ((Triforce, 11-22, DESC-22) a program's descriptor counts kept with it: build_descriptors)
#include "tpltable.h" // ((Triforce, 11-26, C31) the templates' per-thread table: set_template, push_template)
#include "uboonly.h" // ((Triforce, 11-26) a draw that only bound uniform buffers anew resolves those alone: draw)
#include "view_keep.h" // (Triforce: texture looks kept through other textures' ends, texture_view_of)
#include "mesh_ahead.h" // (Triforce: a run of indirect mesh draws' records copied at its first, RX_VK_MESH_AHEAD: mesh_indirect_convert)
#include "checkpoint_kinds.h" // (Triforce: the markers' kinds and what lies after each, checkpoints_report)
@@ -1586,7 +1589,15 @@ void pcache_init() {
_fseeki64(f, 0, SEEK_END);
const int64_t sz = _ftelli64(f);
fclose(f);
if (max_mb > 0 && sz > (max_mb << 20)) {
// ((Triforce, 11-27) not on a PC the library check flagged (nv_own_folder_mark_path): there a start that finds the
// libraries cold makes them all again into this file (2-2.5 GB), and made again from the order at the next start it
// found them cold again: a full preparation at every start (a player's RTX 5090, Linux). Kept as big as it grew)
FILE* own = fopen(nv_own_folder_mark_path().c_str(), "rb");
if (own) fclose(own);
if (own && max_mb > 0 && sz > (max_mb << 20))
logf("vk: pipeline cache: the compact one is %lld MB (over %lld), kept: on this PC the libraries were made again "
"into it (%s)", (long long)(sz >> 20), (long long)max_mb, nv_own_folder_mark_path().c_str());
else if (max_mb > 0 && sz > (max_mb << 20)) {
remove(pcache_path.c_str());
logf("vk: pipeline cache: the compact one has grown to %lld MB (over %lld): made again from the last sessions' order",
(long long)(sz >> 20), (long long)max_mb);
@@ -6436,6 +6447,8 @@ std::atomic<int64_t> st_strict_builds{0}; // ((Triforce, redrawn.h) draws that
std::atomic<int64_t> st_push_full{0}, st_push_full_n{0}, st_push_delta{0}, st_push_delta_n{0}, st_push_none{0}, st_push_tpl{0};
std::atomic<int64_t> st_set_new{0}, st_set_new_n{0}, st_set_tpl{0}, st_set_again{0};
std::atomic<int64_t> st_sig_walks{0}, st_sig_hits{0}, st_sig_checked{0}, st_sig_bad{0}; // ((Triforce) desc_sig.h)
// ((Triforce, 11-26, C31; tpltable.h) the templates' lookups: found in the thread's table, taken through tpl_mu, and the check's)
std::atomic<int64_t> st_tpl_fast{0}, st_tpl_locked{0}, st_tpl_checked{0}, st_tpl_bad{0};
inline void count_add(std::atomic<int64_t>& c, int64_t n) {
c.store(c.load(std::memory_order_relaxed) + n, std::memory_order_relaxed);
}
@@ -7113,6 +7126,36 @@ struct Pushed {
};
TLS_OBJECT(pushed, std::array<Pushed, 2>) // [graphics, compute]
int desc_sig_mode(); // (below: the whole-draw skip by the signature, desc_sig.h)
// ((Triforce, 11-26, the GPU audit's C15; capturepushkeep.h) RX_VK_CAPTURE_PUSH_KEEP: a plain draw's capture push (push_capture)
// left out while its command buffer holds zeros there. Unset or anything else: on (a value but 0, 1 or check is told). 0:
// pushed before every draw, as before. check: pushed before every draw too, and the pushes the rule would have left out
// counted, with those whose bytes the model of the pushes through vk_work.h does not have as zeros (must be 0; 0 by
// construction for every push and bind vk_work.h sees: it checks what pushed and full_pushed claim, not a library's
// recording or a call past the macros). Read once, told when it is not the default. The counts are of the frame
// statistics' "a frame's capture pushes" line (desc_report)
std::atomic<int64_t> st_cap_kept{0}, st_cap_pushed{0}, st_cap_bad{0};
int capture_keep_mode() {
static const int mode = [] {
const char* const asked = getenv("RX_VK_CAPTURE_PUSH_KEEP");
const capturepushkeep::Mode m = capturepushkeep::mode_of(asked);
if (m == capturepushkeep::OFF)
logf("vk: RX_VK_CAPTURE_PUSH_KEEP=0: the capture slot is pushed before every plain draw, as before");
else if (m == capturepushkeep::CHECK)
logf("vk: RX_VK_CAPTURE_PUSH_KEEP=check: the capture slot is pushed before every plain draw, and the pushes the rule "
"would leave out are counted, with those whose bytes differ (the frame statistics' capture pushes line)");
else if (asked && *asked && strcmp(asked, "1"))
logf("vk: RX_VK_CAPTURE_PUSH_KEEP=%s is not 0, 1 or check: the capture slot is kept, as by default", asked);
return (int)m;
}();
return mode;
}
int tpl_table_env(); // (below: the templates' per-thread table, tpltable.h)
// ((Triforce, 11-26) uboonly.h, below: the builds that resolved their user uniform buffers alone and how many of those; the builds
// that were the next draw of the program last built (the rule's candidates), and of them the ones built whole for the program's
// kind, for a texture or storage buffer bound since, for a stamp moved or a result not kept; =check: compared, and differing)
int ubo_only_mode();
std::atomic<int64_t> st_uo_fast{0}, st_uo_ubos{0}, st_uo_same{0}, st_uo_impure{0}, st_uo_bound{0}, st_uo_stale{0};
std::atomic<int64_t> st_uo_checked{0}, st_uo_bad{0};
/// (Triforce) The frame statistics' line of what the draws' descriptors came to (every 120 presents, after the skips' line)
void desc_report(double frames) {
static int64_t l[17];
@@ -7144,6 +7187,54 @@ void desc_report(double frames) {
snprintf(sig, sizeof sig, "%s", sm ? "on" : "off");
logf("vk: a frame's descriptor signatures: %.0f draws read theirs, %.0f kept the descriptors pushed before them whole (%s)", d[14],
d[15], sig);
// ((Triforce, 11-26, C15) capturepushkeep.h: the plain draws' capture pushes left out and made; check: those the rule would
// have left out, and how many of them the pushes' own model did not have as zeros, in all)
{
static int64_t last_kept, last_pushed;
const int64_t kept = st_cap_kept.load(), made = st_cap_pushed.load();
const int cm = capture_keep_mode();
char keep[160];
if (cm == capturepushkeep::CHECK)
snprintf(keep, sizeof keep, "check: every one pushed, the kept ones are those the rule would leave out, %lld of them "
"differed in all", (long long)st_cap_bad.load());
else
snprintf(keep, sizeof keep, "%s", cm ? "on" : "off");
logf("vk: a frame's capture pushes: %.0f kept (zeros the command buffer holds), %.0f pushed (%s)",
(double)(kept - last_kept) / frames, (double)(made - last_pushed) / frames, keep);
last_kept = kept, last_pushed = made;
}
// ((Triforce, 11-26, C31; tpltable.h) the templates looked up, and how many of the lookups missed and took tpl_mu and the map;
// labelled by the switch, as the lines above are, not by the lab's phase at this moment)
static int64_t tl[2];
const int64_t tv[2] = {st_tpl_fast.load(), st_tpl_locked.load()};
const double fast = (double)(tv[0] - tl[0]) / frames, locked = (double)(tv[1] - tl[1]) / frames;
tl[0] = tv[0], tl[1] = tv[1];
const int tm = tpl_table_env();
char wide[160];
if (tm == tpltable::kCheck)
snprintf(wide, sizeof wide, "check: each one found took the lock too, to ask the map; %lld checked in all, %lld of them "
"not the map's", (long long)st_tpl_checked.load(), (long long)st_tpl_bad.load());
else
snprintf(wide, sizeof wide, "%s", tm ? "on" : "off");
logf("vk: a frame's descriptor templates: %.0f looked up, %.0f of them under the lock (the wide table %s)", fast + locked, locked, wide);
// ((Triforce, 11-26) uboonly.h: of the draws that built theirs, those that resolved their user uniform buffers alone)
static int64_t ul[6];
const int64_t uv[6] = {st_uo_fast.load(), st_uo_ubos.load(), st_uo_same.load(), st_uo_impure.load(), st_uo_bound.load(),
st_uo_stale.load()};
double u[6];
for (int i = 0; i < 6; i++) u[i] = (double)(uv[i] - ul[i]) / frames, ul[i] = uv[i];
const int um = ubo_only_mode();
char uo[160];
if (um == 2)
snprintf(uo, sizeof uo, "check: the rule's builds were built whole too, %lld built both ways in all, %lld of them came out "
"otherwise", (long long)st_uo_checked.load(), (long long)st_uo_bad.load());
else
snprintf(uo, sizeof uo, "%s", um ? "on" : "off");
logf("vk: a frame's uniform-buffer-only builds: %.0f of %.0f builds resolved their user uniform buffers alone (%.0f uniform "
"buffers); %.0f more were the next draw of the program last built and were built whole: %.0f of a program the rule does "
"not take (its kind), %.0f after a texture, sampler, image or storage buffer bound to its stages, %.0f "
"with a stamp moved or a result not kept (RX_VK_DESC_UBO_ONLY %s)",
u[0], d[0], u[1], std::max(0.0, u[2] - u[0]), u[3], u[4], u[5], uo);
}
} // namespace
bool uniform_snapshot_on() { // ((Triforce) vk_internal.h: ub_snapshot_wanted's answer for vk_memory.cpp's guard)
@@ -7447,12 +7538,65 @@ TLS_OBJECT(tpl_data, std::vector<uint8_t>) // (the descriptors packed for a te
std::mutex tpl_mu;
std::unordered_map<const Program*, std::unique_ptr<SetTemplate>> tpls; // (never freed in play, as the programs are not)
std::vector<std::unique_ptr<SetTemplate>> tpls_old; // (a program's made again: the old one stays for its readers)
// ((Triforce, 11-26, the GPU audit's C31, its part (a); tpltable.h) A thread's table in front of the templates' maps: 512 sets of 2
// by a hash of the program's address and the template's kind, where 8 entries by the address were. A frame pushes the descriptors of
// far more than 8 programs, so most lookups took tpl_mu and searched the map (0.8% of the Presentation Thread at Lake Hylia, 1.1% in
// the Market). What is found is checked as before (its layout is the program's), a miss is the locked path as before. Busy frames
// still take the lock on about 10% of their lookups (a set holds two keys; tpltable.h). RX_VK_TPL_TABLE=0: the 8 entries; =2 or
// =check: every find checked against the map; the lab's knob "notpltable": the 8 in its phases)
TLS_OBJECT(tpl_wide, tpltable::Table)
static_assert(alignof(Program) >= 4, "a program's address leaves the two bits of a template's kind free (tpltable::key_of)");
/// RX_VK_TPL_TABLE, read once: 0, the 8 entries a kind of template, as before; 1, the wide table; 2 or check, and each find checked
int tpl_table_env() {
static const int env = [] {
const char* const asked = getenv("RX_VK_TPL_TABLE");
const int m = tpltable::mode(asked);
if (m == tpltable::kOld)
logf("vk: RX_VK_TPL_TABLE=%s: the descriptor templates are looked up through 8 entries a kind of template, as before", asked);
else if (m == tpltable::kCheck)
logf("vk: RX_VK_TPL_TABLE=%s: every descriptor template found in a thread's table is checked against the map", asked);
else if (asked && *asked && strcmp(asked, "1"))
logf("vk: RX_VK_TPL_TABLE=%s is not 0, 1, 2 or check: the wide table, as by default", asked);
return m;
}();
return env;
}
/// The table in force now: the switch's, or the 8 entries in the lab's notpltable phases
int tpl_table_mode() {
const int env = tpl_table_env();
return lab_ab::on("notpltable") ? tpltable::kOld : env;
}
/// The check (RX_VK_TPL_TABLE=2 or check): whether t, found in the thread's table, is what the map holds for p now. (Another
/// thread making p's template again between the two is counted too: none does in play)
void tpl_check(const std::unordered_map<const Program*, std::unique_ptr<SetTemplate>>& map, const Program& p, const SetTemplate* t) {
std::lock_guard lk(tpl_mu);
const auto it = map.find(&p);
count_add(st_tpl_checked, 1);
if (it == map.end() || it->second.get() != t) {
count_add(st_tpl_bad, 1);
static std::atomic<int> told{0};
if (told++ < 4) logf("vk: descriptor template check: program %016llx's template in the thread's table is not the map's", (unsigned long long)p.key);
}
}
/// p's set template, made from dw()'s writes at its first set (immutable once made; null when templates are off)
const SetTemplate* set_template(const Program& p) {
struct Last { const Program* p; const SetTemplate* t; };
static thread_local Last last[8];
Last& l = last[((uintptr_t)&p >> 6) & 7];
if (l.p == &p && l.t && l.t->layout == p.set_layout) return l.t;
static thread_local Last last[tpltable::kOldSlots];
const int wide = tpl_table_mode();
const uintptr_t key = tpltable::key_of(&p, tpltable::kSet);
Last& l = last[tpltable::old_slot((uintptr_t)&p)];
if (wide) {
const SetTemplate* t = static_cast<const SetTemplate*>(tpl_wide().find(key));
if (t && t->layout == p.set_layout) {
count_add(st_tpl_fast, 1);
if (wide == tpltable::kCheck) tpl_check(tpls, p, t);
return t;
}
} else if (l.p == &p && l.t && l.t->layout == p.set_layout) {
count_add(st_tpl_fast, 1);
return l.t;
}
count_add(st_tpl_locked, 1);
std::lock_guard lk(tpl_mu);
std::unique_ptr<SetTemplate>& t = tpls[&p];
if (!t || t->layout != p.set_layout) {
@@ -7472,7 +7616,8 @@ const SetTemplate* set_template(const Program& p) {
(unsigned long long)p.key);
}
}
l = {&p, t.get()};
if (wide) tpl_wide().put(key, t.get());
else l = {&p, t.get()};
return t.get();
}
/// set written with dw()'s descriptors through p's template: false when there is none or they do not fit it (then as before)
@@ -7498,10 +7643,23 @@ std::unordered_map<const Program*, std::unique_ptr<SetTemplate>> push_tpls[2];
/// p's push template at bp, made from dw()'s writes at its first whole push (immutable once made; null when templates are off)
const SetTemplate* push_template(const Program& p, VkPipelineBindPoint bp) {
struct Last { const Program* p; const SetTemplate* t; };
static thread_local Last last[2][8];
static thread_local Last last[2][tpltable::kOldSlots];
const int k = bp == VK_PIPELINE_BIND_POINT_COMPUTE;
Last& l = last[k][((uintptr_t)&p >> 6) & 7];
if (l.p == &p && l.t && l.t->pipe_layout == p.layout) return l.t;
const int wide = tpl_table_mode(); // ((Triforce, 11-26, C31; tpltable.h) the thread's wide table first, the 8 entries with it off)
const uintptr_t key = tpltable::key_of(&p, tpltable::kPushGraphics + k);
Last& l = last[k][tpltable::old_slot((uintptr_t)&p)];
if (wide) {
const SetTemplate* t = static_cast<const SetTemplate*>(tpl_wide().find(key));
if (t && t->pipe_layout == p.layout) {
count_add(st_tpl_fast, 1);
if (wide == tpltable::kCheck) tpl_check(push_tpls[k], p, t);
return t;
}
} else if (l.p == &p && l.t && l.t->pipe_layout == p.layout) {
count_add(st_tpl_fast, 1);
return l.t;
}
count_add(st_tpl_locked, 1);
std::lock_guard lk(tpl_mu);
std::unique_ptr<SetTemplate>& t = push_tpls[k][&p];
if (!t || t->pipe_layout != p.layout) {
@@ -7522,7 +7680,8 @@ const SetTemplate* push_template(const Program& p, VkPipelineBindPoint bp) {
(unsigned long long)p.key);
}
}
l = {&p, t.get()};
if (wide) tpl_wide().put(key, t.get());
else l = {&p, t.get()};
return t.get();
}
/// dw()'s descriptors pushed whole at bp through p's push template: false when there is none or they do not fit it (then as before)
@@ -7911,6 +8070,9 @@ void push_constants(VkCommandBuffer cmd, const Program& p, const Targets* at, ui
std::memcpy(data + Shader::Backend::SPIRV::RENDERAREA_LAYOUT_OFFSET, ra, sizeof ra);
}
vkCmdPushConstants(cmd, p.layout, p.push_stages, 0, kPushSize, data);
// ((Triforce, 11-26, C15) the block has zeros in the capture's bytes (the macro forgot what was held: capturepushkeep.h))
static_assert(kPushSize == capturepushkeep::kOffset + capturepushkeep::kSize, "the block ends with the capture's bytes");
capturepushkeep::full_pushed(mkwvk::cmd_work(cmd).cap, p.push_stages);
}
} // namespace
@@ -8174,6 +8336,188 @@ bool desc_slots_kept(uint64_t reg_gen) {
if (texture_slot_version((int)(e & 0xFFFFF)) != (uint32_t)(e >> 20)) return false;
return true;
}
// ---- (Triforce, 11-26) The uniform-buffers-only build of a draw's descriptors (uboonly.h) ----
/// RX_VK_DESC_UBO_ONLY: unset or 1, on: a draw of the program this thread built last, with no texture, sampler, image or storage
/// buffer bound to its stages since, resolves its user uniform buffers alone and leaves the rest of that build as it is (the
/// rule and its conditions: uboonly.h). 0: every such draw builds whole, as before. check: built both ways and compared, the
/// whole build used. Off as well where the rule does not hold: the per-binding reuse off or checked (RX_VK_DESC_KEEP and the
/// switches that turn it off), the signature skip on (RX_VK_DESC_SIG), the uniform buffers snapshots (ub_snapshot_wanted: every
/// Intel GPU, and any other integrated GPU whose pools have no VRAM mirror), the banks kept by bind_gen (RX_VK_BANK_GEN_OFF). Read
/// at the first draw, said once when it is not plainly on, and a value but 0, 1 or check (on) told once
int ubo_only_mode() {
static const int mode = [] {
uboonly::Now n;
const char* const value = getenv("RX_VK_DESC_UBO_ONLY");
n.mode = uboonly::mode_of(value);
if (value && *value && strcmp(value, "0") && strcmp(value, "1") && strcmp(value, "check"))
logf("vk: RX_VK_DESC_UBO_ONLY=%s is not 0, 1 or check: on", value);
const int asked = n.mode;
n.keep_mode = desc_keep_mode(), n.sig_mode = desc_sig_mode(), n.snapshot = ub_snapshot_wanted();
n.bank_gen_off = getenv("RX_VK_BANK_GEN_OFF") != nullptr;
const int m = uboonly::mode_now(n);
const char* const why = !asked ? "RX_VK_DESC_UBO_ONLY=0"
: m ? nullptr
: n.keep_mode != 1 ? "the per-binding reuse is off or checked (RX_VK_DESC_KEEP)"
: n.sig_mode ? "the signature skip is on (RX_VK_DESC_SIG)"
: n.snapshot ? "the uniform buffers are snapshots (RX_VK_UB_SNAPSHOT: Intel, or an integrated GPU with no "
"VRAM mirror)"
: "the banks are kept by every binding (RX_VK_BANK_GEN_OFF)";
if (m != 1)
logf("vk: uniform-buffer-only descriptor builds %s%s%s", m == 2 ? "on, each built whole too and compared, the whole build "
"used (RX_VK_DESC_UBO_ONLY=check)" : "off", why ? ": " : "", why ? why : "");
return m;
}();
return mode;
}
/// The mode for the draw being recorded: 0 as well in the lab's "nouboonly" phases (RX_VK_LAB_AB), in a dump, in the temporal
/// upscaler's second recording, and for a draw that may not leave textures for later (redrawn.h: it takes no kept dummy)
int ubo_only_now(bool strict) {
uboonly::Now n;
n.mode = ubo_only_mode();
if (!n.mode) return 0;
n.lab_off = lab_ab::on("nouboonly");
n.dump = dump_on(), n.retarget = pre_retarget_on, n.strict = strict, n.may_defer = draw_may_defer;
return uboonly::mode_now(n);
}
TLS_OBJECT(uo_plans, std::array<uboonly::Plan, uboonly::kPlans>)
/// p's plan: its user uniform buffers and the descriptors beside them, in build_descriptors' order, and whether the rule takes
/// the program at all (uboonly.h Maker; made once a program a thread, as sig_shape, and again after another program took its slot)
const uboonly::Plan& ubo_only_plan(const Program& p) {
uboonly::Plan& plan = uo_plans()[uboonly::plan_slot(&p)];
if (plan.prog == &p) return plan;
if (!p.ready.load(std::memory_order_acquire)) { // (its stages are filled before ready and never after: not made before)
static const uboonly::Plan none;
return none;
}
uboonly::Maker m(plan);
m.begin(&p, p.compute, p.fallback, p.renodx != 0);
for (const Stage& st : p.stages) {
const Shader::Info& info = st.info;
m.stage(st.nvn_stage);
for (const auto& d : info.constant_buffer_descriptors)
for (uint32_t k = 0; k < d.count; k++) m.cbuf(d.index + k);
for (const auto& d : info.storage_buffers_descriptors)
m.storage(d.count, d.is_written, info.native_global_bounds, Shader::IsSimTurfStorage(d), d.cbuf_index, d.cbuf_offset);
for (const auto& d : info.texture_buffer_descriptors) m.texel(d.count);
for (const auto& d : info.image_buffer_descriptors) m.texel(d.count);
for (const auto& d : info.texture_descriptors)
m.texture(d.count, d.handle_program != ~0U, d.cbuf_index, d.has_secondary, d.secondary_cbuf_index);
for (const auto& d : info.image_descriptors) m.image(d.count);
}
m.end();
return plan;
}
/// The stamps the descriptors such a build leaves stand on, now (uboonly.h stamps_same: not the inline uniform updates')
desc_keep::Stamps ubo_only_stamps() {
desc_keep::Stamps now;
now.rec = desc_rec, now.bind = gpu_bind_stamp();
now.samp = sampler_registrations_generation(), now.destroy = texture_destroy_generation();
now.dummy = texture_dummy_generation(), now.epoch = texture_epoch();
return now;
}
thread_local uboonly::Last uo_last; // (this thread's last whole build by a draw)
/// (RX_VK_DESC_UBO_ONLY=check) What the uniform-buffers-only build made, for the whole build after it to be compared with
struct UboOnlyCheck {
std::vector<VkDescriptorBufferInfo> bufs;
std::vector<VkDescriptorImageInfo> imgs;
std::vector<const Texture*> sampled;
std::vector<uint8_t> is_ubo;
};
TLS_OBJECT(uo_check, UboOnlyCheck)
thread_local bool uo_check_armed = false;
/// The uniform-buffers-only build of p's descriptors for a draw, where uboonly.h's rule holds: true, and the thread's last build
/// (dw()) is this draw's, its user uniform buffers resolved anew, each through kept_uniform as build_descriptors does, and
/// draw_sampled() the textures it samples that the GPU wrote. False: nothing a whole build does not make again was changed, and
/// the whole build follows. last_same: the draw's bookkeeping is of p (last_desc_valid, last_desc_prog). check: the same, and
/// what it made is kept for ubo_only_built to compare with the whole build's; false then
bool ubo_only_build(const NvnState& s, const Program& p, bool last_same, uint64_t reg_gen, bool check) {
auto& dwr = dw();
uboonly::Last& l = uo_last;
if (!uboonly::candidate(l, &p, dwr.prog, last_same)) return false; // (before the plan: most builds are another program's)
count_add(st_uo_same, 1);
const uboonly::Plan& plan = ubo_only_plan(p);
const uboonly::Why why = uboonly::decide(l, plan, &p, dwr.prog, last_same, s.tex_gen, s.ssbo_gen, ubo_only_stamps, reg_gen,
[&](const desc_keep::Stamps& now) {
if (dwr.bufs.size() != plan.nbuf || dwr.imgs.size() != plan.nimg) return false;
return uboonly::stands(plan, desc_keep::prog_of(kept_descs(), &p, plan.n).e, now,
[](uint32_t slot) { return texture_slot_version((int)slot); },
[&](uint32_t at) { return dwr.bufs[at].buffer == VK_NULL_HANDLE; },
[&](uint32_t at) { return dwr.imgs[at].sampler == VK_NULL_HANDLE; });
});
if (why != uboonly::kFast) {
count_add(why == uboonly::kImpure ? st_uo_impure : why == uboonly::kBound ? st_uo_bound : st_uo_stale, 1);
return false;
}
desc_keep::Prog& kp = desc_keep::prog_of(kept_descs(), &p, plan.n);
ub_prog_key = p.key; // (the Grass distance row: uniform_range, as build_descriptors sets it first)
// (every one, not only those bound anew: a copy in the recording's stream is never kept and is made again by each build)
for (const uboonly::Ubo& u : plan.ubos) dwr.bufs[u.buf] = kept_uniform(&kp, u.j, s, p.stages[u.stage], u.index);
// (a mirror made by one of those binds moves the bind stamp: a whole build would resolve the storage buffers after it again)
if (!uboonly::still(l, ubo_only_stamps())) {
count_add(st_uo_stale, 1);
return false;
}
auto& sampled = draw_sampled(); // (as the build left built_textures(): the ones the GPU wrote, read again as a build would)
sampled.clear();
for (const void* t : built_textures())
if (static_cast<const Texture*>(t)->gpu_written) sampled.push_back(static_cast<const Texture*>(t));
if (check) { // (built whole after it: not counted as resolved alone)
UboOnlyCheck& c = uo_check();
c.bufs = dwr.bufs, c.imgs = dwr.imgs, c.sampled = sampled;
c.is_ubo.assign(dwr.bufs.size(), 0);
for (const uboonly::Ubo& u : plan.ubos) c.is_ubo[u.buf] = 1;
uo_check_armed = true;
return false;
}
count_add(st_uo_fast, 1), count_add(st_uo_ubos, (int64_t)plan.ubos.size());
st_dummy_textures += l.dummies, st_dummy_known += l.dummies_known; // (the frame statistics': as its build counted them)
return true;
}
/// (RX_VK_DESC_UBO_ONLY=check) The whole build of a draw whose uniform-buffers-only build was kept: whether the two made the same
/// descriptors (a user uniform buffer copied into the stream by both: the same range and bytes, at its own place) and the same
/// sampled textures the GPU wrote; counted, and logged (40 times) when not
void ubo_only_compare(const Program& p) {
uo_check_armed = false;
const UboOnlyCheck& c = uo_check();
auto& dwr = dw();
count_add(st_uo_checked, 1);
const char* what = nullptr;
size_t at = 0;
if (c.bufs.size() != dwr.bufs.size() || c.imgs.size() != dwr.imgs.size()) what = "another number of descriptors";
for (size_t i = 0; !what && i < c.bufs.size(); i++) {
const VkDescriptorBufferInfo &a = c.bufs[i], &b = dwr.bufs[i];
const bool sa = a.buffer && recording_stream(a.buffer), sb = b.buffer && recording_stream(b.buffer);
bool bytes = true; // (compared only when both copies are in the current stream: a pair with either copy in an older stream
// of the recording passes on its range)
if (c.is_ubo[i] && sa && sb && a.range == b.range && cur && a.buffer == cur->stream && b.buffer == cur->stream && cur->mapped &&
a.range != VK_WHOLE_SIZE)
bytes = !std::memcmp(cur->mapped + a.offset, cur->mapped + b.offset, (size_t)a.range);
if (!uboonly::buffer_same(c.is_ubo[i] != 0, (uint64_t)(uintptr_t)a.buffer, a.offset, a.range, sa, (uint64_t)(uintptr_t)b.buffer,
b.offset, b.range, sb, bytes))
what = c.is_ubo[i] ? "another user uniform buffer" : "another buffer beside the user uniform buffers", at = i;
}
for (size_t i = 0; !what && i < c.imgs.size(); i++)
if (c.imgs[i].sampler != dwr.imgs[i].sampler || c.imgs[i].imageView != dwr.imgs[i].imageView)
what = "another texture or sampler", at = i;
if (!what && c.sampled != draw_sampled()) what = "other sampled textures the GPU wrote";
if (!what) return;
count_add(st_uo_bad, 1);
static std::atomic<int> told{0};
if (told++ < 40)
logf("vk: uniform-buffer-only build check: program %016llx: the whole build made %s (at %zu of its kind)",
(unsigned long long)p.key, what, at);
}
/// A draw built p's descriptors whole. uo: the mode for that draw (ubo_only_now): with it the build is what the next draws' rule
/// stands on, without it none is (a dump's or the upscaler's second recording's is not through the per-binding reuse, a strict
/// draw's is its own). before: the stamps read before the build. dummies, dummies_known: what it added to the frame statistics'
void ubo_only_built(const NvnState& s, const Program& p, int uo, const desc_keep::Stamps& before, int64_t dummies,
int64_t dummies_known) {
if (uo) uboonly::built(uo_last, &p, s.tex_gen, s.ssbo_gen, before, dummies, dummies_known);
else uboonly::forget(uo_last);
if (uo_check_armed) ubo_only_compare(p);
}
thread_local VkPipeline last_pipeline = VK_NULL_HANDLE;
struct LastVb { VkBuffer b[16]; VkDeviceSize o[16], z[16], s[16]; };
thread_local LastVb last_vb;
@@ -11092,6 +11436,10 @@ static const char* skin_check(const NvnState& s, const Program& p, const DrawArg
if (d.mesh || d.indirect || d.instances != 1 || !at.n || !at.color[0] || !at.depth ||
!temporal_scene_size(at.width, at.height) || !temporal_scene_format(at.color_format[0]) || !temporal_motion_wanted())
return "not a plain draw into the scene"; // ((Triforce) AMD FSR 3.1's motion too: temporal_motion_wanted)
// ((Triforce, 11-27, after a player's patch in #bug-tracker "FSR4_navighostingfix.patch") Navi ghosted over Link with an
// upscaler on: her glow is drawn blended and without a depth test, so it has no depth of its own, and its motion was
// paired with the frame before's and dragged with the camera. Only opaque, depth-tested draws give the upscaler motion
if (!s.ds.dt || (s.color.blend_en & 1)) return "the draw does not cover opaque scene depth";
if (s.nvattr < 7) return "fewer than 7 vertex attributes";
const auto attr = [&](int i) { return *reinterpret_cast<const nvn_va_st*>(&s.vattr[i]); };
const nvn_va_st pos = attr(0);
@@ -11139,14 +11487,38 @@ static const char* skin_check(const NvnState& s, const Program& p, const DrawArg
/// an address left from another draw would be written to. Only a plain, single-instance draw of triangles into the scene
/// (its colour target 0 and depth) is given a slot, by the temporal upscaler's chain when it wants positions
/// (vk_temporal.cpp capture_motion). capture: this draw may be one (false: an indirect draw, quads)
/// ((Triforce, 11-26) Whether a draw into the scene gets a motion of its own: not one that blends over the scene (target 0
/// blending). The owner's "white lines" traced by particles after some area loads, caught at last (F8 and F9, Kokiri Forest,
/// AMD FSR 4 before bloom): the frame's steps are clean up to the scene's last particle draw and the lines are there right
/// after the upscaler, rings round every firefly. Every plain draw of triangles was given its own motion, the fireflies,
/// the fairies' glows and the fog cards blended over the scene among them: the upscaler then moved what is behind each sprite
/// as the sprite moved, and drew its outline and its trail into its history. What is blended over the scene is to carry the
/// motion of what is behind it (reactive_policy.h: the reactive mask is for those pixels); the camera's motion stays theirs.
/// RX_VK_DLSS_BLENDED_MOTION=1: a motion of their own too, as before (a lab switch, for the comparison)
static bool own_motion(const NvnState& s) {
static const bool blended_too = getenv("RX_VK_DLSS_BLENDED_MOTION") && atoi(getenv("RX_VK_DLSS_BLENDED_MOTION")) != 0;
if (blended_too || (s.color.blend_en & 1) == 0) return true;
static std::atomic<bool> told{false}; // (said once, at the first: a report with an upscaler's motion says which rule ran)
if (!told.exchange(true, std::memory_order_relaxed))
logf("vk: the upscaler's motion: draws blended over the scene keep the camera's (RX_VK_DLSS_BLENDED_MOTION=1: their own)");
return false;
}
/// ((Triforce, 11-26, the GPU audit's C15; capturepushkeep.h) Not pushed when it is zeros and the command buffer is known to
/// hold zeros there for this program's push stages: with no upscaler's chain asking, every draw pushed the same 16 zeros.
/// Every other push and bind forgets that (vk_work.h's macros, this one's own too: it notes what it left after), and so do a
/// new recording and every library's own recording (the recorder's B_DIRECT boundary: direct_gen); draw()'s program bind
/// takes it back only for the same push stages, and not after a draw state reset. RX_VK_CAPTURE_PUSH_KEEP=0: pushed before
/// every draw, as before; =check: pushed, and the rule's keeps counted against the model of the pushes through vk_work.h
/// (0 by construction for those: it checks what pushed and full_pushed claim, not the bind rule, a library's recording or a
/// call past the macros); the lab's knob nocappush: pushed in its phases)
static void push_capture(VkCommandBuffer cmd, const Program& p, const NvnState& s, const DrawArgs& d, const Targets& at,
VkPrimitiveTopology topo, bool capture) {
if (!p.captures) return;
CaptureSlot slot;
if (capture && !d.mesh && !d.indirect && d.instances <= 1 && d.count > 0 && at.n && at.color[0] && at.depth &&
if (capture && own_motion(s) && !d.mesh && !d.indirect && d.instances <= 1 && d.count > 0 && at.n && at.color[0] && at.depth &&
(topo == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST || topo == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
topo == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN) && temporal_capture_wanted() && temporal_scene_size(at.width, at.height) &&
temporal_scene_format(at.color_format[0])) {
temporal_scene_format(at.color_format[0]) && s.ds.dt && !(s.color.blend_en & 1)) { // ((Triforce, 11-27) as skin_check's
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;
@@ -11163,7 +11535,30 @@ static void push_capture(VkCommandBuffer cmd, const Program& p, const NvnState&
static_assert(Shader::Backend::SPIRV::CAPTURE_FIRST_PUSH_OFFSET == Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET + 8 &&
Shader::Backend::SPIRV::CAPTURE_COUNT_PUSH_OFFSET == Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET + 12,
"push_capture's layout");
static_assert(capturepushkeep::kOffset == Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET && capturepushkeep::kSize == sizeof data,
"capturepushkeep.h's bytes");
const int mode = capture_keep_mode();
if (mode != capturepushkeep::OFF) {
const mkwvk::CmdWork& w = mkwvk::cmd_work(cmd);
if (capturepushkeep::keep(w.cap, w.known, p.push_stages, data)) {
if (mode == capturepushkeep::CHECK) { // (pushed all the same; a keep over bytes not known to be zeros is the rule's fault)
count_add(st_cap_kept, 1);
if (capturepushkeep::check_differs(w.cap)) {
st_cap_bad.fetch_add(1, std::memory_order_relaxed); // (exact with the helper threads: the count that must be 0)
static std::atomic<int> told{0};
if (told.fetch_add(1, std::memory_order_relaxed) < 8)
logf("vk: capture push check: program %016llx: the rule would keep a push over bytes that are not known "
"to be zeros (RX_VK_CAPTURE_PUSH_KEEP=check)", (unsigned long long)p.key);
}
} else if (!lab_ab::on("nocappush")) { // (lab: pushed in the knob's phases, as before)
count_add(st_cap_kept, 1);
return;
}
}
}
vkCmdPushConstants(cmd, p.layout, p.push_stages, Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET, sizeof data, data);
count_add(st_cap_pushed, 1);
if (mode != capturepushkeep::OFF) capturepushkeep::pushed(mkwvk::cmd_work(cmd).cap, p.push_stages, data);
}
static bool writes_memory(const Program& p) {
@@ -11258,7 +11653,10 @@ void draw(VkCommandBuffer cmd, NvnState& s, const DrawArgs& d) {
{
PROF_HOT(PROF_PROGRAM);
ParLock lk(d.mesh); // (graphics programs: each thread's picks, program_pick's own lock)
cp = program_for(s, d.mesh ? ProgramKind::Mesh : ProgramKind::Graphics, types);
// ((Triforce, 11-26, the GPU audit's C02; pickwide.h) a graphics program from the wide memo in front of program_for
// (RX_VK_PICK_WIDE=0: program_for alone)
if (d.mesh) cp = program_for(s, ProgramKind::Mesh, types);
else cp = program_for_wide(s, types);
}
if (use.on) use.program(cp, cp && cp->ready.load(std::memory_order_acquire)), use.count_skips(&st_pending_skips);
{ // (hookshot, a test) RX_VK_NO_MESH=1: task / mesh draws left out, to see what they draw; =2: the others left out
@@ -11629,13 +12027,23 @@ void draw(VkCommandBuffer cmd, NvnState& s, const DrawArgs& d) {
pushed()[0].layout == p.layout && desc_sig::hit(sig_bound(), sig, &p);
const bool same_desc = same_gens || (sig_hit && sig_mode == 1);
bool sig_armed = false; // (the build below kept every descriptor: its signature may stand for them)
bool uo_fast = false; // ((Triforce, 11-26) the build below resolved the user uniform buffers alone: uboonly.h)
if (!same_desc) {
PROF_HOT(PROF_DESC);
FINE_N(FC_BUILDS, 1);
trace_tex_hit = nullptr, trace_tex_mask = 0;
count_add(st_dk_builds, 1);
const int64_t drops = desc_drops, dummies0 = desc_dummies, known0 = desc_dummies_known;
build_descriptors(s, p, true, scene); // (textures first used here are uploaded by the recording's upload command buffer)
// ((Triforce, 11-26) uboonly.h: the next draw of the program this thread built last, with nothing but uniform buffers bound
// anew since, resolves its user uniform buffers alone and leaves the rest of that build as it is: a whole build would take
// each of the others from what was kept. RX_VK_DESC_UBO_ONLY=0: built whole, as before; =check: both ways, compared)
const int uo = no_reuse ? 0 : ubo_only_now(strict);
uo_fast = uo && ubo_only_build(s, p, last_desc_valid && last_desc_prog == &p, reg_gen, uo == 2);
if (!uo_fast) {
const desc_keep::Stamps uo_at = uo ? ubo_only_stamps() : desc_keep::Stamps{}; // (read before the build: uboonly.h)
build_descriptors(s, p, true, scene); // (textures first used here are uploaded by the recording's upload command buffer)
ubo_only_built(s, p, uo, uo_at, desc_dummies - dummies0, desc_dummies_known - known0);
}
FINE_N(FC_WRITES, (int64_t)dw().writes.size());
if (sig_walked) { // ((Triforce) desc_sig.h: what it left besides the descriptors, for a draw that keeps them)
sig_armed = desc_drops == drops;
@@ -11764,7 +12172,13 @@ void draw(VkCommandBuffer cmd, NvnState& s, const DrawArgs& d) {
if (bound) {
FINE_SCOPE(FT_BINDPL);
FINE_N(FC_BIND_PIPE, 1);
const uint32_t cap_held = mkwvk::cmd_work(cmd).cap.zero_stages; // ((Triforce, 11-26, C15) below)
const bool cap_reset = last_pipeline == VK_NULL_HANDLE;
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl), last_pipeline = pl;
// ((Triforce, 11-26, C15) the one bind after which a capture push's zeros are held again (capturepushkeep.h; the
// macro forgot them as at any bind): for the same push stages, and not when the draw state was reset before it
// (last_pipeline cleared: other things were recorded)
capturepushkeep::program_bound(mkwvk::cmd_work(cmd).cap, cap_held, p.push_stages, cap_reset);
// ((Triforce, 11-22) a mesh pipeline has the vertex strides static (only the other pipelines have them dynamic,
// build_graphics' dyn): binding it leaves the strides undefined for the next pipeline that has them dynamic, as it does
// the topology (dyn_pack sets that again after a mesh draw). The next vertex draw binds all 16 streams again, strides
@@ -11782,12 +12196,20 @@ void draw(VkCommandBuffer cmd, NvnState& s, const DrawArgs& d) {
FINE_SCOPE(FT_BINDDESC);
if (sig_hit) sig_check(cmd, p); // ((Triforce) RX_VK_DESC_SIG=check: before the push changes what is pushed)
if (!bind_descriptors(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p)) SKIP_HERE();
last_desc_valid = true, last_desc_prog = &p, last_desc_bind = s.bind_gen, last_desc_reg = reg_gen;
last_desc_ub = ub_gen, last_desc_dgen = dgen, last_desc_scene = scene;
last_desc_fp_on = desc_fp_on;
if (desc_fp_on) // (RX_VK_DESC_SLOTGEN: what its handles resolved; the next such draw may keep it through other slots' churn)
last_desc_fp() = desc_fp(), last_desc_fp_dummy = desc_fp_dummy, last_desc_samp = desc_samp_seen,
last_desc_destroy = desc_destroy_seen;
// ((Triforce, 11-26) uboonly.h: a build of the uniform buffers alone moves only what stands on them, the bindings' and the
// inline updates' generations; the textures' side (the registrations, the slots read, the destroy generation) stays the
// whole build's, which the next draw's same_gens asks as before)
if (uo_fast) {
last_desc_bind = s.bind_gen, last_desc_ub = ub_gen;
} else {
last_desc_valid = true, last_desc_prog = &p, last_desc_bind = s.bind_gen, last_desc_reg = reg_gen;
last_desc_ub = ub_gen, last_desc_dgen = dgen, last_desc_scene = scene;
last_desc_fp_on = desc_fp_on;
if (desc_fp_on) // (RX_VK_DESC_SLOTGEN: what its handles resolved; the next such draw may keep it through other slots' churn)
last_desc_fp() = desc_fp(), last_desc_fp_dummy = desc_fp_dummy, last_desc_samp = desc_samp_seen,
last_desc_destroy = desc_destroy_seen;
uboonly::bound(uo_last, &p); // (the bookkeeping above is this whole build's)
}
// ((Triforce) desc_sig.h: the bind point's descriptors are this build's now; its signature stands for them only when walked
// before it and nothing was dropped)
if (sig_walked) desc_sig::commit(sig_bound(), sig, sig_armed);
@@ -12276,7 +12698,9 @@ static bool movie_keep_all_networks() {
}
static bool typed_upscale(VkCommandBuffer cmd, VkImageView input_view, VkImageView output_view,
Texture* out, uint32_t level, uint64_t key, const char* keys, bool temporal);
Texture* out, uint32_t level, uint64_t key, const char* keys, bool temporal, uint32_t out_w = 0, uint32_t out_h = 0);
static bool wide_upscale(VkCommandBuffer cmd, VkImageView input_view, Texture* out, uint32_t level, uint64_t key, const char* keys,
bool temporal);
static bool temporal_rejected_network(VkCommandBuffer cmd, uint64_t key, Texture* src, const nvn_tex* in, Texture* dst,
const nvn_tex* out);
void stub_picture_written(VkCommandBuffer cmd, Texture* hud, Texture* fx); // ((Triforce) below: the ReShade preset's, after the lock)
@@ -12457,6 +12881,21 @@ bool upscale_stub(VkCommandBuffer cmd, const NvnState& s, uint64_t key) {
if (!warned_gameplay_upscale.exchange(true, std::memory_order_relaxed))
logf("vk: gameplay RGB9E5 upscale unavailable; the fallback blit may have incorrect colors");
}
// ((Triforce, 11-26) RenoDX's RGBA16F scene: a network's input is the square root of the scene colour, which the blit below
// copied as it is (Render resolution 67% and 50% on the lab's RX 7900 XT: the 3D veiled in white). wide_upscale squares it
// back, under the lock held since above
if (src->format == VK_FORMAT_R16G16B16A16_SFLOAT && dst->format == VK_FORMAT_R16G16B16A16_SFLOAT && src->type == VK_IMAGE_TYPE_2D &&
dst->type == VK_IMAGE_TYPE_2D && src->depth == 1 && dst->depth == 1 && src->layers == 1 && dst->layers == 1 && !src->skip) {
const VkImageView input_view = texture_view(src, &in, nullptr, VK_IMAGE_VIEW_TYPE_2D, ViewUse::Sample);
if (input_view && wide_upscale(cmd, input_view, dst, 0, key, "a network left out, RGBA16F", false)) {
stub_picture_written(cmd, stub_hud_picture, stub_fx_picture); // ((Triforce) 11-24: null unless asked, above)
if (told("wide"))
logf("vk: program %016llx does not translate: its dispatch replaced by the squared upscale of %#llx %ux%u into %#llx "
"%ux%u (RGBA16F scene)", (unsigned long long)key, (unsigned long long)in.gpu, in.d.width, in.d.height,
(unsigned long long)out.gpu, out.d.width, out.d.height);
return true;
}
}
VkImageBlit bl{};
bl.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
bl.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
@@ -12545,9 +12984,10 @@ bool taau_key(uint64_t key) {
}
return match;
}
// ((Triforce, 11-26) out_w, out_h: the output's size where it is not out's (wide_upscale's scratch image, out then null)
static bool typed_upscale(VkCommandBuffer cmd, VkImageView input_view, VkImageView output_view,
Texture* out, uint32_t level, uint64_t key, const char* keys, bool temporal) {
if (!dev.push_descriptor || !vkCmdPushDescriptorSetKHR || !input_view || !output_view || !out) return false;
Texture* out, uint32_t level, uint64_t key, const char* keys, bool temporal, uint32_t out_w, uint32_t out_h) {
if (!dev.push_descriptor || !vkCmdPushDescriptorSetKHR || !input_view || !output_view || (!out && (!out_w || !out_h))) return false;
static VkPipeline pipe = VK_NULL_HANDLE;
static VkPipelineLayout layout = VK_NULL_HANDLE;
static VkSampler linear = VK_NULL_HANDLE;
@@ -12584,7 +13024,7 @@ static bool typed_upscale(VkCommandBuffer cmd, VkImageView input_view, VkImageVi
pipe ? "" : ": its pipeline was not made");
}
if (!pipe) return false;
uint32_t size[3] = {std::max(1u, out->width >> level), std::max(1u, out->height >> level), 0};
uint32_t size[3] = {out_w ? out_w : std::max(1u, out->width >> level), out_h ? out_h : std::max(1u, out->height >> level), 0};
// (the stand-in's last output, which bounds this one's pixels: shaders/taau_upscale.comp. Made again at a new size,
// the first frame unbounded; RX_VK_TAAU_NO_CLAMP=1: never bounded)
struct History {
@@ -12665,6 +13105,84 @@ static bool typed_upscale(VkCommandBuffer cmd, VkImageView input_view, VkImageVi
vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 12, size);
vkCmdDispatch(cmd, (size[0] + 7) / 8, (size[1] + 7) / 8, 1);
descriptors_disturbed(); // (the program's own pushes are gone from the bind point)
if (temporal && out) probe_image(cmd, out, level, 0, key, 't');
return true;
}
/// ((Triforce, 11-26) The game's gameplay upscale with RenoDX's RGBA16F scene (host/nn_vi.c hos_scene_rgba16f): typed_upscale's
/// pass (shaders/taau_upscale.comp: the network's input is the square root of the scene colour, which it squares back) into a
/// scratch image of the scene's own SDR format, R11G11B10F, at the output's size, and that blitted into the RGBA16F output (the
/// shader stores R11G11B10F alone). The game's networks were not made for an RGBA16F scene. On the lab's RX 7900 XT with the
/// owner's settings, the 3/4 network (fd029a317a9a4b94: Render resolution 75%, and Auto's dynamic path) drew a black 3D. The
/// networks of 67% (6676619641320ba7) and 50% (72ba090c70fe2614), left out on that card, fell to upscale_stub's plain blit, which
/// copied the square root as it is: the 3D veiled in white. The same at a fresh start; 100%'s network (9dc98871eb7fc101) draws
/// right and is left to run. RX_VK_WIDE_UPSCALE=0: as before. false: nothing recorded (the caller goes on as before)
static bool wide_upscale(VkCommandBuffer cmd, VkImageView input_view, Texture* out, uint32_t level, uint64_t key, const char* keys,
bool temporal) {
static const bool off = getenv("RX_VK_WIDE_UPSCALE") && atoi(getenv("RX_VK_WIDE_UPSCALE")) == 0;
if (off || !input_view || !out || !out->image || out->format != VK_FORMAT_R16G16B16A16_SFLOAT || out->skip ||
!temporal_scene_format(VK_FORMAT_R16G16B16A16_SFLOAT)) // (a run whose scene is RGBA16F alone: vk_temporal.h)
return false;
static const bool able = [] {
VkFormatProperties t{}, o{};
vkGetPhysicalDeviceFormatProperties(dev.physical, VK_FORMAT_B10G11R11_UFLOAT_PACK32, &t);
vkGetPhysicalDeviceFormatProperties(dev.physical, VK_FORMAT_R16G16B16A16_SFLOAT, &o);
const bool ok = (t.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) &&
(t.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && (o.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT);
if (!ok) logf("vk: the RGBA16F scene's gameplay upscale: this card cannot store R11G11B10F or blit it into RGBA16F: the game's own");
return ok;
}();
if (!able) return false;
const uint32_t w = std::max(1u, out->width >> level), h = std::max(1u, out->height >> level);
// (the scratch image, made again at a new size; the one before given back 120 presents later, when no work in flight can
// use it, as typed_upscale's history)
struct Scratch { VkImage image = VK_NULL_HANDLE; VmaAllocation mem = nullptr; VkImageView view = VK_NULL_HANDLE; uint32_t w = 0, h = 0; };
struct Old { Scratch s; uint64_t frame; };
static Scratch scratch;
static std::vector<Old> old;
for (size_t i = 0; i < old.size();) {
if (texture_frame_no() - old[i].frame < 120) { i++; continue; }
if (old[i].s.view) vkDestroyImageView(dev.device, old[i].s.view, nullptr);
destroy_image(old[i].s.image, old[i].s.mem);
old.erase(old.begin() + (ptrdiff_t)i);
}
if (scratch.w != w || scratch.h != h) {
if (scratch.image) old.push_back({scratch, texture_frame_no()});
scratch = {};
VkImageCreateInfo ic{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
ic.imageType = VK_IMAGE_TYPE_2D, ic.format = VK_FORMAT_B10G11R11_UFLOAT_PACK32;
ic.extent = {w, h, 1}, ic.mipLevels = 1, ic.arrayLayers = 1, ic.samples = VK_SAMPLE_COUNT_1_BIT;
ic.tiling = VK_IMAGE_TILING_OPTIMAL, ic.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
if (!create_image(ic, scratch.image, scratch.mem)) return scratch = {}, false;
VkImageViewCreateInfo vc{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
vc.image = scratch.image, vc.viewType = VK_IMAGE_VIEW_TYPE_2D, vc.format = ic.format;
vc.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
if (vkCreateImageView(dev.device, &vc, nullptr, &scratch.view) != VK_SUCCESS) {
destroy_image(scratch.image, scratch.mem);
return scratch = {}, false;
}
VkImageMemoryBarrier2 ib{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; // (UNDEFINED -> GENERAL, once)
ib.srcStageMask = VK_PIPELINE_STAGE_2_NONE, ib.srcAccessMask = VK_ACCESS_2_NONE;
ib.dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, ib.dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT;
ib.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, ib.newLayout = VK_IMAGE_LAYOUT_GENERAL;
ib.srcQueueFamilyIndex = ib.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
ib.image = scratch.image, ib.subresourceRange = vc.subresourceRange;
VkDependencyInfo di{VK_STRUCTURE_TYPE_DEPENDENCY_INFO};
di.imageMemoryBarrierCount = 1, di.pImageMemoryBarriers = &ib;
vkCmdPipelineBarrier2(cmd, &di);
scratch.w = w, scratch.h = h;
logf("vk: the RGBA16F scene's gameplay upscale (%016llx): squared into R11G11B10F at %ux%u, then into the picture",
(unsigned long long)key, w, h);
}
if (!typed_upscale(cmd, input_view, scratch.view, nullptr, 0, key, keys, temporal, w, h)) return false;
full_barrier(cmd);
VkImageBlit bl{};
bl.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
bl.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, level, 0, 1};
bl.srcOffsets[1] = {(int32_t)w, (int32_t)h, 1};
bl.dstOffsets[1] = {(int32_t)w, (int32_t)h, 1};
vkCmdBlitImage(cmd, scratch.image, VK_IMAGE_LAYOUT_GENERAL, out->image, VK_IMAGE_LAYOUT_GENERAL, 1, &bl, VK_FILTER_NEAREST);
full_barrier(cmd);
texture_written(out);
if (temporal) probe_image(cmd, out, level, 0, key, 't');
return true;
}
@@ -12989,7 +13507,8 @@ static bool upscale_off_on() {
static const bool env = getenv("RX_VK_UPSCALE_OFF") && atoi(getenv("RX_VK_UPSCALE_OFF")) > 0;
// ((Triforce) 11-24) and the Upscaler row's Off (upscaler_rows.h OFF), while no engine draws (an environment's engine goes
// over the row: temporal_mode; FSR 3.1 is never at Off)
return env || lab_ab::on("upoff") || (opts.dlss == upscaler_rows::OFF && temporal_mode() == upscaler_rows::GAME);
// ((Triforce, 11-26) the row as applied, as temporal_mode reads it: vk_menu.h applied_dlss)
return env || lab_ab::on("upoff") || (applied_dlss() == upscaler_rows::OFF && temporal_mode() == upscaler_rows::GAME);
}
bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {
if (!dev.push_descriptor || !vkCmdPushDescriptorSetKHR || p.stages.empty()) return false;
@@ -12999,7 +13518,11 @@ bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {
const bool shaped = (off || n64) && st.info.uses_cooperative_matrix && st.info.texture_descriptors.size() == 1 &&
st.info.image_descriptors.size() == 1;
const upscale_off::Choice ch = upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64);
if (!ch.stand_in) return false;
// ((Triforce, 11-26) the 3/4 network (Render resolution 75%, Auto's dynamic path) on RenoDX's RGBA16F scene: wide_upscale in
// its place, which squares its input back; the network drew a black 3D there. Its picture is an RGBA16F image, which the
// stand-in below does not take (B10G11R11 alone): it is looked up as below, then given to wide_upscale
const bool wide = p.key == 0xfd029a317a9a4b94ull && !off && !n64;
if (!ch.stand_in && !wide) return false;
if (st.info.texture_descriptors.empty() || st.info.image_descriptors.empty()) return false;
Texture* in = nullptr; // (the network's input: for one taken by its shape, and for N64 Classic's grid, which needs its size)
if (ch.by_shape || ch.n64) {
@@ -13019,7 +13542,18 @@ bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {
const uint32_t handle = handle_of(s, st, od, 0);
if (!handle) return false;
texture_view_of(handle, VK_IMAGE_VIEW_TYPE_2D, ViewUse::Storage, image_format(od.format), &out, &level);
if (!out || out->format != VK_FORMAT_B10G11R11_UFLOAT_PACK32) return false;
if (wide && out && out->format == VK_FORMAT_R16G16B16A16_SFLOAT) { // ((Triforce, 11-26) above: false, the network runs as before)
bool done;
{
ParLock wide_lk; // (typed_upscale's and wide_upscale's images and pipeline: shared by every recording thread)
done = wide_upscale(cmd, dw().imgs[0].imageView, out, level, p.key, "fd029a317a9a4b94, RGBA16F", true);
}
if (done) {
hudless_after_dispatch(cmd, p.key); // ((Triforce, FG-2) as below)
}
return done;
}
if (!ch.stand_in || !out || out->format != VK_FORMAT_B10G11R11_UFLOAT_PACK32) return false;
const char* keys = !ch.temporal ? "the upscaler Off" : getenv("RX_VK_TAAU_KEYS") ? getenv("RX_VK_TAAU_KEYS") : "fd029a317a9a4b94";
bool done;
{
@@ -16162,7 +16696,8 @@ uint64_t dry_draw_program(void* ctx) { // (asked only where the point's choice
const DryDraw& q = *static_cast<const DryDraw*>(ctx);
uint8_t types[8];
target_types(*q.at, types);
const Program* cp = program_for(*q.s, q.mesh ? ProgramKind::Mesh : ProgramKind::Graphics, types);
// ((Triforce, 11-26, C02; pickwide.h) through the wide memo as draw() goes: the picks' kept programs move only with it)
const Program* cp = q.mesh ? program_for(*q.s, ProgramKind::Mesh, types) : program_for_wide(*q.s, types);
return cp ? cp->key : 0;
}
} // namespace