mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(framegen): stop re-arming frame generation that hangs the GPU on every frame
On the Adreno 850 with DD-Turnip v1.2.0, DD-FG's first generated frame hangs the GPU and the compositor's present returns VK_ERROR_DEVICE_LOST. Since frame generation stays armed across a device loss, every recovery hangs again on the next generated frame: about four losses a second, each a ~250 ms stall and a flicker, and the game itself runs at ~15 fps because its GPU work waits behind the resets. KH3's title screen measured 14 fps with 43 gaps of 250 ms in 15 s; with frame generation off it ran at 59 fps. Two device losses in a row after generation work was submitted, with fewer than 120 generated frames completed in between, now mark the engine failed. The game keeps running without frame generation, the existing "failed" state reaches the UI, and choosing an engine again retries it. A device loss after frame generation has been working still keeps it armed.
This commit is contained in:
1 parent
00b354a40a
commit
7bd636b25a
2 files changed
+83
No files matched your search
@@ -78,6 +78,24 @@ static int format_refused(VkFormat f) {
|
||||
|
||||
static _Atomic unsigned g_stat_generated;
|
||||
static uint64_t g_total_generated;
|
||||
|
||||
#define FG_PROVEN_FRAMES 120
|
||||
#define FG_HANG_STRIKES 2
|
||||
static int g_hang_strikes;
|
||||
static int g_submitted_since_ready;
|
||||
static uint64_t g_generated_at_ready;
|
||||
|
||||
// A driver that hangs on the engine's shaders loses the device on its first generated frame after every
|
||||
// recovery, so the compositor would recover and hang again for as long as frame generation stays armed.
|
||||
static int framegen_loss_strike(int submitted, uint64_t completed_since_ready) {
|
||||
if (!submitted || completed_since_ready >= FG_PROVEN_FRAMES) {
|
||||
g_hang_strikes = 0;
|
||||
return 0;
|
||||
}
|
||||
if (++g_hang_strikes < FG_HANG_STRIKES) return 0;
|
||||
g_hang_strikes = 0;
|
||||
return 1;
|
||||
}
|
||||
static float g_presented_rate, g_source_rate;
|
||||
static uint32_t g_present_accum, g_source_accum;
|
||||
static int64_t g_window_start_ns;
|
||||
@@ -93,6 +111,7 @@ void vkp_framegen_set_engine(int kind) {
|
||||
atomic_store(&g_kind, kind);
|
||||
atomic_store(&g_failed_kind, -1);
|
||||
atomic_store(&g_cfg_dirty, 1);
|
||||
g_hang_strikes = 0;
|
||||
}
|
||||
|
||||
void vkp_framegen_set_armed(int armed, int multiplier, int target_fps) {
|
||||
@@ -188,6 +207,8 @@ void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int f
|
||||
atomic_store(&g_caps_lsfg_ok, fge_caps_ok(VKP_FG_ENGINE_LSFG));
|
||||
atomic_store(&g_caps_ddfg_ok, fge_caps_ok(VKP_FG_ENGINE_DDFG));
|
||||
atomic_store(&g_dev_lost, 0);
|
||||
g_submitted_since_ready = 0;
|
||||
g_generated_at_ready = g_total_generated;
|
||||
atomic_store(&g_dev_ready,
|
||||
vk.CreateImage && vk.CreateImageView && vk.CmdPipelineBarrier);
|
||||
FGLOG("engines ready on the compositor's device: LSFG Native %s (%s), DD-FG Native %s",
|
||||
@@ -196,6 +217,13 @@ void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int f
|
||||
}
|
||||
|
||||
void vkp_framegen_device_lost(void) {
|
||||
if (framegen_loss_strike(g_submitted_since_ready, g_total_generated - g_generated_at_ready)) {
|
||||
int kind = atomic_load(&g_kind);
|
||||
mark_failed(kind);
|
||||
FGLOG("%s lost the GPU %d times in a row before its frames completed; frame generation stays off "
|
||||
"until it is set again", fge_engine_name(kind), FG_HANG_STRIKES);
|
||||
}
|
||||
g_submitted_since_ready = 0;
|
||||
atomic_store(&g_dev_lost, 1);
|
||||
atomic_store(&g_dev_ready, 0);
|
||||
fge_device_lost();
|
||||
@@ -452,6 +480,7 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, NULL, 0, NULL, nb, bars);
|
||||
|
||||
if (n_gen) g_submitted_since_ready = 1;
|
||||
fge_process(cmd, scene, (uint32_t)w, (uint32_t)h, n_gen);
|
||||
for (uint32_t g = 0; g < n_gen; g++) {
|
||||
fge_generate(cmd, g, n_gen, g_ring[g].img, g_ring[g].view, (uint32_t)w, (uint32_t)h);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.tests.test_vk_pending_completion import function
|
||||
|
||||
|
||||
class FramegenHangBreakerTest(unittest.TestCase):
|
||||
def run_c(self, body):
|
||||
compiler = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not compiler:
|
||||
self.skipTest('A host C compiler is required')
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
source = (root / 'app/src/main/cpp/waylandcomp/src/framegen_bridge.c').read_text()
|
||||
code = '#include <assert.h>\n#include <stdint.h>\n#define FG_PROVEN_FRAMES 120\n#define FG_HANG_STRIKES 2\n'
|
||||
code += 'static int g_hang_strikes;\n'
|
||||
code += function(source, 'framegen_loss_strike')
|
||||
code += 'int main(void) {\n' + body + '\n}\n'
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = Path(tmp)
|
||||
probe = folder / 'breaker.c'
|
||||
binary = folder / 'breaker'
|
||||
probe.write_text(code)
|
||||
subprocess.run([compiler, '-std=c11', str(probe), '-o', str(binary)], check=True,
|
||||
capture_output=True, text=True)
|
||||
subprocess.run([str(binary)], check=True, capture_output=True, timeout=10)
|
||||
|
||||
def test_losses_before_any_generated_frame_completes_switch_generation_off(self):
|
||||
self.run_c('''
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
assert(framegen_loss_strike(1, 0) == 1);
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
''')
|
||||
|
||||
def test_a_loss_after_generation_worked_keeps_it_armed(self):
|
||||
self.run_c('''
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
assert(framegen_loss_strike(1, 500) == 0);
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
''')
|
||||
|
||||
def test_a_loss_without_generation_work_is_not_a_strike(self):
|
||||
self.run_c('''
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
assert(framegen_loss_strike(0, 0) == 0);
|
||||
assert(framegen_loss_strike(1, 0) == 0);
|
||||
''')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user