mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 22:19:57 -04:00
Runtime: power opt-out, faster fence wake-ups, feedback barrier, texture re-upload skip
- Opt the process out of Windows power throttling (execution speed and timer resolution) at startup; NX2NAVI_POWER_FULL=0 turns it off. - Fence completion thread wakes waiters before collecting freed memory, so collection no longer delays them. - Add a by-region barrier when a draw or clear writes an attachment that an earlier draw in the same pass sampled; count it and inline uniform updates in the per-frame stats. - Hash small texture contents at upload and skip re-uploads whose bytes are unchanged (removes ~420 redundant uploads per frame in Kokiri Forest); NX2NAVI_TEX_SAME=0 turns it off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -474,6 +474,7 @@ uint64_t plat_counter_hz(void) { return 1000000000u; }
|
||||
// The timer slack (50 us by default) is how late the kernel may wake a sleeping thread to batch wakeups. New threads
|
||||
// inherit it from the thread that creates them.
|
||||
void plat_timer_1ms(void) { prctl(PR_SET_TIMERSLACK, 1000ul, 0, 0, 0); }
|
||||
int plat_power_full(void) { return 0; } // no per-process power throttling to opt out of
|
||||
|
||||
// clock_nanosleep wakes within the timer slack (50 us by default) of its deadline; the last PLAT_SPIN_NS are spent
|
||||
// yielding so the deadline is met closely, as on Windows.
|
||||
|
||||
@@ -104,6 +104,8 @@ uint64_t plat_now_ns(void); // monotonic, high resolution, arbitra
|
||||
uint64_t plat_counter(void); // the OS's raw monotonic counter (QPC on Windows), plat_counter_hz per second
|
||||
uint64_t plat_counter_hz(void);
|
||||
void plat_timer_1ms(void); // asks the OS for timed waits accurate to 1 ms or better (call before threads)
|
||||
int plat_power_full(void); // opts out of the OS's power throttling of an unfocused process: 2 speed and timer,
|
||||
// 1 speed only (Windows 10), 0 not done or nothing to do
|
||||
// t * num / den for a fixed num / den without a 128-bit division per call (__udivti3 took 5% of the game's running
|
||||
// samples through plat_now_ns and rt_ticks): t * q + (t * f >> 64) with q = num / den and f = (num % den) * 2^64 / den.
|
||||
// Monotonic in t and at most one below the exact quotient while t * (num % den) / den fits 64 bits.
|
||||
|
||||
@@ -347,6 +347,23 @@ uint64_t plat_counter_hz(void) { return qpc_freq(); }
|
||||
// The default timer tick is 15.6 ms; a 1 ms wait would cost a full tick.
|
||||
void plat_timer_1ms(void) { timeBeginPeriod(1); }
|
||||
|
||||
// Windows 11 runs a process whose window is not in front (another window focused, a second monitor's overlay) at
|
||||
// efficiency speed (EcoQoS, the E-cores of a hybrid CPU) and may ignore its timer resolution request, which turns the
|
||||
// 1 ms waits the pacing and short sleeps rely on into 15.6 ms ones. Opting out keeps full speed and the 1 ms timer.
|
||||
// The ignore-timer-resolution control needs Windows 11; on Windows 10 the call fails and execution speed alone is asked.
|
||||
#ifndef PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION
|
||||
#define PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION 0x4
|
||||
#endif
|
||||
int plat_power_full(void) {
|
||||
PROCESS_POWER_THROTTLING_STATE st = {.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION,
|
||||
.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED |
|
||||
PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION,
|
||||
.StateMask = 0};
|
||||
if (SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &st, sizeof st)) return 2;
|
||||
st.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
|
||||
return SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &st, sizeof st) ? 1 : 0;
|
||||
}
|
||||
|
||||
static PlatScale qpc_ns; // set before main, so no thread reads it half written
|
||||
|
||||
__attribute__((constructor)) static void qpc_ns_init(void) { qpc_ns = plat_scale(1000000000u, qpc_freq()); }
|
||||
|
||||
Reference in New Issue
Block a user