fix(quest): correct desktop and Steam display corruption across sessions (#733)

fix(quest): stabilize desktop and Steam layer presentation

Keep Quest SDR scenes and the black backdrop off the Android Vulkan swapchain regardless of session order or HDR preferences. Only report the first frame after client content is submitted.

Add backdrop lifecycle and first-frame regression coverage. Record the user's successful Quest 3 Test 2 result.

Co-authored-by: xXJsonDeruloXx <danielhimebauch@gmail.com>
This commit is contained in:
Jagger15andxXJsonDeruloXx authored and GitHub committed 2026-10-15 09:51:02 -04:00
1 parent c3cd955686
commit a692436f67
11 files changed
+510 -10

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
/* Exercise the production vkp_render entrypoint without Android/Vulkan hardware.
* The Python runner extracts that function verbatim into the included file. */
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
struct vkp_draw { int unused; };
static int quest, framegen, cardboard, pass_result, base_result, pass_shown;
static int first_frames, pass_calls, base_calls, fallback_calls;
static int vkp_quest_layer_presentation(void) { return quest; }
static int vkp_framegen_active(void) { return framegen; }
static int vkp_cardboard_active(void) { return cardboard; }
static void vkp_apply_window_request(void) {}
static void sc_layer_hide_overlay(void) {}
static void sc_layer_hide(void) {}
static void droiddeck_log(const char *tag, const char *message, ...) {}
static void vkp_signal_first_frame(void) { first_frames++; }
static int vkp_base_black(int w, int h) { base_calls++; return base_result; }
static int sc_layer_present_pass(const struct vkp_draw *draws, int n, int w, int h) {
pass_calls++;
/* Production sc_layer_present_pass signals only after a content submission.
* Its no-op results (off-screen geometry or pool exhaustion) also return 0. */
if (pass_result == 0 && pass_shown) vkp_signal_first_frame();
return pass_result;
}
static int render_impl(int w, int h, const struct vkp_draw *draws, int n,
const void *hdr, int *how) { fallback_calls++; return 17; }
#include "vkp_render_under_test.inc"
static void reset(void) {
quest = 1;
framegen = cardboard = pass_result = base_result = pass_shown = 0;
first_frames = pass_calls = base_calls = fallback_calls = 0;
}
int main(void) {
const struct vkp_draw draw = {0};
reset();
for (int i = 0; i < 3; i++) assert(vkp_render(1280, 720, NULL, 0) == 0);
assert(base_calls == 3 && pass_calls == 0 && first_frames == 0);
/* An accepted layer operation is not necessarily a displayed client frame. */
reset();
assert(vkp_render(1280, 720, &draw, 1) == 0);
assert(pass_calls == 1 && base_calls == 1 && first_frames == 0);
/* Content is the sole owner of the notification, with no second backdrop event. */
reset(); pass_shown = 1;
assert(vkp_render(1280, 720, &draw, 1) == 0);
assert(first_frames == 1);
assert(vkp_render(1280, 720, NULL, 0) == 0);
assert(first_frames == 1);
reset(); pass_result = -1;
assert(vkp_render(1280, 720, &draw, 1) == -1);
assert(first_frames == 0 && base_calls == 0);
reset(); base_result = -1;
assert(vkp_render(1280, 720, NULL, 0) == -1);
assert(first_frames == 0);
/* Existing routes remain responsible for their own notifications. */
for (int mode = 0; mode < 3; mode++) {
reset();
if (mode == 0) quest = 0;
if (mode == 1) framegen = 1;
if (mode == 2) cardboard = 1;
assert(vkp_render(1280, 720, &draw, 1) == 17);
assert(fallback_calls == 1 && pass_calls == 0 && base_calls == 0);
assert(first_frames == 0);
}
puts("PASS: Quest first-frame notification waits for client content");
return 0;
}
+103
View File
@@ -0,0 +1,103 @@
/* Exercise the production backdrop with mock Android buffers/transactions. */
#include "../../app/src/main/cpp/waylandcomp/src/sc_layer.c"
#include "../../app/src/main/cpp/waylandcomp/src/quest_device.h"
#include <assert.h>
struct AHardwareBuffer { unsigned char pixels[20 * 16 * 4]; };
static struct AHardwareBuffer buffer;
static int fail_alloc, fail_lock, fail_unlock, fail_tx;
static int allocs, locks, unlocks, buffers, applies, creates, releases, retirements;
static int visible, zorder, opacity;
static ARect destination;
static ANativeWindow *window = (ANativeWindow *)1;
ANativeWindow *vkp_window(void) { return window; }
void droiddeck_log(const char *kind, const char *fmt, ...) { (void)kind; (void)fmt; }
int AHardwareBuffer_allocate(const AHardwareBuffer_Desc *d, AHardwareBuffer **b) {
assert(d->width == 16 && d->height == 16);
assert(d->usage & AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY);
allocs++;
if (fail_alloc) return -1;
memset(&buffer, 0xa5, sizeof(buffer)); *b = &buffer; return 0;
}
void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) {
assert(b == &buffer); *d = (AHardwareBuffer_Desc){.width=16,.height=16,.stride=20};
}
int AHardwareBuffer_lock(AHardwareBuffer *b, uint64_t usage, int32_t fd, const ARect *r, void **p) {
(void)usage; (void)fd; (void)r; assert(b == &buffer); locks++;
if (fail_lock) return -1;
*p = buffer.pixels; return 0;
}
int AHardwareBuffer_unlock(AHardwareBuffer *b, int32_t *f) {
assert(b == &buffer && f == NULL); unlocks++; return fail_unlock ? -1 : 0;
}
void AHardwareBuffer_release(AHardwareBuffer *b) { assert(b == &buffer); releases++; }
static ASurfaceControl *create(ANativeWindow *w, const char *n) {
assert(w == window && strcmp(n, "droiddeck_wayland_black") == 0); creates++;
return (ASurfaceControl *)(uintptr_t)(100 + creates);
}
static ASurfaceTransaction *tx_create(void) { return fail_tx ? NULL : (ASurfaceTransaction *)2; }
static void tx_delete(ASurfaceTransaction *t) { assert(t == (ASurfaceTransaction *)2); }
static void tx_apply(ASurfaceTransaction *t) { (void)t; applies++; }
static void set_buffer(ASurfaceTransaction *t, ASurfaceControl *s, AHardwareBuffer *b, int fd) {
(void)t; (void)s; assert(b == &buffer && fd == -1);
/* No garbage, including padded row bytes, reaches the display. */
for (unsigned i=0; i<sizeof(buffer.pixels); i++) assert(buffer.pixels[i] == 0);
assert(unlocks > 0); buffers++;
}
static void visibility(ASurfaceTransaction *t, ASurfaceControl *s, int8_t v) { (void)t; (void)s; visible=v; }
static void z(ASurfaceTransaction *t, ASurfaceControl *s, int32_t v) { (void)t; (void)s; zorder=v; }
static void transparency(ASurfaceTransaction *t, ASurfaceControl *s, int8_t v) { (void)t; (void)s; opacity=v; }
static void geometry(ASurfaceTransaction *t, ASurfaceControl *s, const ARect *src, const ARect *dst, int32_t rotation) {
(void)t; (void)s; assert(src->right==16 && src->bottom==16 && rotation==0); destination=*dst;
}
static void reparent(ASurfaceTransaction *t, ASurfaceControl *s, ASurfaceControl *parent) {
(void)t; (void)s; assert(parent==NULL); retirements++;
}
static void release(ASurfaceControl *s) { assert(s); }
static void reset(void) {
base_hide(1); g_blank=NULL;
fail_alloc=fail_lock=fail_unlock=fail_tx=0;
allocs=locks=unlocks=buffers=applies=creates=releases=retirements=0;
window=(ANativeWindow *)1;
}
int main(void) {
assert(quest_device_matches("Quest 2", "", ""));
assert(quest_device_matches("quest 3", "", ""));
assert(quest_device_matches("Quest 3S", "", ""));
assert(quest_device_matches("unknown", "hollywood", "Oculus"));
assert(quest_device_matches("unknown", "eureka", "Meta"));
assert(quest_device_matches("unknown", "panther", "Oculus"));
assert(!quest_device_matches("Pixel", "panther", "Google"));
assert(!quest_device_matches("Quest Pro", "seacliff", "Meta"));
assert(!quest_device_matches("", "", ""));
api.state=1; api.createFromWindow=create; api.txCreate=tx_create; api.txDelete=tx_delete;
api.txApply=tx_apply; api.setBuffer=set_buffer; api.setVisibility=visibility;
api.setZOrder=z; api.setBufferTransparency=transparency; api.setGeometry=geometry;
api.reparent=reparent; api.release=release;
reset();
assert(sc_layer_base_black(1920,1080)==0);
assert(visible==ASC_VISIBILITY_SHOW && zorder==0 && opacity==ASC_TRANSPARENCY_OPAQUE);
assert(destination.right==1920 && destination.bottom==1080);
assert(allocs==1 && locks==1 && buffers==1 && creates==1);
assert(sc_layer_base_black(1920,1080)==0 && applies==1); /* retained, not redrawn */
assert(sc_layer_base_black(1440,1080)==0 && destination.right==1440 && allocs==1);
sc_layer_hide_base(); assert(!visible && !g_base_shown);
assert(sc_layer_base_black(1440,1080)==0 && visible && allocs==1);
base_hide(1); assert(!g_base_sc && !g_base_shown && retirements==1);
window=(ANativeWindow *)3;
assert(sc_layer_base_black(1280,720)==0 && creates==2 && allocs==1 && locks==1);
reset(); fail_alloc=1;
assert(sc_layer_base_black(1920,1080)==-1 && buffers==0 && locks==0);
reset(); fail_lock=1;
assert(sc_layer_base_black(1920,1080)==-1 && buffers==0 && releases==1 && g_blank==NULL);
reset(); fail_unlock=1;
assert(sc_layer_base_black(1920,1080)==-1 && buffers==0 && releases==1 && g_blank==NULL);
reset(); fail_tx=1;
assert(sc_layer_base_black(1920,1080)==-1 && buffers==0 && !g_base_shown);
fail_tx=0; assert(sc_layer_base_black(1920,1080)==0 && creates==1 && locks==1);
reset(); window=NULL;
assert(sc_layer_base_black(1920,1080)==-1 && allocs==0);
window=(ANativeWindow *)1;
assert(sc_layer_base_black(0,1080)==-1 && allocs==0);
puts("PASS: Quest backdrop initialization, padding, reuse, resize, retire and failure recovery");
}
+75
View File
@@ -0,0 +1,75 @@
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
@unittest.skipUnless(shutil.which('cc'), 'needs a C compiler')
class QuestBackdropTest(unittest.TestCase):
def test_first_frame_requires_client_content(self):
# Compile the real entrypoint with controlled layer outcomes, including the
# successful no-op that previously dismissed the loading UI on a black frame.
source = (ROOT / 'app/src/main/cpp/waylandcomp/src/vk_present.c').read_text()
start = source.index('\nint vkp_render(')
end = source.index('\nint vkp_render_hdr(', start)
with tempfile.TemporaryDirectory() as folder:
work = Path(folder)
(work / 'vkp_render_under_test.inc').write_text(source[start:end])
binary = work / 'test-first-frame'
subprocess.run(['cc', '-std=c11', '-Wall', '-Wextra',
'-Wno-unused-parameter', '-Wno-unused-function', f'-I{work}',
str(ROOT / 'tools/quest/test_first_frame.c'), '-o', str(binary)],
check=True, capture_output=True, text=True)
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn('PASS: Quest first-frame', result.stdout)
def test_backdrop_lifecycle_and_failed_buffer_initialization(self):
with tempfile.TemporaryDirectory() as folder:
work = Path(folder)
android = work / 'android'
android.mkdir()
(android / 'rect.h').write_text('''#pragma once
#include <stdint.h>
typedef struct ARect { int32_t left, top, right, bottom; } ARect;
''')
(android / 'native_window.h').write_text('''#pragma once
typedef struct ANativeWindow ANativeWindow;
''')
(android / 'hardware_buffer.h').write_text('''#pragma once
#include <stdint.h>
#include "rect.h"
typedef struct AHardwareBuffer AHardwareBuffer;
typedef struct { uint32_t width,height,layers,format; uint64_t usage;
uint32_t stride,rfu0; uint64_t rfu1; } AHardwareBuffer_Desc;
#define AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM 1
#define AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM 0x2b
#define AHARDWAREBUFFER_USAGE_CPU_READ_RARELY 2ULL
#define AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY 32ULL
#define AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE 256ULL
#define AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT 512ULL
#define AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY 2048ULL
int AHardwareBuffer_allocate(const AHardwareBuffer_Desc *, AHardwareBuffer **);
void AHardwareBuffer_describe(const AHardwareBuffer *, AHardwareBuffer_Desc *);
int AHardwareBuffer_lock(AHardwareBuffer *, uint64_t, int32_t, const ARect *, void **);
int AHardwareBuffer_unlock(AHardwareBuffer *, int32_t *);
void AHardwareBuffer_release(AHardwareBuffer *);
''')
binary = work / 'test-presentation'
subprocess.run(['cc', '-std=c11', '-O1', '-g', '-Wall', '-Wextra',
'-Wno-unused-parameter', '-Wno-unused-function',
'-ffunction-sections', '-fdata-sections', '-Wl,--gc-sections',
'-fsanitize=address,undefined', f'-I{work}',
f'-I{ROOT}/app/src/main/cpp/waylandcomp/prebuilt/include',
str(ROOT / 'tools/quest/test_presentation.c'), '-ldl', '-pthread',
'-o', str(binary)], check=True, capture_output=True, text=True)
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn('PASS: Quest backdrop', result.stdout)
if __name__ == '__main__':
unittest.main()