From 36d2f3e3681b2f7613a77aa9a5ceaf786a087971 Mon Sep 17 00:00:00 2001 From: Solganis Date: Tue, 24 Nov 2026 12:38:23 +0300 Subject: [PATCH] fix: restore CI build and GPU timing compatibility --- .../runtime/include/dynamic_resolution.h.patch | 4 ++-- .../runtime/src/dynamic_resolution.c.patch | 15 ++++++++------- framework/patches/runtime/src/main.cpp.patch | 4 ++-- src/game/render/adaptive_resolution.cpp | 2 +- tests/unit/adaptive_resolution_test.cpp | 6 +++--- tests/unit/disruptor_render_arena_test.cpp | 16 +++++++++++----- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/framework/patches/runtime/include/dynamic_resolution.h.patch b/framework/patches/runtime/include/dynamic_resolution.h.patch index f30e17e..0e2743f 100644 --- a/framework/patches/runtime/include/dynamic_resolution.h.patch +++ b/framework/patches/runtime/include/dynamic_resolution.h.patch @@ -1,12 +1,12 @@ diff --git a/runtime/include/dynamic_resolution.h b/runtime/include/dynamic_resolution.h -index d43c26adc8b035a9c40bdc1572365914c2bfe3a8..0bc01df3d0fe8888bd2b63861dac15652a567f0a 100644 +index d43c26adc8b035a9c40bdc1572365914c2bfe3a8..9e9bc42fe9f5944ddc900499ee1df02c852b16cc 100644 --- a/runtime/include/dynamic_resolution.h +++ b/runtime/include/dynamic_resolution.h @@ -83,6 +83,7 @@ double wall_s; /* this interval's wall time */ double work_s; /* see LOAD above */ int held; /* the host holds: not a sample, the window restarts */ -+ int measured_frames; ++ int measured_frames; /* -1 for missing timing, 0 for a default single-frame sample */ } DynresSample; typedef struct DynresController { diff --git a/framework/patches/runtime/src/dynamic_resolution.c.patch b/framework/patches/runtime/src/dynamic_resolution.c.patch index ac48143..c17885c 100644 --- a/framework/patches/runtime/src/dynamic_resolution.c.patch +++ b/framework/patches/runtime/src/dynamic_resolution.c.patch @@ -1,5 +1,5 @@ diff --git a/runtime/src/dynamic_resolution.c b/runtime/src/dynamic_resolution.c -index e99e75aab0af7e3b7b1af10b6f6a4a0de444a6a1..20296601907e47da8e59e23e7d5995bf7e2e563d 100644 +index e99e75aab0af7e3b7b1af10b6f6a4a0de444a6a1..35588959c2664a7901a5b780240993557d70b419 100644 --- a/runtime/src/dynamic_resolution.c +++ b/runtime/src/dynamic_resolution.c @@ -77,8 +77,8 @@ @@ -107,22 +107,23 @@ index e99e75aab0af7e3b7b1af10b6f6a4a0de444a6a1..20296601907e47da8e59e23e7d5995bf c->up_streak_s += dur; else { c->up_streak_s = 0.0; -@@ -285,6 +293,7 @@ +@@ -285,6 +293,8 @@ return c->level; } double work = s->work_s < 0.0 ? 0.0 : s->work_s; -+ if (s->measured_frames != 1) c->up_ready = 0; ++ const int measured_frames = s->measured_frames == 0 ? 1 : s->measured_frames; ++ if (measured_frames != 1) c->up_ready = 0; if (c->up_ready) { /* Up steps land in an interval whose idle time covers the step. */ double idle = s->period_s - work; -@@ -292,7 +301,11 @@ +@@ -292,7 +302,11 @@ return step_up(c, now_s, c->last_load, c->level + 1, "headroom"); } c->win_period += s->period_s; - c->win_work += work; -+ if (s->measured_frames != 1) c->win_unpaired = 1; -+ if (s->measured_frames > 0) { -+ c->win_measured += s->measured_frames * s->period_s; ++ if (measured_frames != 1) c->win_unpaired = 1; ++ if (measured_frames > 0) { ++ c->win_measured += measured_frames * s->period_s; + c->win_work += work; + } c->win_wall += s->wall_s; diff --git a/framework/patches/runtime/src/main.cpp.patch b/framework/patches/runtime/src/main.cpp.patch index 8bcf0e6..1bc8095 100644 --- a/framework/patches/runtime/src/main.cpp.patch +++ b/framework/patches/runtime/src/main.cpp.patch @@ -1,5 +1,5 @@ diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp -index 886c0db0e1bdc3ab1284a6ff9b920d6a3f75440d..773cc0e471aa0c99f0b484b1b6aed5f9253088c3 100644 +index 886c0db0e1bdc3ab1284a6ff9b920d6a3f75440d..5afab762ef1df736518e0b6a149b34ea93e805ae 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -1,3 +1,4 @@ @@ -1527,7 +1527,7 @@ index 886c0db0e1bdc3ab1284a6ff9b920d6a3f75440d..773cc0e471aa0c99f0b484b1b6aed5f9 else if (now_s >= g_dynres.ctl.hold_until) g_dynres.hold_reason = ""; - DynresSample smp{ period, wall, work, held }; -+ DynresSample smp{ period, wall, work, held, work > 0.0 }; ++ DynresSample smp{ period, wall, work, held, work > 0.0 ? 1 : -1 }; const int level = dynres_sample(&g_dynres.ctl, now_s, &smp); if (g_dynres.trace && g_dynres.ctl.windows != g_dynres.last_windows) { g_dynres.last_windows = g_dynres.ctl.windows; diff --git a/src/game/render/adaptive_resolution.cpp b/src/game/render/adaptive_resolution.cpp index 209f0f0..cf78ed1 100644 --- a/src/game/render/adaptive_resolution.cpp +++ b/src/game/render/adaptive_resolution.cpp @@ -109,7 +109,7 @@ void frame() { const DynresSample sample{kPeriod, judged_wall(wall, slow, g.late, kPeriod, g.controller.p.gap_factor), work * g_work_scale, held(world, game_menu || menu_shown(psx_host_ui_gl_flags()), g_replaying, psx_netplay_active() != 0), - measured_frames}; + measured_frames ? measured_frames : -1}; g.late = gpu_bound(wall, gpu_per_frame, kPeriod, g.controller.p.late_factor); g.last = now; g.busy_ms = busy_ms; diff --git a/tests/unit/adaptive_resolution_test.cpp b/tests/unit/adaptive_resolution_test.cpp index 5f747f0..865ab50 100644 --- a/tests/unit/adaptive_resolution_test.cpp +++ b/tests/unit/adaptive_resolution_test.cpp @@ -83,7 +83,7 @@ void incomplete_timing_skips_down_step_verification() { int level = 3; for (int index = 0; index < 4; ++index) { now += 1.5 * period; - const DynresSample sample{period, 1.5 * period, index < 3 ? 1.6 * period : 0.0, 0, index < 3}; + const DynresSample sample{period, 1.5 * period, index < 3 ? 1.6 * period : 0.0, 0, index < 3 ? 1 : -1}; level = dynres_sample(&controller, now, &sample); } expect(level == 2 && !controller.post_active, "an incomplete window can ask for a lower resolution without scheduling verification"); @@ -148,7 +148,7 @@ void batched_gpu_results_cover_every_measured_frame() { dynres_init(&controller, ¶ms, 1, 3, 3); double now = 10.0; for (const int frames : window) { - const DynresSample sample{period, period, frames * period * 0.75, 0, frames}; + const DynresSample sample{period, period, frames * period * 0.75, 0, frames ? frames : -1}; dynres_sample(&controller, now += period, &sample); } expect(controller.last_valid && !controller.last_complete && controller.last_load == 0.75, @@ -158,7 +158,7 @@ void batched_gpu_results_cover_every_measured_frame() { dynres_init(&controller, ¶ms, 1, 3, 2); double now = 10.0; for (const int frames : readings[0]) { - const DynresSample sample{period, period, frames * period * 0.25, 0, frames}; + const DynresSample sample{period, period, frames * period * 0.25, 0, frames ? frames : -1}; dynres_sample(&controller, now += period, &sample); } const DynresSample quiet{period, period, period * 0.25, 0, 1}; diff --git a/tests/unit/disruptor_render_arena_test.cpp b/tests/unit/disruptor_render_arena_test.cpp index 9ddf0f9..5e2f7ab 100644 --- a/tests/unit/disruptor_render_arena_test.cpp +++ b/tests/unit/disruptor_render_arena_test.cpp @@ -102,22 +102,28 @@ int main() { psx_mod_write_word(0x800775D0u, 87u); psx_mod_write_word(0x800775C0u, 605u); psx_mod_write_word(0x80077624u, 255u); + psx_mod_write_word(disruptor::stock_frames::kTicks, 101u); cpu.gpr[4] = kContexts[1]; renderer_entry(&cpu, kRendererEntry); psx_mod_write_word(0x80077624u, 0u); psx_mod_write_word(0x800775BCu, 948u); psx_mod_write_word(0x800775D0u, 231u); psx_mod_write_word(0x800775C0u, 417u); + psx_mod_write_word(disruptor::stock_frames::kTicks, 103u); cpu.gpr[4] = kContexts[0]; margin = 0; renderer_entry(&cpu, kRendererEntry); int32_t eye[3]{}; - require(disruptor_draw_camera(240, 12, eye) == 255 && eye[0] == 317 && eye[1] == 87 && eye[2] == 605 && - disruptor_draw_camera(0, 12, eye) == 0 && eye[0] == 948 && eye[1] == 231 && eye[2] == 417, - "each draw page keeps the heading used to build its geometry"); + int64_t tick = -1; + require(disruptor_draw_camera(240, 12, eye, &tick) == 255 && eye[0] == 317 && eye[1] == 87 && eye[2] == 605 && tick == 101, + "the first draw page keeps its heading, camera position and tick"); + require(disruptor_draw_camera(0, 12, eye, &tick) == 0 && eye[0] == 948 && eye[1] == 231 && eye[2] == 417 && tick == 103, + "the second draw page keeps its heading, camera position and tick"); disruptor_reset_draw_headings(); - require(disruptor_draw_camera(240, 12, nullptr) == 12 && disruptor_draw_camera(0, 11, eye) == 11 && - eye[0] == 948 && eye[1] == 231 && eye[2] == 417, "a restored state inherited a draw page heading"); + tick = -1; + require(disruptor_draw_camera(240, 12, nullptr, nullptr) == 12 && disruptor_draw_camera(0, 11, eye, &tick) == 11 && + eye[0] == 948 && eye[1] == 231 && eye[2] == 417 && tick == -1, + "a restored state inherited draw page camera data"); require(!allocated, "4:3 allocated an enhancement arena"); margin = 267; allocation_fails = true;