mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 04:49:57 -04:00
Add oq_hold, which makes a samples-passed report whose draws the full occlusion query ring left uncounted repeat its record's last complete count, and log how often such reports happen.
A draw that finds every query slot still waiting for the completion thread goes uncounted, and the report after it said only what the other draws counted, at least 1: the game takes the object it tested for all but hidden for that frame. With the setting the report writes the larger of that and the last complete count reported into the same record. Off by default and read at start; the count of such reports is logged at the 1st, 10th, 100th and so on either way. tests/oq_hold_check.py checks the rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,7 @@ static const char *const known[] = {
|
||||
"HDR_BLOWOUT", "HDR_CONTRAST", "HDR_EXPOSURE", "HDR_FLARE", "HDR_GAMMA", "HDR_GRADE", "HDR_HIGHLIGHT_SAT",
|
||||
"HDR_HIGHLIGHTS", "HDR_HUE", "HDR_HUE_CLIP", "HDR_MATCH_SLOPE", "HDR_MIDGRAY", "HDR_SATURATION", "HDR_SHADOWS",
|
||||
"HDR_TONEMAP", "HDR_TONE_SLOPE", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
|
||||
"BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "BUILD_FREE_MB", "BUILD_RESERVE_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "COMPUTE_WARM_REUSE", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "LINE_WIDTH", "POOL_SHOWN_FIRST", "POOL_DATA_FIRST", "TEX_REUSE_NAMED", "TEX_OVERWRITTEN_USED", "PIPE_LINK_MS", "FRAME_HOLD_MS", "PACE_SMOOTH", "OQ_BATCH", "CLEAR_SMALL_CPU", "GATE_WAIT_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MEM_NEED_MB", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST",
|
||||
"BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "BUILD_FREE_MB", "BUILD_RESERVE_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "COMPUTE_WARM_REUSE", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "LINE_WIDTH", "POOL_SHOWN_FIRST", "POOL_DATA_FIRST", "TEX_REUSE_NAMED", "TEX_OVERWRITTEN_USED", "PIPE_LINK_MS", "FRAME_HOLD_MS", "PACE_SMOOTH", "OQ_BATCH", "OQ_HOLD", "CLEAR_SMALL_CPU", "GATE_WAIT_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MEM_NEED_MB", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST",
|
||||
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOUSE_TRACE", "MOVIE_HOST", "MOVIE_PACE", "MOVIE_CLOCK", "TEST_HITCH", "SPRINT_BUTTON", "SPRINT_MODE", "SPRINT_BUTTON_PATCH", "TEXT_SPEED", "TEXT_SPEED_PATCH",
|
||||
"MOTION_GUARD_DEGREES", "MOTION_POLICY_TRACE", "SELECTIVE_MOTION", "SELECTIVE_MOTION_RAW", // motion_owner.c, vk_fg_pose.inc
|
||||
"SKIN_MOTION", // vk_skin_motion.inc
|
||||
@@ -150,6 +150,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"PIPE_FRAME_WAIT_MS", "performance"}, {"PIPE_SKIP_STEADY", "performance"}, {"DRAW_WRITERS_WAIT", "performance"},
|
||||
{"CACHE_DIE", "performance"}, {"ONE_PER_CORE", "performance"},
|
||||
{"PIPE_SEED_BOOT", "performance"}, {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"LIB_WARM", "performance"}, {"PIPE_LINK_MS", "performance"}, {"PIPE_LINK_DRAW_MS", "performance"}, {"PIPE_AHEAD", "performance"}, {"LINE_WIDTH", "performance"}, {"POOL_SHOWN_FIRST", "performance"}, {"POOL_DATA_FIRST", "performance"}, {"TEX_REUSE_NAMED", "performance"}, {"TEX_OVERWRITTEN_USED", "performance"}, {"PIPE_FAST_WORKERS", "performance"}, {"GPL_FEEDBACK", "performance"}, {"GPL_MESH", "performance"}, {"FRAME_HOLD_MS", "performance"}, {"PACE_SMOOTH", "performance"}, {"OQ_BATCH", "performance"}, {"CLEAR_SMALL_CPU", "performance"}, {"PATCH_OCCLUSION_OFF", "performance"}, {"GATE_WAIT_MS", "performance"}, {"PIPE_PREBUILD", "performance"}, {"PIPE_SEED", "performance"},
|
||||
{"OQ_HOLD", "performance"},
|
||||
{"COMPUTE_KEEP", "performance"},
|
||||
{"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"},
|
||||
{"TEX_ALIAS", "performance"}, {"DEPTH_INIT_INLINE", "performance"}, {"DEPTH_ALIAS_LOG", "diagnostics"}, {"TEX_DISUSE", "performance"}, {"TEX_DISUSE_EVICT", "performance"}, {"TEX_GEN_UNDO", "performance"}, {"TEX_REUSE", "performance"}, {"TEX_SPLIT_FILL", "performance"}, {"TEX_VRAM_PRESSURE", "performance"}, {"TEX_RELEASED_HOLD", "performance"}, {"TEX_PROC_COMMIT_MB", "performance"}, {"ASTC_BC", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"}, {"WATER_PROJECTIVE", "performance"},
|
||||
@@ -340,6 +341,9 @@ static const CfgMeta metas[] = {
|
||||
{"PACE_SMOOTH", "1", "0|1", RESTART}, // vk_backend.c pace_smooth
|
||||
{"OQ_BATCH", "1", "0|1", RESTART}, // vk_exec_xfer.c oq_take
|
||||
{"CLEAR_SMALL_CPU", "1", "0|1", RESTART}, // vk_exec_xfer.c clear_small
|
||||
// vk_exec_xfer.c oq_report_count: a samples-passed report missing draws the full query ring left uncounted
|
||||
// repeats its record's last complete count where that is more than the part counted
|
||||
{"OQ_HOLD", "0", "0|1", RESTART},
|
||||
// the patch set occlusion_off (recomp/patches-v111.txt): the game makes no occlusion queries. The row is what
|
||||
// gives the set its default (patches.c rt_patches_init).
|
||||
{"PATCH_OCCLUSION_OFF", "0", "0|1", RESTART},
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "tex.h"
|
||||
#include "vk.h"
|
||||
#include "vk_exec.h"
|
||||
#include "vk_oq_hold.h"
|
||||
|
||||
enum { W_FORMAT, W_REGION, W_BUFFER, W_OVERLAP, W_COPY, W_CLEAR, W_QUERY, W_COUNT };
|
||||
|
||||
@@ -556,6 +557,7 @@ void vk_exec_oq_draw(VkExec *ex) {
|
||||
void vk_exec_oq_pass_end(VkExec *ex) { oq_close(ex); }
|
||||
|
||||
static void oq_batch_drop(void); // the results kept by the completion thread (oq_take)
|
||||
static void oq_hold_drop(void); // the counts remembered by the completion thread (oq_report_count)
|
||||
|
||||
void vk_exec_xfer_shutdown(void) {
|
||||
if (oq_state > 0) vkDestroyQueryPool(vk_ctx()->device, oq_pool, NULL);
|
||||
@@ -563,6 +565,7 @@ void vk_exec_xfer_shutdown(void) {
|
||||
oq_nseg = 0, oq_lost = 0, oq_count = 0;
|
||||
memset((void *)oq_busy, 0, sizeof oq_busy);
|
||||
oq_batch_drop();
|
||||
oq_hold_drop();
|
||||
}
|
||||
|
||||
// The completion thread reads the results in batches (NX2NAVI_OQ_BATCH, default 1; 0: every segment by itself, as
|
||||
@@ -630,6 +633,35 @@ static uint64_t oq_take(VkDevice dev, uint32_t q, int *avail) {
|
||||
return OQB.v[2 * k];
|
||||
}
|
||||
|
||||
// NX2NAVI_OQ_HOLD (default 0): a report whose segment left draws uncounted (a full ring, vk_exec_oq_draw) writes the
|
||||
// larger of what was counted and the last complete count of its record (vk_oq_hold.h); off, what was counted, at least
|
||||
// 1. Such reports are counted either way and logged at the 1st, 10th, 100th... so a log shows how often the ring ran
|
||||
// full. Completion thread only, as oq_count.
|
||||
static OqHold oq_held;
|
||||
static int oq_hold_on = -1;
|
||||
static uint64_t oq_lossy;
|
||||
|
||||
static void oq_hold_drop(void) { memset(&oq_held, 0, sizeof oq_held), oq_lossy = 0, oq_hold_on = -1; }
|
||||
|
||||
static uint64_t oq_report_count(const OqSegment *s, uint64_t counted) {
|
||||
if (oq_hold_on < 0) {
|
||||
oq_hold_on = cfg_bool("NX2NAVI_OQ_HOLD");
|
||||
if (oq_hold_on) rt_log("vk: samples-passed reports that miss draws repeat their record's last complete count (NX2NAVI_OQ_HOLD)");
|
||||
}
|
||||
if (!s->lost) {
|
||||
if (oq_hold_on) oqh_note(&oq_held, s->addr, counted);
|
||||
return counted;
|
||||
}
|
||||
uint64_t v = oq_hold_on ? oqh_lost(&oq_held, s->addr, counted) : counted;
|
||||
uint64_t n = ++oq_lossy, p = 1;
|
||||
while (p < n) p *= 10;
|
||||
if (p == n)
|
||||
rt_log("vk: %llu samples-passed reports so far missed draws the full occlusion query ring left uncounted (this "
|
||||
"one: %llu counted, %llu reported%s)", (unsigned long long)n, (unsigned long long)counted,
|
||||
(unsigned long long)v, oq_hold_on ? ", NX2NAVI_OQ_HOLD" : "");
|
||||
return v;
|
||||
}
|
||||
|
||||
static void oq_cb(void *arg) {
|
||||
OqSegment *s = arg;
|
||||
VkDevice dev = vk_ctx()->device;
|
||||
@@ -667,7 +699,7 @@ static void oq_cb(void *arg) {
|
||||
if (s->lost && !oq_count) oq_count = 1;
|
||||
if (s->addr) {
|
||||
if (vk_sync_effect_late()) __atomic_fetch_add(&late_counts, 1, __ATOMIC_RELAXED);
|
||||
report_write(s->addr, s->seq, oq_count, 0);
|
||||
report_write(s->addr, s->seq, oq_report_count(s, oq_count), 0);
|
||||
}
|
||||
}
|
||||
free(s->q), free(s);
|
||||
|
||||
41
runtime/vk_oq_hold.h
Normal file
41
runtime/vk_oq_hold.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// The count a samples-passed report writes when the replay could not count all of its draws (vk_exec_xfer.c oq_cb,
|
||||
// NX2NAVI_OQ_HOLD). Header only, so that tests/oq_hold_check.c checks it without a device.
|
||||
//
|
||||
// A draw that finds every slot of the occlusion query ring still waiting for the completion thread is left uncounted,
|
||||
// and the report after it says only what the other draws counted, at least 1. The game reads these counts as how much
|
||||
// of an object shows, and a count of 1 where an object's proxy covers thousands of samples tells it the object is all
|
||||
// but hidden for that frame: whatever it scales by that count (a light's glare, an object's fade) drops for one frame
|
||||
// and comes back, a flicker. The ring fills while the GPU or the completion thread falls behind the replay, in a hitch
|
||||
// at a few hundred frames a second. With the hold such a report writes the larger of what was counted and what the
|
||||
// last complete report into the same record said: the previous frame's answer for that object. A record with no
|
||||
// complete report remembered keeps the old rule.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define OQH_N 1024 // records remembered, direct-mapped by address; a collision forgets the older one
|
||||
|
||||
typedef struct {
|
||||
uint64_t addr[OQH_N];
|
||||
uint64_t count[OQH_N];
|
||||
} OqHold;
|
||||
|
||||
static inline uint32_t oqh_slot(uint64_t addr) {
|
||||
uint64_t h = (addr >> 4) * 0x9E3779B97F4A7C15ull; // records are 16 bytes apart at least
|
||||
return (uint32_t)(h >> 54) & (OQH_N - 1);
|
||||
}
|
||||
|
||||
// A complete report of count into the record at addr.
|
||||
static inline void oqh_note(OqHold *t, uint64_t addr, uint64_t count) {
|
||||
if (!addr) return;
|
||||
uint32_t i = oqh_slot(addr);
|
||||
t->addr[i] = addr, t->count[i] = count;
|
||||
}
|
||||
|
||||
// The count to report into addr for a report that missed draws, of which the others counted `counted`.
|
||||
static inline uint64_t oqh_lost(const OqHold *t, uint64_t addr, uint64_t counted) {
|
||||
uint64_t c = counted ? counted : 1;
|
||||
if (!addr) return c;
|
||||
uint32_t i = oqh_slot(addr);
|
||||
if (t->addr[i] == addr && t->count[i] > c) c = t->count[i];
|
||||
return c;
|
||||
}
|
||||
Reference in New Issue
Block a user