diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 03f33894cb..95e2709e9e 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -2844,9 +2844,10 @@ 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 && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on && + if (hdr_route == 0 && vkp_quest_layer_presentation() && !cardboard && !cursor_on && !ahb_only) { settle_unwaited(); + g_framegen_layer = framegen; 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; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index faa89e89b5..37873d795c 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -3013,15 +3013,24 @@ 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()) { + if (vkp_quest_layer_presentation() && !vkp_cardboard_active()) { vkp_apply_window_request(); sc_layer_hide_overlay(); if (n > 0) { - if (sc_layer_present_pass(draws, n, scene_w, scene_h) != 0) { + const int fg = vkp_framegen_active(); + const int generated = fg + ? sc_layer_present_generated(draws, n, NULL, scene_w, scene_h, 1, NULL) : 0; + const int r = fg ? (generated >= 0 ? 0 : -1) + : sc_layer_present_pass(draws, n, scene_w, scene_h); + if (r != 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; } + if (fg && generated > 0) { + static int said; + if (!said) { said = 1; droiddeck_log("framegen", "generated frames go on the Quest display layer"); } + } } else { sc_layer_hide(); } diff --git a/tools/quest/test_first_frame.c b/tools/quest/test_first_frame.c index b0f0bac2ab..8fb3a426b4 100644 --- a/tools/quest/test_first_frame.c +++ b/tools/quest/test_first_frame.c @@ -3,8 +3,10 @@ #include 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; +struct vkp_hdr_frame; +struct droiddeck_color; +static int quest, framegen, cardboard, pass_result, gen_result, base_result, pass_shown, gen_shown; +static int first_frames, pass_calls, gen_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; } @@ -19,6 +21,15 @@ static int sc_layer_present_pass(const struct vkp_draw *draws, int n, int w, int if (pass_result == 0 && pass_shown) vkp_signal_first_frame(); return pass_result; } +static int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, + const struct vkp_hdr_frame *hf, int w, int h, + int composed, const struct droiddeck_color *color) { + (void)w; (void)h; + assert(composed == 1 && hf == NULL && color == NULL); + gen_calls++; + if (gen_result == 0 && gen_shown) vkp_signal_first_frame(); + return gen_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; } @@ -26,19 +37,19 @@ static int render_impl(int w, int h, const struct vkp_draw *draws, int n, static void reset(void) { quest = 1; - framegen = cardboard = pass_result = base_result = pass_shown = 0; - first_frames = pass_calls = base_calls = fallback_calls = 0; + framegen = cardboard = pass_result = gen_result = base_result = pass_shown = gen_shown = 0; + first_frames = pass_calls = gen_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); + assert(base_calls == 3 && pass_calls == 0 && gen_calls == 0 && first_frames == 0); reset(); assert(vkp_render(1280, 720, &draw, 1) == 0); - assert(pass_calls == 1 && base_calls == 1 && first_frames == 0); + assert(pass_calls == 1 && gen_calls == 0 && base_calls == 1 && first_frames == 0); reset(); pass_shown = 1; assert(vkp_render(1280, 720, &draw, 1) == 0); @@ -53,15 +64,36 @@ int main(void) { assert(vkp_render(1280, 720, NULL, 0) == -1); assert(first_frames == 0); - for (int mode = 0; mode < 3; mode++) { + for (int mode = 0; mode < 4; mode++) { reset(); if (mode == 0) quest = 0; - if (mode == 1) framegen = 1; - if (mode == 2) cardboard = 1; + if (mode == 1) cardboard = 1; + if (mode == 2) { quest = 0; framegen = 1; } + if (mode == 3) { framegen = 1; cardboard = 1; } assert(vkp_render(1280, 720, &draw, 1) == 17); - assert(fallback_calls == 1 && pass_calls == 0 && base_calls == 0); + assert(fallback_calls == 1 && pass_calls == 0 && gen_calls == 0 && base_calls == 0); assert(first_frames == 0); } - puts("PASS: Quest first-frame notification waits for client content"); + + reset(); framegen = 1; + assert(vkp_render(1280, 720, &draw, 1) == 0); + assert(gen_calls == 1 && pass_calls == 0 && fallback_calls == 0 && base_calls == 1); + + reset(); framegen = 1; gen_result = -1; + assert(vkp_render(1280, 720, &draw, 1) == -1); + assert(gen_calls == 1 && fallback_calls == 0 && base_calls == 0 && first_frames == 0); + + reset(); framegen = 1; gen_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(); framegen = 1; + assert(vkp_render(1280, 720, &draw, 1) == 0); + framegen = 0; + assert(vkp_render(1280, 720, &draw, 1) == 0); + assert(gen_calls == 1 && pass_calls == 1 && fallback_calls == 0 && first_frames == 0); + puts("PASS: Quest first-frame notification and display-layer frame generation"); return 0; } diff --git a/tools/tests/test_quest_presentation.py b/tools/tests/test_quest_presentation.py index 81b726a563..3979ef1b4b 100644 --- a/tools/tests/test_quest_presentation.py +++ b/tools/tests/test_quest_presentation.py @@ -55,6 +55,20 @@ 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 *); +''') + vulkan = work / 'vulkan' + vulkan.mkdir() + (vulkan / 'vulkan.h').write_text('''#pragma once +#include +typedef void *VkInstance; +typedef void *VkPhysicalDevice; +typedef void *VkDevice; +typedef void *VkQueue; +typedef void *VkCommandBuffer; +typedef void *VkImage; +typedef void *VkImageView; +typedef int VkFormat; +typedef void (*PFN_vkGetInstanceProcAddr)(void); ''') binary = work / 'test-presentation' subprocess.run(['cc', '-std=c11', '-O1', '-g', '-Wall', '-Wextra',