Files
DroidDeck/tools/tests/test_vk_terminal_callers.py
T
MaxsTechReview 6e7908ed81 fix(display): copy the game and the window above it in one GPU submit (#3583)
* fix(display): copy the game and the window above it in one GPU submit

When a game's frames go on the layer-copy path and a window sits above
the game, each scene copied the game frame and then the window above it
with two separate submits and two CPU waits. Each wait queued behind
the game's own GPU work, so a GPU-bound game lost on-screen frames to
the second wait.

Record both copies in one command buffer, merge their release fences,
and wait once per scene. The zero-copy path and the single-layer copy
path are unchanged.

* Check overlay eligibility against the frame's own game geometry and keep both release waits when a fence merge fails
2026-12-02 12:12:08 -05:00

153 lines
6.4 KiB
Python

"""Fault-inject complete production render/blit/upload callers, without a GPU.
Uses Vulkan-Headers from the Android NDK (as installed by APK CI), or the host
Vulkan development package. Only Android platform declarations and the external
effect/frame-generation modules are mocked; vk_present.c is compiled unmodified.
"""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
from test_vk_pending_completion import function
ROOT = Path(__file__).resolve().parents[2]
SOURCE = ROOT / 'app/src/main/cpp/waylandcomp/src/vk_present.c'
def vulkan_include():
candidates = [Path(p) for p in [os.environ.get('DROIDDECK_VULKAN_INCLUDE', ''),
'/usr/include', '/usr/local/include'] if p]
for name in ('ANDROID_HOME', 'ANDROID_SDK_ROOT', 'ANDROID_NDK_HOME', 'NDK'):
if os.environ.get(name):
root = Path(os.environ[name])
candidates += sorted(root.glob('ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include'), reverse=True)
candidates += list(root.glob('toolchains/llvm/prebuilt/*/sysroot/usr/include'))
return next((p for p in candidates if (p / 'vulkan/vulkan.h').is_file()), None)
class VkTerminalCallersTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
headers = vulkan_include()
if headers is None:
raise unittest.SkipTest('NDK or host Vulkan-Headers required for full production-C caller tests')
cc = shutil.which(os.environ.get('CC', 'cc'))
if not cc:
raise AssertionError('C compiler required')
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-callers-')
cls.addClassCleanup(cls.tmp.cleanup)
tmp = Path(cls.tmp.name)
(tmp / 'android').mkdir()
(tmp / 'android/native_window.h').write_text('''
#pragma once
#include <stdint.h>
typedef struct ANativeWindow ANativeWindow;
int32_t ANativeWindow_getWidth(ANativeWindow *);
int32_t ANativeWindow_getHeight(ANativeWindow *);
void ANativeWindow_release(ANativeWindow *);
''')
(tmp / 'android/hardware_buffer.h').write_text('''
#pragma once
#include <stdint.h>
typedef struct AHardwareBuffer AHardwareBuffer;
typedef struct AHardwareBuffer_Desc {
uint32_t width, height, layers, format;
uint64_t usage;
uint32_t stride, rfu0;
uint64_t rfu1;
} AHardwareBuffer_Desc;
#define AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE (1ULL << 8)
#define AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT (1ULL << 14)
#define AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE (1ULL << 26)
static inline void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) { (void)b; *d = (AHardwareBuffer_Desc){0}; }
static inline void AHardwareBuffer_acquire(AHardwareBuffer *b) { (void)b; }
static inline void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; }
''')
(tmp / 'sys').mkdir()
(tmp / 'sys/system_properties.h').write_text('''
#pragma once
#define PROP_VALUE_MAX 92
static inline int __system_property_get(const char *name, char *value) { (void)name; value[0] = 0; return 0; }
''')
(tmp / 'android/log.h').write_text('''
#pragma once
#define ANDROID_LOG_INFO 4
int __android_log_print(int, const char *, const char *, ...);
''')
(tmp / 'wayland-server.h').write_text('#pragma once\nstruct wl_display; struct wl_resource; struct wl_client;\n')
compositor = (SOURCE.parent / 'compositor.c').read_text()
# send_buffer_release is a macro over send_buffer_release_at (with buffer tracing).
callers = ('static void buf_trace_release(struct wl_resource *b, int line) { (void)b; (void)line; }\n'
+ '#define send_buffer_release(b) send_buffer_release_at((b), __LINE__)\n'
+ '\n'.join(function(compositor, n) for n in ('buffer_release_blocked', 'send_buffer_release_at', 'take_shm', 'take_pixel')))
harness = (Path(__file__).with_name('vk_terminal_callers_test.c')).read_text()
probe = tmp / 'probe.c'
probe.write_text(harness.replace('/* COMPOSITOR_CALLERS */', callers))
cls.binary = tmp / 'probe'
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror',
'-Wno-unused-parameter', '-Wno-missing-field-initializers', '-UNDEBUG',
'-I', str(tmp), '-idirafter', str(headers), '-I', str(SOURCE.parent),
str(probe), '-pthread', '-lm', '-o', str(cls.binary)],
capture_output=True, text=True)
if built.returncode:
raise AssertionError(built.stdout + built.stderr)
def run_scenario(self, name):
ran = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10)
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
def test_first_acquire_idle_failure(self):
self.run_scenario('first-out-of-date')
def test_first_surface_lost_idle_failure(self):
self.run_scenario('first-surface-lost')
def test_later_framegen_acquire_idle_failure(self):
self.run_scenario('later-out-of-date')
def test_later_framegen_surface_lost_idle_failure(self):
self.run_scenario('later-surface-lost')
def test_blit_wait_error_same_size_shm_upload(self):
self.run_scenario('shm-wait-error')
def test_blit_wait_error_same_size_pixel_upload(self):
self.run_scenario('pixel-wait-error')
def test_layer_copies_share_one_submit_and_wait(self):
self.run_scenario('blit-batched')
def test_lost_device_shm_upload_keeps_cpu_snapshot(self):
self.run_scenario('lost-shm-upload')
def test_delayed_blit_completes_and_next_frame_renders(self):
self.run_scenario('blit-delayed')
def test_normal_present(self):
self.run_scenario('normal')
def test_normal_framegen_present(self):
self.run_scenario('framegen')
def test_healthy_later_acquire_timeout_drains_work(self):
self.run_scenario('later-timeout')
def test_device_loss_with_unconfirmed_idle_retains_resources(self):
self.run_scenario('acquire-device-lost-unconfirmed')
def test_real_device_lost_on_acquire(self):
self.run_scenario('acquire-device-lost')
def test_real_device_lost_on_present(self):
self.run_scenario('present-device-lost')
def test_pass_copy_and_abort_terminal_entry(self):
self.run_scenario('pass-terminal')
if __name__ == '__main__':
unittest.main()