mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
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:
1 parent
c3cd955686
commit
a692436f67
11 files changed
+510
-10
No files matched your search
@@ -1871,7 +1871,12 @@ static void render_scene(void) {
|
||||
else if (rendered && how == 2) droiddeck_color_frame_shown(hs.color, DROIDDECK_HDR_TONEMAPPED, 0);
|
||||
else if (rendered) hdr_copy = "the HDR composition pass is unavailable on this driver";
|
||||
}
|
||||
if (hdr_route == 0 || hdr_route == 3) {
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !framegen && !cardboard &&
|
||||
!ahb_layer_only_candidate(w, h)) {
|
||||
/* The complete SDR scene stays on one display layer. Do not hide/re-show GAME
|
||||
* on each desktop frame just because it is not a single fullscreen window. */
|
||||
rendered = vkp_render(w, h, dl.d, dl.n) == 0;
|
||||
} else if (hdr_route == 0 || hdr_route == 3) {
|
||||
const int pass_on = fx_on || framegen;
|
||||
int li = (g_zero_copy && !framegen && !cardboard) ? layer_candidate(&dl, w, h) : -1;
|
||||
int over = li >= 0 ? dl.n - 1 - li : 0;
|
||||
@@ -3156,6 +3161,9 @@ int droiddeck_wayland_run(void) {
|
||||
open_session_log();
|
||||
|
||||
if (vkp_ready() != 0) WLOGE("renderer unavailable; clients will connect but nothing is drawn");
|
||||
/* Presentation compatibility is not HDR capability. Set the initial layer mode before
|
||||
* clients bind, including when Desktop is the first session in this app process. */
|
||||
if (vkp_quest_layer_presentation() && sc_layer_available()) g_zero_copy = 1;
|
||||
|
||||
struct wl_display *display = wl_display_create();
|
||||
if (!display) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef DROIDDECK_QUEST_DEVICE_H
|
||||
#define DROIDDECK_QUEST_DEVICE_H
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
/* Presentation only; this does not select a GPU driver or expand driver support. */
|
||||
static inline int quest_device_matches(const char *model, const char *device, const char *maker) {
|
||||
return !strcasecmp(model, "Quest 2") || !strcasecmp(model, "Quest 3") ||
|
||||
!strcasecmp(model, "Quest 3S") ||
|
||||
((!strcasecmp(maker, "Oculus") || !strcasecmp(maker, "Meta")) &&
|
||||
(!strcmp(device, "hollywood") || !strcmp(device, "eureka") || !strcmp(device, "panther")));
|
||||
}
|
||||
#endif
|
||||
@@ -185,6 +185,8 @@ static int g_pending_cb;
|
||||
static unsigned g_stat_layer_frames;
|
||||
static int g_two_logged;
|
||||
static AHardwareBuffer *g_blank;
|
||||
static ASurfaceControl *g_base_sc;
|
||||
static int g_base_w, g_base_h, g_base_shown;
|
||||
|
||||
static void layers_init(void) {
|
||||
if (g_layers_ready) return;
|
||||
@@ -262,14 +264,58 @@ static AHardwareBuffer *blank_buffer(void) {
|
||||
AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY};
|
||||
if (AHardwareBuffer_allocate(&d, &g_blank) != 0 || !g_blank) { g_blank = NULL; return NULL; }
|
||||
void *p = NULL;
|
||||
if (AHardwareBuffer_lock(g_blank, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1, NULL, &p) == 0 && p) {
|
||||
AHardwareBuffer_Desc got; AHardwareBuffer_describe(g_blank, &got);
|
||||
memset(p, 0, (size_t)got.stride * 4 * 16);
|
||||
AHardwareBuffer_unlock(g_blank, NULL);
|
||||
int locked = AHardwareBuffer_lock(g_blank, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1, NULL, &p);
|
||||
if (locked != 0 || !p) {
|
||||
if (locked == 0) AHardwareBuffer_unlock(g_blank, NULL);
|
||||
AHardwareBuffer_release(g_blank); g_blank = NULL;
|
||||
return NULL;
|
||||
}
|
||||
AHardwareBuffer_Desc got; AHardwareBuffer_describe(g_blank, &got);
|
||||
memset(p, 0, (size_t)got.stride * 4 * got.height);
|
||||
if (AHardwareBuffer_unlock(g_blank, NULL) != 0) {
|
||||
AHardwareBuffer_release(g_blank); g_blank = NULL;
|
||||
return NULL;
|
||||
}
|
||||
return g_blank;
|
||||
}
|
||||
|
||||
int sc_layer_base_black(int width, int height) {
|
||||
if (width <= 0 || height <= 0 || load_api() != 0 || !vkp_window()) return -1;
|
||||
if (g_base_sc && g_base_shown && width == g_base_w && height == g_base_h) return 0;
|
||||
AHardwareBuffer *black = blank_buffer();
|
||||
if (!black) return -1;
|
||||
if (!g_base_sc) g_base_sc = api.createFromWindow(vkp_window(), "droiddeck_wayland_black");
|
||||
if (!g_base_sc) return -1;
|
||||
ASurfaceTransaction *tx = api.txCreate();
|
||||
if (!tx) return -1;
|
||||
ARect src = {0, 0, 16, 16}, dst = {0, 0, width, height};
|
||||
api.setBuffer(tx, g_base_sc, black, -1);
|
||||
api.setBufferTransparency(tx, g_base_sc, ASC_TRANSPARENCY_OPAQUE);
|
||||
api.setZOrder(tx, g_base_sc, 0); /* GAME = 1, OVERLAY = 2 */
|
||||
api.setGeometry(tx, g_base_sc, &src, &dst, 0);
|
||||
api.setVisibility(tx, g_base_sc, ASC_VISIBILITY_SHOW);
|
||||
api.txApply(tx); api.txDelete(tx);
|
||||
g_base_w = width; g_base_h = height; g_base_shown = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void base_hide(int retire) {
|
||||
if (!g_base_sc) return;
|
||||
ASurfaceTransaction *tx = api.txCreate();
|
||||
if (tx) {
|
||||
api.setVisibility(tx, g_base_sc, ASC_VISIBILITY_HIDE);
|
||||
if (retire) api.reparent(tx, g_base_sc, NULL);
|
||||
api.txApply(tx); api.txDelete(tx);
|
||||
g_base_shown = 0;
|
||||
}
|
||||
if (retire) {
|
||||
api.release(g_base_sc); g_base_sc = NULL;
|
||||
g_base_w = g_base_h = g_base_shown = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sc_layer_hide_base(void) { base_hide(0); }
|
||||
|
||||
static void replace_with_blank(ASurfaceTransaction *tx, struct layer *l) {
|
||||
AHardwareBuffer *b = blank_buffer();
|
||||
if (b) api.setBuffer(tx, l->sc, b, -1);
|
||||
@@ -927,6 +973,7 @@ void sc_layer_hide_overlay(void) {
|
||||
}
|
||||
|
||||
void sc_layer_window_gone(void) {
|
||||
base_hide(1); /* the backdrop belongs to the old window, just like GAME and OVERLAY */
|
||||
if (api.state != 1) return;
|
||||
layers_init();
|
||||
for (int i = SC_LAYER_COUNT - 1; i >= 0; i--) retire_sc(&g_layers[i]);
|
||||
|
||||
@@ -36,6 +36,8 @@ int sc_layer_overlay_affordable(void);
|
||||
int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent);
|
||||
|
||||
void sc_layer_hide(void);
|
||||
int sc_layer_base_black(int width, int height);
|
||||
void sc_layer_hide_base(void);
|
||||
void sc_layer_hide_overlay(void);
|
||||
|
||||
void sc_layer_window_gone(void);
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
#include "hdr_compose.h"
|
||||
#include "blend_pass.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "quest_device.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/system_properties.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
@@ -64,6 +66,21 @@ static VkExtent2D g_extent;
|
||||
static int g_first_frame_done;
|
||||
|
||||
static int g_base_black;
|
||||
|
||||
int vkp_quest_layer_presentation(void) {
|
||||
/* Compositor thread only; this is a process-wide device property, not a session setting.
|
||||
* Quest 2 still needs its separate A6xx driver: this gate only chooses presentation. */
|
||||
static int enabled = -1;
|
||||
if (enabled < 0) {
|
||||
char model[PROP_VALUE_MAX] = {0}, device[PROP_VALUE_MAX] = {0}, maker[PROP_VALUE_MAX] = {0};
|
||||
__system_property_get("ro.product.model", model);
|
||||
__system_property_get("ro.product.device", device);
|
||||
__system_property_get("ro.product.manufacturer", maker);
|
||||
enabled = quest_device_matches(model, device, maker);
|
||||
if (enabled) droiddeck_log("gpu", "Quest presentation: display layers for Steam and desktop, CPU-initialized black backdrop; independent of HDR");
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
static VkExtent2D g_caps_extent;
|
||||
static int64_t g_surface_checked_ns;
|
||||
|
||||
@@ -1335,6 +1352,10 @@ static void check_surface_changed(void) {
|
||||
|
||||
int vkp_base_black(int scene_w, int scene_h) {
|
||||
vkp_apply_window_request();
|
||||
if (vkp_quest_layer_presentation()) {
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
return sc_layer_base_black((int)g_extent.width, (int)g_extent.height);
|
||||
}
|
||||
check_surface_changed();
|
||||
if (g_base_black && g_swapchain && g_window && g_dev_state == 1) {
|
||||
g_perf.base_kept++;
|
||||
@@ -1413,6 +1434,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
const struct vkp_hdr_frame *hf, int *how) {
|
||||
if (how) *how = 0;
|
||||
vkp_apply_window_request();
|
||||
sc_layer_hide_base();
|
||||
check_surface_changed();
|
||||
if (g_dev_state == -2) return -1;
|
||||
if (dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1;
|
||||
@@ -1670,6 +1692,26 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
}
|
||||
|
||||
int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n) {
|
||||
if (vkp_quest_layer_presentation() && !vkp_framegen_active() && !vkp_cardboard_active()) {
|
||||
/* The desktop (multiple windows), overlays and an empty scene must also avoid WSI.
|
||||
* Merely enabling zero-copy handles only a single fullscreen window and leaves both
|
||||
* the letterbox and every fallback frame going through the corrupted swapchain. */
|
||||
vkp_apply_window_request();
|
||||
sc_layer_hide_overlay();
|
||||
if (n > 0) {
|
||||
if (sc_layer_present_pass(draws, n, scene_w, scene_h) != 0) {
|
||||
static int said;
|
||||
if (!said) { said = 1; droiddeck_log("error", "Quest scene layer unavailable; retaining the previous frame rather than using the corrupt Android swapchain"); }
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
sc_layer_hide();
|
||||
}
|
||||
/* sc_layer_present_pass signals only after submitting client content.
|
||||
* A backdrop alone, or a successful no-op while a layer slot is unavailable,
|
||||
* must not dismiss the app's loading UI or mark Steam's window as shown. */
|
||||
return vkp_base_black(scene_w, scene_h);
|
||||
}
|
||||
return render_impl(scene_w, scene_h, draws, n, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -1703,6 +1745,15 @@ void vkp_signal_first_frame(void) {
|
||||
|
||||
int vkp_update_map(int scene_w, int scene_h) {
|
||||
if (g_dev_state == -2 || dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1;
|
||||
if (vkp_quest_layer_presentation()) {
|
||||
/* Layer geometry needs the window size, not a Vulkan swapchain. In particular, do
|
||||
* not create/present a swapchain just to paint black under an otherwise clean layer. */
|
||||
int w = ANativeWindow_getWidth(g_window), h = ANativeWindow_getHeight(g_window);
|
||||
if (w <= 0 || h <= 0) return -1;
|
||||
g_extent = (VkExtent2D){(uint32_t)w, (uint32_t)h};
|
||||
update_map(scene_w, scene_h);
|
||||
return g_map.valid ? 0 : -1;
|
||||
}
|
||||
check_surface_changed();
|
||||
if (!g_swapchain && swap_init() != 0) return -1;
|
||||
update_map(scene_w, scene_h);
|
||||
@@ -1911,11 +1962,7 @@ int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *rw, int *rh) {
|
||||
if (g_pass.active) vkp_pass_abort();
|
||||
if (g_dev_state == -2 || dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1;
|
||||
check_surface_changed();
|
||||
if (!g_swapchain && swap_init() != 0) return -1;
|
||||
update_map(scene_w, scene_h);
|
||||
if (!g_map.valid) return -1;
|
||||
if (vkp_update_map(scene_w, scene_h) != 0) return -1;
|
||||
if (hf) {
|
||||
if (ensure_img(&g_hdrscene, scene_w, scene_h, HDR_FMT,
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
|
||||
@@ -8,6 +8,8 @@ void vk_present_set_driver(const char *driver_path, const char *library_name,
|
||||
void vk_present_set_window(ANativeWindow *window);
|
||||
int vkp_apply_window_request(void);
|
||||
|
||||
int vkp_quest_layer_presentation(void);
|
||||
|
||||
enum vkp_scale_mode { VKP_MODE_OFF = 0, VKP_MODE_FIT = 1, VKP_MODE_STRETCH = 2, VKP_MODE_FILL = 3,
|
||||
VKP_MODE_INTEGER = 4 };
|
||||
enum vkp_align { VKP_ALIGN_CENTER = 0, VKP_ALIGN_TOP = 1, VKP_ALIGN_BOTTOM = 2, VKP_ALIGN_PICTURE_TOP = 3, VKP_ALIGN_PICTURE_BOTTOM = 4 };
|
||||
|
||||
Reference in new issue
Block a user