diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt index 13e9e1b3e..5bdc1e838 100644 --- a/app/src/main/cpp/waylandcomp/CMakeLists.txt +++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt @@ -8,6 +8,7 @@ add_library(droiddeckwayland SHARED src/vk_loader.c src/sc_layer.c src/ahb_swapchain.c + src/display_buffers.c src/waylandcomp_jni.c src/gpu_clock_pin.c src/droiddeck_ext.c @@ -34,7 +35,8 @@ add_library(droiddeckwayland SHARED generated/text-input-unstable-v3-protocol.c generated/xdg-toplevel-icon-v1-protocol.c generated/single-pixel-buffer-v1-protocol.c - generated/banner-ahb-v1-protocol.c + generated/droiddeck-ahb-v1-protocol.c + generated/droiddeck-refresh-v1-protocol.c src/framegen_bridge.c src/framegen_jni.c src/hudframes.c diff --git a/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md b/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md index 37b08b233..f5e717724 100644 --- a/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md +++ b/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md @@ -19,8 +19,8 @@ exactly how Turnip already imports every gralloc buffer on Android (`vk_android. in play already have every extension needed; nothing is missing in the drivers. What is missing is a **WSI hook**: Mesa's Wayland WSI always allocates its own dma-bufs and has no way to receive or allocate compositor-visible buffers, so **option (a) or (c) each need a ~300-line patch to -`wsi_common_wayland.c` in our own Wayland Turnip build** (banners-turnip-wayland -`build_turnip_wayland_wsi.sh`, Mesa `7cda7850`) plus a small private Wayland protocol. Nothing in +`wsi_common_wayland.c` in our own Wayland Turnip build** +(`build_turnip_wayland_wsi.sh`, Mesa `7cda7850`) plus a small private Wayland protocol. Nothing in the app can remove the copy on its own. Recommended: **option (a′) - the game's WSI allocates its swapchain images as `AHardwareBuffer`s (gralloc-native, UBWC), imports them through the AHB path Turnip already has, and hands the compositor the AHB over a Unix socket (`AHardwareBuffer_send/ @@ -77,7 +77,7 @@ Mesa's Wayland WSI creates every native swapchain image with `wsi_create_native_ (the Android-WSI import path, `tu_image.cc:880-925`) is only reachable from the Android swapchain. The patch (in our Wayland Turnip build): a new `create_mem` for the Wayland chain, selected when the -compositor advertises a private global `banner_layer_buffer_v1`: +compositor advertises a private global `droiddeck_layer_buffer_v1`: 1. `AHardwareBuffer_allocate(w, h, R8G8B8A8, GPU_COLOR_OUTPUT | GPU_SAMPLED_IMAGE)`; `vkGetAndroidHardwareBufferPropertiesANDROID` → `vkAllocateMemory` with `VkImportAndroidHardwareBufferInfoANDROID` (Turnip: `tu_device.cc:3828`), bind - the image was @@ -85,7 +85,7 @@ compositor advertises a private global `banner_layer_buffer_v1`: 2. `wsi_image.dma_buf_fd = dup(native_handle->data[0])`, `drm_modifier` / `row_pitches[0]` from the same layout → the existing `zwp_linux_dmabuf_v1` path stays untouched: the compositor keeps importing a dma-buf and can keep the blit path as the fallback. -3. `banner_layer_buffer_v1.attach(wl_buffer, socket_fd)`: the WSI creates a `socketpair`, sends one +3. `droiddeck_layer_buffer_v1.attach(wl_buffer, socket_fd)`: the WSI creates a `socketpair`, sends one end in the request, and calls `AHardwareBuffer_sendHandleToUnixSocket(ahb, other_end)`; the compositor's request handler does `AHardwareBuffer_recvHandleFromUnixSocket` and stores the AHB on `struct dmabuf_buffer`. Per swapchain image, once - not per frame. @@ -262,7 +262,7 @@ D3D12 tabs) as the workload, session log in `Download/Wayland-logs/`. since the blit only changed its destination) and `dumpsys gfxinfo`/battery for 5 min each. This is the baseline the WSI patch is measured against. 4. **Fence probe outcome → choose the acquire-fence design** (§3) before starting the WSI patch. -5. **WSI patch (option a) in banners-turnip-wayland**, wcp rebuild, then the same steps 1–3 with +5. **WSI patch (option a) in the Wayland Turnip build**, wcp rebuild, then the same steps 1–3 with the AHB arriving from the guest: log line to add on the compositor side `layer: buffer N of "" received from the game (AHardwareBuffer WxH, UBWC)` and the fps delta vs X11. @@ -296,7 +296,7 @@ unchanged. Off by default: with the variable unset no new code runs. Not zero-copy yet - it is the receive side. The copy disappears when step 5 lands and `sc_layer_present` is handed the game's own `AHardwareBuffer` instead of a pool slot. -## 7. Step 5 implemented (feat/wayland-zero-copy-wsi + banners-turnip-wayland `banner_ahb_wsi.py`) +## 7. Step 5 implemented (feat/wayland-zero-copy-wsi + the Wayland Turnip build `droiddeck_ahb_wsi.py`) Option (a′) as recommended, with one deviation forced by the build: the Wayland Turnip is a `platforms=wayland` build with Android detection off, so `VK_ANDROID_external_memory_android_hardware_buffer` diff --git a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-protocol.c similarity index 76% rename from app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c rename to app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-protocol.c index 17b0c0dfd..1c7e42dbf 100644 --- a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-protocol.c @@ -38,7 +38,7 @@ extern const struct wl_interface wl_buffer_interface; -static const struct wl_interface *banner_ahb_v1_types[] = { +static const struct wl_interface *droiddeck_ahb_v1_types[] = { NULL, &wl_buffer_interface, NULL, @@ -50,18 +50,18 @@ static const struct wl_interface *banner_ahb_v1_types[] = { NULL, }; -static const struct wl_message banner_ahb_v1_requests[] = { - { "destroy", "", banner_ahb_v1_types + 0 }, - { "attach", "ohuuuuuu", banner_ahb_v1_types + 1 }, +static const struct wl_message droiddeck_ahb_v1_requests[] = { + { "destroy", "", droiddeck_ahb_v1_types + 0 }, + { "attach", "ohuuuuuu", droiddeck_ahb_v1_types + 1 }, }; -static const struct wl_message banner_ahb_v1_events[] = { - { "mode", "2u", banner_ahb_v1_types + 0 }, +static const struct wl_message droiddeck_ahb_v1_events[] = { + { "mode", "2u", droiddeck_ahb_v1_types + 0 }, }; -WL_PRIVATE const struct wl_interface banner_ahb_v1_interface = { - "banner_ahb_v1", 2, - 2, banner_ahb_v1_requests, - 1, banner_ahb_v1_events, +WL_PRIVATE const struct wl_interface droiddeck_ahb_v1_interface = { + "droiddeck_ahb_v1", 2, + 2, droiddeck_ahb_v1_requests, + 1, droiddeck_ahb_v1_events, }; diff --git a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-server-protocol.h similarity index 73% rename from app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h rename to app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-server-protocol.h index 788982c10..118ca6c61 100644 --- a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-ahb-v1-server-protocol.h @@ -1,6 +1,6 @@ -#ifndef BANNER_AHB_V1_SERVER_PROTOCOL_H -#define BANNER_AHB_V1_SERVER_PROTOCOL_H +#ifndef DROIDDECK_AHB_V1_SERVER_PROTOCOL_H +#define DROIDDECK_AHB_V1_SERVER_PROTOCOL_H #include #include @@ -14,7 +14,7 @@ struct wl_client; struct wl_resource; /* - * @section page_copyright_banner_ahb_v1 Copyright + * @section page_copyright_droiddeck_ahb_v1 Copyright * * Copyright 2026 The412Banner * @@ -42,15 +42,15 @@ struct wl_resource; -struct banner_ahb_v1; +struct droiddeck_ahb_v1; struct wl_buffer; -#ifndef BANNER_AHB_V1_INTERFACE -#define BANNER_AHB_V1_INTERFACE -extern const struct wl_interface banner_ahb_v1_interface; +#ifndef DROIDDECK_AHB_V1_INTERFACE +#define DROIDDECK_AHB_V1_INTERFACE +extern const struct wl_interface droiddeck_ahb_v1_interface; #endif -struct banner_ahb_v1_interface { +struct droiddeck_ahb_v1_interface { void (*destroy)(struct wl_client *client, struct wl_resource *resource); void (*attach)(struct wl_client *client, @@ -65,17 +65,17 @@ struct banner_ahb_v1_interface { uint32_t image_count); }; -#define BANNER_AHB_V1_MODE 0 +#define DROIDDECK_AHB_V1_MODE 0 -#define BANNER_AHB_V1_MODE_SINCE_VERSION 2 +#define DROIDDECK_AHB_V1_MODE_SINCE_VERSION 2 -#define BANNER_AHB_V1_DESTROY_SINCE_VERSION 1 -#define BANNER_AHB_V1_ATTACH_SINCE_VERSION 1 +#define DROIDDECK_AHB_V1_DESTROY_SINCE_VERSION 1 +#define DROIDDECK_AHB_V1_ATTACH_SINCE_VERSION 1 static inline void -banner_ahb_v1_send_mode(struct wl_resource *resource_, uint32_t enabled) +droiddeck_ahb_v1_send_mode(struct wl_resource *resource_, uint32_t enabled) { - wl_resource_post_event(resource_, BANNER_AHB_V1_MODE, enabled); + wl_resource_post_event(resource_, DROIDDECK_AHB_V1_MODE, enabled); } #ifdef __cplusplus diff --git a/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-protocol.c new file mode 100644 index 000000000..bd26d77a2 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-protocol.c @@ -0,0 +1,59 @@ +/* + * Copyright 2026 DroidDeck contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + + +static const struct wl_interface *droiddeck_refresh_v1_types[] = { + NULL, + NULL, +}; + +static const struct wl_message droiddeck_refresh_v1_requests[] = { + { "destroy", "", droiddeck_refresh_v1_types + 0 }, + { "set_target", "uu", droiddeck_refresh_v1_types + 0 }, +}; + +static const struct wl_message droiddeck_refresh_v1_events[] = { + { "rate", "u", droiddeck_refresh_v1_types + 0 }, + { "done", "", droiddeck_refresh_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface droiddeck_refresh_v1_interface = { + "droiddeck_refresh_v1", 1, + 2, droiddeck_refresh_v1_requests, + 2, droiddeck_refresh_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-server-protocol.h new file mode 100644 index 000000000..32d1c1778 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/droiddeck-refresh-v1-server-protocol.h @@ -0,0 +1,175 @@ + +#ifndef DROIDDECK_REFRESH_V1_SERVER_PROTOCOL_H +#define DROIDDECK_REFRESH_V1_SERVER_PROTOCOL_H + +#include +#include +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_droiddeck_refresh_v1 The droiddeck_refresh_v1 protocol + * @section page_ifaces_droiddeck_refresh_v1 Interfaces + * - @subpage page_iface_droiddeck_refresh_v1 - panel refresh rates a nested compositor may ask for + * @section page_copyright_droiddeck_refresh_v1 Copyright + *
+ *
+ * Copyright 2026 DroidDeck contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ */ +struct droiddeck_refresh_v1; + +#ifndef DROIDDECK_REFRESH_V1_INTERFACE +#define DROIDDECK_REFRESH_V1_INTERFACE +/** + * @page page_iface_droiddeck_refresh_v1 droiddeck_refresh_v1 + * @section page_iface_droiddeck_refresh_v1_desc Description + * + * A nested compositor paces its clients against the refresh rate of the + * panel it is shown on. When its clients are held to a frame rate the + * panel's current rate does not divide evenly, frames are shown for an + * uneven number of refreshes. This interface lets the nested compositor + * see every refresh rate the panel can run at its current size and ask + * for the one that suits the frame rate it is pacing to. + * + * On bind the compositor sends one rate event per refresh rate, lowest + * first, followed by done. The list is sent again, in full, whenever it + * changes (a different panel, or a limit the user placed on the panel's + * rate). The rate the panel is running at is still reported the standard + * way, through wl_output.mode. + * + * A request is a preference, not a guarantee: the user, the platform or + * another output mirroring the panel may hold the panel at another rate. + * The client reads the result from wl_output.mode. + * @section page_iface_droiddeck_refresh_v1_api API + * See @ref iface_droiddeck_refresh_v1. + */ +/** + * @defgroup iface_droiddeck_refresh_v1 The droiddeck_refresh_v1 interface + * + * A nested compositor paces its clients against the refresh rate of the + * panel it is shown on. When its clients are held to a frame rate the + * panel's current rate does not divide evenly, frames are shown for an + * uneven number of refreshes. This interface lets the nested compositor + * see every refresh rate the panel can run at its current size and ask + * for the one that suits the frame rate it is pacing to. + * + * On bind the compositor sends one rate event per refresh rate, lowest + * first, followed by done. The list is sent again, in full, whenever it + * changes (a different panel, or a limit the user placed on the panel's + * rate). The rate the panel is running at is still reported the standard + * way, through wl_output.mode. + * + * A request is a preference, not a guarantee: the user, the platform or + * another output mirroring the panel may hold the panel at another rate. + * The client reads the result from wl_output.mode. + */ +extern const struct wl_interface droiddeck_refresh_v1_interface; +#endif + +/** + * @ingroup iface_droiddeck_refresh_v1 + * @struct droiddeck_refresh_v1_interface + */ +struct droiddeck_refresh_v1_interface { + /** + * destroy the object + * + * The preference set through this object is dropped. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * ask for a refresh rate + * + * refresh is the panel rate the client would like, in Hz, taken + * from the advertised list; 0 withdraws the preference. frame_rate + * is the frame rate the client holds its content to, in frames per + * second, or 0 when the content is not held to a rate. The + * compositor may multiply the content's frame rate itself + * (generated frames); when it does, it picks the advertised rate + * that the multiplied frame rate divides evenly instead of the + * requested one. + * @param refresh wanted panel refresh rate in Hz, 0 for none + * @param frame_rate content frame rate in frames per second, 0 for unpaced + */ + void (*set_target)(struct wl_client *client, + struct wl_resource *resource, + uint32_t refresh, + uint32_t frame_rate); +}; + +#define DROIDDECK_REFRESH_V1_RATE 0 +#define DROIDDECK_REFRESH_V1_DONE 1 + +/** + * @ingroup iface_droiddeck_refresh_v1 + */ +#define DROIDDECK_REFRESH_V1_RATE_SINCE_VERSION 1 +/** + * @ingroup iface_droiddeck_refresh_v1 + */ +#define DROIDDECK_REFRESH_V1_DONE_SINCE_VERSION 1 + +/** + * @ingroup iface_droiddeck_refresh_v1 + */ +#define DROIDDECK_REFRESH_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_droiddeck_refresh_v1 + */ +#define DROIDDECK_REFRESH_V1_SET_TARGET_SINCE_VERSION 1 + +/** + * @ingroup iface_droiddeck_refresh_v1 + * Sends an rate event to the client owning the resource. + * @param resource_ The client's resource + * @param refresh panel refresh rate in Hz + */ +static inline void +droiddeck_refresh_v1_send_rate(struct wl_resource *resource_, uint32_t refresh) +{ + wl_resource_post_event(resource_, DROIDDECK_REFRESH_V1_RATE, refresh); +} + +/** + * @ingroup iface_droiddeck_refresh_v1 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +droiddeck_refresh_v1_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, DROIDDECK_REFRESH_V1_DONE); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml b/app/src/main/cpp/waylandcomp/protocols/droiddeck-ahb-v1.xml similarity index 98% rename from app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml rename to app/src/main/cpp/waylandcomp/protocols/droiddeck-ahb-v1.xml index 1560c8f7c..a40b0dcd8 100644 --- a/app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml +++ b/app/src/main/cpp/waylandcomp/protocols/droiddeck-ahb-v1.xml @@ -1,5 +1,5 @@ - + Copyright 2026 The412Banner @@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE. - + Zero-copy window layers on Android. A Vulkan swapchain image that the client allocated as an Android AHardwareBuffer (gralloc) is still shared diff --git a/app/src/main/cpp/waylandcomp/protocols/droiddeck-refresh-v1.xml b/app/src/main/cpp/waylandcomp/protocols/droiddeck-refresh-v1.xml new file mode 100644 index 000000000..c4464a041 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/droiddeck-refresh-v1.xml @@ -0,0 +1,81 @@ + + + + Copyright 2026 DroidDeck contributors + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + + + + A nested compositor paces its clients against the refresh rate of the + panel it is shown on. When its clients are held to a frame rate the + panel's current rate does not divide evenly, frames are shown for an + uneven number of refreshes. This interface lets the nested compositor + see every refresh rate the panel can run at its current size and ask + for the one that suits the frame rate it is pacing to. + + On bind the compositor sends one rate event per refresh rate, lowest + first, followed by done. The list is sent again, in full, whenever it + changes (a different panel, or a limit the user placed on the panel's + rate). The rate the panel is running at is still reported the standard + way, through wl_output.mode. + + A request is a preference, not a guarantee: the user, the platform or + another output mirroring the panel may hold the panel at another rate. + The client reads the result from wl_output.mode. + + + + + The preference set through this object is dropped. + + + + + + refresh is the panel rate the client would like, in Hz, taken from + the advertised list; 0 withdraws the preference. frame_rate is the + frame rate the client holds its content to, in frames per second, or + 0 when the content is not held to a rate. The compositor may multiply + the content's frame rate itself (generated frames); when it does, it + picks the advertised rate that the multiplied frame rate divides + evenly instead of the requested one. + + + + + + + + Sent once per rate, lowest first, in Hz rounded to the nearest whole + number. + + + + + + + Ends a list of rate events. The rates received since the previous + done replace the earlier list. + + + + diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c index e33b0c77b..c31915a45 100644 --- a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c @@ -4,7 +4,7 @@ #include "droiddeck_ext.h" #include "sc_layer.h" #include "vk_present.h" -#include "banner-ahb-v1-server-protocol.h" +#include "droiddeck-ahb-v1-server-protocol.h" #include #include #include @@ -25,6 +25,7 @@ struct droiddeck_dma_buf_sync_file { uint32_t flags; int32_t fd; }; #define DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW('b', 3, struct droiddeck_dma_buf_sync_file) extern volatile int g_zero_copy; +void droiddeck_dmabuf_formats_stale(void); struct ahb_buf { uint64_t id; @@ -37,6 +38,7 @@ struct ahb_buf { struct wl_client *client; struct wl_resource *resource; struct wl_listener resource_destroy; + int display; int on_layer; int release_pending; int64_t deferred_ns; @@ -131,10 +133,10 @@ static void handle_released(uint64_t id, int fd) { if (fd >= 0) { struct droiddeck_dma_buf_sync_file imp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = fd}; int dmabuf_fd = droiddeck_dmabuf_fd(ab->b); - if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) { + if (!ab->display && dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) { close(fd); } else { - if (!g_import_failed_logged) { + if (!ab->display && !g_import_failed_logged) { g_import_failed_logged = 1; droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_IMPORT_SYNC_FILE failed (%s): releases wait for the display's fence here instead", strerror(errno)); @@ -187,7 +189,7 @@ int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b) { return b && *droiddeck_dmabuf_ahb_slot((struct dmabuf_buffer *)b) != NULL; } -int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h) { +int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h, const struct vkp_draw *draw) { struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot(b) : NULL; if (!ab) return -1; int dmabuf_fd = droiddeck_dmabuf_fd(b); @@ -205,7 +207,7 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_ int r; do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); } - int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, + int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, draw, s ? droiddeck_surface_color(s) : NULL, ab->format); if (r < 0) return -1; if (r == 1) return 0; @@ -259,6 +261,58 @@ uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b) { } +static int adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb, + uint32_t stride, uint32_t image_count, uint64_t modifier) { + AHardwareBuffer_Desc d; + AHardwareBuffer_describe(ahb, &d); + int bw, bh; + droiddeck_dmabuf_size(b, &bw, &bh); + struct ahb_buf *ab = calloc(1, sizeof(*ab)); + if (!ab) return -1; + ab->id = g_next_id++; + ab->b = b; + droiddeck_dmabuf_ref(b); + ab->ahb = ahb; + ab->w = bw; ab->h = bh; + ab->stride = d.stride ? d.stride : stride; + ab->image_count = image_count; + ab->format = d.format; + ab->modifier = modifier; + ab->client = c; + ab->resource = buffer; + ab->resource_destroy.notify = on_buffer_resource_destroyed; + wl_resource_add_destroy_listener(buffer, &ab->resource_destroy); + ab->fence_fd = -1; + wl_list_insert(g_bufs.prev, &ab->link); + *droiddeck_dmabuf_ahb_slot(b) = ab; + + if (g_last_chain.client != c || g_last_chain.w != bw || g_last_chain.h != bh || + g_last_chain.image_count != image_count || g_last_chain.modifier != modifier || g_last_chain.format != d.format) { + char count[32] = ""; + if (image_count) snprintf(count, sizeof(count), "%u images, ", image_count); + g_last_chain = (struct chain_seen){c, bw, bh, image_count, modifier, d.format}; + droiddeck_log("layer", "zero-copy: %s from %s (%s%dx%d, %s, %s, stride %u px)", + image_count ? "AHB swapchain" : "display buffers", droiddeck_client_name(c), count, bw, bh, + droiddeck_ahb_format_name(d.format), modifier == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" + : modifier == 0 ? "linear" : "unknown modifier", ab->stride); + } + return 0; +} + +int ahb_swapchain_adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb, + uint64_t modifier) { + if (!g_advertised || *droiddeck_dmabuf_ahb_slot(b)) return -1; + AHardwareBuffer_acquire(ahb); + if (adopt(c, buffer, b, ahb, 0, 0, modifier) != 0) { AHardwareBuffer_release(ahb); return -1; } + ((struct ahb_buf *)*droiddeck_dmabuf_ahb_slot(b))->display = 1; + return 0; +} + +AHardwareBuffer *ahb_swapchain_display_buffer(const struct dmabuf_buffer *b) { + struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot((struct dmabuf_buffer *)b) : NULL; + return ab && ab->display ? ab->ahb : NULL; +} + static void ahb_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } static void ahb_attach(struct wl_client *c, struct wl_resource *r, struct wl_resource *buffer, int32_t sock, @@ -295,36 +349,13 @@ static void ahb_attach(struct wl_client *c, struct wl_resource *r, struct wl_res AHardwareBuffer_release(ahb); return; } - - struct ahb_buf *ab = calloc(1, sizeof(*ab)); - if (!ab) { AHardwareBuffer_release(ahb); wl_client_post_no_memory(c); return; } - ab->id = g_next_id++; - ab->b = b; - droiddeck_dmabuf_ref(b); - ab->ahb = ahb; - ab->w = bw; ab->h = bh; - ab->stride = d.stride ? d.stride : stride; - ab->image_count = image_count; - ab->format = d.format; - ab->modifier = modifier; - ab->client = c; - ab->resource = buffer; - ab->resource_destroy.notify = on_buffer_resource_destroyed; - wl_resource_add_destroy_listener(buffer, &ab->resource_destroy); - ab->fence_fd = -1; - wl_list_insert(g_bufs.prev, &ab->link); - *slot = ab; - - if (g_last_chain.client != c || g_last_chain.w != bw || g_last_chain.h != bh || - g_last_chain.image_count != image_count || g_last_chain.modifier != modifier || g_last_chain.format != d.format) { - g_last_chain = (struct chain_seen){c, bw, bh, image_count, modifier, d.format}; - droiddeck_log("layer", "zero-copy: AHB swapchain from %s (%u images, %dx%d, %s, %s, stride %u px)", droiddeck_client_name(c), - image_count, bw, bh, droiddeck_ahb_format_name(d.format), modifier == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" - : modifier == 0 ? "linear" : "unknown modifier", ab->stride); + if (adopt(c, buffer, b, ahb, stride, image_count, modifier) != 0) { + AHardwareBuffer_release(ahb); + wl_client_post_no_memory(c); } } -static const struct banner_ahb_v1_interface ahb_impl = { +static const struct droiddeck_ahb_v1_interface ahb_impl = { .destroy = ahb_destroy, .attach = ahb_attach, }; @@ -336,20 +367,21 @@ static void on_client_resource_destroyed(struct wl_resource *r) { static void bind_ahb(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { static struct wl_client *last_named; if (ver > 2) ver = 2; - struct wl_resource *r = wl_resource_create(c, &banner_ahb_v1_interface, (int)ver, id); + struct wl_resource *r = wl_resource_create(c, &droiddeck_ahb_v1_interface, (int)ver, id); if (!r) { wl_client_post_no_memory(c); return; } wl_resource_set_implementation(r, &ahb_impl, NULL, on_client_resource_destroyed); wl_list_insert(&g_clients, wl_resource_get_link(r)); - if (ver >= BANNER_AHB_V1_MODE_SINCE_VERSION) banner_ahb_v1_send_mode(r, g_zero_copy ? 1u : 0u); + if (ver >= DROIDDECK_AHB_V1_MODE_SINCE_VERSION) droiddeck_ahb_v1_send_mode(r, g_zero_copy ? 1u : 0u); if (last_named != c) { last_named = c; - droiddeck_log("layer", "zero-copy: %s bound banner_ahb_v1 version %u (%s)", droiddeck_client_name(c), ver, + droiddeck_log("layer", "zero-copy: %s bound droiddeck_ahb_v1 version %u (%s)", droiddeck_client_name(c), ver, ver >= 2 ? "follows the live switch" : "version 1: decides from its launch environment only"); } } void ahb_swapchain_set_mode(int on, int live) { on = on ? 1 : 0; + if (g_zero_copy != on) droiddeck_dmabuf_formats_stale(); g_zero_copy = on; if (!g_advertised) { if (live) droiddeck_log("layer", "zero-copy switched %s from the drawer, but no display layer is available on this device: no change", @@ -361,8 +393,8 @@ void ahb_swapchain_set_mode(int on, int live) { int told = 0; struct wl_resource *r; wl_resource_for_each(r, &g_clients) { - if (wl_resource_get_version(r) >= BANNER_AHB_V1_MODE_SINCE_VERSION) { - banner_ahb_v1_send_mode(r, (uint32_t)on); + if (wl_resource_get_version(r) >= DROIDDECK_AHB_V1_MODE_SINCE_VERSION) { + droiddeck_ahb_v1_send_mode(r, (uint32_t)on); told++; } } @@ -385,7 +417,7 @@ void ahb_swapchain_init(struct wl_display *display) { wl_list_init(&g_bufs); wl_list_init(&g_clients); if (!sc_layer_available()) { - droiddeck_log("layer", "zero-copy: no display layer on this device (see the line above): banner_ahb_v1 not advertised"); + droiddeck_log("layer", "zero-copy: no display layer on this device (see the line above): droiddeck_ahb_v1 not advertised"); return; } g_loop = wl_display_get_event_loop(display); @@ -395,11 +427,11 @@ void ahb_swapchain_init(struct wl_display *display) { return; } wl_event_loop_add_fd(g_loop, g_rel_pipe[0], WL_EVENT_READABLE, on_release_pipe, NULL); - if (!wl_global_create(display, &banner_ahb_v1_interface, 2, NULL, bind_ahb)) { - droiddeck_log("error", "zero-copy: banner_ahb_v1 global creation failed"); + if (!wl_global_create(display, &droiddeck_ahb_v1_interface, 2, NULL, bind_ahb)) { + droiddeck_log("error", "zero-copy: droiddeck_ahb_v1 global creation failed"); return; } g_advertised = 1; - droiddeck_log("layer", "zero-copy: banner_ahb_v1 version 2 advertised (games built for it present their own gralloc buffers while the switch is on)"); + droiddeck_log("layer", "zero-copy: droiddeck_ahb_v1 version 2 advertised (games built for it present their own gralloc buffers while the switch is on)"); ahb_swapchain_set_mode(g_zero_copy, 0); } diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h index 777448273..9002e6fc0 100644 --- a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h @@ -2,16 +2,21 @@ #define AHB_SWAPCHAIN_H #include #include +#include #include struct dmabuf_buffer; struct surface; +struct vkp_draw; void ahb_swapchain_init(struct wl_display *display); void ahb_swapchain_set_mode(int on, int live); int ahb_swapchain_last_frame_age_ms(void); int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b); -int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h); +int ahb_swapchain_adopt(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b, AHardwareBuffer *ahb, + uint64_t modifier); +AHardwareBuffer *ahb_swapchain_display_buffer(const struct dmabuf_buffer *b); +int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h, const struct vkp_draw *draw); int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buffer, struct surface *s, int paced); void ahb_swapchain_surface_gone(struct surface *s); unsigned ahb_swapchain_stats_take(void); diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index f78f0d3f8..38c13055b 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -23,8 +23,10 @@ #include "linux-dmabuf-v1-server-protocol.h" #include "sc_layer.h" #include "ahb_swapchain.h" +#include "display_buffers.h" #include "viewporter-server-protocol.h" #include "droiddeck-desktop-v1-server-protocol.h" +#include "droiddeck-refresh-v1-server-protocol.h" #include "presentation-time-server-protocol.h" #include "pointer-constraints-unstable-v1-server-protocol.h" #include "relative-pointer-unstable-v1-server-protocol.h" @@ -218,6 +220,7 @@ struct surface { struct vkp_image *shm_img; + int black_fill; struct wl_resource *dmabuf; struct dmabuf_buffer *dmabuf_buf; struct wl_listener dmabuf_destroy; @@ -280,6 +283,8 @@ static int g_dirty; static int64_t g_dirty_since_ns; volatile int g_render_on_commit = 1; static int64_t g_rendered_tick_ns; +static int g_tick_spare; +static int g_scene_queues; static int g_tick_held; static int64_t g_hold_missed_ns; #define HOLD_RETRY_NS 1000000000LL @@ -289,7 +294,11 @@ static struct { int64_t tick_late_ns, tick_late_max_ns, wait_ns, wait_max_ns; const void *buffers[PACE_BUFFERS]; uint64_t game_frames_seen; + unsigned gaps[4]; } g_pace; +static int64_t g_game_frame_ns; + +static void note_game_frame_gap(void); static void pace_note_buffer(const void *buffer) { for (unsigned i = 0; i < g_pace.distinct && i < PACE_BUFFERS; i++) @@ -318,6 +327,16 @@ volatile int g_hide_shell; volatile int g_zero_copy; static int g_zero_copy_paused; +extern volatile int g_display_buffer_driver; +extern void droiddeck_on_overlay_planes(int planes); +static int g_overlay_planes_told = -1; + +static void tell_overlay_planes(void) { + const int planes = (g_zero_copy && g_display_buffer_driver) ? (sc_layer_overlay_affordable() ? 1 : 0) : -1; + if (planes == g_overlay_planes_told) return; + g_overlay_planes_told = planes; + droiddeck_on_overlay_planes(planes); +} static int g_zero_copy_fx_skip_said; volatile int g_ubwc = 1; @@ -689,6 +708,13 @@ const struct wl_buffer_interface dbuf_buffer_impl = { .destroy = dbuf_buffer_destroy_req, }; +static struct vkp_image *import_dmabuf(struct dmabuf_buffer *b) { + AHardwareBuffer *ahb = ahb_swapchain_display_buffer(b); + struct vkp_image *img = ahb ? vkp_image_from_ahb(ahb) : NULL; + return img ? img : vkp_image_from_dmabuf(b->fd[0], b->format, b->modifier, b->width, b->height, b->stride[0], + b->offset[0]); +} + static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer) { if (buffer && wl_resource_instance_of(buffer, &wl_buffer_interface, &dbuf_buffer_impl)) return wl_resource_get_user_data(buffer); @@ -868,6 +894,12 @@ int droiddeck_hud_frame_times(float *out, int len, int64_t *total) { static uint64_t g_game_frames; extern void droiddeck_on_game_surface(const char *window, const char *gpu); extern void droiddeck_on_game_frame(void); +extern void droiddeck_on_content_rate(int fps); +static int64_t g_cadence_ns; +static int64_t g_cadence_frames; +static int g_content_fps; +static int g_framegen_layer_said; +static int g_framegen_layer; extern void droiddeck_on_game_program(int pid, const char *program); static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_resource *buffer) { @@ -888,6 +920,7 @@ static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_res s->buf_w = w; s->buf_h = h; s->buf_alpha = wl_shm_buffer_get_format(shm) == WL_SHM_FORMAT_ARGB8888; + s->black_fill = 0; s->has_content = s->shm_img != NULL; g_stat_shm++; struct client_info *ci = client_info_of(wl_resource_get_client(s->resource)); @@ -932,6 +965,7 @@ static void take_pixel(struct surface *s, const uint8_t bgra[4], struct wl_resou s->buf_w = 1; s->buf_h = 1; s->buf_alpha = bgra[3] != 0xff; + s->black_fill = !bgra[0] && !bgra[1] && !bgra[2] && bgra[3] == 0xff; s->has_content = s->shm_img != NULL; } @@ -950,8 +984,7 @@ static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_re wl_resource_add_destroy_listener(buffer, &s->dmabuf_destroy); } if (!b->img && !b->import_failed && b->n_planes >= 1) { - b->img = vkp_image_from_dmabuf(b->fd[0], b->format, b->modifier, b->width, b->height, - b->stride[0], b->offset[0]); + b->img = import_dmabuf(b); if (b->img && g_zero_copy) sc_layer_probe_dmabuf_fd(b->fd[0]); if (!b->img) { b->import_failed = 1; @@ -1019,7 +1052,25 @@ static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_re } if (s == g_hud_surface) { g_hud_alive_ns = now_ns(); - if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; g_hud_new = 1; g_game_frames++; droiddeck_on_game_frame(); } + if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; g_hud_new = 1; g_game_frames++; note_game_frame_gap(); droiddeck_on_game_frame(); } + } +} + +static void note_game_frame_gap(void) { + const int64_t now = now_ns(); + if (g_game_frame_ns && g_refresh_ns > 0) { + const int64_t gap = (now - g_game_frame_ns + g_refresh_ns / 2) / g_refresh_ns; + g_pace.gaps[gap < 1 ? 0 : gap > 4 ? 3 : gap - 1]++; + } + if (g_game_frame_ns && now - g_game_frame_ns >= 1000000000LL) { g_cadence_ns = 0; g_cadence_frames = 0; } + g_game_frame_ns = now; + if (!g_cadence_ns) g_cadence_ns = now; + g_cadence_frames++; + if (now - g_cadence_ns >= 1000000000LL) { + g_content_fps = (int)((g_cadence_frames * 1000000000LL + (now - g_cadence_ns) / 2) / (now - g_cadence_ns)); + droiddeck_on_content_rate(g_content_fps); + g_cadence_ns = now; + g_cadence_frames = 0; } } @@ -1204,8 +1255,7 @@ static void cursor_publish_buffer(struct surface *s, struct wl_resource *buffer) } else if (db && db->n_planes >= 1 && db->width > 0 && db->height > 0 && (int64_t)db->width * db->height <= CURSOR_MAX_PX) { if (!db->img && !db->import_failed) { - db->img = vkp_image_from_dmabuf(db->fd[0], db->format, db->modifier, db->width, db->height, - db->stride[0], db->offset[0]); + db->img = import_dmabuf(db); if (!db->img) db->import_failed = 1; } if (!db->img) return; @@ -1213,8 +1263,9 @@ static void cursor_publish_buffer(struct surface *s, struct wl_resource *buffer) int r; do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); if (vkp_image_readback(db->img, g_cursor_rb, CURSOR_MAX_PX) != 0) return; + const int row = vkp_image_width(db->img); cursor_publish_pixels((const uint8_t *)g_cursor_rb, db->width, db->height, - (size_t)db->width * 4, g_cursor_hx, g_cursor_hy); + (size_t)(row > db->width ? row : db->width) * 4, g_cursor_hx, g_cursor_hy); } else { return; } @@ -1884,6 +1935,57 @@ static void output_send_mode(struct wl_resource *r, int mhz) { mhz); } +#define PANEL_RATES_MAX 16 +extern void droiddeck_on_refresh_target(int refresh, int frame_rate); +static pthread_mutex_t g_panel_rates_lock = PTHREAD_MUTEX_INITIALIZER; +static int g_panel_rates[PANEL_RATES_MAX], g_panel_rate_count; +static atomic_int g_panel_rates_pending; +static struct wl_list g_refresh_clients; +static struct wl_resource *g_refresh_target_owner; + +static void refresh_send_rates(struct wl_resource *r) { + int rates[PANEL_RATES_MAX]; + pthread_mutex_lock(&g_panel_rates_lock); + const int count = g_panel_rate_count; + memcpy(rates, g_panel_rates, sizeof(rates)); + pthread_mutex_unlock(&g_panel_rates_lock); + for (int i = 0; i < count; i++) droiddeck_refresh_v1_send_rate(r, (uint32_t)rates[i]); + droiddeck_refresh_v1_send_done(r); +} + +static void refresh_notify_rates(void) { + struct wl_resource *r; + wl_resource_for_each(r, &g_refresh_clients) refresh_send_rates(r); +} + +static void refresh_resource_destroy(struct wl_resource *r) { + wl_list_remove(wl_resource_get_link(r)); + if (g_refresh_target_owner != r) return; + g_refresh_target_owner = NULL; + droiddeck_on_refresh_target(0, 0); +} + +static void refresh_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } + +static void refresh_set_target(struct wl_client *c, struct wl_resource *r, uint32_t refresh, uint32_t frame_rate) { + if (!refresh && !frame_rate && g_refresh_target_owner && g_refresh_target_owner != r) return; + g_refresh_target_owner = refresh || frame_rate ? r : NULL; + droiddeck_on_refresh_target((int)refresh, (int)frame_rate); +} + +static const struct droiddeck_refresh_v1_interface refresh_impl = { + .destroy = refresh_destroy_req, + .set_target = refresh_set_target, +}; + +static void bind_refresh(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &droiddeck_refresh_v1_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &refresh_impl, NULL, refresh_resource_destroy); + wl_list_insert(&g_refresh_clients, wl_resource_get_link(r)); + refresh_send_rates(r); +} + static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { struct wl_resource *r = wl_resource_create(c, &wl_output_interface, ver, id); if (!r) { wl_client_post_no_memory(c); return; } @@ -2014,19 +2116,47 @@ static int on_frame_timer(void *data) { return 0; } +static int black_fill_below(const struct draw_list *dl, int n) { + for (int i = 0; i < n; i++) { + struct surface *s, *found = NULL; + wl_list_for_each(s, &g_surfaces, link) + if (s->shm_img == dl->d[i].img) { found = s; break; } + if (!found || !found->black_fill || dl->d[i].blend) return 0; + } + return 1; +} + static int layer_candidate(const struct draw_list *dl, int scene_w, int scene_h) { for (int i = dl->n - 1; i >= 0 && i >= dl->n - 2; i--) { const struct vkp_draw *d = &dl->d[i]; if (d->blend) continue; if (!vkp_image_is_dmabuf(d->img)) continue; - if (d->dx != 0 || d->dy != 0 || d->dw != scene_w || d->dh != scene_h) continue; - if (d->sx != 0 || d->sy != 0 || (int)d->sw != vkp_image_width(d->img) || - (int)d->sh != vkp_image_height(d->img)) continue; + if (d->sx < 0 || d->sy < 0 || d->sw < 1.0f || d->sh < 1.0f || + d->sx + d->sw >= vkp_image_width(d->img) + 1.0f || + d->sy + d->sh >= vkp_image_height(d->img) + 1.0f) continue; + if (d->dx == 0 && d->dy == 0 && d->dw == scene_w && d->dh == scene_h) return i; + if (d->dx < 0 || d->dy < 0 || d->dw <= 0 || d->dh <= 0 || d->dx + d->dw > scene_w || + d->dy + d->dh > scene_h || !black_fill_below(dl, i)) continue; return i; } return -1; } +static void note_copy_scene(const struct draw_list *dl, int scene_w, int scene_h, int pointer) { + static int said[6]; + const struct vkp_draw *t = dl->n > 0 ? &dl->d[dl->n - 1] : NULL; + const int now[6] = {dl->n, pointer, t ? t->dw : 0, t ? t->dh : 0, scene_w, scene_h}; + if (!memcmp(now, said, sizeof(said))) return; + memcpy(said, now, sizeof(said)); + if (pointer) + droiddeck_log("layer", "zero-copy: copy path while the pointer is drawn into the scene"); + else if (t) + droiddeck_log("layer", "zero-copy: copy path: no window fills the %dx%d scene on its own (%d surfaces, top one " + "%dx%d at %d,%d from %.2f,%.2f %.2fx%.2f of a %dx%d %s buffer%s)", scene_w, scene_h, dl->n, t->dw, t->dh, + t->dx, t->dy, t->sx, t->sy, t->sw, t->sh, vkp_image_width(t->img), vkp_image_height(t->img), + vkp_image_is_dmabuf(t->img) ? "GPU" : "memory", t->blend ? ", translucent" : ""); +} + static struct surface *surface_for_image(const struct vkp_image *img) { struct surface *s; wl_list_for_each(s, &g_surfaces, link) @@ -2066,17 +2196,28 @@ static struct surface *hdr_unimported_fullscreen(const struct draw_list *dl, int } static int is_hdr_surface(struct surface *s) { + const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL; + return c && (c->dataspace || c->convert); +} + +static int is_raw_hdr_surface(struct surface *s) { const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL; return c && c->dataspace; } +static int framegen_fits_layer(void) { + const int64_t rate = (int64_t)g_content_fps * (1 + vkp_framegen_extra_images()) * 1000; + return g_content_fps > 0 && + rate * 100 <= (int64_t)atomic_load(&g_output_refresh_mhz) * (g_framegen_layer ? 108 : 104); +} + static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int framegen, struct hdr_scene *hs) { memset(hs, 0, sizeof(*hs)); if (!droiddeck_color_hdr_open()) return 0; struct surface *un = hdr_unimported_fullscreen(dl, w, h); if (!un) { struct surface *lo = ahb_layer_only_candidate(w, h); - if (lo && is_hdr_surface(lo)) un = lo; + if (lo && is_raw_hdr_surface(lo)) un = lo; } if (un && g_zero_copy) { hs->color = droiddeck_color_of(un->resource); hs->who = un; return 3; } hs->hf.tonemap = !droiddeck_color_output(); @@ -2084,24 +2225,48 @@ static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int fra for (int i = 0; i < dl->n; i++) { struct surface *s = surface_for_image(dl->d[i].img); if (!is_hdr_surface(s)) continue; - hs->is_hdr[i] = 1; + const struct droiddeck_color *c = droiddeck_color_of(s->resource); + if (c->convert && hs->hf.convert && (hs->hf.convert->gain != c->gain || + memcmp(hs->hf.convert->to2020, c->to2020, sizeof(c->to2020)) != 0)) { + static int said; + if (!said) { + said = 1; + droiddeck_log("color", "two windows need different colour conversions in one frame: the upper one is " + "shown as SDR"); + } + continue; + } + hs->is_hdr[i] = c->convert ? 2 : 1; + if (c->convert) hs->hf.convert = c; hs->n_hdr++; - hs->color = droiddeck_color_of(s->resource); + hs->color = c; hs->who = s; } if (!hs->n_hdr) { free(hs->is_hdr); hs->is_hdr = NULL; return 0; } + if (hs->color->convert) { + static struct droiddeck_color composed; + composed = *hs->color; + composed.dataspace = DROIDDECK_ADATASPACE_BT2020_PQ; + composed.convert = 0; + hs->color = &composed; + } hs->hf.is_hdr = hs->is_hdr; hs->hf.color = hs->color; hs->hf.peak_nits = hs->color->max_cll > 0.0f ? hs->color->max_cll : hs->color->has_st2086 ? hs->color->max_lum : 1000.0f; - if (framegen) return 2; + if (framegen) { + if (!g_zero_copy || !framegen_fits_layer()) return 2; + hs->why = "frame generation is on"; + return 1; + } int li = g_zero_copy ? layer_candidate(dl, w, h) : -1; int over = li >= 0 ? dl->n - 1 - li : 0; - if (!hs->hf.tonemap && !fx_on && li >= 0 && hs->is_hdr[li] && + if (!hs->hf.tonemap && !hs->hf.convert && !fx_on && li >= 0 && hs->is_hdr[li] && (over == 0 || (over == 1 && sc_layer_overlay_affordable()))) return 0; hs->why = hs->hf.tonemap ? "HDR output is switched off in the drawer" : fx_on ? "screen effects are on" + : hs->hf.convert ? "its colours are converted to BT.2020 PQ" : !g_zero_copy ? "zero-copy presentation is off" : (li >= 0 && hs->is_hdr[li]) ? "a window is above the game and this display cannot compose a second layer" : "the HDR game is not one fullscreen window"; @@ -2174,8 +2339,7 @@ static void hdr_note_precedence(struct surface *hs, int fx_on, int framegen) { static void hdr_count_copied(const struct draw_list *dl, const char *reason) { for (int i = 0; i < dl->n; i++) { struct surface *s = surface_for_image(dl->d[i].img); - const struct droiddeck_color *c = s ? droiddeck_color_of(s->resource) : NULL; - if (!c || !c->dataspace) continue; + if (!is_hdr_surface(s)) continue; char name[160]; describe(s, name, sizeof(name)); droiddeck_color_frame_copied(name, reason); @@ -2317,6 +2481,8 @@ static void render_scene(void) { g_dirty_since_ns = 0; } g_dirty = 0; + if (g_rendered_tick_ns == g_tick_vsync_ns) g_tick_spare = 0; + g_scene_queues = 0; g_rendered_tick_ns = g_tick_vsync_ns; g_tick_held = 0; g_hud_fresh = 0; @@ -2378,7 +2544,13 @@ static void render_scene(void) { static int fell_back; vkp_apply_window_request(); sc_layer_hide_overlay(); - if (sc_layer_present_hdr_scene(dl.d, dl.n, &hs.hf, w, h, hs.color) == 0) { + const int generated = framegen ? sc_layer_present_generated(dl.d, dl.n, &hs.hf, w, h, 1, hs.color) : 0; + if (framegen) g_framegen_layer = generated >= 0; + if (generated > 0 && g_framegen_layer_said != 3) { + g_framegen_layer_said = 3; + droiddeck_log("framegen", "generated frames and the composed HDR picture go on the game's display layer"); + } + if (framegen ? generated >= 0 : sc_layer_present_hdr_scene(dl.d, dl.n, &hs.hf, w, h, hs.color) == 0) { rendered = vkp_base_black(w, h) == 0; if (fell_back) { fell_back = 0; droiddeck_log("color", "the composed picture is on the game's display layer again"); } } else { @@ -2404,13 +2576,16 @@ static void render_scene(void) { 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 && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1; + tell_overlay_planes(); + const int fg_layer = framegen && hdr_route == 0 && framegen_fits_layer(); + g_framegen_layer = fg_layer; + int li = (g_zero_copy && (!framegen || fg_layer) && !bfi && !cardboard && !cursor_on) ? layer_candidate(&dl, w, h) : -1; int over = li >= 0 ? dl.n - 1 - li : 0; const int fx_blocks = (li >= 0 && fx_on && over > 0); if (fx_blocks) { li = -1; over = 0; } const int ov_blocks = (li >= 0 && over > 0 && !fx_blocks && !sc_layer_overlay_affordable()); if (ov_blocks) { li = -1; over = 0; } - const int blocked = framegen ? 1 : bfi ? 4 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0)); + const int blocked = (framegen && !fg_layer) ? 1 : bfi ? 4 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0)); if (g_zero_copy && !cursor_on && blocked != g_zero_copy_paused) { g_zero_copy_paused = blocked; if (blocked == 1) @@ -2419,14 +2594,21 @@ static void render_scene(void) { droiddeck_log("effects", "zero-copy paused: a window above the game needs the compositor pass for the whole scene"); else if (blocked == 4) droiddeck_log("bfi", "zero-copy paused: black frame insertion needs the compositor pass"); - else if (blocked == 3) - droiddeck_log("layer", "zero-copy paused: a window above the game would need a second display layer, " - "which this display cannot compose in hardware - whole scene on the copy path"); + else if (blocked == 3) { + const struct vkp_draw *top = &dl.d[dl.n - 1]; + struct surface *ts = surface_for_image(top->img); + droiddeck_log("layer", "zero-copy paused: a window above the game (%dx%d at %d,%d%s, %s) would need a second " + "display layer, which this display cannot compose in hardware - whole scene on the copy path", + top->dw, top->dh, top->dx, top->dy, top->blend ? ", translucent" : "", + ts ? client_name(wl_resource_get_client(ts->resource)) : "no client surface"); + } else droiddeck_log("effects", "zero-copy resumed: the game is back on its own display layer"); } struct surface *ls = li >= 0 ? surface_for_image(dl.d[li].img) : NULL; + const struct vkp_draw *ld = li >= 0 ? &dl.d[li] : NULL; if (li < 0) ls = layer_only; + if (g_zero_copy && li < 0 && !ls && !blocked && !cardboard) note_copy_scene(&dl, w, h, cursor_on); if (cardboard) ls = NULL; if (cursor_on) ls = NULL; if (bfi) ls = NULL; @@ -2439,11 +2621,23 @@ static void render_scene(void) { if (li >= 0 || ls) { vkp_apply_window_request(); int r = -1; - if (!(fx_on && li >= 0) && ls && ls->dmabuf_buf && ahb_swapchain_has_ahb(ls->dmabuf_buf)) - r = ahb_swapchain_present(ls->dmabuf_buf, ls, w, h); - if (r != 0 && li >= 0) + const int fg_pass = framegen && fx_on && li >= 0; + const int generated = (framegen && li >= 0) + ? sc_layer_present_generated(&dl.d[li], 1, NULL, w, h, fg_pass, + ls ? droiddeck_surface_color(ls) : NULL) : 0; + if (generated > 0 && g_framegen_layer_said != 1 + fg_pass) { + g_framegen_layer_said = 1 + fg_pass; + droiddeck_log("framegen", fg_pass + ? "generated frames and the game's frames go on the game's display layer straight from the screen effects pass" + : "generated frames go on the game's display layer between the game's own frames"); + } + if (fg_pass) + r = generated >= 0 ? 0 : -1; + else if (generated >= 0 && !(fx_on && li >= 0) && ls && ls->dmabuf_buf && ahb_swapchain_has_ahb(ls->dmabuf_buf)) + r = ahb_swapchain_present(ls->dmabuf_buf, ls, w, h, ld); + if (!fg_pass && generated >= 0 && r != 0 && li >= 0) r = fx_on ? sc_layer_present_pass(&dl.d[li], 1, w, h) - : sc_layer_present(dl.d[li].img, w, h, ls ? droiddeck_surface_color(ls) : NULL); + : sc_layer_present(dl.d[li].img, w, h, ld, ls ? droiddeck_surface_color(ls) : NULL); if (r == 0) { if (ls) ls->drawn = 1; int go[8], ov = 0; @@ -2457,8 +2651,10 @@ static void render_scene(void) { hdr_copy = "the overlay layer refused the window above it"; } else { rendered = vkp_base_black(w, h) == 0; + g_scene_queues = sc_layer_queues(); } } else { + sc_layer_hide(); rendered = vkp_render(w, h, dl.d, dl.n) == 0; copy = 1; hdr_copy = "its display layer was unavailable this frame"; @@ -2518,8 +2714,12 @@ static int commit_renders_on(void) { !g_bfi_running; } +static int tick_takes_scene(void) { + return g_rendered_tick_ns != g_tick_vsync_ns || (g_tick_spare && g_scene_queues); +} + static int render_on_commit(void) { - return commit_renders_on() && !g_render_idle && g_rendered_tick_ns != g_tick_vsync_ns; + return commit_renders_on() && !g_render_idle && tick_takes_scene(); } static void schedule_render(void) { @@ -2546,7 +2746,7 @@ static int scene_waits_for_game(int64_t now) { static void on_commit_idle(void *data) { g_render_idle = NULL; - if (!g_dirty || !commit_renders_on() || g_rendered_tick_ns == g_tick_vsync_ns || scene_waits_for_game(now_ns())) return; + if (!g_dirty || !commit_renders_on() || !tick_takes_scene() || scene_waits_for_game(now_ns())) return; g_pace.commit_renders++; render_scene(); } @@ -2621,6 +2821,7 @@ static void on_vsync(int64_t frame_time_ns) { if (d > 3000000LL && d < 40000000LL) g_refresh_ns = (g_refresh_ns * 7 + d) / 8; } g_last_vsync_ns = now; + g_tick_spare = g_rendered_tick_ns != g_tick_vsync_ns; g_tick_vsync_ns = frame_time_ns; int tick_change = 0; if (vkp_apply_window_request()) tick_change = 1; @@ -3843,6 +4044,10 @@ static int on_input_readable(int fd, uint32_t mask, void *data) { output_notify_mode(); wl_display_flush_clients(g_display); } + if (atomic_exchange(&g_panel_rates_pending, 0)) { + refresh_notify_rates(); + wl_display_flush_clients(g_display); + } if (vsync) on_vsync(vsync_ns); return 0; } @@ -3892,6 +4097,23 @@ void droiddeck_wayland_output_resized(void) { (void)n; } +void droiddeck_wayland_set_panel_rates(const int *rates, int count) { + if (count > PANEL_RATES_MAX) count = PANEL_RATES_MAX; + pthread_mutex_lock(&g_panel_rates_lock); + const int same = count == g_panel_rate_count && !memcmp(rates, g_panel_rates, (size_t)count * sizeof(int)); + if (!same) { + memcpy(g_panel_rates, rates, (size_t)count * sizeof(int)); + g_panel_rate_count = count; + } + pthread_mutex_unlock(&g_panel_rates_lock); + if (same || g_input_pipe[1] < 0) return; + atomic_store(&g_panel_rates_pending, 1); + struct input_msg m = { 10, 0, 0, 0, 0 }; + ssize_t n; + do { n = write(g_input_pipe[1], &m, sizeof(m)); } while (n < 0 && errno == EINTR); + (void)n; +} + void droiddeck_wayland_set_output_refresh_rate(int mhz) { if (mhz <= 0) mhz = 60000; if (atomic_exchange(&g_output_refresh_mhz, mhz) == mhz || g_input_pipe[1] < 0) return; @@ -3974,12 +4196,15 @@ static int on_stats_timer(void *data) { struct vkp_perf vp; vkp_perf_take(&vp); const unsigned drops = sc_layer_drops_take(); + unsigned aimed_next, aimed_later, aimed_even; + sc_layer_aim_take(&aimed_next, &aimed_later, &aimed_even); #define PERF_MS(sum, n) ((n) ? (double)(sum) / 1e6 / (double)(n) : 0.0) if (g_perf.scenes || vp.presents || g_perf.releases || drops) droiddeck_log("perf", "last 10 s: %u ticks, %u scenes, %u on screen (copy %u, zero-copy %u, layer copy %u) | " "render_scene %.2f/%.2f ms | base %u black kept, %u presented | acquire %.2f/%.2f ms | " "present %.2f/%.2f ms (%u) | fence wait %.2f/%.2f ms (%u, %u GPU release waits) | " - "release %.2f/%.2f ms (%u, %u held) | %u pool drops", + "release %.2f/%.2f ms (%u, %u held) | %u pool drops | layer frames timed for the next refresh %u, " + "the one after %u, held to an even step %u", g_perf.ticks, g_perf.scenes, g_stat_frames, g_perf.copy_scenes, zero_copy, layer_frames, PERF_MS(g_perf.scene_ns, g_perf.scenes), (double)g_perf.scene_max_ns / 1e6, vp.base_kept, vp.base_presents, @@ -3987,7 +4212,7 @@ static int on_stats_timer(void *data) { PERF_MS(vp.present_ns, vp.presents), (double)vp.present_max_ns / 1e6, vp.presents, PERF_MS(vp.wait_ns, vp.waits), (double)vp.wait_max_ns / 1e6, vp.waits, vp.gpu_release_waits, PERF_MS(g_perf.release_ns, g_perf.releases), (double)g_perf.release_max_ns / 1e6, - g_perf.releases, g_perf.releases_held, drops); + g_perf.releases, g_perf.releases_held, drops, aimed_next, aimed_later, aimed_even); #undef PERF_MS memset(&g_perf, 0, sizeof(g_perf)); } @@ -3997,12 +4222,12 @@ static int on_stats_timer(void *data) { droiddeck_log("pacing", "last 10 s: tick reaches compositor %.2f/%.2f ms late (%u ticks, %u over 2 ms) | " "new frame waits %.2f/%.2f ms to be drawn (%u scenes, %u on arrival) | %llu game frames, %u re-attached after an " "empty attach, %u empty attaches, %u distinct buffers | feedback %u shown, %u replaced before drawing, " - "%u not drawn", + "%u not drawn | game frames arrived 1/2/3/4+ refreshes apart %u/%u/%u/%u", g_pace.ticks ? (double)g_pace.tick_late_ns / 1e6 / g_pace.ticks : 0.0, (double)g_pace.tick_late_max_ns / 1e6, g_pace.ticks, g_pace.ticks_late_2ms, g_pace.renders ? (double)g_pace.wait_ns / 1e6 / g_pace.renders : 0.0, (double)g_pace.wait_max_ns / 1e6, g_pace.renders, g_pace.commit_renders, (unsigned long long)game, g_pace.reattaches, g_pace.null_attaches, g_pace.distinct, - g_pace.presented, g_pace.replaced, g_pace.undrawn); + g_pace.presented, g_pace.replaced, g_pace.undrawn, g_pace.gaps[0], g_pace.gaps[1], g_pace.gaps[2], g_pace.gaps[3]); } if (g_bfi_stats.lit || g_bfi_stats.dark || g_bfi_stats.failed) { droiddeck_log("bfi", "last 10 s: %u pictures, %u black refreshes, %u black refreshes not presented", @@ -4028,6 +4253,12 @@ static int on_stats_timer(void *data) { "draw - expect a black picture (main device %u:%u)", ci->name, (unsigned)major(g_main_device), (unsigned)minor(g_main_device)); } + if (g_content_fps > 0 && now_ns() - g_game_frame_ns >= 2000000000LL) { + g_content_fps = 0; + g_cadence_ns = 0; + g_cadence_frames = 0; + droiddeck_on_content_rate(0); + } wl_event_source_timer_update(g_stats_timer, 10000); return 0; } @@ -4106,6 +4337,7 @@ int droiddeck_wayland_run(void) { wl_list_init(&g_surfaces); wl_list_init(&g_toplevels); wl_list_init(&g_outputs); + wl_list_init(&g_refresh_clients); wl_list_init(&g_constraints); wl_list_init(&g_relative_pointers); open_session_log(); @@ -4143,6 +4375,7 @@ int droiddeck_wayland_run(void) { wl_display_init_shm(display); wl_global_create(display, &wl_output_interface, 4, NULL, bind_output); + wl_global_create(display, &droiddeck_refresh_v1_interface, 1, NULL, bind_refresh); wl_global_create(display, &xdg_wm_base_interface, 1, NULL, bind_xdg_wm_base); wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf); droiddeck_android_wlegl_init(display); @@ -4153,6 +4386,7 @@ int droiddeck_wayland_run(void) { wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, 1, NULL, bind_relative_pointer_manager); droiddeck_ext_init(display); ahb_swapchain_init(display); + display_buffers_init(display); droiddeck_color_init(display); diff --git a/app/src/main/cpp/waylandcomp/src/compositor_internal.h b/app/src/main/cpp/waylandcomp/src/compositor_internal.h index c70f9dd19..b17329c12 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor_internal.h +++ b/app/src/main/cpp/waylandcomp/src/compositor_internal.h @@ -20,6 +20,7 @@ #define DRM_XBGR8888 FOURCC('X', 'B', '2', '4') #define MOD_LINEAR VKP_MOD_LINEAR #define MOD_INVALID VKP_MOD_INVALID +#define MOD_QCOM_COMPRESSED VKP_MOD_QCOM_COMPRESSED #define MAX_PLANES 4 struct dmabuf_params { diff --git a/app/src/main/cpp/waylandcomp/src/display_buffers.c b/app/src/main/cpp/waylandcomp/src/display_buffers.c new file mode 100644 index 000000000..99f6993a5 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/display_buffers.c @@ -0,0 +1,343 @@ +#define _GNU_SOURCE +#include "display_buffers.h" +#include "ahb_swapchain.h" +#include "compositor_internal.h" +#include "droiddeck_color.h" +#include "droiddeck_ext.h" +#include "sc_layer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DISPLAY_BUFFERS_SOCKET "droiddeck-display-buffers" +#define DISPLAY_BUFFERS_MAGIC 0x42444444u +#define DISPLAY_BUFFERS_VERSION 1u +#define DISPLAY_BUFFERS_ALLOC 1u +#define DISPLAY_BUFFERS_FREE 2u +#define DISPLAY_BUFFERS_MAX_SIDE 16384u +#define DISPLAY_BUFFERS_MAX_PER_CLIENT 256 +#define DISPLAY_BUFFERS_PROBE_W 1280u +#define DISPLAY_BUFFERS_PROBE_H 720u +#define ALIGN_UP(v, a) (((v) + (a) - 1) / (a) * (a)) + +extern volatile int g_zero_copy; +volatile int g_display_buffer_driver; + +struct display_buffers_request { + uint32_t magic, version, op, width, height, format, stride, offset; + uint64_t size, id, modifier; +}; + +struct display_buffers_reply { + uint32_t magic, status; + uint64_t id, size; +}; + +struct peer { + int fd; + pid_t pid; + int count; + int logged_w, logged_h; + uint32_t logged_format; + struct wl_event_source *src; +}; + +struct entry { + uint64_t id; + dev_t dev; + ino_t ino; + AHardwareBuffer *ahb; + uint32_t format, stride, width, height; + uint64_t modifier; + struct peer *peer; + struct wl_list link; +}; + +static struct wl_list g_entries; +static struct wl_event_loop *g_loop; +static uint64_t g_next_id = 1; +static int g_refused_logged; +static int g_ubwc_promised; +static int g_ubwc_probed[2]; + +static uint32_t ahb_format_of(uint32_t drm, uint64_t modifier) { + switch (drm) { + case DRM_ABGR8888: case DRM_XBGR8888: return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; + case DRM_ARGB8888: case DRM_XRGB8888: return modifier == MOD_QCOM_COMPRESSED ? AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM : 0; + case FOURCC('A', 'B', '3', '0'): case FOURCC('X', 'B', '3', '0'): return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM; + default: return 0; + } +} + +static uint64_t ubwc_meta_size(uint32_t w, uint32_t h) { + return ALIGN_UP((uint64_t)ALIGN_UP((w + 15) / 16, 64) * ALIGN_UP((h + 3) / 4, 16), 4096); +} + +static uint64_t ubwc_size(uint32_t w, uint32_t h, uint32_t stride) { + return ubwc_meta_size(w, h) + ALIGN_UP((uint64_t)stride * ALIGN_UP(h, 16), 4096); +} + +static void entry_free(struct entry *e) { + wl_list_remove(&e->link); + e->peer->count--; + AHardwareBuffer_release(e->ahb); + free(e); +} + +static AHardwareBuffer *allocate_ubwc(uint32_t w, uint32_t h, uint32_t format, uint32_t stride, int *fd, uint64_t *size) { + const uint64_t tiers[2] = {SC_LAYER_AHB_USAGE_VENDOR_UBWC, 0}; + for (int i = 0; i < 2; i++) { + AHardwareBuffer_Desc d = { + .width = w, .height = h, .layers = 1, .format = format, + .usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | + AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | tiers[i]}; + AHardwareBuffer *ahb = NULL; + if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) continue; + AHardwareBuffer_Desc got; + AHardwareBuffer_describe(ahb, &got); + const uint64_t need = ubwc_size(w, h, got.stride * 4); + *fd = !stride || (uint64_t)got.stride * 4 == stride ? sc_layer_ahb_fd(ahb, need) : -1; + if (*fd >= 0 && (uint64_t)lseek(*fd, 0, SEEK_END) == need) { *size = need; return ahb; } + *fd = -1; + AHardwareBuffer_release(ahb); + } + return NULL; +} + +static uint64_t gralloc_bytes(uint32_t format, uint64_t usage, uint32_t *stride) { + AHardwareBuffer_Desc d = { + .width = DISPLAY_BUFFERS_PROBE_W, .height = DISPLAY_BUFFERS_PROBE_H, .layers = 1, .format = format, + .usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | + AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | usage}; + AHardwareBuffer *ahb = NULL; + if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) return 0; + AHardwareBuffer_describe(ahb, &d); + const int fd = sc_layer_ahb_fd(ahb, 1); + const off_t bytes = fd >= 0 ? lseek(fd, 0, SEEK_END) : 0; + if (fd >= 0) lseek(fd, 0, SEEK_SET); + AHardwareBuffer_release(ahb); + *stride = d.stride; + return bytes > 0 ? (uint64_t)bytes : 0; +} + +static int ubwc_probe(uint32_t format) { + int *state = &g_ubwc_probed[format == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM ? 0 : 1]; + if (*state) return *state > 0; + uint32_t stride = 0, linear_stride = 0; + const uint64_t flagged = gralloc_bytes(format, SC_LAYER_AHB_USAGE_VENDOR_UBWC, &stride); + const uint64_t plain = gralloc_bytes(format, 0, &stride); + const uint64_t linear = gralloc_bytes(format, AHARDWAREBUFFER_USAGE_CPU_READ_RARELY, &linear_stride); + const uint64_t need = ubwc_size(DISPLAY_BUFFERS_PROBE_W, DISPLAY_BUFFERS_PROBE_H, stride * 4); + *state = stride && linear != need && (flagged == need || plain == need) ? 1 : -1; + droiddeck_log("layer", "display buffers: gralloc %s buffers %s (%ux%u: the layout takes %llu bytes; gralloc gives %llu " + "asked for UBWC, %llu unasked, %llu linear)", droiddeck_ahb_format_name(format), + *state > 0 ? "use the UBWC layout the drivers render to: compressed frames can go on the display layer" + : "do not match the UBWC layout the drivers render to: compressed frames are not offered", + DISPLAY_BUFFERS_PROBE_W, DISPLAY_BUFFERS_PROBE_H, (unsigned long long)need, (unsigned long long)flagged, + (unsigned long long)plain, (unsigned long long)linear); + return *state > 0; +} + +int display_buffers_offer_ubwc(uint32_t drm) { + const uint32_t format = ahb_format_of(drm, MOD_QCOM_COMPRESSED); + if (!g_loop || !g_zero_copy || !g_ubwc || !g_display_buffer_driver || !format || !ubwc_probe(format)) return 0; + g_ubwc_promised = 1; + return 1; +} + +void display_buffers_withdraw_ubwc(void) { g_ubwc_promised = 0; } + +static AHardwareBuffer *allocate(const struct display_buffers_request *q, uint32_t format, int *fd) { + const uint32_t rows = (uint32_t)((q->size + q->stride - 1) / q->stride); + const uint32_t dims[2][2] = {{q->width, q->height}, {q->stride / 4, rows}}; + for (int i = 0; i < 2; i++) { + AHardwareBuffer_Desc d = { + .width = dims[i][0], .height = dims[i][1], .layers = 1, .format = format, + .usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | + AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | AHARDWAREBUFFER_USAGE_CPU_READ_RARELY}; + AHardwareBuffer *ahb = NULL; + if (i && dims[1][0] == dims[0][0] && dims[1][1] == dims[0][1]) break; + if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) continue; + AHardwareBuffer_Desc got; + AHardwareBuffer_describe(ahb, &got); + *fd = (uint64_t)got.stride * 4 == q->stride ? sc_layer_ahb_fd(ahb, q->size) : -1; + if (*fd >= 0) return ahb; + AHardwareBuffer_release(ahb); + } + return NULL; +} + +static int reply(struct peer *p, const struct display_buffers_reply *r, int fd) { + char control[CMSG_SPACE(sizeof(int))] = {0}; + struct iovec iov = {.iov_base = (void *)r, .iov_len = sizeof(*r)}; + struct msghdr msg = {.msg_iov = &iov, .msg_iovlen = 1}; + if (fd >= 0) { + msg.msg_control = control; + msg.msg_controllen = sizeof(control); + struct cmsghdr *c = CMSG_FIRSTHDR(&msg); + c->cmsg_level = SOL_SOCKET; + c->cmsg_type = SCM_RIGHTS; + c->cmsg_len = CMSG_LEN(sizeof(int)); + memcpy(CMSG_DATA(c), &fd, sizeof(int)); + } + ssize_t n; + do { n = sendmsg(p->fd, &msg, MSG_NOSIGNAL); } while (n < 0 && errno == EINTR); + return n == (ssize_t)sizeof(*r) ? 0 : -1; +} + +static void handle_alloc(struct peer *p, const struct display_buffers_request *q) { + struct display_buffers_reply r = {.magic = DISPLAY_BUFFERS_MAGIC, .status = 1}; + const int compressed = q->modifier == MOD_QCOM_COMPRESSED; + const uint32_t format = compressed || q->modifier == MOD_LINEAR ? ahb_format_of(q->format, q->modifier) : 0; + struct entry *e = NULL; + AHardwareBuffer *ahb = NULL; + struct stat st; + uint64_t need = 0; + int fd = -1; + const int sized = format && q->width && q->height && q->width <= DISPLAY_BUFFERS_MAX_SIDE && + q->height <= DISPLAY_BUFFERS_MAX_SIDE && q->stride % 4 == 0 && q->stride / 4 >= q->width && + q->stride / 4 <= DISPLAY_BUFFERS_MAX_SIDE; + const int sane = !sized ? 0 + : compressed ? q->offset == ubwc_meta_size(q->width, q->height) && + q->size == ubwc_size(q->width, q->height, q->stride) + : q->offset == 0 && q->size >= (uint64_t)q->stride * q->height && + q->size <= (uint64_t)q->stride * DISPLAY_BUFFERS_MAX_SIDE; + const int wanted = compressed ? g_ubwc_promised : g_zero_copy; + if (sane && wanted && ahb_swapchain_advertised() && p->count < DISPLAY_BUFFERS_MAX_PER_CLIENT) + ahb = compressed ? allocate_ubwc(q->width, q->height, format, q->stride, &fd, &need) : allocate(q, format, &fd); + if (ahb && fstat(fd, &st) == 0) e = calloc(1, sizeof(*e)); + if (e) { + e->id = r.id = g_next_id++; + e->dev = st.st_dev; e->ino = st.st_ino; + e->ahb = ahb; + e->format = format; e->stride = q->stride; + e->width = q->width; e->height = q->height; + e->modifier = q->modifier; + e->peer = p; + p->count++; + wl_list_insert(&g_entries, &e->link); + r.status = 0; + r.size = (uint64_t)lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + if (p->logged_w != (int)q->width || p->logged_h != (int)q->height || p->logged_format != q->format) { + AHardwareBuffer_Desc got; + AHardwareBuffer_describe(ahb, &got); + p->logged_w = (int)q->width; p->logged_h = (int)q->height; p->logged_format = q->format; + droiddeck_log("layer", "display buffers: pid %d renders %ux%u %c%c%c%c %s straight into gralloc buffers " + "(%s %ux%u, stride %u px, %llu bytes for the %llu it asked for)", (int)p->pid, q->width, q->height, + q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff, + compressed ? "UBWC" : "linear", droiddeck_ahb_format_name(format), got.width, got.height, + got.stride, (unsigned long long)r.size, (unsigned long long)q->size); + } + } else { + if (ahb) AHardwareBuffer_release(ahb); + fd = -1; + if (sized && wanted && (compressed || !g_refused_logged)) { + g_refused_logged = 1; + droiddeck_log(compressed ? "error" : "layer", "display buffers: no gralloc buffer matches pid %d's %ux%u " + "%c%c%c%c %s layout (stride %u bytes, pixels at %u, %llu bytes; gralloc's layout has pixels at " + "%llu, %llu bytes): %s", (int)p->pid, q->width, q->height, + q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff, + compressed ? "UBWC" : "linear", q->stride, q->offset, (unsigned long long)q->size, + (unsigned long long)(compressed ? ubwc_meta_size(q->width, q->height) : 0), + (unsigned long long)(compressed ? ubwc_size(q->width, q->height, q->stride) : q->size), + compressed ? "its compressed frames cannot be shown" : "its frames keep the copy path"); + } + } + if (reply(p, &r, fd) != 0 && e) entry_free(e); +} + +static void peer_gone(struct peer *p) { + struct entry *e, *tmp; + wl_list_for_each_safe(e, tmp, &g_entries, link) + if (e->peer == p) entry_free(e); + wl_event_source_remove(p->src); + close(p->fd); + free(p); +} + +static int on_peer(int fd, uint32_t mask, void *data) { + struct peer *p = data; + for (;;) { + struct display_buffers_request q; + ssize_t n = recv(fd, &q, sizeof(q), MSG_DONTWAIT); + if (n < 0 && errno == EINTR) continue; + if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return 0; + if (n != (ssize_t)sizeof(q) || q.magic != DISPLAY_BUFFERS_MAGIC || q.version != DISPLAY_BUFFERS_VERSION) break; + if (q.op == DISPLAY_BUFFERS_ALLOC) { + handle_alloc(p, &q); + } else if (q.op == DISPLAY_BUFFERS_FREE) { + struct entry *e, *tmp; + wl_list_for_each_safe(e, tmp, &g_entries, link) + if (e->peer == p && e->id == q.id) entry_free(e); + } else { + break; + } + } + peer_gone(p); + return 0; +} + +static int on_listen(int fd, uint32_t mask, void *data) { + int c = accept4(fd, NULL, NULL, SOCK_CLOEXEC | SOCK_NONBLOCK); + if (c < 0) return 0; + struct peer *p = calloc(1, sizeof(*p)); + if (!p) { close(c); return 0; } + struct ucred cred = {0}; + socklen_t len = sizeof(cred); + if (getsockopt(c, SOL_SOCKET, SO_PEERCRED, &cred, &len) == 0) p->pid = cred.pid; + p->fd = c; + p->src = wl_event_loop_add_fd(g_loop, c, WL_EVENT_READABLE, on_peer, p); + if (!p->src) { close(c); free(p); } + return 0; +} + +void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b) { + struct stat st; + struct entry *e; + if (!g_loop || wl_list_empty(&g_entries) || b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) return; + wl_list_for_each(e, &g_entries, link) { + if (e->dev != st.st_dev || e->ino != st.st_ino) continue; + AHardwareBuffer_Desc d; + AHardwareBuffer_describe(e->ahb, &d); + const int compressed = e->modifier == MOD_QCOM_COMPRESSED; + const int laid_out = compressed ? b->modifier == MOD_QCOM_COMPRESSED && (uint32_t)b->width == e->width && + (uint32_t)b->height == e->height + : (b->modifier == MOD_LINEAR || b->modifier == MOD_INVALID) && + e->stride == b->stride[0]; + if (laid_out && e->format == ahb_format_of(b->format, e->modifier) && b->width > 0 && b->height > 0 && + (uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height) + ahb_swapchain_adopt(c, buffer, b, e->ahb, e->modifier); + return; + } +} + +void display_buffers_init(struct wl_display *display) { + wl_list_init(&g_entries); + const char *dir = getenv("XDG_RUNTIME_DIR"); + struct sockaddr_un addr = {.sun_family = AF_UNIX}; + if (!ahb_swapchain_advertised() || !dir) return; + if (snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/" DISPLAY_BUFFERS_SOCKET, dir) >= (int)sizeof(addr.sun_path)) { + droiddeck_log("layer", "display buffers: %s is too long for a socket path, not offered", dir); + return; + } + int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); + if (fd < 0) return; + unlink(addr.sun_path); + struct wl_event_loop *loop = wl_display_get_event_loop(display); + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0 || listen(fd, 16) != 0 || + !wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, on_listen, NULL)) { + droiddeck_log("layer", "display buffers: socket %s failed (%s), not offered", addr.sun_path, strerror(errno)); + close(fd); + return; + } + g_loop = loop; + droiddeck_log("layer", "display buffers: offered on %s (programs whose driver asks render into gralloc buffers while " + "zero-copy is on)", addr.sun_path); +} diff --git a/app/src/main/cpp/waylandcomp/src/display_buffers.h b/app/src/main/cpp/waylandcomp/src/display_buffers.h new file mode 100644 index 000000000..4943be521 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/display_buffers.h @@ -0,0 +1,12 @@ +#ifndef DISPLAY_BUFFERS_H +#define DISPLAY_BUFFERS_H +#include + +struct dmabuf_buffer; + +void display_buffers_init(struct wl_display *display); +int display_buffers_offer_ubwc(uint32_t drm); +void display_buffers_withdraw_ubwc(void); +void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/droiddeck_color.h b/app/src/main/cpp/waylandcomp/src/droiddeck_color.h index a578301ae..8809b7ed6 100644 --- a/app/src/main/cpp/waylandcomp/src/droiddeck_color.h +++ b/app/src/main/cpp/waylandcomp/src/droiddeck_color.h @@ -16,6 +16,9 @@ struct droiddeck_color { float max_lum, min_lum; int has_cta861; float max_cll, max_fall; + int convert; + float to2020[9]; + float gain; char text[256]; }; diff --git a/app/src/main/cpp/waylandcomp/src/hdr_compose.c b/app/src/main/cpp/waylandcomp/src/hdr_compose.c index 01d8be6f6..8cedd51b5 100644 --- a/app/src/main/cpp/waylandcomp/src/hdr_compose.c +++ b/app/src/main/cpp/waylandcomp/src/hdr_compose.c @@ -12,7 +12,7 @@ #define MIXED_FORMAT VK_FORMAT_A2B10G10R10_UNORM_PACK32 -struct pc_encode { float ndc[4]; float params[4]; float rects[HDRC_MAX_RECTS][4]; }; +struct pc_encode { float ndc[4]; float params[4]; uint32_t rects[HDRC_MAX_RECTS][2]; float conv[3][4]; }; static VkDevice g_dev; static int g_ready; @@ -266,7 +266,16 @@ int hdrc_encode(VkCommandBuffer cmd, VkImage mixed, VkImage out, VkFormat out_fm pc.params[1] = p->peak_nits > 0.0f ? p->peak_nits : 1000.0f; pc.params[2] = p->mode == HDRC_OUT_SDR ? 1.0f : 0.0f; pc.params[3] = (float)count + 16.0f * (float)mask; - for (int i = 0; i < count; i++) memcpy(pc.rects[i], p->rects[i], sizeof(pc.rects[i])); + for (int i = 0; i < count; i++) { + uint32_t v[4]; + for (int k = 0; k < 4; k++) v[k] = p->rects[i][k] <= 0.0f ? 0u : p->rects[i][k] >= 65535.0f ? 65535u : (uint32_t)p->rects[i][k]; + pc.rects[i][0] = v[0] | v[1] << 16; + pc.rects[i][1] = v[2] | v[3] << 16; + } + for (int k = 0; k < 3; k++) memcpy(pc.conv[k], &p->conv[3 * k], 3 * sizeof(float)); + pc.conv[0][3] = (float)(p->conv_mask & mask); + pc.conv[1][3] = p->conv_linear ? 1.0f : 0.0f; + pc.conv[2][3] = p->conv_gain; VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_out[slot].rp, .framebuffer = fb, .renderArea = {{0, 0}, {(uint32_t)w, (uint32_t)h}}}; diff --git a/app/src/main/cpp/waylandcomp/src/hdr_compose.h b/app/src/main/cpp/waylandcomp/src/hdr_compose.h index 5a37d42ad..e49f575a3 100644 --- a/app/src/main/cpp/waylandcomp/src/hdr_compose.h +++ b/app/src/main/cpp/waylandcomp/src/hdr_compose.h @@ -14,6 +14,10 @@ struct hdrc_params { int count; unsigned hdr_mask; float rects[HDRC_MAX_RECTS][4]; + unsigned conv_mask; + int conv_linear; + float conv_gain; + float conv[9]; }; void hdrc_bind_device(VkDevice dev, const VkPhysicalDeviceMemoryProperties *memprops); diff --git a/app/src/main/cpp/waylandcomp/src/hdr_encode.frag b/app/src/main/cpp/waylandcomp/src/hdr_encode.frag index db3ea8bca..1900bc4b9 100644 --- a/app/src/main/cpp/waylandcomp/src/hdr_encode.frag +++ b/app/src/main/cpp/waylandcomp/src/hdr_encode.frag @@ -6,7 +6,8 @@ layout(binding = 0) uniform sampler2D Mixed; layout(push_constant) uniform PC { vec4 ndc; vec4 params; - vec4 rects[6]; + uvec2 rects[6]; + vec4 conv[3]; } pc; layout(location = 0) in vec2 fragTexCoord; @@ -55,28 +56,38 @@ float toneCurve(float x, float peak) { return knee + (1.0 - knee) * (1.0 - exp(-(x - knee) / rate)); } -bool isHdrPixel(vec2 p) { - float packed = pc.params.w; - float count = mod(packed, 16.0); - float mask = floor(packed / 16.0); +int rectAt(vec2 p) { + float count = mod(pc.params.w, 16.0); for (int i = 0; i < 6; i++) { if (float(i) >= count - 0.5) break; - vec4 r = pc.rects[i]; - if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) { - float bit = mod(floor(mask / exp2(float(i))), 2.0); - return bit > 0.5; - } + uvec2 r = pc.rects[i]; + vec2 lo = vec2(float(r.x & 0xFFFFu), float(r.x >> 16)); + vec2 hi = vec2(float(r.y & 0xFFFFu), float(r.y >> 16)); + if (p.x >= lo.x && p.y >= lo.y && p.x < hi.x && p.y < hi.y) return i; } - return false; + return -1; +} + +bool bitOf(float mask, int i) { + return i >= 0 && mod(floor(mask / exp2(float(i))), 2.0) > 0.5; +} + +vec3 convertedNits(vec3 c) { + vec3 lin = pc.conv[1].w > 0.5 ? c : pqToLinear(c); + return vec3(dot(pc.conv[0].xyz, lin), dot(pc.conv[1].xyz, lin), dot(pc.conv[2].xyz, lin)) * pc.conv[2].w; } void main() { vec3 c = texelFetch(Mixed, ivec2(gl_FragCoord.xy), 0).rgb; - bool hdr = isHdrPixel(gl_FragCoord.xy); + int at = rectAt(gl_FragCoord.xy); + bool hdr = bitOf(floor(pc.params.w / 16.0), at); + bool conv = hdr && bitOf(pc.conv[0].w, at); float sdrWhite = max(pc.params.x, 1.0); vec3 outc; if (pc.params.z < 0.5) { - if (hdr) { + if (conv) { + outc = linearToPq(max(convertedNits(c), 0.0) / 10000.0); + } else if (hdr) { outc = c; } else { vec3 nits = (BT709_TO_BT2020 * srgbToLinear(c)) * sdrWhite; @@ -86,7 +97,8 @@ void main() { if (!hdr) { outc = c; } else { - vec3 rel = max(BT2020_TO_BT709 * (pqToLinear(c) * 10000.0), 0.0) / sdrWhite; + vec3 nits = conv ? convertedNits(c) : pqToLinear(c) * 10000.0; + vec3 rel = max(BT2020_TO_BT709 * nits, 0.0) / sdrWhite; float m = max(max(rel.r, rel.g), rel.b); if (m > 1e-6) rel *= toneCurve(m, max(pc.params.y, sdrWhite) / sdrWhite) / m; outc = linearToSrgb(clamp(rel, 0.0, 1.0)); diff --git a/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h b/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h index ba52146fc..68baea4f8 100644 --- a/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h +++ b/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h @@ -1,8 +1,8 @@ #pragma once const uint32_t hdr_encode_code[] = { - 0x07230203,0x00010000,0x0008000b,0x0000018e,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000001ff,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0008000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000010d,0x00000186,0x0000018d, + 0x0008000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000151,0x000001f7,0x000001fe, 0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004, 0x6e69616d,0x00000000,0x00070005,0x0000000b,0x62677273,0x694c6f54,0x7261656e,0x33667628, 0x0000003b,0x00030005,0x0000000a,0x00000063,0x00070005,0x0000000e,0x656e696c,0x6f547261, @@ -10,272 +10,354 @@ const uint32_t hdr_encode_code[] = { 0x6f547170,0x656e694c,0x76287261,0x003b3366,0x00030005,0x00000010,0x00000065,0x00060005, 0x00000014,0x656e696c,0x6f547261,0x76287150,0x003b3366,0x00030005,0x00000013,0x00000079, 0x00070005,0x0000001a,0x656e6f74,0x76727543,0x31662865,0x3b31663b,0x00000000,0x00030005, - 0x00000018,0x00000078,0x00040005,0x00000019,0x6b616570,0x00000000,0x00060005,0x00000021, - 0x64487369,0x78695072,0x76286c65,0x003b3266,0x00030005,0x00000020,0x00000070,0x00030005, - 0x00000023,0x00006f6c,0x00030005,0x00000028,0x00006968,0x00030005,0x0000003c,0x00006f6c, - 0x00030005,0x0000003f,0x00006968,0x00030005,0x00000050,0x00000070,0x00030005,0x0000006f, - 0x00000070,0x00040005,0x0000008c,0x6e617073,0x00000000,0x00040005,0x00000091,0x65746172, - 0x00000000,0x00040005,0x000000a2,0x6b636170,0x00006465,0x00030005,0x000000a7,0x00004350, - 0x00040006,0x000000a7,0x00000000,0x0063646e,0x00050006,0x000000a7,0x00000001,0x61726170, - 0x0000736d,0x00050006,0x000000a7,0x00000002,0x74636572,0x00000073,0x00030005,0x000000a9, - 0x00006370,0x00040005,0x000000b0,0x6e756f63,0x00000074,0x00040005,0x000000b4,0x6b73616d, - 0x00000000,0x00030005,0x000000b9,0x00000069,0x00030005,0x000000cd,0x00000072,0x00030005, - 0x000000f5,0x00746962,0x00030005,0x00000106,0x00000063,0x00040005,0x0000010a,0x6578694d, - 0x00000064,0x00060005,0x0000010d,0x465f6c67,0x43676172,0x64726f6f,0x00000000,0x00030005, - 0x00000116,0x00726468,0x00040005,0x00000117,0x61726170,0x0000006d,0x00050005,0x0000011b, - 0x57726473,0x65746968,0x00000000,0x00040005,0x00000127,0x6374756f,0x00000000,0x00040005, - 0x0000012a,0x7374696e,0x00000000,0x00040005,0x00000139,0x61726170,0x0000006d,0x00040005, - 0x00000143,0x61726170,0x0000006d,0x00030005,0x0000014c,0x006c6572,0x00040005,0x0000015a, - 0x61726170,0x0000006d,0x00030005,0x00000164,0x0000006d,0x00040005,0x00000177,0x61726170, - 0x0000006d,0x00040005,0x00000179,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170, - 0x0000006d,0x00050005,0x00000186,0x4374756f,0x726f6c6f,0x00000000,0x00060005,0x0000018d, - 0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040047,0x000000a6,0x00000006,0x00000010, - 0x00030047,0x000000a7,0x00000002,0x00050048,0x000000a7,0x00000000,0x00000023,0x00000000, - 0x00050048,0x000000a7,0x00000001,0x00000023,0x00000010,0x00050048,0x000000a7,0x00000002, - 0x00000023,0x00000020,0x00040047,0x0000010a,0x00000021,0x00000000,0x00040047,0x0000010a, - 0x00000022,0x00000000,0x00040047,0x0000010d,0x0000000b,0x0000000f,0x00040047,0x00000186, - 0x0000001e,0x00000000,0x00040047,0x0000018d,0x0000001e,0x00000000,0x00020013,0x00000002, - 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007, - 0x00000006,0x00000003,0x00040020,0x00000008,0x00000007,0x00000007,0x00040021,0x00000009, - 0x00000007,0x00000008,0x00040020,0x00000016,0x00000007,0x00000006,0x00050021,0x00000017, - 0x00000006,0x00000016,0x00000016,0x00040017,0x0000001c,0x00000006,0x00000002,0x00040020, - 0x0000001d,0x00000007,0x0000001c,0x00020014,0x0000001e,0x00040021,0x0000001f,0x0000001e, - 0x0000001d,0x0004002b,0x00000006,0x00000025,0x414eb852,0x0004002b,0x00000006,0x0000002a, - 0x3d6147ae,0x0004002b,0x00000006,0x0000002d,0x3f870a3d,0x0004002b,0x00000006,0x00000030, - 0x4019999a,0x0006002c,0x00000007,0x00000031,0x00000030,0x00000030,0x00000030,0x0004002b, - 0x00000006,0x00000035,0x3d25aee6,0x0006002c,0x00000007,0x00000036,0x00000035,0x00000035, - 0x00000035,0x0004002b,0x00000006,0x00000041,0x3ed55555,0x0006002c,0x00000007,0x00000042, - 0x00000041,0x00000041,0x00000041,0x0004002b,0x00000006,0x00000049,0x3b4d2e1c,0x0006002c, - 0x00000007,0x0000004a,0x00000049,0x00000049,0x00000049,0x0004002b,0x00000006,0x00000052, - 0x00000000,0x0004002b,0x00000006,0x00000053,0x3f800000,0x0004002b,0x00000006,0x00000057, - 0x3c4fcdac,0x0006002c,0x00000007,0x00000058,0x00000057,0x00000057,0x00000057,0x0004002b, - 0x00000006,0x0000005b,0x3f560000,0x0004002b,0x00000006,0x00000060,0x4196d000,0x0004002b, - 0x00000006,0x00000061,0x41958000,0x0004002b,0x00000006,0x00000066,0x358637bd,0x0004002b, - 0x00000006,0x0000006a,0x40c8e06b,0x0006002c,0x00000007,0x0000006b,0x0000006a,0x0000006a, - 0x0000006a,0x0004002b,0x00000006,0x00000074,0x3e232000,0x0006002c,0x00000007,0x00000075, - 0x00000074,0x00000074,0x00000074,0x0004002b,0x00000006,0x00000080,0x429db000,0x0006002c, - 0x00000007,0x00000081,0x00000080,0x00000080,0x00000080,0x0004002b,0x00000006,0x00000086, - 0x3f4ccccd,0x0004002b,0x00000006,0x0000008f,0x3d4ccccd,0x0004002b,0x00000006,0x00000093, - 0x407a5e35,0x0004002b,0x00000006,0x00000095,0x3e4ccccd,0x00040017,0x000000a3,0x00000006, - 0x00000004,0x00040015,0x000000a4,0x00000020,0x00000000,0x0004002b,0x000000a4,0x000000a5, - 0x00000006,0x0004001c,0x000000a6,0x000000a3,0x000000a5,0x0005001e,0x000000a7,0x000000a3, - 0x000000a3,0x000000a6,0x00040020,0x000000a8,0x00000009,0x000000a7,0x0004003b,0x000000a8, - 0x000000a9,0x00000009,0x00040015,0x000000aa,0x00000020,0x00000001,0x0004002b,0x000000aa, - 0x000000ab,0x00000001,0x0004002b,0x000000a4,0x000000ac,0x00000003,0x00040020,0x000000ad, - 0x00000009,0x00000006,0x0004002b,0x00000006,0x000000b2,0x41800000,0x00040020,0x000000b8, - 0x00000007,0x000000aa,0x0004002b,0x000000aa,0x000000ba,0x00000000,0x0004002b,0x000000aa, - 0x000000c1,0x00000006,0x0004002b,0x00000006,0x000000c6,0x3f000000,0x00040020,0x000000cc, - 0x00000007,0x000000a3,0x0004002b,0x000000aa,0x000000ce,0x00000002,0x00040020,0x000000d0, - 0x00000009,0x000000a3,0x0004002b,0x000000a4,0x000000d3,0x00000000,0x0004002b,0x000000a4, - 0x000000db,0x00000001,0x0004002b,0x000000a4,0x000000e6,0x00000002,0x0004002b,0x00000006, - 0x000000fc,0x40000000,0x0003002a,0x0000001e,0x00000103,0x00090019,0x00000107,0x00000006, - 0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000108, - 0x00000107,0x00040020,0x00000109,0x00000000,0x00000108,0x0004003b,0x00000109,0x0000010a, - 0x00000000,0x00040020,0x0000010c,0x00000001,0x000000a3,0x0004003b,0x0000010c,0x0000010d, - 0x00000001,0x00040017,0x00000110,0x000000aa,0x00000002,0x00040020,0x00000115,0x00000007, - 0x0000001e,0x00040018,0x0000012b,0x00000007,0x00000003,0x0004002b,0x00000006,0x0000012c, - 0x3f209d49,0x0004002b,0x00000006,0x0000012d,0x3d8d844d,0x0004002b,0x00000006,0x0000012e, - 0x3c86594b,0x0006002c,0x00000007,0x0000012f,0x0000012c,0x0000012d,0x0000012e,0x0004002b, - 0x00000006,0x00000130,0x3ea89a02,0x0004002b,0x00000006,0x00000131,0x3f6b645a,0x0004002b, - 0x00000006,0x00000132,0x3db43958,0x0006002c,0x00000007,0x00000133,0x00000130,0x00000131, - 0x00000132,0x0004002b,0x00000006,0x00000134,0x3d315b57,0x0004002b,0x00000006,0x00000135, - 0x3c3ac711,0x0004002b,0x00000006,0x00000136,0x3f65460b,0x0006002c,0x00000007,0x00000137, - 0x00000134,0x00000135,0x00000136,0x0006002c,0x0000012b,0x00000138,0x0000012f,0x00000133, - 0x00000137,0x0004002b,0x00000006,0x00000140,0x461c4000,0x0004002b,0x00000006,0x0000014d, - 0x3fd48b44,0x0004002b,0x00000006,0x0000014e,0xbdff2e49,0x0004002b,0x00000006,0x0000014f, - 0xbc95182b,0x0006002c,0x00000007,0x00000150,0x0000014d,0x0000014e,0x0000014f,0x0004002b, - 0x00000006,0x00000151,0xbf166cf4,0x0004002b,0x00000006,0x00000152,0x3f9102de,0x0004002b, - 0x00000006,0x00000153,0xbdce075f,0x0006002c,0x00000007,0x00000154,0x00000151,0x00000152, - 0x00000153,0x0004002b,0x00000006,0x00000155,0xbd95182b,0x0004002b,0x00000006,0x00000156, - 0xbc07fcb9,0x0004002b,0x00000006,0x00000157,0x3f8f3190,0x0006002c,0x00000007,0x00000158, - 0x00000155,0x00000156,0x00000157,0x0006002c,0x0000012b,0x00000159,0x00000150,0x00000154, - 0x00000158,0x00040020,0x00000185,0x00000003,0x000000a3,0x0004003b,0x00000185,0x00000186, - 0x00000003,0x00040020,0x0000018c,0x00000001,0x0000001c,0x0004003b,0x0000018c,0x0000018d, + 0x00000018,0x00000078,0x00040005,0x00000019,0x6b616570,0x00000000,0x00050005,0x00000021, + 0x74636572,0x76287441,0x003b3266,0x00030005,0x00000020,0x00000070,0x00060005,0x00000028, + 0x4f746962,0x31662866,0x3b31693b,0x00000000,0x00040005,0x00000026,0x6b73616d,0x00000000, + 0x00030005,0x00000027,0x00000069,0x00070005,0x0000002b,0x766e6f63,0x65747265,0x74694e64, + 0x66762873,0x00003b33,0x00030005,0x0000002a,0x00000063,0x00030005,0x0000002d,0x00006f6c, + 0x00030005,0x00000032,0x00006968,0x00030005,0x00000046,0x00006f6c,0x00030005,0x00000049, + 0x00006968,0x00030005,0x0000005a,0x00000070,0x00030005,0x00000079,0x00000070,0x00040005, + 0x00000096,0x6e617073,0x00000000,0x00040005,0x0000009b,0x65746172,0x00000000,0x00040005, + 0x000000ac,0x6e756f63,0x00000074,0x00030005,0x000000b4,0x00004350,0x00040006,0x000000b4, + 0x00000000,0x0063646e,0x00050006,0x000000b4,0x00000001,0x61726170,0x0000736d,0x00050006, + 0x000000b4,0x00000002,0x74636572,0x00000073,0x00050006,0x000000b4,0x00000003,0x766e6f63, + 0x00000000,0x00030005,0x000000b6,0x00006370,0x00030005,0x000000bd,0x00000069,0x00030005, + 0x000000d1,0x00000072,0x00030005,0x000000d7,0x00006f6c,0x00030005,0x000000e5,0x00006968, + 0x00030005,0x00000126,0x006e696c,0x00040005,0x00000130,0x61726170,0x0000006d,0x00030005, + 0x0000014a,0x00000063,0x00040005,0x0000014e,0x6578694d,0x00000064,0x00060005,0x00000151, + 0x465f6c67,0x43676172,0x64726f6f,0x00000000,0x00030005,0x00000159,0x00007461,0x00040005, + 0x0000015a,0x61726170,0x0000006d,0x00030005,0x0000015f,0x00726468,0x00040005,0x00000164, + 0x61726170,0x0000006d,0x00040005,0x00000165,0x61726170,0x0000006d,0x00040005,0x00000168, + 0x766e6f63,0x00000000,0x00040005,0x0000016c,0x61726170,0x0000006d,0x00040005,0x0000016f, + 0x61726170,0x0000006d,0x00050005,0x00000173,0x57726473,0x65746968,0x00000000,0x00040005, + 0x00000180,0x6374756f,0x00000000,0x00040005,0x00000181,0x61726170,0x0000006d,0x00040005, + 0x00000189,0x61726170,0x0000006d,0x00040005,0x00000191,0x7374696e,0x00000000,0x00040005, + 0x000001a0,0x61726170,0x0000006d,0x00040005,0x000001a9,0x61726170,0x0000006d,0x00040005, + 0x000001b2,0x7374696e,0x00000000,0x00040005,0x000001b7,0x61726170,0x0000006d,0x00040005, + 0x000001bb,0x61726170,0x0000006d,0x00030005,0x000001c0,0x006c6572,0x00030005,0x000001d5, + 0x0000006d,0x00040005,0x000001e8,0x61726170,0x0000006d,0x00040005,0x000001ea,0x61726170, + 0x0000006d,0x00040005,0x000001f4,0x61726170,0x0000006d,0x00050005,0x000001f7,0x4374756f, + 0x726f6c6f,0x00000000,0x00060005,0x000001fe,0x67617266,0x43786554,0x64726f6f,0x00000000, + 0x00040047,0x000000b1,0x00000006,0x00000008,0x00040047,0x000000b3,0x00000006,0x00000010, + 0x00030047,0x000000b4,0x00000002,0x00050048,0x000000b4,0x00000000,0x00000023,0x00000000, + 0x00050048,0x000000b4,0x00000001,0x00000023,0x00000010,0x00050048,0x000000b4,0x00000002, + 0x00000023,0x00000020,0x00050048,0x000000b4,0x00000003,0x00000023,0x00000050,0x00040047, + 0x0000014e,0x00000021,0x00000000,0x00040047,0x0000014e,0x00000022,0x00000000,0x00040047, + 0x00000151,0x0000000b,0x0000000f,0x00040047,0x000001f7,0x0000001e,0x00000000,0x00040047, + 0x000001fe,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002, + 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000003,0x00040020, + 0x00000008,0x00000007,0x00000007,0x00040021,0x00000009,0x00000007,0x00000008,0x00040020, + 0x00000016,0x00000007,0x00000006,0x00050021,0x00000017,0x00000006,0x00000016,0x00000016, + 0x00040017,0x0000001c,0x00000006,0x00000002,0x00040020,0x0000001d,0x00000007,0x0000001c, + 0x00040015,0x0000001e,0x00000020,0x00000001,0x00040021,0x0000001f,0x0000001e,0x0000001d, + 0x00040020,0x00000023,0x00000007,0x0000001e,0x00020014,0x00000024,0x00050021,0x00000025, + 0x00000024,0x00000016,0x00000023,0x0004002b,0x00000006,0x0000002f,0x414eb852,0x0004002b, + 0x00000006,0x00000034,0x3d6147ae,0x0004002b,0x00000006,0x00000037,0x3f870a3d,0x0004002b, + 0x00000006,0x0000003a,0x4019999a,0x0006002c,0x00000007,0x0000003b,0x0000003a,0x0000003a, + 0x0000003a,0x0004002b,0x00000006,0x0000003f,0x3d25aee6,0x0006002c,0x00000007,0x00000040, + 0x0000003f,0x0000003f,0x0000003f,0x0004002b,0x00000006,0x0000004b,0x3ed55555,0x0006002c, + 0x00000007,0x0000004c,0x0000004b,0x0000004b,0x0000004b,0x0004002b,0x00000006,0x00000053, + 0x3b4d2e1c,0x0006002c,0x00000007,0x00000054,0x00000053,0x00000053,0x00000053,0x0004002b, + 0x00000006,0x0000005c,0x00000000,0x0004002b,0x00000006,0x0000005d,0x3f800000,0x0004002b, + 0x00000006,0x00000061,0x3c4fcdac,0x0006002c,0x00000007,0x00000062,0x00000061,0x00000061, + 0x00000061,0x0004002b,0x00000006,0x00000065,0x3f560000,0x0004002b,0x00000006,0x0000006a, + 0x4196d000,0x0004002b,0x00000006,0x0000006b,0x41958000,0x0004002b,0x00000006,0x00000070, + 0x358637bd,0x0004002b,0x00000006,0x00000074,0x40c8e06b,0x0006002c,0x00000007,0x00000075, + 0x00000074,0x00000074,0x00000074,0x0004002b,0x00000006,0x0000007e,0x3e232000,0x0006002c, + 0x00000007,0x0000007f,0x0000007e,0x0000007e,0x0000007e,0x0004002b,0x00000006,0x0000008a, + 0x429db000,0x0006002c,0x00000007,0x0000008b,0x0000008a,0x0000008a,0x0000008a,0x0004002b, + 0x00000006,0x00000090,0x3f4ccccd,0x0004002b,0x00000006,0x00000099,0x3d4ccccd,0x0004002b, + 0x00000006,0x0000009d,0x407a5e35,0x0004002b,0x00000006,0x0000009f,0x3e4ccccd,0x00040017, + 0x000000ad,0x00000006,0x00000004,0x00040015,0x000000ae,0x00000020,0x00000000,0x00040017, + 0x000000af,0x000000ae,0x00000002,0x0004002b,0x000000ae,0x000000b0,0x00000006,0x0004001c, + 0x000000b1,0x000000af,0x000000b0,0x0004002b,0x000000ae,0x000000b2,0x00000003,0x0004001c, + 0x000000b3,0x000000ad,0x000000b2,0x0006001e,0x000000b4,0x000000ad,0x000000ad,0x000000b1, + 0x000000b3,0x00040020,0x000000b5,0x00000009,0x000000b4,0x0004003b,0x000000b5,0x000000b6, + 0x00000009,0x0004002b,0x0000001e,0x000000b7,0x00000001,0x00040020,0x000000b8,0x00000009, + 0x00000006,0x0004002b,0x00000006,0x000000bb,0x41800000,0x0004002b,0x0000001e,0x000000be, + 0x00000000,0x0004002b,0x0000001e,0x000000c5,0x00000006,0x0004002b,0x00000006,0x000000ca, + 0x3f000000,0x00040020,0x000000d0,0x00000007,0x000000af,0x0004002b,0x0000001e,0x000000d2, + 0x00000002,0x00040020,0x000000d4,0x00000009,0x000000af,0x0004002b,0x000000ae,0x000000d8, + 0x00000000,0x00040020,0x000000d9,0x00000007,0x000000ae,0x0004002b,0x000000ae,0x000000dc, + 0x0000ffff,0x0004002b,0x0000001e,0x000000e1,0x00000010,0x0004002b,0x000000ae,0x000000e6, + 0x00000001,0x0004002b,0x0000001e,0x00000113,0xffffffff,0x0004002b,0x00000006,0x00000120, + 0x40000000,0x0004002b,0x0000001e,0x00000127,0x00000003,0x00040020,0x00000134,0x00000009, + 0x000000ad,0x00090019,0x0000014b,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, + 0x00000001,0x00000000,0x0003001b,0x0000014c,0x0000014b,0x00040020,0x0000014d,0x00000000, + 0x0000014c,0x0004003b,0x0000014d,0x0000014e,0x00000000,0x00040020,0x00000150,0x00000001, + 0x000000ad,0x0004003b,0x00000150,0x00000151,0x00000001,0x00040017,0x00000154,0x0000001e, + 0x00000002,0x00040020,0x0000015e,0x00000007,0x00000024,0x0004002b,0x000000ae,0x00000177, + 0x00000002,0x0004002b,0x00000006,0x00000186,0x461c4000,0x00040018,0x00000192,0x00000007, + 0x00000003,0x0004002b,0x00000006,0x00000193,0x3f209d49,0x0004002b,0x00000006,0x00000194, + 0x3d8d844d,0x0004002b,0x00000006,0x00000195,0x3c86594b,0x0006002c,0x00000007,0x00000196, + 0x00000193,0x00000194,0x00000195,0x0004002b,0x00000006,0x00000197,0x3ea89a02,0x0004002b, + 0x00000006,0x00000198,0x3f6b645a,0x0004002b,0x00000006,0x00000199,0x3db43958,0x0006002c, + 0x00000007,0x0000019a,0x00000197,0x00000198,0x00000199,0x0004002b,0x00000006,0x0000019b, + 0x3d315b57,0x0004002b,0x00000006,0x0000019c,0x3c3ac711,0x0004002b,0x00000006,0x0000019d, + 0x3f65460b,0x0006002c,0x00000007,0x0000019e,0x0000019b,0x0000019c,0x0000019d,0x0006002c, + 0x00000192,0x0000019f,0x00000196,0x0000019a,0x0000019e,0x0004002b,0x00000006,0x000001c1, + 0x3fd48b44,0x0004002b,0x00000006,0x000001c2,0xbdff2e49,0x0004002b,0x00000006,0x000001c3, + 0xbc95182b,0x0006002c,0x00000007,0x000001c4,0x000001c1,0x000001c2,0x000001c3,0x0004002b, + 0x00000006,0x000001c5,0xbf166cf4,0x0004002b,0x00000006,0x000001c6,0x3f9102de,0x0004002b, + 0x00000006,0x000001c7,0xbdce075f,0x0006002c,0x00000007,0x000001c8,0x000001c5,0x000001c6, + 0x000001c7,0x0004002b,0x00000006,0x000001c9,0xbd95182b,0x0004002b,0x00000006,0x000001ca, + 0xbc07fcb9,0x0004002b,0x00000006,0x000001cb,0x3f8f3190,0x0006002c,0x00000007,0x000001cc, + 0x000001c9,0x000001ca,0x000001cb,0x0006002c,0x00000192,0x000001cd,0x000001c4,0x000001c8, + 0x000001cc,0x00040020,0x000001f6,0x00000003,0x000000ad,0x0004003b,0x000001f6,0x000001f7, + 0x00000003,0x00040020,0x000001fd,0x00000001,0x0000001c,0x0004003b,0x000001fd,0x000001fe, 0x00000001,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005, - 0x0004003b,0x00000008,0x00000106,0x00000007,0x0004003b,0x00000115,0x00000116,0x00000007, - 0x0004003b,0x0000001d,0x00000117,0x00000007,0x0004003b,0x00000016,0x0000011b,0x00000007, - 0x0004003b,0x00000008,0x00000127,0x00000007,0x0004003b,0x00000008,0x0000012a,0x00000007, - 0x0004003b,0x00000008,0x00000139,0x00000007,0x0004003b,0x00000008,0x00000143,0x00000007, - 0x0004003b,0x00000008,0x0000014c,0x00000007,0x0004003b,0x00000008,0x0000015a,0x00000007, - 0x0004003b,0x00000016,0x00000164,0x00000007,0x0004003b,0x00000016,0x00000177,0x00000007, - 0x0004003b,0x00000016,0x00000179,0x00000007,0x0004003b,0x00000008,0x00000183,0x00000007, - 0x0004003d,0x00000108,0x0000010b,0x0000010a,0x0004003d,0x000000a3,0x0000010e,0x0000010d, - 0x0007004f,0x0000001c,0x0000010f,0x0000010e,0x0000010e,0x00000000,0x00000001,0x0004006e, - 0x00000110,0x00000111,0x0000010f,0x00040064,0x00000107,0x00000112,0x0000010b,0x0007005f, - 0x000000a3,0x00000113,0x00000112,0x00000111,0x00000002,0x000000ba,0x0008004f,0x00000007, - 0x00000114,0x00000113,0x00000113,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000106, - 0x00000114,0x0004003d,0x000000a3,0x00000118,0x0000010d,0x0007004f,0x0000001c,0x00000119, - 0x00000118,0x00000118,0x00000000,0x00000001,0x0003003e,0x00000117,0x00000119,0x00050039, - 0x0000001e,0x0000011a,0x00000021,0x00000117,0x0003003e,0x00000116,0x0000011a,0x00060041, - 0x000000ad,0x0000011c,0x000000a9,0x000000ab,0x000000d3,0x0004003d,0x00000006,0x0000011d, - 0x0000011c,0x0007000c,0x00000006,0x0000011e,0x00000001,0x00000028,0x0000011d,0x00000053, - 0x0003003e,0x0000011b,0x0000011e,0x00060041,0x000000ad,0x0000011f,0x000000a9,0x000000ab, - 0x000000e6,0x0004003d,0x00000006,0x00000120,0x0000011f,0x000500b8,0x0000001e,0x00000121, - 0x00000120,0x000000c6,0x000300f7,0x00000123,0x00000000,0x000400fa,0x00000121,0x00000122, - 0x00000145,0x000200f8,0x00000122,0x0004003d,0x0000001e,0x00000124,0x00000116,0x000300f7, - 0x00000126,0x00000000,0x000400fa,0x00000124,0x00000125,0x00000129,0x000200f8,0x00000125, - 0x0004003d,0x00000007,0x00000128,0x00000106,0x0003003e,0x00000127,0x00000128,0x000200f9, - 0x00000126,0x000200f8,0x00000129,0x0004003d,0x00000007,0x0000013a,0x00000106,0x0003003e, - 0x00000139,0x0000013a,0x00050039,0x00000007,0x0000013b,0x0000000b,0x00000139,0x00050091, - 0x00000007,0x0000013c,0x00000138,0x0000013b,0x0004003d,0x00000006,0x0000013d,0x0000011b, - 0x0005008e,0x00000007,0x0000013e,0x0000013c,0x0000013d,0x0003003e,0x0000012a,0x0000013e, - 0x0004003d,0x00000007,0x0000013f,0x0000012a,0x00060050,0x00000007,0x00000141,0x00000140, - 0x00000140,0x00000140,0x00050088,0x00000007,0x00000142,0x0000013f,0x00000141,0x0003003e, - 0x00000143,0x00000142,0x00050039,0x00000007,0x00000144,0x00000014,0x00000143,0x0003003e, - 0x00000127,0x00000144,0x000200f9,0x00000126,0x000200f8,0x00000126,0x000200f9,0x00000123, - 0x000200f8,0x00000145,0x0004003d,0x0000001e,0x00000146,0x00000116,0x000400a8,0x0000001e, - 0x00000147,0x00000146,0x000300f7,0x00000149,0x00000000,0x000400fa,0x00000147,0x00000148, - 0x0000014b,0x000200f8,0x00000148,0x0004003d,0x00000007,0x0000014a,0x00000106,0x0003003e, - 0x00000127,0x0000014a,0x000200f9,0x00000149,0x000200f8,0x0000014b,0x0004003d,0x00000007, - 0x0000015b,0x00000106,0x0003003e,0x0000015a,0x0000015b,0x00050039,0x00000007,0x0000015c, - 0x00000011,0x0000015a,0x0005008e,0x00000007,0x0000015d,0x0000015c,0x00000140,0x00050091, - 0x00000007,0x0000015e,0x00000159,0x0000015d,0x00060050,0x00000007,0x0000015f,0x00000052, - 0x00000052,0x00000052,0x0007000c,0x00000007,0x00000160,0x00000001,0x00000028,0x0000015e, - 0x0000015f,0x0004003d,0x00000006,0x00000161,0x0000011b,0x00060050,0x00000007,0x00000162, - 0x00000161,0x00000161,0x00000161,0x00050088,0x00000007,0x00000163,0x00000160,0x00000162, - 0x0003003e,0x0000014c,0x00000163,0x00050041,0x00000016,0x00000165,0x0000014c,0x000000d3, - 0x0004003d,0x00000006,0x00000166,0x00000165,0x00050041,0x00000016,0x00000167,0x0000014c, - 0x000000db,0x0004003d,0x00000006,0x00000168,0x00000167,0x0007000c,0x00000006,0x00000169, - 0x00000001,0x00000028,0x00000166,0x00000168,0x00050041,0x00000016,0x0000016a,0x0000014c, - 0x000000e6,0x0004003d,0x00000006,0x0000016b,0x0000016a,0x0007000c,0x00000006,0x0000016c, - 0x00000001,0x00000028,0x00000169,0x0000016b,0x0003003e,0x00000164,0x0000016c,0x0004003d, - 0x00000006,0x0000016d,0x00000164,0x000500ba,0x0000001e,0x0000016e,0x0000016d,0x00000066, - 0x000300f7,0x00000170,0x00000000,0x000400fa,0x0000016e,0x0000016f,0x00000170,0x000200f8, - 0x0000016f,0x00060041,0x000000ad,0x00000171,0x000000a9,0x000000ab,0x000000db,0x0004003d, - 0x00000006,0x00000172,0x00000171,0x0004003d,0x00000006,0x00000173,0x0000011b,0x0007000c, - 0x00000006,0x00000174,0x00000001,0x00000028,0x00000172,0x00000173,0x0004003d,0x00000006, - 0x00000175,0x0000011b,0x00050088,0x00000006,0x00000176,0x00000174,0x00000175,0x0004003d, - 0x00000006,0x00000178,0x00000164,0x0003003e,0x00000177,0x00000178,0x0003003e,0x00000179, - 0x00000176,0x00060039,0x00000006,0x0000017a,0x0000001a,0x00000177,0x00000179,0x0004003d, - 0x00000006,0x0000017b,0x00000164,0x00050088,0x00000006,0x0000017c,0x0000017a,0x0000017b, - 0x0004003d,0x00000007,0x0000017d,0x0000014c,0x0005008e,0x00000007,0x0000017e,0x0000017d, - 0x0000017c,0x0003003e,0x0000014c,0x0000017e,0x000200f9,0x00000170,0x000200f8,0x00000170, - 0x0004003d,0x00000007,0x0000017f,0x0000014c,0x00060050,0x00000007,0x00000180,0x00000052, - 0x00000052,0x00000052,0x00060050,0x00000007,0x00000181,0x00000053,0x00000053,0x00000053, - 0x0008000c,0x00000007,0x00000182,0x00000001,0x0000002b,0x0000017f,0x00000180,0x00000181, - 0x0003003e,0x00000183,0x00000182,0x00050039,0x00000007,0x00000184,0x0000000e,0x00000183, - 0x0003003e,0x00000127,0x00000184,0x000200f9,0x00000149,0x000200f8,0x00000149,0x000200f9, - 0x00000123,0x000200f8,0x00000123,0x0004003d,0x00000007,0x00000187,0x00000127,0x00050051, - 0x00000006,0x00000188,0x00000187,0x00000000,0x00050051,0x00000006,0x00000189,0x00000187, - 0x00000001,0x00050051,0x00000006,0x0000018a,0x00000187,0x00000002,0x00070050,0x000000a3, - 0x0000018b,0x00000188,0x00000189,0x0000018a,0x00000053,0x0003003e,0x00000186,0x0000018b, + 0x0004003b,0x00000008,0x0000014a,0x00000007,0x0004003b,0x00000023,0x00000159,0x00000007, + 0x0004003b,0x0000001d,0x0000015a,0x00000007,0x0004003b,0x0000015e,0x0000015f,0x00000007, + 0x0004003b,0x00000016,0x00000164,0x00000007,0x0004003b,0x00000023,0x00000165,0x00000007, + 0x0004003b,0x0000015e,0x00000168,0x00000007,0x0004003b,0x00000016,0x0000016c,0x00000007, + 0x0004003b,0x00000023,0x0000016f,0x00000007,0x0004003b,0x00000016,0x00000173,0x00000007, + 0x0004003b,0x00000008,0x00000180,0x00000007,0x0004003b,0x00000008,0x00000181,0x00000007, + 0x0004003b,0x00000008,0x00000189,0x00000007,0x0004003b,0x00000008,0x00000191,0x00000007, + 0x0004003b,0x00000008,0x000001a0,0x00000007,0x0004003b,0x00000008,0x000001a9,0x00000007, + 0x0004003b,0x00000008,0x000001b2,0x00000007,0x0004003b,0x00000008,0x000001b4,0x00000007, + 0x0004003b,0x00000008,0x000001b7,0x00000007,0x0004003b,0x00000008,0x000001bb,0x00000007, + 0x0004003b,0x00000008,0x000001c0,0x00000007,0x0004003b,0x00000016,0x000001d5,0x00000007, + 0x0004003b,0x00000016,0x000001e8,0x00000007,0x0004003b,0x00000016,0x000001ea,0x00000007, + 0x0004003b,0x00000008,0x000001f4,0x00000007,0x0004003d,0x0000014c,0x0000014f,0x0000014e, + 0x0004003d,0x000000ad,0x00000152,0x00000151,0x0007004f,0x0000001c,0x00000153,0x00000152, + 0x00000152,0x00000000,0x00000001,0x0004006e,0x00000154,0x00000155,0x00000153,0x00040064, + 0x0000014b,0x00000156,0x0000014f,0x0007005f,0x000000ad,0x00000157,0x00000156,0x00000155, + 0x00000002,0x000000be,0x0008004f,0x00000007,0x00000158,0x00000157,0x00000157,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x0000014a,0x00000158,0x0004003d,0x000000ad,0x0000015b, + 0x00000151,0x0007004f,0x0000001c,0x0000015c,0x0000015b,0x0000015b,0x00000000,0x00000001, + 0x0003003e,0x0000015a,0x0000015c,0x00050039,0x0000001e,0x0000015d,0x00000021,0x0000015a, + 0x0003003e,0x00000159,0x0000015d,0x00060041,0x000000b8,0x00000160,0x000000b6,0x000000b7, + 0x000000b2,0x0004003d,0x00000006,0x00000161,0x00000160,0x00050088,0x00000006,0x00000162, + 0x00000161,0x000000bb,0x0006000c,0x00000006,0x00000163,0x00000001,0x00000008,0x00000162, + 0x0003003e,0x00000164,0x00000163,0x0004003d,0x0000001e,0x00000166,0x00000159,0x0003003e, + 0x00000165,0x00000166,0x00060039,0x00000024,0x00000167,0x00000028,0x00000164,0x00000165, + 0x0003003e,0x0000015f,0x00000167,0x0004003d,0x00000024,0x00000169,0x0000015f,0x000300f7, + 0x0000016b,0x00000000,0x000400fa,0x00000169,0x0000016a,0x0000016b,0x000200f8,0x0000016a, + 0x00070041,0x000000b8,0x0000016d,0x000000b6,0x00000127,0x000000be,0x000000b2,0x0004003d, + 0x00000006,0x0000016e,0x0000016d,0x0003003e,0x0000016c,0x0000016e,0x0004003d,0x0000001e, + 0x00000170,0x00000159,0x0003003e,0x0000016f,0x00000170,0x00060039,0x00000024,0x00000171, + 0x00000028,0x0000016c,0x0000016f,0x000200f9,0x0000016b,0x000200f8,0x0000016b,0x000700f5, + 0x00000024,0x00000172,0x00000169,0x00000005,0x00000171,0x0000016a,0x0003003e,0x00000168, + 0x00000172,0x00060041,0x000000b8,0x00000174,0x000000b6,0x000000b7,0x000000d8,0x0004003d, + 0x00000006,0x00000175,0x00000174,0x0007000c,0x00000006,0x00000176,0x00000001,0x00000028, + 0x00000175,0x0000005d,0x0003003e,0x00000173,0x00000176,0x00060041,0x000000b8,0x00000178, + 0x000000b6,0x000000b7,0x00000177,0x0004003d,0x00000006,0x00000179,0x00000178,0x000500b8, + 0x00000024,0x0000017a,0x00000179,0x000000ca,0x000300f7,0x0000017c,0x00000000,0x000400fa, + 0x0000017a,0x0000017b,0x000001ab,0x000200f8,0x0000017b,0x0004003d,0x00000024,0x0000017d, + 0x00000168,0x000300f7,0x0000017f,0x00000000,0x000400fa,0x0000017d,0x0000017e,0x0000018b, + 0x000200f8,0x0000017e,0x0004003d,0x00000007,0x00000182,0x0000014a,0x0003003e,0x00000181, + 0x00000182,0x00050039,0x00000007,0x00000183,0x0000002b,0x00000181,0x00060050,0x00000007, + 0x00000184,0x0000005c,0x0000005c,0x0000005c,0x0007000c,0x00000007,0x00000185,0x00000001, + 0x00000028,0x00000183,0x00000184,0x00060050,0x00000007,0x00000187,0x00000186,0x00000186, + 0x00000186,0x00050088,0x00000007,0x00000188,0x00000185,0x00000187,0x0003003e,0x00000189, + 0x00000188,0x00050039,0x00000007,0x0000018a,0x00000014,0x00000189,0x0003003e,0x00000180, + 0x0000018a,0x000200f9,0x0000017f,0x000200f8,0x0000018b,0x0004003d,0x00000024,0x0000018c, + 0x0000015f,0x000300f7,0x0000018e,0x00000000,0x000400fa,0x0000018c,0x0000018d,0x00000190, + 0x000200f8,0x0000018d,0x0004003d,0x00000007,0x0000018f,0x0000014a,0x0003003e,0x00000180, + 0x0000018f,0x000200f9,0x0000018e,0x000200f8,0x00000190,0x0004003d,0x00000007,0x000001a1, + 0x0000014a,0x0003003e,0x000001a0,0x000001a1,0x00050039,0x00000007,0x000001a2,0x0000000b, + 0x000001a0,0x00050091,0x00000007,0x000001a3,0x0000019f,0x000001a2,0x0004003d,0x00000006, + 0x000001a4,0x00000173,0x0005008e,0x00000007,0x000001a5,0x000001a3,0x000001a4,0x0003003e, + 0x00000191,0x000001a5,0x0004003d,0x00000007,0x000001a6,0x00000191,0x00060050,0x00000007, + 0x000001a7,0x00000186,0x00000186,0x00000186,0x00050088,0x00000007,0x000001a8,0x000001a6, + 0x000001a7,0x0003003e,0x000001a9,0x000001a8,0x00050039,0x00000007,0x000001aa,0x00000014, + 0x000001a9,0x0003003e,0x00000180,0x000001aa,0x000200f9,0x0000018e,0x000200f8,0x0000018e, + 0x000200f9,0x0000017f,0x000200f8,0x0000017f,0x000200f9,0x0000017c,0x000200f8,0x000001ab, + 0x0004003d,0x00000024,0x000001ac,0x0000015f,0x000400a8,0x00000024,0x000001ad,0x000001ac, + 0x000300f7,0x000001af,0x00000000,0x000400fa,0x000001ad,0x000001ae,0x000001b1,0x000200f8, + 0x000001ae,0x0004003d,0x00000007,0x000001b0,0x0000014a,0x0003003e,0x00000180,0x000001b0, + 0x000200f9,0x000001af,0x000200f8,0x000001b1,0x0004003d,0x00000024,0x000001b3,0x00000168, + 0x000300f7,0x000001b6,0x00000000,0x000400fa,0x000001b3,0x000001b5,0x000001ba,0x000200f8, + 0x000001b5,0x0004003d,0x00000007,0x000001b8,0x0000014a,0x0003003e,0x000001b7,0x000001b8, + 0x00050039,0x00000007,0x000001b9,0x0000002b,0x000001b7,0x0003003e,0x000001b4,0x000001b9, + 0x000200f9,0x000001b6,0x000200f8,0x000001ba,0x0004003d,0x00000007,0x000001bc,0x0000014a, + 0x0003003e,0x000001bb,0x000001bc,0x00050039,0x00000007,0x000001bd,0x00000011,0x000001bb, + 0x0005008e,0x00000007,0x000001be,0x000001bd,0x00000186,0x0003003e,0x000001b4,0x000001be, + 0x000200f9,0x000001b6,0x000200f8,0x000001b6,0x0004003d,0x00000007,0x000001bf,0x000001b4, + 0x0003003e,0x000001b2,0x000001bf,0x0004003d,0x00000007,0x000001ce,0x000001b2,0x00050091, + 0x00000007,0x000001cf,0x000001cd,0x000001ce,0x00060050,0x00000007,0x000001d0,0x0000005c, + 0x0000005c,0x0000005c,0x0007000c,0x00000007,0x000001d1,0x00000001,0x00000028,0x000001cf, + 0x000001d0,0x0004003d,0x00000006,0x000001d2,0x00000173,0x00060050,0x00000007,0x000001d3, + 0x000001d2,0x000001d2,0x000001d2,0x00050088,0x00000007,0x000001d4,0x000001d1,0x000001d3, + 0x0003003e,0x000001c0,0x000001d4,0x00050041,0x00000016,0x000001d6,0x000001c0,0x000000d8, + 0x0004003d,0x00000006,0x000001d7,0x000001d6,0x00050041,0x00000016,0x000001d8,0x000001c0, + 0x000000e6,0x0004003d,0x00000006,0x000001d9,0x000001d8,0x0007000c,0x00000006,0x000001da, + 0x00000001,0x00000028,0x000001d7,0x000001d9,0x00050041,0x00000016,0x000001db,0x000001c0, + 0x00000177,0x0004003d,0x00000006,0x000001dc,0x000001db,0x0007000c,0x00000006,0x000001dd, + 0x00000001,0x00000028,0x000001da,0x000001dc,0x0003003e,0x000001d5,0x000001dd,0x0004003d, + 0x00000006,0x000001de,0x000001d5,0x000500ba,0x00000024,0x000001df,0x000001de,0x00000070, + 0x000300f7,0x000001e1,0x00000000,0x000400fa,0x000001df,0x000001e0,0x000001e1,0x000200f8, + 0x000001e0,0x00060041,0x000000b8,0x000001e2,0x000000b6,0x000000b7,0x000000e6,0x0004003d, + 0x00000006,0x000001e3,0x000001e2,0x0004003d,0x00000006,0x000001e4,0x00000173,0x0007000c, + 0x00000006,0x000001e5,0x00000001,0x00000028,0x000001e3,0x000001e4,0x0004003d,0x00000006, + 0x000001e6,0x00000173,0x00050088,0x00000006,0x000001e7,0x000001e5,0x000001e6,0x0004003d, + 0x00000006,0x000001e9,0x000001d5,0x0003003e,0x000001e8,0x000001e9,0x0003003e,0x000001ea, + 0x000001e7,0x00060039,0x00000006,0x000001eb,0x0000001a,0x000001e8,0x000001ea,0x0004003d, + 0x00000006,0x000001ec,0x000001d5,0x00050088,0x00000006,0x000001ed,0x000001eb,0x000001ec, + 0x0004003d,0x00000007,0x000001ee,0x000001c0,0x0005008e,0x00000007,0x000001ef,0x000001ee, + 0x000001ed,0x0003003e,0x000001c0,0x000001ef,0x000200f9,0x000001e1,0x000200f8,0x000001e1, + 0x0004003d,0x00000007,0x000001f0,0x000001c0,0x00060050,0x00000007,0x000001f1,0x0000005c, + 0x0000005c,0x0000005c,0x00060050,0x00000007,0x000001f2,0x0000005d,0x0000005d,0x0000005d, + 0x0008000c,0x00000007,0x000001f3,0x00000001,0x0000002b,0x000001f0,0x000001f1,0x000001f2, + 0x0003003e,0x000001f4,0x000001f3,0x00050039,0x00000007,0x000001f5,0x0000000e,0x000001f4, + 0x0003003e,0x00000180,0x000001f5,0x000200f9,0x000001af,0x000200f8,0x000001af,0x000200f9, + 0x0000017c,0x000200f8,0x0000017c,0x0004003d,0x00000007,0x000001f8,0x00000180,0x00050051, + 0x00000006,0x000001f9,0x000001f8,0x00000000,0x00050051,0x00000006,0x000001fa,0x000001f8, + 0x00000001,0x00050051,0x00000006,0x000001fb,0x000001f8,0x00000002,0x00070050,0x000000ad, + 0x000001fc,0x000001f9,0x000001fa,0x000001fb,0x0000005d,0x0003003e,0x000001f7,0x000001fc, 0x000100fd,0x00010038,0x00050036,0x00000007,0x0000000b,0x00000000,0x00000009,0x00030037, - 0x00000008,0x0000000a,0x000200f8,0x0000000c,0x0004003b,0x00000008,0x00000023,0x00000007, - 0x0004003b,0x00000008,0x00000028,0x00000007,0x0004003d,0x00000007,0x00000024,0x0000000a, - 0x00060050,0x00000007,0x00000026,0x00000025,0x00000025,0x00000025,0x00050088,0x00000007, - 0x00000027,0x00000024,0x00000026,0x0003003e,0x00000023,0x00000027,0x0004003d,0x00000007, - 0x00000029,0x0000000a,0x00060050,0x00000007,0x0000002b,0x0000002a,0x0000002a,0x0000002a, - 0x00050081,0x00000007,0x0000002c,0x00000029,0x0000002b,0x00060050,0x00000007,0x0000002e, - 0x0000002d,0x0000002d,0x0000002d,0x00050088,0x00000007,0x0000002f,0x0000002c,0x0000002e, - 0x0007000c,0x00000007,0x00000032,0x00000001,0x0000001a,0x0000002f,0x00000031,0x0003003e, - 0x00000028,0x00000032,0x0004003d,0x00000007,0x00000033,0x00000023,0x0004003d,0x00000007, - 0x00000034,0x00000028,0x0004003d,0x00000007,0x00000037,0x0000000a,0x0007000c,0x00000007, - 0x00000038,0x00000001,0x00000030,0x00000036,0x00000037,0x0008000c,0x00000007,0x00000039, - 0x00000001,0x0000002e,0x00000033,0x00000034,0x00000038,0x000200fe,0x00000039,0x00010038, + 0x00000008,0x0000000a,0x000200f8,0x0000000c,0x0004003b,0x00000008,0x0000002d,0x00000007, + 0x0004003b,0x00000008,0x00000032,0x00000007,0x0004003d,0x00000007,0x0000002e,0x0000000a, + 0x00060050,0x00000007,0x00000030,0x0000002f,0x0000002f,0x0000002f,0x00050088,0x00000007, + 0x00000031,0x0000002e,0x00000030,0x0003003e,0x0000002d,0x00000031,0x0004003d,0x00000007, + 0x00000033,0x0000000a,0x00060050,0x00000007,0x00000035,0x00000034,0x00000034,0x00000034, + 0x00050081,0x00000007,0x00000036,0x00000033,0x00000035,0x00060050,0x00000007,0x00000038, + 0x00000037,0x00000037,0x00000037,0x00050088,0x00000007,0x00000039,0x00000036,0x00000038, + 0x0007000c,0x00000007,0x0000003c,0x00000001,0x0000001a,0x00000039,0x0000003b,0x0003003e, + 0x00000032,0x0000003c,0x0004003d,0x00000007,0x0000003d,0x0000002d,0x0004003d,0x00000007, + 0x0000003e,0x00000032,0x0004003d,0x00000007,0x00000041,0x0000000a,0x0007000c,0x00000007, + 0x00000042,0x00000001,0x00000030,0x00000040,0x00000041,0x0008000c,0x00000007,0x00000043, + 0x00000001,0x0000002e,0x0000003d,0x0000003e,0x00000042,0x000200fe,0x00000043,0x00010038, 0x00050036,0x00000007,0x0000000e,0x00000000,0x00000009,0x00030037,0x00000008,0x0000000d, - 0x000200f8,0x0000000f,0x0004003b,0x00000008,0x0000003c,0x00000007,0x0004003b,0x00000008, - 0x0000003f,0x00000007,0x0004003d,0x00000007,0x0000003d,0x0000000d,0x0005008e,0x00000007, - 0x0000003e,0x0000003d,0x00000025,0x0003003e,0x0000003c,0x0000003e,0x0004003d,0x00000007, - 0x00000040,0x0000000d,0x0007000c,0x00000007,0x00000043,0x00000001,0x0000001a,0x00000040, - 0x00000042,0x0005008e,0x00000007,0x00000044,0x00000043,0x0000002d,0x00060050,0x00000007, - 0x00000045,0x0000002a,0x0000002a,0x0000002a,0x00050083,0x00000007,0x00000046,0x00000044, - 0x00000045,0x0003003e,0x0000003f,0x00000046,0x0004003d,0x00000007,0x00000047,0x0000003c, - 0x0004003d,0x00000007,0x00000048,0x0000003f,0x0004003d,0x00000007,0x0000004b,0x0000000d, - 0x0007000c,0x00000007,0x0000004c,0x00000001,0x00000030,0x0000004a,0x0000004b,0x0008000c, - 0x00000007,0x0000004d,0x00000001,0x0000002e,0x00000047,0x00000048,0x0000004c,0x000200fe, - 0x0000004d,0x00010038,0x00050036,0x00000007,0x00000011,0x00000000,0x00000009,0x00030037, - 0x00000008,0x00000010,0x000200f8,0x00000012,0x0004003b,0x00000008,0x00000050,0x00000007, - 0x0004003d,0x00000007,0x00000051,0x00000010,0x00060050,0x00000007,0x00000054,0x00000052, - 0x00000052,0x00000052,0x00060050,0x00000007,0x00000055,0x00000053,0x00000053,0x00000053, - 0x0008000c,0x00000007,0x00000056,0x00000001,0x0000002b,0x00000051,0x00000054,0x00000055, - 0x0007000c,0x00000007,0x00000059,0x00000001,0x0000001a,0x00000056,0x00000058,0x0003003e, - 0x00000050,0x00000059,0x0004003d,0x00000007,0x0000005a,0x00000050,0x00060050,0x00000007, - 0x0000005c,0x0000005b,0x0000005b,0x0000005b,0x00050083,0x00000007,0x0000005d,0x0000005a, - 0x0000005c,0x00060050,0x00000007,0x0000005e,0x00000052,0x00000052,0x00000052,0x0007000c, - 0x00000007,0x0000005f,0x00000001,0x00000028,0x0000005d,0x0000005e,0x0004003d,0x00000007, - 0x00000062,0x00000050,0x0005008e,0x00000007,0x00000063,0x00000062,0x00000061,0x00060050, - 0x00000007,0x00000064,0x00000060,0x00000060,0x00000060,0x00050083,0x00000007,0x00000065, - 0x00000064,0x00000063,0x00060050,0x00000007,0x00000067,0x00000066,0x00000066,0x00000066, - 0x0007000c,0x00000007,0x00000068,0x00000001,0x00000028,0x00000065,0x00000067,0x00050088, - 0x00000007,0x00000069,0x0000005f,0x00000068,0x0007000c,0x00000007,0x0000006c,0x00000001, - 0x0000001a,0x00000069,0x0000006b,0x000200fe,0x0000006c,0x00010038,0x00050036,0x00000007, + 0x000200f8,0x0000000f,0x0004003b,0x00000008,0x00000046,0x00000007,0x0004003b,0x00000008, + 0x00000049,0x00000007,0x0004003d,0x00000007,0x00000047,0x0000000d,0x0005008e,0x00000007, + 0x00000048,0x00000047,0x0000002f,0x0003003e,0x00000046,0x00000048,0x0004003d,0x00000007, + 0x0000004a,0x0000000d,0x0007000c,0x00000007,0x0000004d,0x00000001,0x0000001a,0x0000004a, + 0x0000004c,0x0005008e,0x00000007,0x0000004e,0x0000004d,0x00000037,0x00060050,0x00000007, + 0x0000004f,0x00000034,0x00000034,0x00000034,0x00050083,0x00000007,0x00000050,0x0000004e, + 0x0000004f,0x0003003e,0x00000049,0x00000050,0x0004003d,0x00000007,0x00000051,0x00000046, + 0x0004003d,0x00000007,0x00000052,0x00000049,0x0004003d,0x00000007,0x00000055,0x0000000d, + 0x0007000c,0x00000007,0x00000056,0x00000001,0x00000030,0x00000054,0x00000055,0x0008000c, + 0x00000007,0x00000057,0x00000001,0x0000002e,0x00000051,0x00000052,0x00000056,0x000200fe, + 0x00000057,0x00010038,0x00050036,0x00000007,0x00000011,0x00000000,0x00000009,0x00030037, + 0x00000008,0x00000010,0x000200f8,0x00000012,0x0004003b,0x00000008,0x0000005a,0x00000007, + 0x0004003d,0x00000007,0x0000005b,0x00000010,0x00060050,0x00000007,0x0000005e,0x0000005c, + 0x0000005c,0x0000005c,0x00060050,0x00000007,0x0000005f,0x0000005d,0x0000005d,0x0000005d, + 0x0008000c,0x00000007,0x00000060,0x00000001,0x0000002b,0x0000005b,0x0000005e,0x0000005f, + 0x0007000c,0x00000007,0x00000063,0x00000001,0x0000001a,0x00000060,0x00000062,0x0003003e, + 0x0000005a,0x00000063,0x0004003d,0x00000007,0x00000064,0x0000005a,0x00060050,0x00000007, + 0x00000066,0x00000065,0x00000065,0x00000065,0x00050083,0x00000007,0x00000067,0x00000064, + 0x00000066,0x00060050,0x00000007,0x00000068,0x0000005c,0x0000005c,0x0000005c,0x0007000c, + 0x00000007,0x00000069,0x00000001,0x00000028,0x00000067,0x00000068,0x0004003d,0x00000007, + 0x0000006c,0x0000005a,0x0005008e,0x00000007,0x0000006d,0x0000006c,0x0000006b,0x00060050, + 0x00000007,0x0000006e,0x0000006a,0x0000006a,0x0000006a,0x00050083,0x00000007,0x0000006f, + 0x0000006e,0x0000006d,0x00060050,0x00000007,0x00000071,0x00000070,0x00000070,0x00000070, + 0x0007000c,0x00000007,0x00000072,0x00000001,0x00000028,0x0000006f,0x00000071,0x00050088, + 0x00000007,0x00000073,0x00000069,0x00000072,0x0007000c,0x00000007,0x00000076,0x00000001, + 0x0000001a,0x00000073,0x00000075,0x000200fe,0x00000076,0x00010038,0x00050036,0x00000007, 0x00000014,0x00000000,0x00000009,0x00030037,0x00000008,0x00000013,0x000200f8,0x00000015, - 0x0004003b,0x00000008,0x0000006f,0x00000007,0x0004003d,0x00000007,0x00000070,0x00000013, - 0x00060050,0x00000007,0x00000071,0x00000052,0x00000052,0x00000052,0x00060050,0x00000007, - 0x00000072,0x00000053,0x00000053,0x00000053,0x0008000c,0x00000007,0x00000073,0x00000001, - 0x0000002b,0x00000070,0x00000071,0x00000072,0x0007000c,0x00000007,0x00000076,0x00000001, - 0x0000001a,0x00000073,0x00000075,0x0003003e,0x0000006f,0x00000076,0x0004003d,0x00000007, - 0x00000077,0x0000006f,0x0005008e,0x00000007,0x00000078,0x00000077,0x00000060,0x00060050, - 0x00000007,0x00000079,0x0000005b,0x0000005b,0x0000005b,0x00050081,0x00000007,0x0000007a, - 0x00000079,0x00000078,0x0004003d,0x00000007,0x0000007b,0x0000006f,0x0005008e,0x00000007, - 0x0000007c,0x0000007b,0x00000061,0x00060050,0x00000007,0x0000007d,0x00000053,0x00000053, - 0x00000053,0x00050081,0x00000007,0x0000007e,0x0000007d,0x0000007c,0x00050088,0x00000007, - 0x0000007f,0x0000007a,0x0000007e,0x0007000c,0x00000007,0x00000082,0x00000001,0x0000001a, - 0x0000007f,0x00000081,0x000200fe,0x00000082,0x00010038,0x00050036,0x00000006,0x0000001a, + 0x0004003b,0x00000008,0x00000079,0x00000007,0x0004003d,0x00000007,0x0000007a,0x00000013, + 0x00060050,0x00000007,0x0000007b,0x0000005c,0x0000005c,0x0000005c,0x00060050,0x00000007, + 0x0000007c,0x0000005d,0x0000005d,0x0000005d,0x0008000c,0x00000007,0x0000007d,0x00000001, + 0x0000002b,0x0000007a,0x0000007b,0x0000007c,0x0007000c,0x00000007,0x00000080,0x00000001, + 0x0000001a,0x0000007d,0x0000007f,0x0003003e,0x00000079,0x00000080,0x0004003d,0x00000007, + 0x00000081,0x00000079,0x0005008e,0x00000007,0x00000082,0x00000081,0x0000006a,0x00060050, + 0x00000007,0x00000083,0x00000065,0x00000065,0x00000065,0x00050081,0x00000007,0x00000084, + 0x00000083,0x00000082,0x0004003d,0x00000007,0x00000085,0x00000079,0x0005008e,0x00000007, + 0x00000086,0x00000085,0x0000006b,0x00060050,0x00000007,0x00000087,0x0000005d,0x0000005d, + 0x0000005d,0x00050081,0x00000007,0x00000088,0x00000087,0x00000086,0x00050088,0x00000007, + 0x00000089,0x00000084,0x00000088,0x0007000c,0x00000007,0x0000008c,0x00000001,0x0000001a, + 0x00000089,0x0000008b,0x000200fe,0x0000008c,0x00010038,0x00050036,0x00000006,0x0000001a, 0x00000000,0x00000017,0x00030037,0x00000016,0x00000018,0x00030037,0x00000016,0x00000019, - 0x000200f8,0x0000001b,0x0004003b,0x00000016,0x0000008c,0x00000007,0x0004003b,0x00000016, - 0x00000091,0x00000007,0x0004003d,0x00000006,0x00000085,0x00000018,0x000500bc,0x0000001e, - 0x00000087,0x00000085,0x00000086,0x000300f7,0x00000089,0x00000000,0x000400fa,0x00000087, - 0x00000088,0x00000089,0x000200f8,0x00000088,0x0004003d,0x00000006,0x0000008a,0x00000018, - 0x000200fe,0x0000008a,0x000200f8,0x00000089,0x0004003d,0x00000006,0x0000008d,0x00000019, - 0x00050083,0x00000006,0x0000008e,0x0000008d,0x00000086,0x0007000c,0x00000006,0x00000090, - 0x00000001,0x00000028,0x0000008e,0x0000008f,0x0003003e,0x0000008c,0x00000090,0x0004003d, - 0x00000006,0x00000092,0x0000008c,0x00050088,0x00000006,0x00000094,0x00000092,0x00000093, - 0x0007000c,0x00000006,0x00000096,0x00000001,0x00000028,0x00000094,0x00000095,0x0003003e, - 0x00000091,0x00000096,0x0004003d,0x00000006,0x00000097,0x00000018,0x00050083,0x00000006, - 0x00000098,0x00000097,0x00000086,0x0004007f,0x00000006,0x00000099,0x00000098,0x0004003d, - 0x00000006,0x0000009a,0x00000091,0x00050088,0x00000006,0x0000009b,0x00000099,0x0000009a, - 0x0006000c,0x00000006,0x0000009c,0x00000001,0x0000001b,0x0000009b,0x00050083,0x00000006, - 0x0000009d,0x00000053,0x0000009c,0x00050085,0x00000006,0x0000009e,0x00000095,0x0000009d, - 0x00050081,0x00000006,0x0000009f,0x00000086,0x0000009e,0x000200fe,0x0000009f,0x00010038, + 0x000200f8,0x0000001b,0x0004003b,0x00000016,0x00000096,0x00000007,0x0004003b,0x00000016, + 0x0000009b,0x00000007,0x0004003d,0x00000006,0x0000008f,0x00000018,0x000500bc,0x00000024, + 0x00000091,0x0000008f,0x00000090,0x000300f7,0x00000093,0x00000000,0x000400fa,0x00000091, + 0x00000092,0x00000093,0x000200f8,0x00000092,0x0004003d,0x00000006,0x00000094,0x00000018, + 0x000200fe,0x00000094,0x000200f8,0x00000093,0x0004003d,0x00000006,0x00000097,0x00000019, + 0x00050083,0x00000006,0x00000098,0x00000097,0x00000090,0x0007000c,0x00000006,0x0000009a, + 0x00000001,0x00000028,0x00000098,0x00000099,0x0003003e,0x00000096,0x0000009a,0x0004003d, + 0x00000006,0x0000009c,0x00000096,0x00050088,0x00000006,0x0000009e,0x0000009c,0x0000009d, + 0x0007000c,0x00000006,0x000000a0,0x00000001,0x00000028,0x0000009e,0x0000009f,0x0003003e, + 0x0000009b,0x000000a0,0x0004003d,0x00000006,0x000000a1,0x00000018,0x00050083,0x00000006, + 0x000000a2,0x000000a1,0x00000090,0x0004007f,0x00000006,0x000000a3,0x000000a2,0x0004003d, + 0x00000006,0x000000a4,0x0000009b,0x00050088,0x00000006,0x000000a5,0x000000a3,0x000000a4, + 0x0006000c,0x00000006,0x000000a6,0x00000001,0x0000001b,0x000000a5,0x00050083,0x00000006, + 0x000000a7,0x0000005d,0x000000a6,0x00050085,0x00000006,0x000000a8,0x0000009f,0x000000a7, + 0x00050081,0x00000006,0x000000a9,0x00000090,0x000000a8,0x000200fe,0x000000a9,0x00010038, 0x00050036,0x0000001e,0x00000021,0x00000000,0x0000001f,0x00030037,0x0000001d,0x00000020, - 0x000200f8,0x00000022,0x0004003b,0x00000016,0x000000a2,0x00000007,0x0004003b,0x00000016, - 0x000000b0,0x00000007,0x0004003b,0x00000016,0x000000b4,0x00000007,0x0004003b,0x000000b8, - 0x000000b9,0x00000007,0x0004003b,0x000000cc,0x000000cd,0x00000007,0x0004003b,0x00000016, - 0x000000f5,0x00000007,0x00060041,0x000000ad,0x000000ae,0x000000a9,0x000000ab,0x000000ac, - 0x0004003d,0x00000006,0x000000af,0x000000ae,0x0003003e,0x000000a2,0x000000af,0x0004003d, - 0x00000006,0x000000b1,0x000000a2,0x0005008d,0x00000006,0x000000b3,0x000000b1,0x000000b2, - 0x0003003e,0x000000b0,0x000000b3,0x0004003d,0x00000006,0x000000b5,0x000000a2,0x00050088, - 0x00000006,0x000000b6,0x000000b5,0x000000b2,0x0006000c,0x00000006,0x000000b7,0x00000001, - 0x00000008,0x000000b6,0x0003003e,0x000000b4,0x000000b7,0x0003003e,0x000000b9,0x000000ba, - 0x000200f9,0x000000bb,0x000200f8,0x000000bb,0x000400f6,0x000000bd,0x000000be,0x00000000, - 0x000200f9,0x000000bf,0x000200f8,0x000000bf,0x0004003d,0x000000aa,0x000000c0,0x000000b9, - 0x000500b1,0x0000001e,0x000000c2,0x000000c0,0x000000c1,0x000400fa,0x000000c2,0x000000bc, - 0x000000bd,0x000200f8,0x000000bc,0x0004003d,0x000000aa,0x000000c3,0x000000b9,0x0004006f, - 0x00000006,0x000000c4,0x000000c3,0x0004003d,0x00000006,0x000000c5,0x000000b0,0x00050083, - 0x00000006,0x000000c7,0x000000c5,0x000000c6,0x000500be,0x0000001e,0x000000c8,0x000000c4, - 0x000000c7,0x000300f7,0x000000ca,0x00000000,0x000400fa,0x000000c8,0x000000c9,0x000000ca, - 0x000200f8,0x000000c9,0x000200f9,0x000000bd,0x000200f8,0x000000ca,0x0004003d,0x000000aa, - 0x000000cf,0x000000b9,0x00060041,0x000000d0,0x000000d1,0x000000a9,0x000000ce,0x000000cf, - 0x0004003d,0x000000a3,0x000000d2,0x000000d1,0x0003003e,0x000000cd,0x000000d2,0x00050041, - 0x00000016,0x000000d4,0x00000020,0x000000d3,0x0004003d,0x00000006,0x000000d5,0x000000d4, - 0x00050041,0x00000016,0x000000d6,0x000000cd,0x000000d3,0x0004003d,0x00000006,0x000000d7, - 0x000000d6,0x000500be,0x0000001e,0x000000d8,0x000000d5,0x000000d7,0x000300f7,0x000000da, - 0x00000000,0x000400fa,0x000000d8,0x000000d9,0x000000da,0x000200f8,0x000000d9,0x00050041, - 0x00000016,0x000000dc,0x00000020,0x000000db,0x0004003d,0x00000006,0x000000dd,0x000000dc, - 0x00050041,0x00000016,0x000000de,0x000000cd,0x000000db,0x0004003d,0x00000006,0x000000df, - 0x000000de,0x000500be,0x0000001e,0x000000e0,0x000000dd,0x000000df,0x000200f9,0x000000da, - 0x000200f8,0x000000da,0x000700f5,0x0000001e,0x000000e1,0x000000d8,0x000000ca,0x000000e0, - 0x000000d9,0x000300f7,0x000000e3,0x00000000,0x000400fa,0x000000e1,0x000000e2,0x000000e3, - 0x000200f8,0x000000e2,0x00050041,0x00000016,0x000000e4,0x00000020,0x000000d3,0x0004003d, - 0x00000006,0x000000e5,0x000000e4,0x00050041,0x00000016,0x000000e7,0x000000cd,0x000000e6, - 0x0004003d,0x00000006,0x000000e8,0x000000e7,0x000500b8,0x0000001e,0x000000e9,0x000000e5, - 0x000000e8,0x000200f9,0x000000e3,0x000200f8,0x000000e3,0x000700f5,0x0000001e,0x000000ea, - 0x000000e1,0x000000da,0x000000e9,0x000000e2,0x000300f7,0x000000ec,0x00000000,0x000400fa, - 0x000000ea,0x000000eb,0x000000ec,0x000200f8,0x000000eb,0x00050041,0x00000016,0x000000ed, - 0x00000020,0x000000db,0x0004003d,0x00000006,0x000000ee,0x000000ed,0x00050041,0x00000016, - 0x000000ef,0x000000cd,0x000000ac,0x0004003d,0x00000006,0x000000f0,0x000000ef,0x000500b8, - 0x0000001e,0x000000f1,0x000000ee,0x000000f0,0x000200f9,0x000000ec,0x000200f8,0x000000ec, - 0x000700f5,0x0000001e,0x000000f2,0x000000ea,0x000000e3,0x000000f1,0x000000eb,0x000300f7, - 0x000000f4,0x00000000,0x000400fa,0x000000f2,0x000000f3,0x000000f4,0x000200f8,0x000000f3, - 0x0004003d,0x00000006,0x000000f6,0x000000b4,0x0004003d,0x000000aa,0x000000f7,0x000000b9, - 0x0004006f,0x00000006,0x000000f8,0x000000f7,0x0006000c,0x00000006,0x000000f9,0x00000001, - 0x0000001d,0x000000f8,0x00050088,0x00000006,0x000000fa,0x000000f6,0x000000f9,0x0006000c, - 0x00000006,0x000000fb,0x00000001,0x00000008,0x000000fa,0x0005008d,0x00000006,0x000000fd, - 0x000000fb,0x000000fc,0x0003003e,0x000000f5,0x000000fd,0x0004003d,0x00000006,0x000000fe, - 0x000000f5,0x000500ba,0x0000001e,0x000000ff,0x000000fe,0x000000c6,0x000200fe,0x000000ff, - 0x000200f8,0x000000f4,0x000200f9,0x000000be,0x000200f8,0x000000be,0x0004003d,0x000000aa, - 0x00000101,0x000000b9,0x00050080,0x000000aa,0x00000102,0x00000101,0x000000ab,0x0003003e, - 0x000000b9,0x00000102,0x000200f9,0x000000bb,0x000200f8,0x000000bd,0x000200fe,0x00000103, - 0x00010038 + 0x000200f8,0x00000022,0x0004003b,0x00000016,0x000000ac,0x00000007,0x0004003b,0x00000023, + 0x000000bd,0x00000007,0x0004003b,0x000000d0,0x000000d1,0x00000007,0x0004003b,0x0000001d, + 0x000000d7,0x00000007,0x0004003b,0x0000001d,0x000000e5,0x00000007,0x00060041,0x000000b8, + 0x000000b9,0x000000b6,0x000000b7,0x000000b2,0x0004003d,0x00000006,0x000000ba,0x000000b9, + 0x0005008d,0x00000006,0x000000bc,0x000000ba,0x000000bb,0x0003003e,0x000000ac,0x000000bc, + 0x0003003e,0x000000bd,0x000000be,0x000200f9,0x000000bf,0x000200f8,0x000000bf,0x000400f6, + 0x000000c1,0x000000c2,0x00000000,0x000200f9,0x000000c3,0x000200f8,0x000000c3,0x0004003d, + 0x0000001e,0x000000c4,0x000000bd,0x000500b1,0x00000024,0x000000c6,0x000000c4,0x000000c5, + 0x000400fa,0x000000c6,0x000000c0,0x000000c1,0x000200f8,0x000000c0,0x0004003d,0x0000001e, + 0x000000c7,0x000000bd,0x0004006f,0x00000006,0x000000c8,0x000000c7,0x0004003d,0x00000006, + 0x000000c9,0x000000ac,0x00050083,0x00000006,0x000000cb,0x000000c9,0x000000ca,0x000500be, + 0x00000024,0x000000cc,0x000000c8,0x000000cb,0x000300f7,0x000000ce,0x00000000,0x000400fa, + 0x000000cc,0x000000cd,0x000000ce,0x000200f8,0x000000cd,0x000200f9,0x000000c1,0x000200f8, + 0x000000ce,0x0004003d,0x0000001e,0x000000d3,0x000000bd,0x00060041,0x000000d4,0x000000d5, + 0x000000b6,0x000000d2,0x000000d3,0x0004003d,0x000000af,0x000000d6,0x000000d5,0x0003003e, + 0x000000d1,0x000000d6,0x00050041,0x000000d9,0x000000da,0x000000d1,0x000000d8,0x0004003d, + 0x000000ae,0x000000db,0x000000da,0x000500c7,0x000000ae,0x000000dd,0x000000db,0x000000dc, + 0x00040070,0x00000006,0x000000de,0x000000dd,0x00050041,0x000000d9,0x000000df,0x000000d1, + 0x000000d8,0x0004003d,0x000000ae,0x000000e0,0x000000df,0x000500c2,0x000000ae,0x000000e2, + 0x000000e0,0x000000e1,0x00040070,0x00000006,0x000000e3,0x000000e2,0x00050050,0x0000001c, + 0x000000e4,0x000000de,0x000000e3,0x0003003e,0x000000d7,0x000000e4,0x00050041,0x000000d9, + 0x000000e7,0x000000d1,0x000000e6,0x0004003d,0x000000ae,0x000000e8,0x000000e7,0x000500c7, + 0x000000ae,0x000000e9,0x000000e8,0x000000dc,0x00040070,0x00000006,0x000000ea,0x000000e9, + 0x00050041,0x000000d9,0x000000eb,0x000000d1,0x000000e6,0x0004003d,0x000000ae,0x000000ec, + 0x000000eb,0x000500c2,0x000000ae,0x000000ed,0x000000ec,0x000000e1,0x00040070,0x00000006, + 0x000000ee,0x000000ed,0x00050050,0x0000001c,0x000000ef,0x000000ea,0x000000ee,0x0003003e, + 0x000000e5,0x000000ef,0x00050041,0x00000016,0x000000f0,0x00000020,0x000000d8,0x0004003d, + 0x00000006,0x000000f1,0x000000f0,0x00050041,0x00000016,0x000000f2,0x000000d7,0x000000d8, + 0x0004003d,0x00000006,0x000000f3,0x000000f2,0x000500be,0x00000024,0x000000f4,0x000000f1, + 0x000000f3,0x000300f7,0x000000f6,0x00000000,0x000400fa,0x000000f4,0x000000f5,0x000000f6, + 0x000200f8,0x000000f5,0x00050041,0x00000016,0x000000f7,0x00000020,0x000000e6,0x0004003d, + 0x00000006,0x000000f8,0x000000f7,0x00050041,0x00000016,0x000000f9,0x000000d7,0x000000e6, + 0x0004003d,0x00000006,0x000000fa,0x000000f9,0x000500be,0x00000024,0x000000fb,0x000000f8, + 0x000000fa,0x000200f9,0x000000f6,0x000200f8,0x000000f6,0x000700f5,0x00000024,0x000000fc, + 0x000000f4,0x000000ce,0x000000fb,0x000000f5,0x000300f7,0x000000fe,0x00000000,0x000400fa, + 0x000000fc,0x000000fd,0x000000fe,0x000200f8,0x000000fd,0x00050041,0x00000016,0x000000ff, + 0x00000020,0x000000d8,0x0004003d,0x00000006,0x00000100,0x000000ff,0x00050041,0x00000016, + 0x00000101,0x000000e5,0x000000d8,0x0004003d,0x00000006,0x00000102,0x00000101,0x000500b8, + 0x00000024,0x00000103,0x00000100,0x00000102,0x000200f9,0x000000fe,0x000200f8,0x000000fe, + 0x000700f5,0x00000024,0x00000104,0x000000fc,0x000000f6,0x00000103,0x000000fd,0x000300f7, + 0x00000106,0x00000000,0x000400fa,0x00000104,0x00000105,0x00000106,0x000200f8,0x00000105, + 0x00050041,0x00000016,0x00000107,0x00000020,0x000000e6,0x0004003d,0x00000006,0x00000108, + 0x00000107,0x00050041,0x00000016,0x00000109,0x000000e5,0x000000e6,0x0004003d,0x00000006, + 0x0000010a,0x00000109,0x000500b8,0x00000024,0x0000010b,0x00000108,0x0000010a,0x000200f9, + 0x00000106,0x000200f8,0x00000106,0x000700f5,0x00000024,0x0000010c,0x00000104,0x000000fe, + 0x0000010b,0x00000105,0x000300f7,0x0000010e,0x00000000,0x000400fa,0x0000010c,0x0000010d, + 0x0000010e,0x000200f8,0x0000010d,0x0004003d,0x0000001e,0x0000010f,0x000000bd,0x000200fe, + 0x0000010f,0x000200f8,0x0000010e,0x000200f9,0x000000c2,0x000200f8,0x000000c2,0x0004003d, + 0x0000001e,0x00000111,0x000000bd,0x00050080,0x0000001e,0x00000112,0x00000111,0x000000b7, + 0x0003003e,0x000000bd,0x00000112,0x000200f9,0x000000bf,0x000200f8,0x000000c1,0x000200fe, + 0x00000113,0x00010038,0x00050036,0x00000024,0x00000028,0x00000000,0x00000025,0x00030037, + 0x00000016,0x00000026,0x00030037,0x00000023,0x00000027,0x000200f8,0x00000029,0x0004003d, + 0x0000001e,0x00000116,0x00000027,0x000500af,0x00000024,0x00000117,0x00000116,0x000000be, + 0x000300f7,0x00000119,0x00000000,0x000400fa,0x00000117,0x00000118,0x00000119,0x000200f8, + 0x00000118,0x0004003d,0x00000006,0x0000011a,0x00000026,0x0004003d,0x0000001e,0x0000011b, + 0x00000027,0x0004006f,0x00000006,0x0000011c,0x0000011b,0x0006000c,0x00000006,0x0000011d, + 0x00000001,0x0000001d,0x0000011c,0x00050088,0x00000006,0x0000011e,0x0000011a,0x0000011d, + 0x0006000c,0x00000006,0x0000011f,0x00000001,0x00000008,0x0000011e,0x0005008d,0x00000006, + 0x00000121,0x0000011f,0x00000120,0x000500ba,0x00000024,0x00000122,0x00000121,0x000000ca, + 0x000200f9,0x00000119,0x000200f8,0x00000119,0x000700f5,0x00000024,0x00000123,0x00000117, + 0x00000029,0x00000122,0x00000118,0x000200fe,0x00000123,0x00010038,0x00050036,0x00000007, + 0x0000002b,0x00000000,0x00000009,0x00030037,0x00000008,0x0000002a,0x000200f8,0x0000002c, + 0x0004003b,0x00000008,0x00000126,0x00000007,0x0004003b,0x00000008,0x0000012b,0x00000007, + 0x0004003b,0x00000008,0x00000130,0x00000007,0x00070041,0x000000b8,0x00000128,0x000000b6, + 0x00000127,0x000000b7,0x000000b2,0x0004003d,0x00000006,0x00000129,0x00000128,0x000500ba, + 0x00000024,0x0000012a,0x00000129,0x000000ca,0x000300f7,0x0000012d,0x00000000,0x000400fa, + 0x0000012a,0x0000012c,0x0000012f,0x000200f8,0x0000012c,0x0004003d,0x00000007,0x0000012e, + 0x0000002a,0x0003003e,0x0000012b,0x0000012e,0x000200f9,0x0000012d,0x000200f8,0x0000012f, + 0x0004003d,0x00000007,0x00000131,0x0000002a,0x0003003e,0x00000130,0x00000131,0x00050039, + 0x00000007,0x00000132,0x00000011,0x00000130,0x0003003e,0x0000012b,0x00000132,0x000200f9, + 0x0000012d,0x000200f8,0x0000012d,0x0004003d,0x00000007,0x00000133,0x0000012b,0x0003003e, + 0x00000126,0x00000133,0x00060041,0x00000134,0x00000135,0x000000b6,0x00000127,0x000000be, + 0x0004003d,0x000000ad,0x00000136,0x00000135,0x0008004f,0x00000007,0x00000137,0x00000136, + 0x00000136,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000007,0x00000138,0x00000126, + 0x00050094,0x00000006,0x00000139,0x00000137,0x00000138,0x00060041,0x00000134,0x0000013a, + 0x000000b6,0x00000127,0x000000b7,0x0004003d,0x000000ad,0x0000013b,0x0000013a,0x0008004f, + 0x00000007,0x0000013c,0x0000013b,0x0000013b,0x00000000,0x00000001,0x00000002,0x0004003d, + 0x00000007,0x0000013d,0x00000126,0x00050094,0x00000006,0x0000013e,0x0000013c,0x0000013d, + 0x00060041,0x00000134,0x0000013f,0x000000b6,0x00000127,0x000000d2,0x0004003d,0x000000ad, + 0x00000140,0x0000013f,0x0008004f,0x00000007,0x00000141,0x00000140,0x00000140,0x00000000, + 0x00000001,0x00000002,0x0004003d,0x00000007,0x00000142,0x00000126,0x00050094,0x00000006, + 0x00000143,0x00000141,0x00000142,0x00060050,0x00000007,0x00000144,0x00000139,0x0000013e, + 0x00000143,0x00070041,0x000000b8,0x00000145,0x000000b6,0x00000127,0x000000d2,0x000000b2, + 0x0004003d,0x00000006,0x00000146,0x00000145,0x0005008e,0x00000007,0x00000147,0x00000144, + 0x00000146,0x000200fe,0x00000147,0x00010038 }; diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.c b/app/src/main/cpp/waylandcomp/src/sc_layer.c index c760d91c2..05b201b2e 100644 --- a/app/src/main/cpp/waylandcomp/src/sc_layer.c +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.c @@ -3,6 +3,7 @@ #include "ahb_swapchain.h" #include "droiddeck_color.h" #include "vk_present.h" +#include "framegen_bridge.h" #include #include #include @@ -64,6 +65,8 @@ static struct { void (*setHdrMetadata_cta861_3)(ASurfaceTransaction *, ASurfaceControl *, const struct droiddeck_hdr_cta861_3 *); const void *(*getNativeHandle)(const AHardwareBuffer *); void (*setDesiredHdrHeadroom)(ASurfaceTransaction *, ASurfaceControl *, float); + void (*setEnableBackPressure)(ASurfaceTransaction *, ASurfaceControl *, bool); + void (*setDesiredPresentTime)(ASurfaceTransaction *, int64_t); int state; } api; @@ -105,6 +108,8 @@ static int load_api(void) { SYM(setHdrMetadata_smpte2086, "ASurfaceTransaction_setHdrMetadata_smpte2086"); SYM(setHdrMetadata_cta861_3, "ASurfaceTransaction_setHdrMetadata_cta861_3"); SYM(setDesiredHdrHeadroom, "ASurfaceTransaction_setDesiredHdrHeadroom"); + SYM(setEnableBackPressure, "ASurfaceTransaction_setEnableBackPressure"); + SYM(setDesiredPresentTime, "ASurfaceTransaction_setDesiredPresentTime"); #undef SYM if (!api.createFromWindow || !api.release || !api.txCreate || !api.txDelete || !api.txApply || !api.setBuffer || !api.setZOrder || !api.setVisibility || !api.setGeometry || @@ -134,7 +139,7 @@ void sc_layer_set_frame_rate(float fps) { } -#define POOL_MAX 5 +#define POOL_MAX 8 struct slot { AHardwareBuffer *ahb; @@ -183,6 +188,12 @@ static int g_layers_ready; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static int g_pending_cb; static unsigned g_stat_layer_frames; +static pthread_mutex_t g_timeline_lock = PTHREAD_MUTEX_INITIALIZER; +static int64_t g_timeline_present_ns, g_timeline_deadline_ns, g_timeline_period_ns; +static int g_timeline_late; +static int64_t g_cadence_seen_ns, g_cadence_gap_ns, g_cadence_target_ns; +static int g_group_frames = 1, g_group_index; +static unsigned g_stat_aimed_next, g_stat_aimed_later, g_stat_aimed_even; static int g_two_logged; static AHardwareBuffer *g_blank; static ASurfaceControl *g_base_sc; @@ -219,6 +230,58 @@ static int64_t now_ns(void) { return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; } +void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns) { + pthread_mutex_lock(&g_timeline_lock); + g_timeline_present_ns = present_ns; + g_timeline_deadline_ns = deadline_ns; + g_timeline_period_ns = period_ns; + pthread_mutex_unlock(&g_timeline_lock); +} + +static int64_t cadence_target(int64_t now, int64_t earliest, int64_t period) { + const int64_t gap = now - g_cadence_seen_ns; + g_cadence_seen_ns = now; + if (gap <= 0 || gap > 8 * period) { + g_cadence_gap_ns = 0; + g_cadence_target_ns = earliest; + return earliest; + } + g_cadence_gap_ns = g_cadence_gap_ns ? (g_cadence_gap_ns * 15 + gap) / 16 : gap; + const int64_t steps = (g_cadence_gap_ns + period / 2) / period; + const int64_t even = g_cadence_target_ns + steps * period; + int64_t target = earliest; + if (steps >= 1 && llabs(g_cadence_gap_ns - steps * period) < period / 8 && + even > earliest + period / 2 && even < earliest + steps * period + period / 2) { + target = even; + g_stat_aimed_even++; + } + g_cadence_target_ns = target; + return target; +} + +static void apply_present_time(ASurfaceTransaction *tx, int game) { + if (!api.setDesiredPresentTime) return; + pthread_mutex_lock(&g_timeline_lock); + const int64_t present = g_timeline_present_ns, deadline = g_timeline_deadline_ns, period = g_timeline_period_ns; + pthread_mutex_unlock(&g_timeline_lock); + const int64_t now = now_ns(); + if (period <= 0 || now - deadline > 4 * period) return; + int64_t ahead = now > deadline ? (now - deadline + period - 1) / period : -((deadline - now) / period); + const int64_t slack = deadline + ahead * period - now; + g_timeline_late = slack < (g_timeline_late ? period * 5 / 8 : period / 8); + if (g_timeline_late) { ahead++; g_stat_aimed_later++; } else g_stat_aimed_next++; + int64_t target = present + ahead * period; + if (game && g_group_index > 0) { + int64_t steps = (g_group_index * g_cadence_gap_ns / g_group_frames + period / 2) / period; + if (steps < g_group_index) steps = g_group_index; + if (target < g_cadence_target_ns + steps * period) target = g_cadence_target_ns + steps * period; + } else if (game) { + target = cadence_target(now, target, period); + } + if (game && g_group_frames > 1 && ++g_group_index >= g_group_frames) { g_group_index = 0; g_group_frames = 1; } + api.setDesiredPresentTime(tx, target - period / 2); +} + static void on_complete(void *context, ASurfaceTransactionStats *stats) { struct complete_ctx *ctx = context; pthread_mutex_lock(&g_lock); @@ -401,10 +464,22 @@ static void describe_handle(const struct droiddeck_native_handle *h, char *out, o += (size_t)snprintf(out + o, n - o, " %#x", (unsigned)h->data[h->numFds + i]); } +static int handle_fd(const struct droiddeck_native_handle *h, off_t need, int *which) { + for (int i = 0; h && i < h->numFds; i++) { + off_t sz = lseek(h->data[i], 0, SEEK_END); + if (sz >= 0) lseek(h->data[i], 0, SEEK_SET); + if (sz >= need) { if (which) *which = i; return h->data[i]; } + } + return -1; +} + +int sc_layer_ahb_fd(AHardwareBuffer *ahb, uint64_t need) { + return load_api() == 0 ? handle_fd(api.getNativeHandle(ahb), (off_t)need, NULL) : -1; +} + static int g_alloc_failed; enum { TIER_UBWC, TIER_PLAIN, TIER_LINEAR }; -#define DROIDDECK_AHB_USAGE_VENDOR_UBWC (1ULL << 28) static const char *tier_name(int tier) { return tier == TIER_UBWC ? "asked for UBWC" : tier == TIER_PLAIN ? "no UBWC request" : "linear by request (CPU bit)"; @@ -419,7 +494,7 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm .format = fmt, .usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | - (tier == TIER_UBWC ? DROIDDECK_AHB_USAGE_VENDOR_UBWC : 0) | + (tier == TIER_UBWC ? SC_LAYER_AHB_USAGE_VENDOR_UBWC : 0) | (tier == TIER_LINEAR ? AHARDWAREBUFFER_USAGE_CPU_READ_RARELY : 0)}; AHardwareBuffer *ahb = NULL; if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) { @@ -459,13 +534,8 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm path = "AHardwareBuffer"; img = vkp_image_import_ahb(ahb, info, sizeof(info)); if (!img && tier == TIER_LINEAR) { - const off_t need = (off_t)got.stride * 4 * h; - int fd = -1, which = -1; - for (int i = 0; nh && i < nh->numFds; i++) { - off_t sz = lseek(nh->data[i], 0, SEEK_END); - if (sz >= 0) lseek(nh->data[i], 0, SEEK_SET); - if (sz >= need) { fd = nh->data[i]; which = i; break; } - } + int which = -1; + int fd = handle_fd(nh, (off_t)got.stride * 4 * h, &which); if (fd < 0 && nh && nh->numFds > 0) { fd = nh->data[0]; which = 0; } mod = MOD_LINEAR; path = "linear dma-buf"; @@ -506,16 +576,27 @@ static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fm return -1; } -static int fence_signalled(int fd) { +static int fence_wait(int fd, int timeout_ms) { struct pollfd p = {.fd = fd, .events = POLLIN}; int r; - do { r = poll(&p, 1, 0); } while (r < 0 && errno == EINTR); - return r > 0; + do { r = poll(&p, 1, timeout_ms); } while (r < 0 && errno == EINTR); + return r; +} + +static int fence_signalled(int fd) { + return fence_wait(fd, 0) > 0; +} + +static void slot_keep_fence(struct slot *s, int fd) { + pthread_mutex_lock(&g_lock); + if (s->release_fd < 0) s->release_fd = fd; else close(fd); + pthread_mutex_unlock(&g_lock); } static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait_fd) { int idx = -1, pending = -1, fd = -1; *wait_fd = -1; + g_alloc_failed = 0; pthread_mutex_lock(&g_lock); for (int i = 0; i < l->pool_n; i++) { if (i == l->cur_slot || l->slots[i].busy) continue; @@ -535,15 +616,7 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait memset(s, 0, sizeof(*s)); s->release_fd = -1; } if (fd >= 0 && !vkp_can_wait_sync_fd()) { - struct pollfd p = {.fd = fd, .events = POLLIN}; - int r; - do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); - if (r == 0) { - pthread_mutex_lock(&g_lock); - if (s->release_fd < 0) s->release_fd = fd; else close(fd); - pthread_mutex_unlock(&g_lock); - return -1; - } + if (fence_wait(fd, 100) == 0) { slot_keep_fence(s, fd); return -1; } close(fd); fd = -1; } @@ -558,6 +631,8 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait int sc_layer_available(void) { return load_api() == 0; } +int sc_layer_queues(void) { return load_api() == 0 && api.setEnableBackPressure != NULL; } + void sc_layer_probe_dmabuf_fd(int fd) { static int done; if (done || fd < 0) return; @@ -595,9 +670,10 @@ static int ensure_sc(struct layer *l) { return 0; } -static int layer_geometry(int w, int h, int scene_w, int scene_h, int r[8]) { +static int layer_geometry(int w, int h, int scene_w, int scene_h, const struct vkp_draw *draw, int r[8]) { if (vkp_update_map(scene_w, scene_h) != 0) return -1; - return vkp_map_rect(w, h, scene_w, scene_h, r) ? 1 : 0; + if (draw) return vkp_map_draw(draw, r) ? 1 : 0; + return vkp_map_rect(w, h, (const int[4]){0, 0, scene_w, scene_h}, r) ? 1 : 0; } static ARect g_game_src, g_game_dst; @@ -757,6 +833,7 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d ASurfaceControl *old = swap_sc_begin(l); if (old) api.setZOrder(tx, l->sc, l->z); api.setBuffer(tx, l->sc, s->ahb, -1); + if (api.setEnableBackPressure) api.setEnableBackPressure(tx, l->sc, true); api.setBufferTransparency(tx, l->sc, translucent ? ASC_TRANSPARENCY_TRANSLUCENT : ASC_TRANSPARENCY_OPAQUE); apply_geometry(tx, l, r); @@ -769,6 +846,7 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d pthread_mutex_lock(&g_lock); s->busy = 1; pthread_mutex_unlock(&g_lock); + apply_present_time(tx, l == &g_layers[SC_LAYER_GAME]); api.txApply(tx); api.txDelete(tx); l->cur_slot = idx; @@ -799,11 +877,12 @@ unsigned sc_layer_drops_take(void) { } int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token, int scene_w, int scene_h, + const struct vkp_draw *draw, const struct droiddeck_color *color, uint32_t ahb_format) { struct layer *l = layer_of(SC_LAYER_GAME); int r[8]; if (!ahb || !token || ensure_sc(l) != 0) goto unavailable; - int g = layer_geometry(w, h, scene_w, scene_h, r); + int g = layer_geometry(w, h, scene_w, scene_h, draw, r); if (g < 0) goto unavailable; if (g == 0) { if (acquire_fd >= 0) close(acquire_fd); sc_layer_hide(); return 1; } if (token == l->cur_token && l->shown && !l->recreate_pending) { @@ -821,6 +900,7 @@ int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, voi ASurfaceControl *old = swap_sc_begin(l); if (old) api.setZOrder(tx, l->sc, l->z); api.setBuffer(tx, l->sc, ahb, acquire_fd); + if (api.setEnableBackPressure) api.setEnableBackPressure(tx, l->sc, true); api.setBufferTransparency(tx, l->sc, ASC_TRANSPARENCY_OPAQUE); apply_geometry(tx, l, r); apply_frame_rate(tx, l); @@ -834,6 +914,7 @@ int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, voi l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; return -1; } + apply_present_time(tx, 1); api.txApply(tx); api.txDelete(tx); l->cur_slot = -1; @@ -848,12 +929,13 @@ unavailable: return -1; } -int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct droiddeck_color *color) { +int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw, + const struct droiddeck_color *color) { struct layer *l = layer_of(SC_LAYER_GAME); if (!src || ensure_sc(l) != 0) return -1; int sw = vkp_image_width(src), sh = vkp_image_height(src); int r[8]; - int g = layer_geometry(sw, sh, scene_w, scene_h, r); + int g = layer_geometry(sw, sh, scene_w, scene_h, draw, r); if (g < 0) return -1; if (g == 0) { sc_layer_hide(); return 0; } @@ -879,10 +961,10 @@ int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int if (!draws || n <= 0 || ensure_sc(l) != 0) return -1; if (vkp_update_map(scene_w, scene_h) != 0) return -1; if (vkp_pass_begin(scene_w, scene_h, draws, n, &rw, &rh) != 0) return -1; - if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } + if (!vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } int wait_fd; int idx = take_free_slot(l, rw, rh, AHB_RGBA8, &wait_fd); - if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; } + if (idx < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; } if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1; if (present_slot(l, idx, r, NULL, 0) != 0) return -1; if (!l->first_logged) { @@ -895,8 +977,97 @@ int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int return 0; } +static void slots_idle(struct layer *l, const int *idx, int from, int to) { + pthread_mutex_lock(&g_lock); + for (int i = from; i < to; i++) l->slots[idx[i]].busy = 0; + pthread_mutex_unlock(&g_lock); +} + static uint32_t g_hdr_pool_fmt = AHB_RGB10A2; +static int take_hdr_slot(struct layer *l, int w, int h, int *wait_fd) { + int idx = take_free_slot(l, w, h, g_hdr_pool_fmt, wait_fd); + if (idx < 0 && g_alloc_failed && g_hdr_pool_fmt == AHB_RGB10A2) { + g_hdr_pool_fmt = AHB_RGBA8; + droiddeck_log("color", "%s: this device will not make a 10-bit layer buffer (RGBA1010102): the HDR picture goes " + "on 8-bit buffers instead (still tagged BT2020_PQ; less precision)", l->name); + idx = take_free_slot(l, w, h, g_hdr_pool_fmt, wait_fd); + } + return idx; +} + +int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const struct vkp_hdr_frame *hf, + int scene_w, int scene_h, int composed, const struct droiddeck_color *color) { + struct layer *l = layer_of(SC_LAYER_GAME); + int rw = 0, rh = 0, r[8], idx[VKP_FG_MAX_GENERATIONS + 1], m = 0, first_fd = -1, have_fd = 0; + struct vkp_image *dst[VKP_FG_MAX_GENERATIONS], *real = NULL; + g_group_index = 0; + g_group_frames = 1; + if (!draws || n_draws <= 0 || ensure_sc(l) != 0) return -1; + if (vkp_update_map(scene_w, scene_h) != 0) return -1; + const int deep = hf && !hf->tonemap; + if (hf) composed = 1; + if (hf && hf->tonemap) color = NULL; + int n = vkp_pass_begin_generate(scene_w, scene_h, draws, n_draws, hf, &rw, &rh); + if (n < 0) return -1; + const int mapped = vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r); + if (!mapped) n = 0; + if (composed) { + if (!mapped) { vkp_pass_abort(); sc_layer_hide(); return 0; } + idx[VKP_FG_MAX_GENERATIONS] = deep ? take_hdr_slot(l, rw, rh, &first_fd) + : take_free_slot(l, rw, rh, AHB_RGBA8, &first_fd); + if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; } + pthread_mutex_lock(&g_lock); + l->slots[idx[VKP_FG_MAX_GENERATIONS]].busy = 1; + pthread_mutex_unlock(&g_lock); + real = l->slots[idx[VKP_FG_MAX_GENERATIONS]].img; + have_fd = 1; + } + for (; m < n; m++) { + int fd; + idx[m] = take_free_slot(l, rw, rh, deep ? g_hdr_pool_fmt : AHB_RGBA8, &fd); + if (idx[m] < 0) { log_drop(l); break; } + if (have_fd && fd >= 0) { + if (fence_wait(fd, 100) == 0) { slot_keep_fence(&l->slots[idx[m]], fd); log_drop(l); break; } + close(fd); + } + pthread_mutex_lock(&g_lock); + l->slots[idx[m]].busy = 1; + pthread_mutex_unlock(&g_lock); + dst[m] = l->slots[idx[m]].img; + if (!have_fd) { first_fd = fd; have_fd = 1; } + } + if (vkp_pass_copy_generated(dst, m, real, first_fd) != 0) { + slots_idle(l, idx, 0, m); + if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1); + return -1; + } + g_group_frames = m + 1; + for (int k = 0; k < m; k++) { + if (present_slot(l, idx[k], r, color, 0) == 0) continue; + slots_idle(l, idx, k, m); + if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1); + g_group_index = 0; + g_group_frames = 1; + return -1; + } + vkp_framegen_presented(m); + if (real) { + if (present_slot(l, idx[VKP_FG_MAX_GENERATIONS], r, color, 0) != 0) { + slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1); + g_group_index = 0; + g_group_frames = 1; + return -1; + } + l->first_logged = 1; + vkp_signal_first_frame(); + } + if (hf && hf->color && hf->color->dataspace) + droiddeck_color_frame_shown(hf->color, deep ? DROIDDECK_HDR_COMPOSED : DROIDDECK_HDR_TONEMAPPED, + deep ? g_hdr_pool_fmt : AHB_RGBA8); + return m; +} + int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int scene_w, int scene_h, const struct droiddeck_color *color) { struct layer *l = layer_of(SC_LAYER_GAME); @@ -904,19 +1075,11 @@ int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct if (!draws || n <= 0 || !hf || ensure_sc(l) != 0) return -1; if (vkp_update_map(scene_w, scene_h) != 0) return -1; if (vkp_pass_begin_hdr(scene_w, scene_h, draws, n, hf, &rw, &rh) != 0) return -1; - if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } + if (!vkp_map_rect(rw, rh, (const int[4]){0, 0, scene_w, scene_h}, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } const int tm = hf->tonemap; - const uint32_t fmt = tm ? AHB_RGBA8 : g_hdr_pool_fmt; - g_alloc_failed = 0; int wait_fd; - int idx = take_free_slot(l, rw, rh, fmt, &wait_fd); - if (idx < 0 && g_alloc_failed && fmt == AHB_RGB10A2) { - g_hdr_pool_fmt = AHB_RGBA8; - droiddeck_log("color", "%s: this device will not make a 10-bit layer buffer (RGBA1010102): the HDR picture goes " - "on 8-bit buffers instead (still tagged BT2020_PQ; less precision)", l->name); - idx = take_free_slot(l, rw, rh, g_hdr_pool_fmt, &wait_fd); - } - if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; } + int idx = tm ? take_free_slot(l, rw, rh, AHB_RGBA8, &wait_fd) : take_hdr_slot(l, rw, rh, &wait_fd); + if (idx < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; } if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1; if (present_slot(l, idx, r, tm ? NULL : color, 0) != 0) return -1; if (color && color->dataspace) @@ -967,8 +1130,9 @@ int sc_layer_overlay_affordable(void) { if (want) droiddeck_log("layer", "overlay layer declined: this display rotates every layer %d° and the game " "layer is scaled %dx%d -> %dx%d, and on that combination a second layer drops the " - "whole frame to GPU composition for the rest of the session (measured). The window " - "above the game goes on the copy path instead - same picture, one blit.", + "whole frame to GPU composition for the rest of the session (measured). A nested " + "compositor is asked to compose its own overlays into the game picture; any other " + "window above the game goes on the copy path instead.", deg, sr[0], sr[1], ds[0], ds[1]); else if (!first) droiddeck_log("layer", "overlay layer allowed again: the game layer is no longer both rotated and " @@ -1033,6 +1197,13 @@ void sc_layer_window_gone(void) { drain_and_free_pools(); } +void sc_layer_aim_take(unsigned *next, unsigned *later, unsigned *even) { + *next = g_stat_aimed_next; + *later = g_stat_aimed_later; + *even = g_stat_aimed_even; + g_stat_aimed_next = g_stat_aimed_later = g_stat_aimed_even = 0; +} + unsigned sc_layer_frames_take(void) { unsigned n = g_stat_layer_frames; g_stat_layer_frames = 0; diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.h b/app/src/main/cpp/waylandcomp/src/sc_layer.h index 58fe5f6d6..24a24fc25 100644 --- a/app/src/main/cpp/waylandcomp/src/sc_layer.h +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.h @@ -7,10 +7,13 @@ struct vkp_image; struct vkp_draw; struct droiddeck_color; +struct vkp_hdr_frame; enum sc_layer_id { SC_LAYER_GAME = 0, SC_LAYER_OVERLAY = 1, SC_LAYER_COUNT = 2 }; int sc_layer_available(void); +#define SC_LAYER_AHB_USAGE_VENDOR_UBWC (1ULL << 28) +int sc_layer_ahb_fd(AHardwareBuffer *ahb, uint64_t need); void sc_layer_probe_dmabuf_fd(int fd); @@ -18,21 +21,25 @@ int sc_layer_can_tag_hdr(void); void sc_layer_hdr_symbols(char *out, size_t size); -int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct droiddeck_color *color); +int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw, + const struct droiddeck_color *color); int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int scene_h); +int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const struct vkp_hdr_frame *hf, + int scene_w, int scene_h, int composed, const struct droiddeck_color *color); -struct vkp_hdr_frame; int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int scene_w, int scene_h, const struct droiddeck_color *color); int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token, - int scene_w, int scene_h, const struct droiddeck_color *color, uint32_t ahb_format); + int scene_w, int scene_h, const struct vkp_draw *draw, const struct droiddeck_color *color, uint32_t ahb_format); void sc_layer_set_frame_rate(float fps); int sc_layer_overlay_affordable(void); +int sc_layer_queues(void); + int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent); void sc_layer_hide(void); @@ -42,6 +49,8 @@ void sc_layer_hide_overlay(void); void sc_layer_window_gone(void); +void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns); +void sc_layer_aim_take(unsigned *next, unsigned *later, unsigned *even); unsigned sc_layer_frames_take(void); unsigned sc_layer_drops_take(void); diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index cbf0c6f69..ebd940428 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -1880,6 +1880,11 @@ static int compose_hdr(VkCommandBuffer cmd, const struct vkp_draw *draws, int n, struct hdrc_params p = {.mode = mode, .sdr_white_nits = droiddeck_color_sdr_white(), .peak_nits = hf->peak_nits > 0.0f ? hf->peak_nits : 1000.0f}; + if (hf->convert) { + p.conv_linear = hf->convert->convert == 2; + p.conv_gain = hf->convert->gain; + memcpy(p.conv, hf->convert->to2020, sizeof(p.conv)); + } int lowest_hdr = -1; for (int i = 0; i < n; i++) { VkImageBlit blit; @@ -1896,6 +1901,7 @@ static int compose_hdr(VkCommandBuffer cmd, const struct vkp_draw *draws, int n, p.rects[p.count][0] = (float)blit.dstOffsets[0].x; p.rects[p.count][1] = (float)blit.dstOffsets[0].y; p.rects[p.count][2] = (float)blit.dstOffsets[1].x; p.rects[p.count][3] = (float)blit.dstOffsets[1].y; if (hf->is_hdr[i]) p.hdr_mask |= 1u << p.count; + if (hf->is_hdr[i] == 2 && hf->convert) p.conv_mask |= 1u << p.count; p.count++; } if (i >= lowest_hdr && !truncated_said) { @@ -2500,9 +2506,9 @@ int vkp_update_map(int scene_w, int scene_h) { return g_map.valid ? 0 : -1; } -int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]) { +int vkp_map_rect(int img_w, int img_h, const int dst[4], int out[8]) { struct vkp_image tmp = {.w = img_w, .h = img_h}; - struct vkp_draw d = {&tmp, 0, 0, (float)img_w, (float)img_h, 0, 0, scene_w, scene_h}; + struct vkp_draw d = {&tmp, 0, 0, (float)img_w, (float)img_h, dst[0], dst[1], dst[2], dst[3]}; return vkp_map_draw(&d, out); } @@ -2703,24 +2709,33 @@ static struct { int active; VkImage result; int rw, rh; + int ngen; + VkImage gens[VKP_FG_MAX_GENERATIONS]; } g_pass; 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); + const struct vkp_hdr_frame *hf, int generate, int *rw, int *rh); int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh) { - return pass_begin_impl(scene_w, scene_h, draws, n, NULL, rw, rh); + return pass_begin_impl(scene_w, scene_h, draws, n, NULL, 0, rw, rh); +} + +int vkp_pass_begin_generate(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh) { + if (pass_begin_impl(scene_w, scene_h, draws, n, hf, 1, rw, rh) != 0) return -1; + return g_pass.ngen; } int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int *rw, int *rh) { if (!hf) return -1; - return pass_begin_impl(scene_w, scene_h, draws, n, hf, rw, rh); + return pass_begin_impl(scene_w, scene_h, draws, n, hf, 0, rw, rh); } 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) { + const struct vkp_hdr_frame *hf, int generate, int *rw, int *rh) { if (g_pass.active) vkp_pass_abort(); + g_pass.ngen = 0; if (vkp_update_map(scene_w, scene_h) != 0) return -1; int input_w = scene_w, input_h = scene_h; int pass_n = n, overlay_start = n; @@ -2740,13 +2755,31 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw effects_source_note(scene_w, scene_h, draws, n, input_w, input_h, (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f)); } - if (hf) { + const int deep = hf && generate && !hf->tonemap && vkp_framegen_format_ok(FG_HDR_FMT) && + ensure_img(&g_fgscene, scene_w, scene_h, FG_HDR_FMT, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + "HDR frame generation (scene)") == 0; + const int narrow = hf && generate && !deep; + if (hf && !deep && !narrow) { if (ensure_img(&g_hdrscene, scene_w, scene_h, HDR_FMT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, "HDR composition (picture)") != 0) return -1; - } else if (ensure_scene_image(input_w, input_h) != 0) return -1; + } else if (!deep && ensure_scene_image(input_w, input_h) != 0) return -1; + const VkFormat scene_fmt = deep ? FG_HDR_FMT : narrow || !hf ? SCENE_FMT : HDR_FMT; + if (hf && generate) { + static int said = -1; + if (said != deep + 2 * hf->tonemap) { + said = deep + 2 * hf->tonemap; + droiddeck_log("color", hf->tonemap + ? "frame generation runs on the tone-mapped picture in 8 bits, onto the game's display layer" + : deep ? "frame generation runs on the HDR picture in FP16 (RGBA16F), onto the game's display layer" + : "frame generation runs on the HDR picture in 8 bits (the engine cannot take FP16 here), onto " + "the game's display layer: banding possible in smooth gradients"); + } + } VkCommandBuffer cmd = g_cmds[0]; g_vk.ResetCommandBuffer(cmd, 0); @@ -2760,7 +2793,7 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars)); if (!bars) { g_vk.EndCommandBuffer(cmd); return -1; } int nb = 0; - VkImage scene_img = hf ? g_hdrscene.img : g_scene.img; + VkImage scene_img = deep ? g_fgscene.img : narrow || !hf ? g_scene.img : g_hdrscene.img; bars[nb++] = (VkImageMemoryBarrier){ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, @@ -2791,12 +2824,12 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw free(bars); if (hf) { - if (compose_hdr(cmd, draws, n, hf, scene_w, scene_h, g_hdrscene.img, HDR_FMT, + if (compose_hdr(cmd, draws, n, hf, scene_w, scene_h, scene_img, scene_fmt, hf->tonemap ? HDRC_OUT_SDR : HDRC_OUT_PQ) != 0) { g_vk.EndCommandBuffer(cmd); return -1; } - if (vkp_effects_active()) vkp_effects_set_formats(HDR_FMT, HDR_FMT); + if (vkp_effects_active()) vkp_effects_set_formats(scene_fmt, scene_fmt); } else { VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; g_vk.CmdClearColorImage(cmd, g_scene.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); @@ -2815,24 +2848,42 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw } int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); + if (generate && !vkp_effects_sharpening()) { mapped_w = scene_w; mapped_h = scene_h; } g_pass.rw = input_w; g_pass.rh = input_h; g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &g_pass.rw, &g_pass.rh); effects_overlay_draws(cmd, g_pass.result, g_pass.rw, g_pass.rh, scene_w, scene_h, draws ? draws + overlay_start : NULL, n - overlay_start); release_external_client_draws(cmd, draws, n); + if (generate) { + VkImageMemoryBarrier b = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = g_pass.result, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, 0, NULL, 0, NULL, 1, &b); + int ngen = vkp_framegen_run(cmd, g_pass.result, VK_NULL_HANDLE, g_pass.rw, g_pass.rh, scene_fmt, g_pass.gens); + if (ngen < 0) ngen = 0; + g_pass.ngen = ngen > VKP_FG_MAX_GENERATIONS ? VKP_FG_MAX_GENERATIONS : ngen; + } g_pass.active = 1; if (rw) *rw = g_pass.rw; if (rh) *rh = g_pass.rh; return 0; } -int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { +static int pass_finish(const VkImage *srcs, VkImageLayout src_layout, struct vkp_image *const *dsts, int n, + int wait_fd) { if (!g_pass.active) { if (wait_fd >= 0) close(wait_fd); return -1; } g_pass.active = 0; if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; } VkCommandBuffer cmd = g_cmds[0]; - if (!dst || !dst->blit_dst) { + for (int i = 0; i < n; i++) { + if (dsts[i] && dsts[i]->blit_dst) continue; if (wait_fd >= 0) close(wait_fd); g_vk.EndCommandBuffer(cmd); return -1; @@ -2841,27 +2892,30 @@ int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { if (gpu_wait < 0) { g_vk.EndCommandBuffer(cmd); return -1; } VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; - VkImageMemoryBarrier acq = { - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, - .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, - .dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range, - .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; - g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 0, NULL, 0, NULL, 1, &acq); - VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, - .srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}}, - .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, - .dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}}; - g_vk.CmdBlitImage(cmd, g_pass.result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst->image, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, - (g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR); - VkImageMemoryBarrier rel = { - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam, - .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range, - .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; - g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, - 0, 0, NULL, 0, NULL, 1, &rel); + for (int i = 0; i < n; i++) { + struct vkp_image *dst = dsts[i]; + VkImageMemoryBarrier acq = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, + .dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &acq); + VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}}; + g_vk.CmdBlitImage(cmd, srcs[i], src_layout, dst->image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, + (g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR); + VkImageMemoryBarrier rel = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &rel); + } g_vk.EndCommandBuffer(cmd); VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; @@ -2881,6 +2935,19 @@ int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { return 0; } +int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { + return pass_finish(&g_pass.result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, &dst, 1, wait_fd); +} + +int vkp_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_image *real, int wait_fd) { + VkImage srcs[VKP_FG_MAX_GENERATIONS + 1]; + struct vkp_image *all[VKP_FG_MAX_GENERATIONS + 1]; + if (n > g_pass.ngen) n = g_pass.ngen; + for (int i = 0; i < n; i++) { srcs[i] = g_pass.gens[i]; all[i] = dsts[i]; } + if (real) { srcs[n] = g_pass.result; all[n] = real; } + return pass_finish(srcs, VK_IMAGE_LAYOUT_GENERAL, all, n + (real ? 1 : 0), wait_fd); +} + void vkp_pass_abort(void) { if (!g_pass.active) return; g_pass.active = 0; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h index b8cd88921..69af7dca2 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.h +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -96,6 +96,7 @@ struct vkp_hdr_frame { float peak_nits; int tonemap; const struct droiddeck_color *color; + const struct droiddeck_color *convert; }; int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, int *how); @@ -106,7 +107,7 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd); int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px); int vkp_update_map(int scene_w, int scene_h); int vkp_map_draw(const struct vkp_draw *d, int out[8]); -int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]); +int vkp_map_rect(int img_w, int img_h, const int dst[4], int out[8]); int vkp_surface_rotation_degrees(void); ANativeWindow *vkp_window(void); @@ -114,6 +115,9 @@ void vkp_signal_first_frame(void); int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh); int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd); +int vkp_pass_begin_generate(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh); +int vkp_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_image *real, int wait_fd); void vkp_pass_abort(void); void droiddeck_log(const char *tag, const char *fmt, ...) __attribute__((format(printf, 2, 3))); diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index 7879d5152..4dc2f2c08 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -34,11 +34,13 @@ extern int droiddeck_cursor_input_pos(int *x, int *y); extern void droiddeck_wayland_send_scene_input(int type, int a, int b); extern void droiddeck_wayland_set_cursor_composite(int on); extern void droiddeck_wayland_vsync(int64_t frame_time_ns); +extern void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns); extern void droiddeck_stream_set(int on); extern void droiddeck_stream_frame(AHardwareBuffer *ahb); extern unsigned droiddeck_stream_frames(void); extern void droiddeck_wayland_output_resized(void); extern void droiddeck_wayland_set_output_refresh_rate(int mhz); +extern void droiddeck_wayland_set_panel_rates(const int *rates, int count); extern volatile int g_fps_limit; extern volatile int g_release_unpaced; extern volatile int g_render_on_commit; @@ -48,6 +50,8 @@ extern volatile int g_hide_shell; extern volatile int g_zero_copy; extern volatile unsigned g_zero_copy_last; extern volatile int g_ubwc; +extern volatile int g_display_buffer_driver; +void droiddeck_dmabuf_formats_stale(void); extern volatile int g_no_render_node; extern volatile int g_output_w, g_output_h; @@ -63,6 +67,9 @@ static jmethodID g_on_game_program; static jmethodID g_on_pointer_lock; static jmethodID g_on_clipboard; static jmethodID g_on_text_input; +static jmethodID g_on_overlay_planes; +static jmethodID g_on_refresh_target; +static jmethodID g_on_content_rate; JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { (void)reserved; @@ -84,6 +91,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { g_on_clipboard = (*env)->GetStaticMethodID(env, g_compositor_cls, "onClipboardText", "([B)V"); g_on_text_input = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInput", "(ZLjava/lang/String;IIII)V"); + g_on_overlay_planes = (*env)->GetStaticMethodID(env, g_compositor_cls, "onOverlayPlanes", "(I)V"); + g_on_refresh_target = (*env)->GetStaticMethodID(env, g_compositor_cls, "onRefreshTarget", "(II)V"); + g_on_content_rate = (*env)->GetStaticMethodID(env, g_compositor_cls, "onContentRate", "(I)V"); } } return JNI_VERSION_1_6; @@ -144,6 +154,27 @@ void droiddeck_on_game_frame(void) { if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); } +void droiddeck_on_refresh_target(int refresh, int frame_rate) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_refresh_target || !(env = thread_env())) return; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_refresh_target, (jint)refresh, (jint)frame_rate); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); +} + +void droiddeck_on_content_rate(int fps) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_content_rate || !(env = thread_env())) return; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_content_rate, (jint)fps); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); +} + +void droiddeck_on_overlay_planes(int planes) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_overlay_planes || !(env = thread_env())) return; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_overlay_planes, (jint)planes); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); +} + void droiddeck_on_pointer_lock(int locked, int x, int y) { JNIEnv *env; if (!g_compositor_cls || !g_on_pointer_lock || !(env = thread_env())) return; @@ -365,6 +396,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeVsync(JNIEnv *env, j droiddeck_wayland_vsync((int64_t)frameTimeNanos); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeFrameTimeline(JNIEnv *env, jclass clazz, jlong presentNanos, + jlong deadlineNanos, jlong periodNanos) { + sc_layer_frame_timeline((int64_t)presentNanos, (int64_t)deadlineNanos, (int64_t)periodNanos); +} + JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetClockControl(JNIEnv *env, jclass clazz, jstring path) { const char *value = path ? (*env)->GetStringUTFChars(env, path, NULL) : NULL; @@ -380,11 +417,18 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetHideShell(JNIEnv JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetZeroCopy(JNIEnv *env, jclass clazz, jboolean on) { int live = droiddeck_get_display() != NULL; - if (!live) g_zero_copy = on ? 1 : 0; + if (!live) { g_zero_copy = on ? 1 : 0; droiddeck_dmabuf_formats_stale(); } droiddeck_host_zero_copy(on ? 1 : 0, live); __android_log_print(ANDROID_LOG_INFO, TAG, "zero-copy layer mode %s%s", on ? "on" : "off", live ? " (live)" : ""); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetDisplayBufferDriver(JNIEnv *env, jclass clazz, jboolean on) { + g_display_buffer_driver = on ? 1 : 0; + droiddeck_dmabuf_formats_stale(); + __android_log_print(ANDROID_LOG_INFO, TAG, "session driver %s for display buffers", on ? "asks" : "does not ask"); +} + JNIEXPORT jint JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeZeroCopyLastFrameAgeMs(JNIEnv *env, jclass clazz) { return (jint)ahb_swapchain_last_frame_age_ms(); @@ -418,6 +462,16 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetOutputRefreshRate droiddeck_wayland_set_output_refresh_rate(hz > 1.0f ? (int)(hz * 1000.0f + 0.5f) : 0); } +JNIEXPORT void JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetPanelRates(JNIEnv *env, jclass clazz, jintArray rates) { + (void)clazz; + jint values[16]; + jsize count = rates ? (*env)->GetArrayLength(env, rates) : 0; + if (count > 16) count = 16; + if (count > 0) (*env)->GetIntArrayRegion(env, rates, 0, count, values); + droiddeck_wayland_set_panel_rates((const int *)values, (int)count); +} + extern void vkp_reset_first_frame(void); JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeResetFirstFrame(JNIEnv *env, jclass clazz) { diff --git a/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c b/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c index 1ba254c4c..a45d2691c 100644 --- a/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c +++ b/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c @@ -84,15 +84,18 @@ static struct { static _Atomic int g_gate = -1; static char g_gate_why[320]; static _Atomic int g_output_on = 1; +static _Atomic int g_output_wanted = 1; +static pthread_mutex_t g_output_mu = PTHREAD_MUTEX_INITIALIZER; void droiddeck_color_set_request(int mode, const char *source, int dxvk_hdr, int zero_copy_forced) { pthread_mutex_lock(&g_mu); - g_req.mode = mode < 0 ? 0 : mode > 2 ? 2 : mode; + g_req.mode = mode < 0 ? 0 : mode > 3 ? 3 : mode; snprintf(g_req.source, sizeof(g_req.source), "%s", source ? source : "environment"); g_req.dxvk_hdr = dxvk_hdr ? 1 : 0; g_req.zero_copy_forced = zero_copy_forced ? 1 : 0; pthread_mutex_unlock(&g_mu); atomic_store(&g_output_on, 1); + atomic_store(&g_output_wanted, 1); } void droiddeck_color_set_display(int id, const char *name, const char *formats, int hdr10, float max_lum, @@ -610,11 +613,23 @@ int droiddeck_color_tonemapped_on_screen(void) { void droiddeck_color_set_output(int on) { on = on ? 1 : 0; - if (atomic_load(&g_gate) != 1) { - droiddeck_log(TAG, "HDR output switch (%s) ignored: HDR is not open in this session", on ? "on" : "off"); + pthread_mutex_lock(&g_mu); + const int tonemap_only = g_req.mode == 3; + pthread_mutex_unlock(&g_mu); + pthread_mutex_lock(&g_output_mu); + atomic_store(&g_output_wanted, on); + const int gate = atomic_load(&g_gate); + const int changed = gate == 1 && !(on && tonemap_only) && atomic_exchange(&g_output_on, on) != on; + pthread_mutex_unlock(&g_output_mu); + if (gate != 1) { + if (gate == 0) droiddeck_log(TAG, "HDR output switch (%s) ignored: HDR is not open in this session", on ? "on" : "off"); return; } - if (atomic_exchange(&g_output_on, on) == on) return; + if (on && tonemap_only) { + droiddeck_log(TAG, "HDR output switch (on) ignored: this display cannot show HDR10, HDR frames stay tone-mapped"); + return; + } + if (!changed) return; char who[160]; int age = droiddeck_color_last_frame_age_ms(), tm = droiddeck_color_tonemapped_on_screen(); pthread_mutex_lock(&g_mu); @@ -658,6 +673,8 @@ static void desc_unref(struct cm_desc *d) { if (d && --d->refs <= 0) free(d); } struct cm_params { uint32_t tf, primaries; + int has_prim; int32_t prim[8]; + int has_lum; uint32_t lum_ref; int has_mprim; int32_t mprim[8]; int has_mlum; uint32_t mlum_min, mlum_max; int has_cll; uint32_t cll; @@ -730,9 +747,83 @@ static void make_output_description(struct wl_client *c, struct wl_resource *par droiddeck_client_name(c), what, col->text); } +static const float BT709_XY[8] = {0.64f, 0.33f, 0.30f, 0.60f, 0.15f, 0.06f, 0.3127f, 0.3290f}; +static const float BT2020_XY[8] = {0.708f, 0.292f, 0.170f, 0.797f, 0.131f, 0.046f, 0.3127f, 0.3290f}; + +static void mat_mul(const double a[9], const double b[9], double out[9]) { + double m[9]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + m[3 * i + j] = a[3 * i] * b[j] + a[3 * i + 1] * b[3 + j] + a[3 * i + 2] * b[6 + j]; + memcpy(out, m, sizeof(m)); +} + +static int mat_invert(const double m[9], double out[9]) { + const double det = m[0] * (m[4] * m[8] - m[5] * m[7]) - m[1] * (m[3] * m[8] - m[5] * m[6]) + + m[2] * (m[3] * m[7] - m[4] * m[6]); + if (det > -1e-12 && det < 1e-12) return -1; + const double k = 1.0 / det; + double r[9] = {(m[4] * m[8] - m[5] * m[7]) * k, (m[2] * m[7] - m[1] * m[8]) * k, (m[1] * m[5] - m[2] * m[4]) * k, + (m[5] * m[6] - m[3] * m[8]) * k, (m[0] * m[8] - m[2] * m[6]) * k, (m[2] * m[3] - m[0] * m[5]) * k, + (m[3] * m[7] - m[4] * m[6]) * k, (m[1] * m[6] - m[0] * m[7]) * k, (m[0] * m[4] - m[1] * m[3]) * k}; + memcpy(out, r, sizeof(r)); + return 0; +} + +static int rgb_to_xyz(const float xy[8], double out[9], double white[3]) { + for (int i = 0; i < 4; i++) + if (xy[2 * i + 1] < 1e-4f) return -1; + double p[9], inv[9]; + for (int i = 0; i < 3; i++) { + const double x = xy[2 * i], y = xy[2 * i + 1]; + p[i] = x / y; p[3 + i] = 1.0; p[6 + i] = (1.0 - x - y) / y; + } + white[0] = xy[6] / xy[7]; white[1] = 1.0; white[2] = (1.0 - xy[6] - xy[7]) / xy[7]; + if (mat_invert(p, inv) != 0) return -1; + for (int i = 0; i < 3; i++) { + const double scale = inv[3 * i] * white[0] + inv[3 * i + 1] * white[1] + inv[3 * i + 2] * white[2]; + out[i] = p[i] * scale; out[3 + i] = p[3 + i] * scale; out[6 + i] = p[6 + i] * scale; + } + return 0; +} + +static int matrix_to_bt2020(const float xy[8], float out[9]) { + static const double bradford[9] = {0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296}; + double src[9], dst[9], dst_inv[9], sw[3], dw[3], cone_inv[9], adapt[9], m[9]; + if (rgb_to_xyz(xy, src, sw) != 0 || rgb_to_xyz(BT2020_XY, dst, dw) != 0) return -1; + if (mat_invert(dst, dst_inv) != 0 || mat_invert(bradford, cone_inv) != 0) return -1; + double scale[9] = {0}; + for (int i = 0; i < 3; i++) { + const double from = bradford[3 * i] * sw[0] + bradford[3 * i + 1] * sw[1] + bradford[3 * i + 2] * sw[2]; + const double to = bradford[3 * i] * dw[0] + bradford[3 * i + 1] * dw[1] + bradford[3 * i + 2] * dw[2]; + if (from > -1e-9 && from < 1e-9) return -1; + scale[4 * i] = to / from; + } + mat_mul(scale, bradford, adapt); + mat_mul(cone_inv, adapt, adapt); + mat_mul(adapt, src, m); + mat_mul(dst_inv, m, m); + for (int i = 0; i < 9; i++) out[i] = (float)m[i]; + return 0; +} + +static struct wl_resource *publish_description(struct wl_client *client, struct wl_resource *parent, uint32_t id, + struct cm_desc *d) { + struct wl_resource *out = wl_resource_create(client, &wp_image_description_v1_interface, + wl_resource_get_version(parent), id); + if (!out) { free(d); wl_client_post_no_memory(client); return NULL; } + d->refs = 1; + wl_resource_set_implementation(out, &image_description_impl, d, image_description_resource_destroy); + wp_image_description_v1_send_ready(out, d->c.identity); + pthread_mutex_lock(&g_mu); + g_hdr.descs++; + pthread_mutex_unlock(&g_mu); + return out; +} + static void params_create(struct wl_client *client, struct wl_resource *r, uint32_t id) { struct cm_params *p = wl_resource_get_user_data(r); - if (!p->tf || !p->primaries) { + if (!p->tf || (!p->primaries && !p->has_prim)) { wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET, "transfer function and primaries must both be set"); return; @@ -744,10 +835,29 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3 if (!g_next_identity) g_next_identity = 1; c->primaries = p->primaries; c->tf = p->tf; - if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ) + const float ref = p->has_lum ? (float)p->lum_ref : 203.0f; + float xy[8]; + for (int i = 0; i < 8; i++) + xy[i] = p->has_prim ? p->prim[i] / 1e6f + : p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_SRGB ? BT709_XY[i] : BT2020_XY[i]; + if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && ref == 203.0f) { c->dataspace = DROIDDECK_ADATASPACE_BT2020_PQ; - else if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG) - c->dataspace = DROIDDECK_ADATASPACE_BT2020_HLG; + } else if (matrix_to_bt2020(xy, c->to2020) == 0) { + c->convert = 1; + c->gain = 10000.0f * 203.0f / ref; + } else { + struct wl_resource *bad = wl_resource_create(client, &wp_image_description_v1_interface, + wl_resource_get_version(r), id); + free(d); + if (!bad) { wl_client_post_no_memory(client); return; } + wl_resource_set_implementation(bad, &image_description_impl, NULL, NULL); + wp_image_description_v1_send_failed(bad, WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED, + "the primaries do not form a colour space"); + droiddeck_log(TAG, "image description from %s refused: its primaries do not form a colour space", + droiddeck_client_name(client)); + wl_resource_destroy(r); + return; + } char dropped[160] = ""; float mlum_min = 0.005f, mlum_max = 10000.0f; @@ -781,7 +891,12 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3 } if (cll > 0.0f || fall > 0.0f) { c->has_cta861 = 1; c->max_cll = cll; c->max_fall = fall; } - int n = snprintf(c->text, sizeof(c->text), "%s, %s", primaries_name(c->primaries), tf_name(c->tf)); + int n = snprintf(c->text, sizeof(c->text), "%s, %s", p->has_prim ? "custom primaries" : primaries_name(c->primaries), + tf_name(c->tf)); + if (c->convert && n < (int)sizeof(c->text)) + n += snprintf(c->text + n, sizeof(c->text) - (size_t)n, + "; R %.4f,%.4f G %.4f,%.4f B %.4f,%.4f W %.4f,%.4f, reference white %.0f nits", + xy[0], xy[1], xy[2], xy[3], xy[4], xy[5], xy[6], xy[7], ref); if (c->has_st2086 && n < (int)sizeof(c->text)) n += snprintf(c->text + n, sizeof(c->text) - (size_t)n, "; mastering R %.4f,%.4f G %.4f,%.4f B %.4f,%.4f W %.4f,%.4f, %.4f-%.0f nits%s", @@ -793,19 +908,13 @@ static void params_create(struct wl_client *client, struct wl_resource *r, uint3 if (!c->has_st2086 && !c->has_cta861 && n < (int)sizeof(c->text)) snprintf(c->text + n, sizeof(c->text) - (size_t)n, " (no HDR metadata: the game has not called vkSetHdrMetadataEXT)"); - struct wl_resource *out = wl_resource_create(client, &wp_image_description_v1_interface, - wl_resource_get_version(r), id); - if (!out) { free(d); wl_client_post_no_memory(client); return; } - d->refs = 1; - wl_resource_set_implementation(out, &image_description_impl, d, image_description_resource_destroy); - wp_image_description_v1_send_ready(out, c->identity); - if (c->dataspace) { - pthread_mutex_lock(&g_mu); - g_hdr.descs++; - pthread_mutex_unlock(&g_mu); - } - droiddeck_log(TAG, "image description #%u from %s: %s -> ready (on a display layer: dataspace %s)", c->identity, - droiddeck_client_name(client), c->text, dataspace_name(c->dataspace)); + if (!publish_description(client, r, id, d)) return; + if (c->convert) + droiddeck_log(TAG, "image description #%u from %s: %s -> ready (converted to BT.2020 PQ when the scene is " + "composed)", c->identity, droiddeck_client_name(client), c->text); + else + droiddeck_log(TAG, "image description #%u from %s: %s -> ready (on a display layer: dataspace %s)", c->identity, + droiddeck_client_name(client), c->text, dataspace_name(c->dataspace)); if (dropped[0]) { size_t l = strlen(dropped); if (l && dropped[l - 1] == ',') dropped[l - 1] = 0; @@ -840,8 +949,8 @@ static void params_set_tf_power(struct wl_client *c, struct wl_resource *r, uint } static void params_set_primaries_named(struct wl_client *c, struct wl_resource *r, uint32_t primaries) { struct cm_params *p = wl_resource_get_user_data(r); - PARAMS_ONCE(p->primaries, "primaries"); - if (primaries != WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) { + PARAMS_ONCE(p->primaries || p->has_prim, "primaries"); + if (primaries != WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && primaries != WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) { wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED, "primaries %u were not advertised", primaries); return; @@ -850,12 +959,21 @@ static void params_set_primaries_named(struct wl_client *c, struct wl_resource * } static void params_set_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry, int32_t gx, int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) { - wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE, - "set_primaries is not supported"); + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->primaries || p->has_prim, "primaries"); + p->has_prim = 1; + p->prim[0] = rx; p->prim[1] = ry; p->prim[2] = gx; p->prim[3] = gy; + p->prim[4] = bx; p->prim[5] = by; p->prim[6] = wx; p->prim[7] = wy; } static void params_set_luminances(struct wl_client *c, struct wl_resource *r, uint32_t mn, uint32_t mx, uint32_t ref) { - wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE, - "set_luminances is not supported"); + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->has_lum, "luminances"); + if ((uint64_t)mx * 10000u <= mn || (uint64_t)ref * 10000u <= mn) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE, + "maximum and reference luminance must be above the minimum"); + return; + } + p->has_lum = 1; p->lum_ref = ref; } static void params_set_mastering_display_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry, int32_t gx, int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) { @@ -1083,7 +1201,20 @@ static void cm_create_parametric_creator(struct wl_client *c, struct wl_resource } static void cm_create_windows_scrgb(struct wl_client *c, struct wl_resource *r, uint32_t id) { - wl_resource_post_error(r, WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "windows_scrgb is not supported"); + struct cm_desc *d = calloc(1, sizeof(*d)); + if (!d) { wl_client_post_no_memory(c); return; } + struct droiddeck_color *col = &d->c; + col->identity = g_next_identity++; + if (!g_next_identity) g_next_identity = 1; + col->primaries = WP_COLOR_MANAGER_V1_PRIMARIES_SRGB; + col->tf = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR; + col->convert = 2; + col->gain = 80.0f; + matrix_to_bt2020(BT709_XY, col->to2020); + snprintf(col->text, sizeof(col->text), "%s, %s (1.0 = 80 nits)", primaries_name(col->primaries), tf_name(col->tf)); + if (!publish_description(c, r, id, d)) return; + droiddeck_log(TAG, "image description #%u from %s: %s -> ready (converted to BT.2020 PQ when the scene is composed)", + col->identity, droiddeck_client_name(c), col->text); } static const struct wp_color_manager_v1_interface cm_impl = { @@ -1103,14 +1234,20 @@ static void bind_cm(struct wl_client *c, void *data, uint32_t ver, uint32_t id) wl_resource_set_implementation(r, &cm_impl, NULL, NULL); wp_color_manager_v1_send_supported_intent(r, WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES); wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_WINDOWS_SCRGB); + wp_color_manager_v1_send_supported_primaries_named(r, WP_COLOR_MANAGER_V1_PRIMARIES_SRGB); wp_color_manager_v1_send_supported_primaries_named(r, WP_COLOR_MANAGER_V1_PRIMARIES_BT2020); wp_color_manager_v1_send_supported_tf_named(r, WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ); wp_color_manager_v1_send_done(r); if (last_named != c) { last_named = c; droiddeck_log(TAG, "%s bound wp_color_manager_v1 version %u (offered: perceptual intent; parametric descriptions " - "with mastering metadata; BT.2020 primaries; ST 2084 PQ) - its Vulkan driver can now list " + "with custom primaries, luminances and mastering metadata; Windows scRGB; sRGB and BT.2020 primaries; " + "ST 2084 PQ) - its Vulkan driver can now list " "VK_COLOR_SPACE_HDR10_ST2084_EXT", droiddeck_client_name(c), ver > 1 ? 1u : ver); } } @@ -1150,6 +1287,7 @@ void droiddeck_color_init(struct wl_display *display) { char asked[128]; if (mode == 2) snprintf(asked, sizeof(asked), "DROIDDECK_WAYLAND_HDR=force (%s)", source); + else if (mode == 3) snprintf(asked, sizeof(asked), "HDR is on, tone-mapped for this display (%s)", source); else if (strstr(source, "env")) snprintf(asked, sizeof(asked), "DROIDDECK_WAYLAND_HDR=1 (%s)", source); else snprintf(asked, sizeof(asked), "HDR output is on (%s)", source); @@ -1168,7 +1306,7 @@ void droiddeck_color_init(struct wl_display *display) { snprintf(why, sizeof(why), "this Android has no display layers with dataspace control " "(ASurfaceControl + ASurfaceTransaction_setBufferDataSpace, Android 10+)"); else if (!ahb_ok) - snprintf(why, sizeof(why), "zero-copy presentation is unavailable here (banner_ahb_v1 not advertised), and an " + snprintf(why, sizeof(why), "zero-copy presentation is unavailable here (droiddeck_ahb_v1 not advertised), and an " "HDR frame is only honest on the game's own display layer"); if (why[0]) { @@ -1198,13 +1336,20 @@ void droiddeck_color_init(struct wl_display *display) { log_verdict(1); return; } + pthread_mutex_lock(&g_output_mu); atomic_store(&g_gate, 1); + if (mode == 3 || !atomic_load(&g_output_wanted)) atomic_store(&g_output_on, 0); + pthread_mutex_unlock(&g_output_mu); char syms[160]; sc_layer_hdr_symbols(syms, sizeof(syms)); droiddeck_log(TAG, "HDR gate %s: %s and %s. Offering games HDR10: wp_color_manager_v1 version 1 (BT.2020 primaries " "+ ST 2084 PQ, parametric descriptions with mastering metadata) and 10-bit AB30/XB30 dma-buf formats; HDR " "frames go on the game's own display layer as BT2020_PQ (%s)", mode == 2 ? "FORCED OPEN (testing)" : "OPEN", asked, disp, syms); + if (mode == 3) { + droiddeck_log(TAG, "this display cannot show HDR10: games still render HDR and every HDR frame is tone-mapped to " + "SDR on the game's display layer"); + } if (mode == 2 && !hdr10) droiddeck_log(TAG, "DROIDDECK_WAYLAND_HDR=force on a display without HDR10 - testing only: SurfaceFlinger will tone-map " "the game layer for this panel (expect GPU/CLIENT composition for it), nothing looks HDR"); diff --git a/app/src/main/cpp/waylandcomp/src/wl_dmabuf.c b/app/src/main/cpp/waylandcomp/src/wl_dmabuf.c index cc85bd32e..a6e0eac3a 100644 --- a/app/src/main/cpp/waylandcomp/src/wl_dmabuf.c +++ b/app/src/main/cpp/waylandcomp/src/wl_dmabuf.c @@ -14,6 +14,7 @@ #include "droiddeck_ext.h" #include "droiddeck_color.h" #include "compositor_internal.h" +#include "display_buffers.h" static void dbuf_buffer_resource_destroy(struct wl_resource *r) { @@ -58,6 +59,7 @@ static struct wl_resource *params_do_create(struct wl_client *c, struct wl_resou wl_resource_set_implementation(buf, &dbuf_buffer_impl, b, dbuf_buffer_resource_destroy); struct client_info *ci = client_info_of(c); if (ci) ci->dmabuf_buffers++; + display_buffers_match(c, buf, b); return buf; } static void params_create(struct wl_client *c, struct wl_resource *r, int32_t w, int32_t h, @@ -111,13 +113,16 @@ static const struct zwp_linux_dmabuf_v1_interface dmabuf_impl = { static struct { uint32_t fmt; uint64_t mods[DMABUF_NMOD]; int n; } g_dmabuf_fmts[DMABUF_NFMT_MAX] = { {DRM_ARGB8888}, {DRM_XRGB8888}, {DRM_ABGR8888}, {DRM_XBGR8888}, {DRM_ABGR2101010}, {DRM_XBGR2101010}}; static int g_dmabuf_nfmt = DMABUF_NFMT_SDR; -static int g_dmabuf_fmts_ready; +static volatile int g_dmabuf_fmts_ready; static void dmabuf_build_feedback(void); +void droiddeck_dmabuf_formats_stale(void) { g_dmabuf_fmts_ready = 0; } + static void dmabuf_build_formats(void) { char line[320]; - int pos = 0, compressed = 0; + int pos = 0, compressed = 0, backed = 0; g_dmabuf_fmts_ready = 1; + display_buffers_withdraw_ubwc(); g_dmabuf_nfmt = droiddeck_color_hdr_open() ? DMABUF_NFMT_MAX : DMABUF_NFMT_SDR; for (int f = 0; f < g_dmabuf_nfmt; f++) { uint64_t got[DMABUF_NMOD]; @@ -129,6 +134,12 @@ static void dmabuf_build_formats(void) { g_dmabuf_fmts[f].mods[k++] = got[i]; if (got[i] == VKP_MOD_QCOM_COMPRESSED) compressed++; } + int listed = 0; + for (int i = 0; i < k; i++) if (g_dmabuf_fmts[f].mods[i] == VKP_MOD_QCOM_COMPRESSED) listed = 1; + if (display_buffers_offer_ubwc(g_dmabuf_fmts[f].fmt) && !listed) { + g_dmabuf_fmts[f].mods[k++] = VKP_MOD_QCOM_COMPRESSED; + backed++; + } g_dmabuf_fmts[f].mods[k++] = MOD_INVALID; g_dmabuf_fmts[f].n = k; uint32_t fmt = g_dmabuf_fmts[f].fmt; @@ -141,7 +152,10 @@ static void dmabuf_build_formats(void) { } droiddeck_log("dmabuf", "formats: %s%s", line, !g_ubwc ? " (DROIDDECK_WAYLAND_UBWC=0: qcom_compressed not advertised)" : ""); - if (g_ubwc && !compressed) + if (backed) + droiddeck_log("dmabuf", "qcom_compressed is advertised for %d formats the compositor's driver (%s) does not " + "import as dma-bufs: this session's driver renders them into gralloc buffers", backed, vkp_gpu_name()); + else if (g_ubwc && !compressed) droiddeck_log("dmabuf", "the compositor's driver (%s) reports no importable qcom_compressed layout: " "game swapchains stay linear", vkp_gpu_name()); if (g_dmabuf_nfmt > DMABUF_NFMT_SDR) { @@ -212,6 +226,7 @@ static void dmabuf_build_feedback(void) { return; } fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE); + if (g_fmt_table_fd >= 0) close(g_fmt_table_fd); g_fmt_table_fd = fd; g_fmt_table_size = size; g_fmt_table_n = (uint16_t)n; diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index d286cce1f..0cb8e939b 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -596,9 +596,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet private var theme by mutableStateOf("graphite") private var appScale by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.DEFAULT_SCALE) private var hdrOn by mutableStateOf(false) + private var zeroCopyOn by mutableStateOf(true) private var upscaler by mutableStateOf(0) private var upscaleSharpness by mutableStateOf(75) private var hdrReason by mutableStateOf(null) + private var hdrDisplay by mutableStateOf(true) private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO) private var pen by mutableStateOf(null) private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL) @@ -2079,6 +2081,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet refreshHomeAppState() } if (settingsMode == SessionService.MODE_STEAM) refreshFoundSteamLibraries() + settingsMode?.let { hdrOn = SessionPrefs.hdr(this, it) } compatLaunchVisible = true com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false) @@ -2586,7 +2589,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet ModeSettings( mode = mode, resolution = resolution, panelSize = com.droiddeck.launcher.session.SessionDisplay.panelSize(this), - hdr = hdrOn, hdrReason = hdrReason, + hdr = hdrOn, hdrReason = hdrReason, hdrDisplay = hdrDisplay, zeroCopy = zeroCopyOn, upscaler = upscaler, upscaleSharpness = upscaleSharpness, gpuDrivers = drivers.summary(), touchMode = touchMode, @@ -2639,7 +2642,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet onIntegrationAppInfo = ::openAppInfo, onIntegrationLocation = ::openWifiDiscoverySettings, onResolution = { value -> SessionPrefs.setResolutionChoice(this, mode, value); resolution = value }, - onHdr = { on -> SessionPrefs.setHdr(this, mode, on); hdrOn = on }, + onHdr = { on -> com.droiddeck.launcher.session.SessionHdr.set(this, mode, on); hdrOn = on }, + onZeroCopy = { on -> + SessionPrefs.setZeroCopy(this, mode, on); zeroCopyOn = on + if (com.droiddeck.launcher.wayland.CompositorHost.isStarted && !SessionState.hdr && + SessionPrefs.prefMode(SessionState.mode) == SessionPrefs.prefMode(mode)) + com.droiddeck.launcher.wayland.WaylandCompositor.nativeSetZeroCopy(on) + }, onGpuDrivers = { openComponents(focusContent = true, tab = com.droiddeck.launcher.ui.GPU_TAB) }, onUpscaler = { m -> SessionPrefs.setUpscaler(this, m); upscaler = m }, onUpscaleSharpness = { pct -> SessionPrefs.setUpscaleSharpness(this, pct); upscaleSharpness = pct }, @@ -2983,9 +2992,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet startupSession = SessionPrefs.startupSession(this) loadBootMovie() hdrOn = SessionPrefs.hdr(this, mode) + zeroCopyOn = SessionPrefs.zeroCopy(this, mode) upscaler = SessionPrefs.upscaler(this) upscaleSharpness = SessionPrefs.upscaleSharpness(this) - hdrReason = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason + hdrReason = com.droiddeck.launcher.wayland.HdrSupport.blocked(this) + hdrDisplay = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason == null touchMode = SessionPrefs.touchMode(this) if (!SessionPrefs.penSeen(this) && com.droiddeck.launcher.input.PenStream.penConnected()) SessionPrefs.setPenSeen(this) pen = SessionPrefs.pen(this).takeIf { SessionPrefs.penSeen(this) } diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 08c8f958c..cb5ee5318 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -109,6 +109,7 @@ import com.droiddeck.launcher.input.TouchpadGestures import com.droiddeck.launcher.input.TouchscreenGestures import com.droiddeck.launcher.input.ScrollTouchGestures import com.droiddeck.launcher.runtime.LinuxRuntime +import com.droiddeck.launcher.session.ContentCadence import com.droiddeck.launcher.session.LoadingState import com.droiddeck.launcher.hud.DroidDeckHudConfig import com.droiddeck.launcher.hud.DroidDeckHudHost @@ -306,7 +307,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_CLICK) private var relativeMouseMode by mutableIntStateOf(0) @Volatile private var appliedRelativeMouseMode: Int? = null - private val agentReadyListener: () -> Unit = { relativeMouseRetries = 0; requestRelativeMouse() } + private val agentReadyListener: () -> Unit = { + relativeMouseRetries = 0 + requestRelativeMouse() + appliedOverlayPlanes = null + overlayPlanesRetries = 0 + requestOverlayPlanes() + } private val appTextFocus get() = wowChat.request != null private val wowChat by lazy { com.droiddeck.launcher.ui.WowChat(this, ::sendWowChat, ::cancelWowChat, ::readGameField) } private var wowChatBottom: SecondScreenPresentation? = null @@ -510,6 +517,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun fpsLimitKey(): String? = if (SessionState.running) SessionPrefs.fpsLimitKey(SessionState.mode, SessionState.gameId) else SessionPrefs.fpsLimitKey(intent.getStringExtra(SessionService.EXTRA_MODE), intent.getStringExtra(SessionService.EXTRA_GAME_ID)) private var blackFrameInsertion by mutableStateOf(false) + private var hdrWanted by mutableStateOf(false) + private var hdrAvailable by mutableStateOf(false) private fun noSteamSession(): Boolean = (SessionState.mode == SessionService.MODE_RUN && SessionState.program in setOf( @@ -610,6 +619,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde syncActiveScreenEffectsProfile() } } + private val hdrPrefListener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key -> + if (key == SessionPrefs.hdrKey(hdrPrefMode())) uiHandler.post { hdrWanted = SessionPrefs.hdr(this, hdrPrefMode()) } + } private val shortcutPrefListener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == null || key == PhysicalShortcuts.KEY) { physicalShortcuts.bindings = PhysicalShortcuts.read(this) @@ -1038,6 +1050,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde updateOnScreenControls() WaylandCompositor.setFirstFrameListener(firstFrameListener) WaylandCompositor.setPointerLockListener(pointerLockListener) + WaylandCompositor.setOverlayPlanesListener(overlayPlanesListener) + WaylandCompositor.setRefreshTargetListener(refreshTargetListener) + WaylandCompositor.setContentRateListener(contentRateListener) SessionEvents.markReadyIfPossible() SessionState.endListener = endListener onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { @@ -1645,6 +1660,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde blackFrameInsertion = on CompositorHost.setBlackFrameInsertion(on, refreshHz(), outputFpsLimit()) }, + hdr = hdrWanted, + hdrAvailable = hdrAvailable, + onHdr = { on -> com.droiddeck.launcher.session.SessionHdr.set(this@SessionActivity, hdrPrefMode(), on); hdrWanted = on }, onFrameGenPick = { mode -> val appId = frameGenTargetGameId() @@ -2492,6 +2510,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde hudOn = SessionPrefs.hudEnabled(this) gpuClockPin = gpuClockHeld() blackFrameInsertion = SessionPrefs.blackFrameInsertion(this) + hdrWanted = SessionPrefs.hdr(this, hdrPrefMode()) + hdrAvailable = HdrSupport.probe(this, glassesScreen?.display).reason == null hudConfig = DroidDeckHudConfig.load(this) hudColor = SessionPrefs.hudColor(this) hudOpacity = SessionPrefs.hudOpacity(this) @@ -2747,6 +2767,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde .onFailure { Log.e(TAG, "Could not update game environment", it) } }, "game-env-publish").start() applyGameAlignment() + val attached = CompositorHost.isStarted + val probe = if (attached) null else HdrSupport.probe(this, glassesScreen?.display) + if (probe != null) SessionState.hdrDisplay = probe.reason == null val activeProfileId = currentScreenEffectsProfileId() val activeUpscaler = SessionPrefs.screenEffectsUpscaler(this, activeProfileId) val activeEffects = SessionPrefs.screenEffects(this, activeProfileId) @@ -2766,27 +2789,31 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde Log.w(TAG, "could not point the compositor's log at $waylandLog", e) } } - if (!CompositorHost.isStarted) { - val mode = SessionPrefs.prefMode(intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM) - val probe = HdrSupport.probe(this, glassesScreen?.display) + val mode = hdrPrefMode() + if (probe != null) { WaylandCompositor.nativeSetHdrDisplay( probe.displayId, probe.name, probe.formats, probe.hdr10, probe.maxLuminance, probe.maxAverageLuminance, probe.minLuminance, probe.ratioAvailable, probe.ratio, Build.VERSION.SDK_INT, ) - val wanted = SessionPrefs.hdr(this, mode) - val on = wanted && probe.reason == null - SessionState.hdr = on - if (on) { + val capable = HdrSupport.blocked(this) == null + val tonemap = capable && probe.reason != null + SessionState.hdrCapable = capable + if (capable) { try { android.system.Os.setenv("DROIDDECK_WAYLAND_HDR", "1", true) } catch (e: Exception) { Log.w(TAG, "DROIDDECK_WAYLAND_HDR", e) } - WaylandCompositor.nativeSetZeroCopy(true) } WaylandCompositor.nativeSetHdrRequest( - if (on) WaylandCompositor.HDR_MODE_ON else WaylandCompositor.HDR_MODE_OFF, - "$mode session settings" + (if (wanted && !on) " (refused: ${probe.reason})" else ""), - on, on, + if (tonemap) WaylandCompositor.HDR_MODE_TONEMAP else if (capable) WaylandCompositor.HDR_MODE_ON else WaylandCompositor.HDR_MODE_OFF, + "$mode session settings", capable, false, ) - Log.i(TAG, "hdr: " + (if (on) "on" else if (wanted) "wanted but ${probe.reason}" else "off") + " · display ${probe.formats.ifEmpty { "SDR" }}") + Log.i(TAG, "hdr: " + (if (tonemap) "tone-mapped (${probe.reason})" else if (capable) "available" else "unavailable") + " · display ${probe.formats.ifEmpty { "SDR" }}") + } + if (!SessionState.running) { + val on = SessionState.hdrCapable && SessionPrefs.hdr(this, mode) + SessionState.hdr = on + WaylandCompositor.nativeSetHdrOutput(on) + WaylandCompositor.nativeSetZeroCopy(on || SessionPrefs.zeroCopy(this, mode)) + Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session") } com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId") CompositorHost.startOrAttach( @@ -2962,6 +2989,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde return if (capped > 1f) capped else 60f } + private fun hdrPrefMode(): String = SessionPrefs.prefMode( + if (SessionState.running) SessionState.mode + else intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM, + ) + private fun blackFrameInsertionAvailable(): Boolean { // Glasses that present the game run at their own rate, uncapped, as refreshHz() reads them. glassesScreen?.display?.let { glasses -> @@ -2981,9 +3013,38 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun outputFpsLimit(pip: Boolean): Int = SessionPrefs.compositorFpsLimit(mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pip) + private var panelHeld = false + private val panelHeldCheck = Runnable { + if (!panelHeld && hasWindowFocus() && PerfMode.panelHeld(this)) { + panelHeld = true + uiHandler.removeCallbacks(panelHeldRetry) + uiHandler.postDelayed(panelHeldRetry, PANEL_HELD_RETRY_MS) + applyOutputPacing() + } + } + private val panelHeldRetry = Runnable { + if (panelHeld && !isDestroyed) { + panelHeld = false + applyOutputPacing() + } + } + private fun applyOutputPacing() { - Log.i(TAG, "perf: " + PerfMode.apply(this, outputFpsLimit(false), mirrorRefreshLimit())) + val frameGen = appliedFrameGenMode + pacedFrameGenMode = frameGen + val ownLimit = outputFpsLimit(false) + val content = PerfMode.contentRate( + PerfMode.pacedRate(ownLimit, guestFrameRate, guestRefresh, contentCadence.rate), + frameGen?.outputFactor ?: 1, frameGen?.target ?: 0, + ) + Log.i(TAG, "perf: " + PerfMode.apply(this, content, mirrorRefreshLimit(), if (ownLimit > 0) 0 else guestRefresh, panelHeld)) + uiHandler.removeCallbacks(panelHeldCheck) + if (!panelHeld) uiHandler.postDelayed(panelHeldCheck, PANEL_HELD_CHECK_MS) if (CompositorHost.isStarted) { + WaylandCompositor.nativeSetPanelRates( + if (glassesScreen == null && !bottomOutputActive) PerfMode.panelRates(this, mirrorRefreshLimit(), panelHeld) + else IntArray(0), + ) val hz = refreshHz() val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f CompositorHost.updatePacing(hz, outputFpsLimit()) @@ -3149,6 +3210,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (frameGenActivityGeneration != frameGenGlobalGeneration.get()) return@runOnUiThread lossless = state if (problem != null) Toast.makeText(this, problem, Toast.LENGTH_LONG).show() + if (appliedFrameGenMode != pacedFrameGenMode) applyOutputPacing() } }, "frame-gen").start() } @@ -3749,8 +3811,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } - private val relativeMouseRequests = java.util.concurrent.Executors.newSingleThreadExecutor { runnable -> - Thread(runnable, "relative-mouse").apply { isDaemon = true } + private val gamescopeConvarRequests = java.util.concurrent.Executors.newSingleThreadExecutor { runnable -> + Thread(runnable, "gamescope-convar").apply { isDaemon = true } } @Volatile private var desiredRelativeMouseMode = 0 @@ -3763,7 +3825,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } private fun requestRelativeMouse() { - runCatching { relativeMouseRequests.execute { applyRelativeMouse() } } + runCatching { gamescopeConvarRequests.execute { applyRelativeMouse() } } } private fun applyRelativeMouse() { @@ -3777,23 +3839,58 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde )) == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD val mode = com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, mouseAttached(), touchpadRoute) if (appliedRelativeMouseMode == mode) return - val request = org.json.JSONObject() - .put("kind", "exec") - .put("argv", org.json.JSONArray(listOf("gamescopectl", "relative_mouse", mode.toString()))) - .put("timeout", 5.0) - val result = runCatching { AgentGuest.call(this, request, 8_000, trusted = true) } - val answer = result.getOrNull() - val applied = answer?.optBoolean("ok") == true - && answer.optInt("exitCode", -1) == 0 - && !answer.optBoolean("timedOut") - if (applied) appliedRelativeMouseMode = mode - else { - Log.w(TAG, "gamescope did not take relative mouse $mode: ${result.exceptionOrNull() ?: answer}") - if (relativeMouseRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestRelativeMouse() }, 2_000) - } + if (AgentGuest.setGamescopeConvar(this, "relative_mouse", mode)) appliedRelativeMouseMode = mode + else if (relativeMouseRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestRelativeMouse() }, 2_000) if (desiredRelativeMouseMode != wanted) requestRelativeMouse() } + @Volatile private var desiredOverlayPlanes = -1 + @Volatile private var appliedOverlayPlanes: Int? = -1 + @Volatile private var overlayPlanesRetries = 0 + @Volatile private var guestRefresh = 0 + @Volatile private var guestFrameRate = 0 + private var pacedFrameGenMode: FrameGen.Mode? = null + private val contentCadence = ContentCadence() + private val contentRateListener = WaylandCompositor.ContentRateListener { fps -> + runOnUiThread { + if (isDestroyed) return@runOnUiThread + val changed = if (fps > 0) contentCadence.note(fps, PerfMode.panelRates(this, mirrorRefreshLimit(), panelHeld)) + else contentCadence.reset() + if (changed) { + Log.i(TAG, "perf: steady content rate " + contentCadence.rate + " fps") + applyOutputPacing() + } + } + } + private val refreshTargetListener = WaylandCompositor.RefreshTargetListener { refresh, frameRate -> + runOnUiThread { + if (isDestroyed) return@runOnUiThread + if (guestRefresh != refresh || guestFrameRate != frameRate) { + guestRefresh = refresh + guestFrameRate = frameRate + applyOutputPacing() + } + } + } + + private val overlayPlanesListener = WaylandCompositor.OverlayPlanesListener { planes -> + desiredOverlayPlanes = planes + overlayPlanesRetries = 0 + requestOverlayPlanes() + } + + private fun requestOverlayPlanes() { + runCatching { gamescopeConvarRequests.execute { applyOverlayPlanes() } } + } + + private fun applyOverlayPlanes() { + val wanted = desiredOverlayPlanes + if (appliedOverlayPlanes == wanted) return + if (AgentGuest.setGamescopeConvar(this, "wayland_overlay_planes", wanted)) appliedOverlayPlanes = wanted + else if (overlayPlanesRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestOverlayPlanes() }, 2_000) + if (desiredOverlayPlanes != wanted) requestOverlayPlanes() + } + private fun refreshGestureConfig() { gestureConfig = com.droiddeck.launcher.input.GesturePrefs.read(this, gestureGame) directHoldBehavior = gestureConfig.directHoldBehavior @@ -5754,6 +5851,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde updatePadMotion() ControllerPrefs.prefs(this).registerOnSharedPreferenceChangeListener(shortcutPrefListener) SessionPrefs.sessionPrefs(this).registerOnSharedPreferenceChangeListener(screenEffectsProfilePrefListener) + SessionPrefs.sessionPrefs(this).registerOnSharedPreferenceChangeListener(hdrPrefListener) observedScreenEffectsProfileId = SessionPrefs.activeScreenEffectsProfileId(this) readPrefs() observedScreenEffectsProfileId = SessionPrefs.activeScreenEffectsProfileId(this) @@ -5824,6 +5922,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde hidePrimaryKeyboard() pendingFieldKeyboard = pendingKeyboard SessionPrefs.sessionPrefs(this).unregisterOnSharedPreferenceChangeListener(cardboardPrefListener) + SessionPrefs.sessionPrefs(this).unregisterOnSharedPreferenceChangeListener(hdrPrefListener) SessionPrefs.sessionPrefs(this).unregisterOnSharedPreferenceChangeListener(screenEffectsProfilePrefListener) ControllerPrefs.prefs(this).unregisterOnSharedPreferenceChangeListener(shortcutPrefListener) updateHeadTracker() @@ -6438,6 +6537,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } override fun onDestroy() { + uiHandler.removeCallbacks(panelHeldCheck) + uiHandler.removeCallbacks(panelHeldRetry) synchronized(frameGenGlobalLock) { frameGenActivityActive = false frameGenRequests.incrementAndGet() @@ -6445,7 +6546,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (AgentGuest.readyListener === agentReadyListener) AgentGuest.readyListener = null if (com.droiddeck.launcher.agent.AgentAttachments.gameFrame === gameFrame) com.droiddeck.launcher.agent.AgentAttachments.gameFrame = null com.droiddeck.launcher.input.HomeButtonShortcuts.detach(this) - relativeMouseRequests.shutdownNow() + gamescopeConvarRequests.shutdownNow() backQamInput.cancel() steamVrRecovery.close() uiHandler.removeCallbacks(steamTouchRetry) @@ -6488,6 +6589,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (SessionState.endListener === endListener) SessionState.endListener = null WaylandCompositor.clearFirstFrameListener(firstFrameListener) WaylandCompositor.clearPointerLockListener(pointerLockListener) + WaylandCompositor.clearOverlayPlanesListener(overlayPlanesListener) + WaylandCompositor.clearRefreshTargetListener(refreshTargetListener) + WaylandCompositor.clearContentRateListener(contentRateListener) super.onDestroy() } @@ -6562,6 +6666,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde const val EXTRA_STEAMVR = "steamVr" const val EXTRA_PLAYED_GAME = "com.droiddeck.launcher.PLAYED_GAME" const val EXTRA_REPAIR_RUNTIME = "repairRuntime" + private const val PANEL_HELD_CHECK_MS = 2_500L + private const val PANEL_HELD_RETRY_MS = 60_000L private const val LEAVE_TIMEOUT_MS = 1_500L private const val TEXT_FIELD_TAP_MS = 1_000L private const val PAUSED_FRAME_MAX_EDGE = 1920f diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt index e04dda258..abe8abb3a 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt @@ -230,6 +230,20 @@ object AgentGuest { call(context, JSONObject().put("kind", "cdp").put("expression", expression).put("timeout", timeoutMs / 1000.0), timeoutMs + 2_000, trusted = true) + fun setGamescopeConvar(context: Context, name: String, value: Int): Boolean { + val request = JSONObject() + .put("kind", "exec") + .put("argv", org.json.JSONArray(listOf("gamescopectl", name, value.toString()))) + .put("timeout", 5.0) + val result = runCatching { call(context, request, 8_000, trusted = true) } + val answer = result.getOrNull() + val applied = answer?.optBoolean("ok") == true + && answer.optInt("exitCode", -1) == 0 + && !answer.optBoolean("timedOut") + if (!applied) Log.w(TAG, "gamescope did not take $name $value: ${result.exceptionOrNull() ?: answer}") + return applied + } + fun call(context: Context, request: JSONObject, timeoutMs: Long, trusted: Boolean = false): JSONObject { if (!trusted && request.optString("kind") in setOf("exec", "cdp")) AgentAccess.requireCommands(context) if (!SessionState.running) throw AgentException("NO_ACTIVE_SESSION", "There is no running session") diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt index 1623c1010..25124a6a5 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/FrameGen.kt @@ -21,6 +21,8 @@ object FrameGen { private const val PREFS = "frame_gen" data class Mode(val engine: String, val multiplier: Int = 2, val target: Int = 0) { + val outputFactor: Int get() = if (engine == ENGINE_OFF) 1 else multiplier + companion object { val OFF = Mode(ENGINE_OFF) } diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java index 4f0b62edd..11fc19c87 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/LinuxVulkanDriverManager.java @@ -89,6 +89,11 @@ public class LinuxVulkanDriverManager { return m != null ? m.optString("minGlibc", "") : ""; } + public boolean rendersToDisplayBuffers(String id) { + JSONObject m = id == null || id.isEmpty() ? null : readMeta(id); + return m != null && m.optBoolean("displayBuffers", false); + } + public void removeDriver(String id) { if (id == null || id.isEmpty() || id.contains("/") || id.contains("..")) return; Log.d(TAG, "removing imported Linux Vulkan driver " + id); @@ -182,6 +187,7 @@ public class LinuxVulkanDriverManager { meta.put("driverVersion", version); meta.put("libc", "glibc"); meta.put("minGlibc", minGlibc); + meta.put("displayBuffers", zipMeta != null && zipMeta.optBoolean("displayBuffers", false)); meta.put("sourceLibraryName", soName); meta.put("libraryName", stored); meta.put("importedAt", System.currentTimeMillis()); diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/ScreenEffects.kt b/app/src/main/java/com/droiddeck/launcher/gpu/ScreenEffects.kt index 84b29bd5d..c3ecfa514 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/ScreenEffects.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/ScreenEffects.kt @@ -2,6 +2,7 @@ package com.droiddeck.launcher.gpu import androidx.annotation.StringRes import com.droiddeck.launcher.R +import com.droiddeck.launcher.session.SessionState import com.droiddeck.launcher.wayland.WaylandCompositor import org.json.JSONObject import kotlin.math.abs @@ -30,7 +31,7 @@ data class ScreenEffects( fun push(upscaler: Int) { WaylandCompositor.nativeSetCas(cas, casLevel) - WaylandCompositor.nativeSetHdr(hdr) + WaylandCompositor.nativeSetHdr(hdr && !SessionState.hdrDisplay) WaylandCompositor.nativeSetDeband(deband, debandStrength) WaylandCompositor.nativeSetScreenEffects(brightness.toFloat(), contrast.toFloat(), gamma, saturation.toFloat(), aaMode, toon, crt, ntsc) WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(this, upscaler)?.name) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/DeviceControlsComponent.kt b/app/src/main/java/com/droiddeck/launcher/runtime/DeviceControlsComponent.kt index 0f5c48ce2..e589c5c8b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/DeviceControlsComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/DeviceControlsComponent.kt @@ -17,6 +17,9 @@ import android.provider.Settings import android.util.Log import com.droiddeck.launcher.core.SessionPart import com.droiddeck.launcher.R +import com.droiddeck.launcher.session.SessionHdr +import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.session.SessionState import java.io.File import java.nio.file.Files import java.nio.file.StandardCopyOption @@ -74,8 +77,10 @@ class DeviceControlsComponent(context: Context, root: File, private val activity val value = Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, 128) write("backlight/droiddeck/brightness", "$value\n") write("backlight/droiddeck/actual_brightness", "$value\n") - val state = JSONObject().put("brightness", (value.coerceIn(1, 255) - 1) / 254.0) - .put("brightnessWritable", Settings.System.canWrite(context)).toString() + val controls = JSONObject().put("brightness", (value.coerceIn(1, 255) - 1) / 254.0) + .put("brightnessWritable", Settings.System.canWrite(context)) + if (SessionState.hdrCapable) controls.put("hdr", SessionState.hdr) + val state = controls.toString() if (force || state != previous) { write("state.json", JSONObject(state).put("revision", ++revision).toString()) previous = state @@ -132,6 +137,9 @@ class DeviceControlsComponent(context: Context, root: File, private val activity audio.setStreamVolume(AudioManager.STREAM_MUSIC, it.coerceIn(0, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)), 0) } + "hdr.request" -> if (text == "0" || text == "1") { + SessionHdr.set(context, SessionPrefs.prefMode(SessionState.mode), text == "1") + } "mute.request" -> if (text == "0" || text == "1") { audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, if (text == "1") AudioManager.ADJUST_MUTE else AudioManager.ADJUST_UNMUTE, 0) @@ -196,7 +204,7 @@ class DeviceControlsComponent(context: Context, root: File, private val activity private const val STREAM_MUTE_CHANGED_ACTION = "android.media.STREAM_MUTE_CHANGED_ACTION" private const val PERMISSION_CHANNEL = "brightness_permission" private const val PERMISSION_NOTIFICATION = 0x4442 - private val REQUESTS = setOf("brightness.request", "volume.request", "mute.request") + private val REQUESTS = setOf("brightness.request", "volume.request", "mute.request", "hdr.request") @JvmStatic fun directory(root: File) = File(root, "etc/droiddeck-device-controls") @JvmStatic fun prepareBacklight(context: Context, root: File): File { val base = File(directory(root), "backlight") diff --git a/app/src/main/java/com/droiddeck/launcher/session/ContentCadence.kt b/app/src/main/java/com/droiddeck/launcher/session/ContentCadence.kt new file mode 100644 index 000000000..a0a5fae49 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/ContentCadence.kt @@ -0,0 +1,65 @@ +package com.droiddeck.launcher.session + +class ContentCadence { + var rate = 0 + private set + private var candidate = 0 + private var streak = 0 + private var misses = 0 + private val reengage = HashMap() + + fun note(fps: Int, panelRates: IntArray): Boolean { + val snapped = snap(fps, panelRates) + if (rate != 0) { + if (snapped == rate) { + misses = 0 + return false + } + if (++misses < RELEASE_SAMPLES) return false + reengage[rate] = minOf((reengage[rate] ?: ENGAGE_SAMPLES) * 2, MAX_ENGAGE_SAMPLES) + rate = 0 + misses = 0 + candidate = snapped + streak = if (snapped > 0) 1 else 0 + return true + } + if (snapped == 0 || snapped != candidate) { + candidate = snapped + streak = if (snapped > 0) 1 else 0 + return false + } + if (++streak < (reengage[snapped] ?: ENGAGE_SAMPLES)) return false + rate = snapped + misses = 0 + return true + } + + fun reset(): Boolean { + val engaged = rate != 0 + rate = 0 + candidate = 0 + streak = 0 + misses = 0 + return engaged + } + + companion object { + const val ENGAGE_SAMPLES = 3 + const val RELEASE_SAMPLES = 3 + const val MAX_ENGAGE_SAMPLES = 30 + private const val MIN_FPS = 20 + private const val MAX_DIVISOR = 6 + + fun snap(fps: Int, panelRates: IntArray): Int { + if (fps < MIN_FPS) return 0 + var best = 0 + for (hz in panelRates) for (divisor in 1..MAX_DIVISOR) { + if (hz % divisor != 0) continue + val step = hz / divisor + val miss = Math.abs(step - fps) + if (miss <= 1 && (best == 0 || miss < Math.abs(best - fps) || (miss == Math.abs(best - fps) && step > best))) best = step + } + return best + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/PerfMode.kt b/app/src/main/java/com/droiddeck/launcher/session/PerfMode.kt index 531f5f460..71e97a9fc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/PerfMode.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/PerfMode.kt @@ -13,15 +13,19 @@ object PerfMode { private const val TAG = "PerfMode" const val BFI_MIN_REFRESH_HZ = 100f - fun apply(a: Activity, fpsLimit: Int = 0, refreshLimit: Int = 0): String { + fun apply(a: Activity, fpsLimit: Int = 0, refreshLimit: Int = 0, requestedRefresh: Int = 0, held: Boolean = false): String { val parts = ArrayList(2) parts += try { val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay - if (display == null || Build.VERSION.SDK_INT < 23) "display mode unchanged" else { + if (display == null || Build.VERSION.SDK_INT < 23) "display mode unchanged" else if (held) { + if (a.window.attributes.preferredDisplayModeId != 0) { + a.window.attributes = a.window.attributes.apply { preferredDisplayModeId = 0 } + } + "display ${display.mode.refreshRate.toInt()} Hz (set by the system)" + } else { val cur = display.mode - val cap = minOf(peakRefreshCap(a), refreshLimit.takeIf { it > 0 }?.toFloat() ?: Float.POSITIVE_INFINITY) - val best = selectMode(display.supportedModes, cur, fpsLimit, cap) + val best = selectMode(display.supportedModes, cur, fpsLimit, refreshCap(a, refreshLimit), requestedRefresh) if (best != null && needsChange(display.supportedModes, a.window.attributes.preferredDisplayModeId, best)) { a.window.attributes = a.window.attributes.apply { preferredDisplayModeId = best.modeId } "display ${cur.refreshRate.toInt()} → ${best.refreshRate.toInt()} Hz (mode ${best.modeId})" @@ -55,12 +59,64 @@ object PerfMode { return if (peak >= 1f) peak else Float.POSITIVE_INFINITY } - internal fun selectMode(modes: Array, current: Display.Mode, fpsLimit: Int, cap: Float): Display.Mode? { + private fun refreshCap(context: Context, refreshLimit: Int): Float = + minOf(peakRefreshCap(context), refreshLimit.takeIf { it > 0 }?.toFloat() ?: Float.POSITIVE_INFINITY) + + fun panelRates(a: Activity, refreshLimit: Int = 0, held: Boolean = false): IntArray = try { + val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay + if (display == null || Build.VERSION.SDK_INT < 23) IntArray(0) + else panelRates(display.supportedModes, display.mode, refreshCap(a, refreshLimit), held) + } catch (t: Throwable) { Log.w(TAG, "panel rates", t); IntArray(0) } + + internal fun panelRates(modes: Array, current: Display.Mode, cap: Float, held: Boolean = false): IntArray = + if (held) intArrayOf(Math.round(current.refreshRate)) + else allowedModes(modes, current, cap).map { Math.round(it.refreshRate) }.distinct().sorted().toIntArray() + + fun panelHeld(a: Activity): Boolean = try { + val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay + val wanted = a.window.attributes.preferredDisplayModeId + val requested = display?.supportedModes?.firstOrNull { wanted != 0 && it.modeId == wanted } + display != null && requested != null && panelHeld(requested.refreshRate, display.mode.refreshRate) + } catch (t: Throwable) { Log.w(TAG, "panel held", t); false } + + internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean = + requestedHz > 1f && activeHz > 1f && Math.abs(requestedHz - activeHz) > 0.5f + + fun pacedRate(ownLimit: Int, limiterRate: Int, limiterRefresh: Int, steadyRate: Int): Int = when { + ownLimit > 0 -> ownLimit + limiterRate <= 0 -> steadyRate + steadyRate <= 0 || limiterRate < limiterRefresh || limiterRefresh <= 0 -> limiterRate + cadenceFits(limiterRate.toFloat(), steadyRate) -> limiterRate + else -> steadyRate + } + + fun contentRate(fps: Int, frameGenFactor: Int, frameGenTarget: Int): Int = when { + frameGenFactor <= 1 -> fps + frameGenTarget > 0 -> frameGenTarget + else -> fps * frameGenFactor + } + + private fun allowedModes(modes: Array, current: Display.Mode, cap: Float): List = + modes.filter { + it.physicalWidth == current.physicalWidth && it.physicalHeight == current.physicalHeight && + it.refreshRate <= cap + 0.5f + } + + internal fun selectMode( + modes: Array, + current: Display.Mode, + fpsLimit: Int, + cap: Float, + requestedRefresh: Int = 0, + ): Display.Mode? { val sameSize = modes.filter { it.physicalWidth == current.physicalWidth && it.physicalHeight == current.physicalHeight } - val allowed = sameSize.filter { it.refreshRate <= cap + 0.5f } - return allowed.filter { cadenceFits(it.refreshRate, fpsLimit) }.maxByOrNull { it.refreshRate } + val allowed = allowedModes(modes, current, cap) + val requested = if (fpsLimit > 0 || requestedRefresh <= 0) null else allowed + .filter { it.refreshRate >= requestedRefresh - 0.5f }.minByOrNull { it.refreshRate } + return requested + ?: allowed.filter { cadenceFits(it.refreshRate, fpsLimit) }.maxByOrNull { it.refreshRate } ?: allowed.maxByOrNull { it.refreshRate } ?: sameSize.minByOrNull { it.refreshRate } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionHdr.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionHdr.kt new file mode 100644 index 000000000..e559ac4ff --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionHdr.kt @@ -0,0 +1,36 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import com.droiddeck.launcher.agent.AgentGuest +import com.droiddeck.launcher.wayland.CompositorHost +import com.droiddeck.launcher.wayland.WaylandCompositor +import java.util.concurrent.Executors + +object SessionHdr { + private const val RETRIES = 5 + private const val RETRY_MS = 2_000L + + private val requests = Executors.newSingleThreadExecutor { runnable -> + Thread(runnable, "session-hdr").apply { isDaemon = true } + } + @Volatile private var wanted = false + + fun set(context: Context, mode: String, on: Boolean) { + SessionPrefs.setHdr(context, mode, on) + if (!SessionState.running || !SessionState.hdrCapable || !CompositorHost.isStarted) return + if (SessionPrefs.prefMode(SessionState.mode) != mode) return + SessionState.hdr = on + wanted = on + WaylandCompositor.nativeSetHdrOutput(on) + WaylandCompositor.nativeSetZeroCopy(on || SessionPrefs.zeroCopy(context, mode)) + val app = context.applicationContext + val session = SessionState.sessionId + requests.execute { + var tries = 0 + while (wanted == on && SessionState.running && SessionState.sessionId == session && + !AgentGuest.setGamescopeConvar(app, "hdr_enabled", if (on) 1 else 0) && tries++ < RETRIES) { + try { Thread.sleep(RETRY_MS) } catch (e: InterruptedException) { return@execute } + } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 2c87bb86c..ab258b95c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -1620,10 +1620,18 @@ object SessionPrefs { return Pair(w and 1.inv(), h and 1.inv()) } - fun hdr(context: Context, mode: String): Boolean = prefs(context).getBoolean("hdr.$mode", false) + fun hdrKey(mode: String): String = "hdr.$mode" + + fun hdr(context: Context, mode: String): Boolean = prefs(context).getBoolean(hdrKey(mode), false) fun setHdr(context: Context, mode: String, on: Boolean) { - prefs(context).edit().putBoolean("hdr.$mode", on).apply() + prefs(context).edit().putBoolean(hdrKey(mode), on).apply() + } + + fun zeroCopy(context: Context, mode: String): Boolean = prefs(context).getBoolean("zeroCopy.$mode", true) + + fun setZeroCopy(context: Context, mode: String, on: Boolean) { + prefs(context).edit().putBoolean("zeroCopy.$mode", on).apply() } const val FPS_UNPACED = -1 diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 285f6b7c0..5d7873001 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1025,6 +1025,9 @@ class SessionService : Service() { if (!bridge && !venus && SystemVulkanDriver.usesDefault(linuxDriverId)) { SystemVulkanDriver.addEnvironment(this, guest) } + com.droiddeck.launcher.wayland.WaylandCompositor.nativeSetDisplayBufferDriver( + !bridge && !venus && LinuxVulkanDriverManager(this).rendersToDisplayBuffers(linuxDriverId), + ) (if (bridge || venus) null else LinuxVulkanDriver.resolveIcdPath(this, linuxDriverId)) ?.let { guest.add(LinuxVulkanDriver.ENV + "=" + it) } if (!com.droiddeck.launcher.core.DeviceSupport.adreno() && lastXwaylandCrashed()) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt index 612494715..847ed340b 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt @@ -115,6 +115,10 @@ object SessionState { @JvmStatic var hdr = false + @JvmStatic var hdrCapable = false + + @JvmStatic var hdrDisplay = false + @Volatile private var deckPadValue = false @JvmStatic var deckPad: Boolean get() = deckPadValue diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 1cc039338..f871406fc 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -59,6 +59,8 @@ class ModeSettings( val panelSize: Pair = 1280 to 720, val hdr: Boolean, val hdrReason: String?, + val hdrDisplay: Boolean = true, + val zeroCopy: Boolean = true, val gpuDrivers: String? = null, val upscaler: Int = 0, val upscaleSharpness: Int = 75, @@ -114,6 +116,7 @@ class ModeSettings( class ModeSettingsActions( val onResolution: (String) -> Unit, val onHdr: (Boolean) -> Unit, + val onZeroCopy: (Boolean) -> Unit = {}, val onGpuDrivers: () -> Unit = {}, val onUpscaler: (Int) -> Unit = {}, val onUpscaleSharpness: (Int) -> Unit = {}, @@ -250,6 +253,7 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: listOf(false to stringResource(R.string.display_preserve), true to stringResource(R.string.display_stretch)), s.stretch16x9 && canStretch, enabled = canStretch, onPick = a.onStretch16x9) } + ToggleRow(host, "zero-copy", stringResource(R.string.display_zero_copy), null, checked = s.zeroCopy, onChange = a.onZeroCopy) } SettingsGroup(stringResource(R.string.display_image_scaling)) { s.integerScaling?.let { enabled -> @@ -276,9 +280,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: } SettingsGroup(stringResource(R.string.mode_hdr)) { ToggleRow( - host, "hdr", stringResource(R.string.mode_hdr10), - s.hdrReason?.let { stringResource(R.string.mode_hdr_unavailable, it) } - ?: stringResource(R.string.mode_hdr_restart), + host, "hdr", stringResource(if (s.hdrDisplay) R.string.mode_hdr10 else R.string.drawer_fake_hdr), + s.hdrReason?.let { stringResource(R.string.mode_hdr_unavailable, it) }, checked = s.hdr && s.hdrReason == null, enabled = s.hdrReason == null, onChange = a.onHdr, ) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 09e169e73..9c244b930 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -281,6 +281,9 @@ class DrawerActions( val blackFrameInsertion: Boolean = false, val blackFrameInsertionAvailable: Boolean = false, val onBlackFrameInsertion: (Boolean) -> Unit = {}, + val hdr: Boolean = false, + val hdrAvailable: Boolean = false, + val onHdr: (Boolean) -> Unit = {}, val onImportLossless: () -> Unit, val onKeyboard: () -> Unit, val onHardwareKeyboard: () -> Unit, @@ -1161,7 +1164,9 @@ private fun ScreenEffectsGroup( ToggleRow(host, "toon", stringResource(R.string.drawer_toon), null, e.toon, chipModifier = track("toon")) { a.onEffects(e.copy(toon = it)) } ToggleRow(host, "crt", stringResource(R.string.drawer_crt), null, e.crt, chipModifier = track("crt")) { a.onEffects(e.copy(crt = it)) } ToggleRow(host, "ntsc", stringResource(R.string.drawer_ntsc), null, e.ntsc, chipModifier = track("ntsc")) { a.onEffects(e.copy(ntsc = it)) } - ToggleRow(host, "fake-hdr", stringResource(R.string.drawer_fake_hdr), null, e.hdr, chipModifier = track("fake-hdr")) { a.onEffects(e.copy(hdr = it)) } + if (a.hdrAvailable) ToggleRow(host, "hdr", stringResource(R.string.mode_hdr), null, a.hdr, + chipModifier = track("hdr"), onChange = a.onHdr) + else ToggleRow(host, "fake-hdr", stringResource(R.string.drawer_fake_hdr), null, e.hdr, chipModifier = track("fake-hdr")) { a.onEffects(e.copy(hdr = it)) } if (a.blackFrameInsertionAvailable) ToggleRow(host, "bfi", stringResource(R.string.drawer_bfi), stringResource(R.string.drawer_bfi_note), a.blackFrameInsertion, chipModifier = track("bfi"), onChange = a.onBlackFrameInsertion) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt index 135cd79a6..9f9c1b4a4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt @@ -137,7 +137,7 @@ internal object SettingsIndex { SettingsEntry(SettingsPlace.STEAM_QAM, R.string.drawer_frame_limit, R.string.perf_title, words = listOf("fps", "cap", "limit", "steam games")), SettingsEntry(SettingsPlace.STEAM_QAM, R.string.perf_title, words = listOf("performance overlay", "fps", "counter", "tdp")), - sh(R.string.drawer_page_display, R.string.display_session, "resolution", "scaling", "hdr", "refresh"), + sh(R.string.drawer_page_display, R.string.display_session, "resolution", "scaling", "hdr", "refresh", "zero-copy"), sh(R.string.drawer_page_display, R.string.sheet_graphics_drivers, "turnip", "driver", "gpu", "adreno", "mali"), sh(R.string.mode_tab_steam, R.string.setup_offline, "offline", "steam"), sh(R.string.mode_audio, R.string.mode_mic, "microphone", "voice"), diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt index 4ad426316..8d43d09c7 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.wayland +import android.os.Build import android.os.Handler import android.os.HandlerThread import android.os.Process @@ -29,11 +30,28 @@ object CompositorHost { @Volatile private var vsyncGeneration = 0 - private fun vsyncCallback(generation: Int) = object : Choreographer.FrameCallback { - override fun doFrame(frameTimeNanos: Long) { - if (generation != vsyncGeneration) return + private fun postVsync(generation: Int) { + val choreographer = Choreographer.getInstance() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + choreographer.postVsyncCallback { data -> + if (generation != vsyncGeneration) return@postVsyncCallback + val lines = data.frameTimelines + val line = data.preferredFrameTimeline + val period = if (lines.size > 1) { + lines[1].expectedPresentationTimeNanos - lines[0].expectedPresentationTimeNanos + } else { + 0L + } + WaylandCompositor.nativeFrameTimeline(line.expectedPresentationTimeNanos, line.deadlineNanos, period) + WaylandCompositor.nativeVsync(data.frameTimeNanos) + if (vsyncRunning) postVsync(generation) + } + return + } + choreographer.postFrameCallback { frameTimeNanos -> + if (generation != vsyncGeneration) return@postFrameCallback WaylandCompositor.nativeVsync(frameTimeNanos) - if (vsyncRunning) Choreographer.getInstance().postFrameCallback(this) + if (vsyncRunning) postVsync(generation) } } @@ -149,14 +167,14 @@ object CompositorHost { private fun resumeVsync() { if (vsyncRunning) return - val callback = vsyncCallback(++vsyncGeneration) + val generation = ++vsyncGeneration vsyncRunning = true WaylandCompositor.nativeLog("screen", if (ownVsyncThread) "screen tick runs on its own display-priority thread" else "screen tick runs on the main thread") if (!ownVsyncThread) { - Choreographer.getInstance().postFrameCallback(callback) + postVsync(generation) return } - vsyncHandler.post { Choreographer.getInstance().postFrameCallback(callback) } + vsyncHandler.post { postVsync(generation) } } private fun pauseVsync() { diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/HdrSupport.kt b/app/src/main/java/com/droiddeck/launcher/wayland/HdrSupport.kt index 91f408d91..0a5cb88be 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/HdrSupport.kt +++ b/app/src/main/java/com/droiddeck/launcher/wayland/HdrSupport.kt @@ -48,8 +48,11 @@ object HdrSupport { ) } + fun blocked(context: Context): String? = + if (Build.VERSION.SDK_INT < 29) context.getString(R.string.hdr_needs_android_10) else null + private fun reason(context: Context, hdr10: Boolean, formats: String): String? = when { - Build.VERSION.SDK_INT < 29 -> context.getString(R.string.hdr_needs_android_10) + Build.VERSION.SDK_INT < 29 -> blocked(context) !hdr10 -> if (formats.isEmpty()) context.getString(R.string.hdr_none) else context.getString(R.string.hdr_not_hdr10, formats) else -> null } diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java index 874493e41..81543e6d1 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java +++ b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java @@ -94,6 +94,73 @@ public final class WaylandCompositor { if (l != null) l.onPointerLock(locked, x, y); } + public interface OverlayPlanesListener { + void onOverlayPlanes(int planes); + } + + private static volatile OverlayPlanesListener overlayPlanesListener; + private static volatile int overlayPlanes = -1; + + public static synchronized void setOverlayPlanesListener(OverlayPlanesListener l) { + overlayPlanesListener = l; + if (l != null) l.onOverlayPlanes(overlayPlanes); + } + + public static synchronized void clearOverlayPlanesListener(OverlayPlanesListener l) { + if (overlayPlanesListener == l) overlayPlanesListener = null; + } + + @SuppressWarnings("unused") + static synchronized void onOverlayPlanes(int planes) { + overlayPlanes = planes; + OverlayPlanesListener l = overlayPlanesListener; + if (l != null) l.onOverlayPlanes(planes); + } + + public interface RefreshTargetListener { + void onRefreshTarget(int refresh, int frameRate); + } + + private static volatile RefreshTargetListener refreshTargetListener; + private static volatile long refreshTarget; + + public static void setRefreshTargetListener(RefreshTargetListener l) { + refreshTargetListener = l; + long target = refreshTarget; + if (l != null) l.onRefreshTarget((int) (target >> 32), (int) target); + } + + public static void clearRefreshTargetListener(RefreshTargetListener l) { + if (refreshTargetListener == l) refreshTargetListener = null; + } + + public interface ContentRateListener { + void onContentRate(int fps); + } + + private static volatile ContentRateListener contentRateListener; + + public static void setContentRateListener(ContentRateListener l) { + contentRateListener = l; + } + + public static void clearContentRateListener(ContentRateListener l) { + if (contentRateListener == l) contentRateListener = null; + } + + @SuppressWarnings("unused") + static void onContentRate(int fps) { + ContentRateListener l = contentRateListener; + if (l != null) l.onContentRate(fps); + } + + @SuppressWarnings("unused") + static void onRefreshTarget(int refresh, int frameRate) { + refreshTarget = ((long) refresh << 32) | (frameRate & 0xffffffffL); + RefreshTargetListener l = refreshTargetListener; + if (l != null) l.onRefreshTarget(refresh, frameRate); + } + public interface ClipboardListener { void onGuestClipboardText(String text); } @@ -180,6 +247,8 @@ public final class WaylandCompositor { public static native void nativeVsync(long frameTimeNanos); + public static native void nativeFrameTimeline(long presentNanos, long deadlineNanos, long periodNanos); + public static native void nativeSetClockControl(String path); public static native int nativeCompositorTid(); @@ -210,8 +279,12 @@ public final class WaylandCompositor { public static native void nativeSetOutputRefreshRate(float hz); + public static native void nativeSetPanelRates(int[] rates); + public static native void nativeSetZeroCopy(boolean on); + public static native void nativeSetDisplayBufferDriver(boolean on); + public static native int nativeZeroCopyFrames(); public static native int nativeZeroCopyLastFrameAgeMs(); @@ -247,7 +320,7 @@ public final class WaylandCompositor { public static native void nativeResetFirstFrame(); - public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2; + public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2, HDR_MODE_TONEMAP = 3; public static native void nativeSetHdrRequest(int mode, String source, boolean dxvkHdr, boolean zeroCopyForced); diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 643394391..f9d6d205b 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -281,7 +281,6 @@ HDR إخراج HDR10 غير متاح: %1$s. - أعد تشغيل التطبيق لتطبيق التغيير. برامج التشغيل برامج تشغيل GPU مشتركة بين Steam وسطح المكتب. يتم ضبطها في صفحة «المكوّنات». @@ -2565,6 +2564,7 @@ Android + Linux %1$s. %2$s\n\n%3$s شاشة الجلسة + العرض بدون نسخ الدقة ملاءمة اللعبة لنسبة 16:9 كيفية ملاءمة ألعاب 16:9 لهذه الشاشة. يُطبَّق في الجلسة التالية. diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 922b1407f..194e5d3af 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -281,7 +281,6 @@ HDR Salida HDR10 No disponible: %1$s. - Reinicia la app para aplicarlo. Controladores Controladores de GPU Compartidos por Steam y Escritorio. Se definen en la página Componentes. @@ -2557,6 +2556,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Pantalla de la sesión + Presentación sin copia Resolución Ajuste de juegos 16:9 Cómo se ajustan los juegos 16:9 a esta pantalla. Próxima sesión. diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 57566ec95..03ba45f84 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 изход Не е налично: %1$s. - Рестартирайте приложението, за да се приложи. Драйвери GPU драйвери Общи за Steam и работния плот. Задават се в страницата Компоненти. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Екран на сесията + Представяне без копиране Разделителна способност Напасване на игра 16:9 Как игрите с 16:9 се напасват на този екран. При следващата сесия. diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index c2b89c6e1..246926fff 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -281,7 +281,6 @@ HDR Výstup HDR10 Není k dispozici: %1$s. - Pro použití restartujte aplikaci. Ovladače Ovladače GPU Společné pro Steam a Plochu. Nastavuje se na stránce Komponenty. @@ -2513,6 +2512,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Obrazovka relace + Zobrazení bez kopírování Rozlišení Přizpůsobení hry 16:9 Jak se hry s poměrem 16:9 přizpůsobí této obrazovce. Příští relace. diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 67037ab95..dc190f6e6 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-output Ikke tilgængelig: %1$s. - Genstart appen for at anvende ændringen. Drivere GPU-drivere Delt mellem Steam og Skrivebord. Indstilles på siden Komponenter. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Sessionsskærm + Præsentation uden kopiering Opløsning 16:9-spiltilpasning Hvordan 16:9-spil tilpasses denne skærm. Fra næste session. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c913e57c7..3f42bc4e2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-Ausgabe Nicht verfügbar: %1$s. - Starte die App neu, um dies anzuwenden. Treiber GPU-Treiber Für Steam und Desktop gemeinsam. Wird auf der Seite „Komponenten“ festgelegt. @@ -2453,6 +2452,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Sitzungsanzeige + Kopierfreie Darstellung Auflösung 16:9-Spielanpassung Wie 16:9-Spiele auf dieses Display passen. Ab der nächsten Sitzung. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index c1e1ffcb7..6cce64d9c 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -281,7 +281,6 @@ HDR Έξοδος HDR10 Μη διαθέσιμο: %1$s. - Κάντε επανεκκίνηση της εφαρμογής για να εφαρμοστεί. Προγράμματα οδήγησης Προγράμματα οδήγησης GPU Κοινά για το Steam και την Επιφάνεια εργασίας. Ορίζονται στη σελίδα Στοιχεία. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Οθόνη συνεδρίας + Παρουσίαση χωρίς αντιγραφή Ανάλυση Προσαρμογή παιχνιδιού 16:9 Πώς προσαρμόζονται τα παιχνίδια 16:9 σε αυτή την οθόνη. Από την επόμενη συνεδρία. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 124192c1a..ac6c6d894 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -281,7 +281,6 @@ HDR Salida HDR10 No disponible: %1$s. - Reinicia la app para aplicarlo. Controladores Controladores de GPU Compartidos por Steam y Escritorio. Se definen en la página Componentes. @@ -2487,6 +2486,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Pantalla de la sesión + Presentación sin copia Resolución Ajuste de juegos 16:9 Cómo se ajustan los juegos 16:9 a esta pantalla. Próxima sesión. diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 2d7ea36c7..8164624f8 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-lähtö Ei käytettävissä: %1$s. - Käynnistä sovellus uudelleen, jotta muutos tulee voimaan. Ajurit GPU-ajurit Jaettu Steamin ja Työpöydän kesken. Asetetaan Komponentit-sivulla. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Istunnon näyttö + Kopioimaton esitys Tarkkuus 16:9-pelin sovitus Miten 16:9-pelit sovitetaan tähän näyttöön. Seuraava istunto. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f21ab1e3a..1743a855e 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -281,7 +281,6 @@ HDR Sortie HDR10 Non disponible : %1$s. - Prendra effet après le redémarrage de l\'application. Pilotes Pilotes GPU Partagés entre Steam et le bureau. À configurer dans la page « Composants ». @@ -2486,6 +2485,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Affichage de la session + Affichage sans copie Résolution Ajustement des jeux 16:9 Comment les jeux 16:9 s\'adaptent à cet écran. À la prochaine session. diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index d322fa0d0..01ad1e44d 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 आउटपुट उपलब्ध नहीं: %1$s। - लागू करने के लिए ऐप रीस्टार्ट करें। ड्राइवर GPU ड्राइवर Steam और डेस्कटॉप दोनों में साझा। Components पेज पर सेट करें। @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s। %2$s\n\n%3$s सेशन डिस्प्ले + बिना कॉपी प्रस्तुति रिज़ॉल्यूशन 16:9 गेम फ़िट 16:9 गेम इस डिस्प्ले में कैसे फ़िट होते हैं। अगले सेशन से। diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 4f7ad2c7c..ab299b122 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-kimenet Nem elérhető: %1$s. - Indítsa újra az alkalmazást az érvényesítéshez. Illesztőprogramok GPU-illesztőprogramok A Steam és az Asztal közösen használja. Az Összetevők oldalon állítható be. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Munkamenet kijelzője + Másolásmentes megjelenítés Felbontás 16:9 játék illesztése Hogyan illeszkednek a 16:9 játékok ehhez a kijelzőhöz. A következő munkamenettől. diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 4ea3788f5..23a49ce8d 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -281,7 +281,6 @@ HDR Output HDR10 Tidak tersedia: %1$s. - Mulai ulang aplikasi untuk menerapkannya. Driver Driver GPU Digunakan bersama oleh Steam dan Desktop. Diatur di halaman Komponen. @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Tampilan sesi + Presentasi tanpa salin Resolusi Penyesuaian gim 16:9 Cara gim 16:9 disesuaikan dengan tampilan ini. Berlaku pada sesi berikutnya. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 4e7fdf08d..7e6909e99 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -281,7 +281,6 @@ HDR Uscita HDR10 Non disponibile: %1$s. - Riavvia l\'app per applicare. Driver Driver GPU Condivisi da Steam e Desktop. Si impostano nella pagina Componenti. @@ -2478,6 +2477,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Schermo della sessione + Presentazione senza copia Risoluzione Adattamento giochi 16:9 Come i giochi 16:9 si adattano a questo schermo. Dalla prossima sessione. diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index e74e3e706..a9927cc1c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -281,7 +281,6 @@ HDR HDR10出力 利用不可:%1$s。 - アプリの再起動後に有効になります。 ドライバー GPUドライバー Steamとデスクトップで共有されます。「コンポーネント」ページで設定してください。 @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s。%2$s\n\n%3$s セッションの表示 + ゼロコピー表示 解像度 16:9ゲームの表示 16:9のゲームをこのディスプレイにどう合わせるか。次回のセッションから。 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 557cabab2..aba825df8 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 출력 사용 불가: %1$s. - 앱을 다시 시작한 후 적용됩니다. 드라이버 GPU 드라이버 Steam과 데스크톱에서 공유됩니다. \"구성 요소\" 페이지에서 설정하세요. @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s 세션 디스플레이 + 제로카피 표시 해상도 16:9 게임 맞춤 16:9 게임을 이 디스플레이에 맞추는 방식입니다. 다음 세션부터 적용됩니다. diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 168ceaa97..21f75a28c 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -281,7 +281,6 @@ HDR Output HDR10 Tidak tersedia: %1$s. - Mulakan semula apl untuk menggunakannya. Pemacu Pemacu GPU Dikongsi oleh Steam dan Desktop. Ditetapkan pada halaman Komponen. @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Paparan sesi + Paparan tanpa salinan Resolusi Suaian permainan 16:9 Cara permainan 16:9 disuaikan ke paparan ini. Sesi seterusnya. diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index e5115e83a..f4772e7a0 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-utgang Ikke tilgjengelig: %1$s. - Start appen på nytt for å bruke dette. Drivere GPU-drivere Delt av Steam og Skrivebord. Angis på Komponenter-siden. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Sesjonsskjerm + Presentasjon uten kopiering Oppløsning 16:9-spilltilpasning Hvordan 16:9-spill tilpasses denne skjermen. Fra neste sesjon. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 9151d3b21..9292a1a56 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-uitvoer Niet beschikbaar: %1$s. - Start de app opnieuw om dit toe te passen. Drivers GPU-drivers Gedeeld door Steam en Desktop. In te stellen op de pagina Componenten. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Sessiescherm + Weergave zonder kopie Resolutie 16:9-beeldvulling Hoe 16:9-games dit scherm vullen. Volgende sessie. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 31742655a..12a3bed38 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -281,7 +281,6 @@ HDR Wyjście HDR10 Niedostępne: %1$s. - Uruchom ponownie aplikację, aby zastosować. Sterowniki Sterowniki GPU Wspólne dla Steam i pulpitu. Ustawiane na stronie Komponenty. @@ -2513,6 +2512,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Ekran sesji + Prezentacja bez kopiowania Rozdzielczość Dopasowanie gier 16:9 Jak gry 16:9 mieszczą się na tym ekranie. Od następnej sesji. diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index a5745195b..39c9526f1 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -281,7 +281,6 @@ HDR Saída HDR10 Indisponível: %1$s. - Reinicie a app para aplicar. Controladores Controladores da GPU Partilhados pelo Steam e pelo Ambiente de trabalho. Defina-os na página Componentes. @@ -2492,6 +2491,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Ecrã da sessão + Apresentação sem cópia Resolução Ajuste de jogos 16:9 Como os jogos 16:9 se ajustam a este ecrã. Próxima sessão. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index f5eca4b04..80bbc786f 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -281,7 +281,6 @@ HDR Saída HDR10 Indisponível: %1$s. - Reinicie o app para aplicar. Drivers Drivers de GPU Compartilhados pela Steam e pela Área de trabalho. Defina na página Componentes. @@ -2500,6 +2499,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Tela da sessão + Apresentação sem cópia Resolução Ajuste de jogos 16:9 Como os jogos 16:9 se ajustam a esta tela. Na próxima sessão. diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index cc7a55a18..a4cc2e943 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -281,7 +281,6 @@ HDR Ieșire HDR10 Indisponibil: %1$s. - Repornește aplicația pentru a aplica. Drivere Drivere GPU Partajate de Steam și Desktop. Se stabilesc pe pagina Componente. @@ -2487,6 +2486,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Afișajul sesiunii + Prezentare fără copiere Rezoluție Potrivire joc 16:9 Cum se potrivesc jocurile 16:9 cu acest afișaj. Sesiunea următoare. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a5f31948a..6e403bc05 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -281,7 +281,6 @@ HDR Вывод HDR10 Недоступно: %1$s. - Вступит в силу после перезапуска приложения. Драйверы Драйверы GPU Общие для Steam и рабочего стола. Настройте на странице «Компоненты». @@ -2513,6 +2512,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Экран сессии + Вывод без копирования Разрешение Игры 16:9 Как игры 16:9 вписываются в этот экран. Вступит в силу в следующей сессии. diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 9bc129df9..588673ab1 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -281,7 +281,6 @@ HDR HDR10-utgång Inte tillgängligt: %1$s. - Starta om appen för att tillämpa. Drivrutiner GPU-drivrutiner Delas av Steam och skrivbordet. Ställs in på sidan Komponenter. @@ -2461,6 +2460,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Sessionsskärm + Presentation utan kopiering Upplösning 16:9-spelanpassning Hur 16:9-spel anpassas till den här skärmen. Nästa session. diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 2402c15f8..8706c82ef 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -281,7 +281,6 @@ HDR เอาต์พุต HDR10 ไม่พร้อมใช้งาน: %1$s - รีสตาร์ทแอปเพื่อให้มีผล ไดรเวอร์ ไดรเวอร์ GPU ใช้ร่วมกันระหว่าง Steam และเดสก์ท็อป ตั้งค่าได้ที่หน้า Components @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s %2$s\n\n%3$s การแสดงผลของเซสชัน + การแสดงผลแบบไม่คัดลอก ความละเอียด การแสดงเกม 16:9 ให้พอดี วิธีที่เกม 16:9 แสดงพอดีกับหน้าจอนี้ มีผลในเซสชันถัดไป diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index bdcb3b8b0..b9bc2ab81 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 çıkışı Kullanılamıyor: %1$s. - Uygulamak için uygulamayı yeniden başlatın. Sürücüler GPU sürücüleri Steam ve Masaüstü tarafından paylaşılır. Bileşenler sayfasından ayarlanır. @@ -2453,6 +2452,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Oturum ekranı + Kopyasız sunum Çözünürlük 16:9 oyun sığdırma 16:9 oyunların bu ekrana nasıl sığacağı. Sonraki oturumda. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 625916040..2c8caec50 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -281,7 +281,6 @@ HDR Вивід HDR10 Недоступно: %1$s. - Перезапустіть додаток, щоб застосувати. Драйвери Драйвери GPU Спільні для Steam і робочого столу. Налаштовуються на сторінці «Компоненти». @@ -2513,6 +2512,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Дисплей сеансу + Показ без копіювання Роздільна здатність Вписування гри 16:9 Як ігри 16:9 вписуються в цей дисплей. З наступного сеансу. diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 424ff42df..7c1a384f3 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -281,7 +281,6 @@ HDR Xuất HDR10 Không khả dụng: %1$s. - Khởi động lại ứng dụng để áp dụng. Driver Driver GPU Dùng chung cho Steam và Desktop. Đặt ở trang Components. @@ -2436,6 +2435,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Hiển thị phiên + Hiển thị không sao chép Độ phân giải Khớp game 16:9 Cách game 16:9 khớp với màn hình này. Từ phiên sau. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4343a946b..b2085b286 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 输出 不可用:%1$s。 - 重启应用以生效。 驱动 GPU 驱动 由 Steam 和桌面共享。在“组件”页面设置。 @@ -2513,6 +2512,7 @@ Android + Linux %1$s。%2$s\n\n%3$s 会话显示 + 零拷贝呈现 分辨率 16:9 游戏适配 16:9 游戏如何适配此屏幕。下次会话生效。 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 71ec80c4d..84d53e734 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 輸出 不可用:%1$s。 - 重新啟動應用程式後生效。 驅動程式 GPU 驅動程式 Steam 和桌面共用,請在「組件」頁面設定。 @@ -2433,6 +2432,7 @@ ANDROID + LINUX %1$s。%2$s\n\n%3$s 會話顯示 + 零複製呈現 解像度 16:9 遊戲顯示方式 16:9 遊戲如何配合此螢幕。下次會話生效。 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 105d095c9..0d1092700 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -281,7 +281,6 @@ HDR HDR10 輸出 無法使用:%1$s。 - 重新啟動應用程式後生效。 驅動程式 GPU 驅動程式 Steam 和桌面共用。請在「元件」頁面設定。 @@ -2433,6 +2432,7 @@ ANDROID + LINUX %1$s。%2$s\n\n%3$s 工作階段顯示 + 零複製呈現 解析度 16:9 遊戲顯示方式 16:9 遊戲如何配合此螢幕。下次工作階段生效。 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2e6d905e..8d3d519ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -309,7 +309,6 @@ HDR HDR10 output Not available: %1$s. - Restart the app to apply. Drivers GPU drivers Shared by Steam and Desktop. Set on the Components page. @@ -2716,6 +2715,7 @@ ANDROID + LINUX %1$s. %2$s\n\n%3$s Session display + Zero-copy presentation Resolution 16:9 game fit How 16:9 games fit this display. Next session. diff --git a/app/src/test/java/com/droiddeck/launcher/session/ContentCadenceTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ContentCadenceTest.kt new file mode 100644 index 000000000..2cb2e42fd --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/ContentCadenceTest.kt @@ -0,0 +1,84 @@ +package com.droiddeck.launcher.session + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class ContentCadenceTest { + private val rates = intArrayOf(60, 90, 120, 144) + + @Test + fun aMeasuredRateSnapsToAStepAPanelRateDividesInto() { + assertEquals(45, ContentCadence.snap(44, rates)) + assertEquals(48, ContentCadence.snap(49, rates)) + assertEquals(72, ContentCadence.snap(72, rates)) + assertEquals(60, ContentCadence.snap(61, rates)) + assertEquals(0, ContentCadence.snap(53, rates)) + assertEquals(0, ContentCadence.snap(12, rates)) + assertEquals(0, ContentCadence.snap(45, intArrayOf(60))) + } + + @Test + fun aSteadyRateEngagesOnlyAfterItHolds() { + val cadence = ContentCadence() + assertFalse(cadence.note(45, rates)) + assertFalse(cadence.note(44, rates)) + assertEquals(0, cadence.rate) + assertTrue(cadence.note(45, rates)) + assertEquals(45, cadence.rate) + } + + @Test + fun aWanderingRateNeverEngages() { + val cadence = ContentCadence() + for (fps in intArrayOf(45, 53, 60, 71, 48, 45, 66, 45, 45, 58)) assertFalse(cadence.note(fps, rates)) + assertEquals(0, cadence.rate) + } + + @Test + fun oneOffSampleDoesNotReleaseAnEngagedRate() { + val cadence = ContentCadence() + repeat(3) { cadence.note(72, rates) } + assertFalse(cadence.note(55, rates)) + assertFalse(cadence.note(72, rates)) + assertFalse(cadence.note(51, rates)) + assertFalse(cadence.note(53, rates)) + assertEquals(72, cadence.rate) + assertTrue(cadence.note(55, rates)) + assertEquals(0, cadence.rate) + } + + @Test + fun aRateThatWasReleasedMustHoldLongerToEngageAgain() { + val cadence = ContentCadence() + repeat(3) { cadence.note(45, rates) } + repeat(3) { cadence.note(57, rates) } + assertEquals(0, cadence.rate) + repeat(5) { assertFalse(cadence.note(45, rates)) } + assertTrue(cadence.note(45, rates)) + assertEquals(45, cadence.rate) + } + + @Test + fun aReleasedRateDoesNotDelayARateThatWasNeverReleased() { + val cadence = ContentCadence() + repeat(3) { cadence.note(45, rates) } + repeat(3) { cadence.note(57, rates) } + assertEquals(0, cadence.rate) + repeat(2) { assertFalse(cadence.note(60, rates)) } + assertTrue(cadence.note(60, rates)) + assertEquals(60, cadence.rate) + } + + @Test + fun aResetDropsTheEngagedRateAndReportsTheChangeOnce() { + val cadence = ContentCadence() + repeat(3) { cadence.note(60, rates) } + assertTrue(cadence.reset()) + assertEquals(0, cadence.rate) + assertFalse(cadence.reset()) + repeat(2) { assertFalse(cadence.note(60, rates)) } + assertTrue(cadence.note(60, rates)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/PerfModeTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PerfModeTest.kt index 3a7dff017..1bd7ed344 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/PerfModeTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/PerfModeTest.kt @@ -56,4 +56,64 @@ class PerfModeTest { assertTrue(PerfMode.needsChange(modes, 0, oneTwenty)) assertTrue(PerfMode.needsChange(modes, 99, oneTwenty)) } + + @Test fun aGuestFrameRateChoosesTheHighestPanelRateItDividesEvenly() { + val modes = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f), mode(4, 144f)) + val current = modes[3] + assertEquals(modes[2], PerfMode.selectMode(modes, current, 60, Float.POSITIVE_INFINITY, 120)) + assertEquals(modes[2], PerfMode.selectMode(modes, current, 40, Float.POSITIVE_INFINITY, 120)) + assertEquals(modes[1], PerfMode.selectMode(modes, current, 45, Float.POSITIVE_INFINITY, 90)) + assertEquals(modes[3], PerfMode.selectMode(modes, current, 72, Float.POSITIVE_INFINITY, 144)) + assertEquals(modes[3], PerfMode.selectMode(modes, current, 50, Float.POSITIVE_INFINITY, 144)) + } + + @Test fun frameGenerationRaisesThePanelRateToItsOutputRate() { + val modes = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f), mode(4, 144f)) + val current = modes[0] + assertEquals(120, PerfMode.contentRate(60, 2, 0)) + assertEquals(60, PerfMode.contentRate(60, 1, 0)) + assertEquals(90, PerfMode.contentRate(40, 3, 90)) + assertEquals(0, PerfMode.contentRate(0, 2, 0)) + assertEquals(modes[2], PerfMode.selectMode(modes, current, PerfMode.contentRate(60, 2, 0), Float.POSITIVE_INFINITY)) + assertEquals(modes[1], PerfMode.selectMode(modes, current, PerfMode.contentRate(45, 2, 0), Float.POSITIVE_INFINITY)) + assertEquals(modes[3], PerfMode.selectMode(modes, current, PerfMode.contentRate(72, 2, 0), Float.POSITIVE_INFINITY)) + assertEquals(modes[3], PerfMode.selectMode(modes, current, PerfMode.contentRate(60, 3, 0), Float.POSITIVE_INFINITY)) + assertEquals(modes[2], PerfMode.selectMode(modes, current, PerfMode.contentRate(60, 4, 0), 120f)) + } + + @Test fun aGuestRefreshRequestWithoutAFrameRatePicksThatPanelRate() { + val modes = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f)) + val current = modes[2] + assertEquals(modes[0], PerfMode.selectMode(modes, current, 0, Float.POSITIVE_INFINITY, 60)) + assertEquals(modes[1], PerfMode.selectMode(modes, current, 0, Float.POSITIVE_INFINITY, 75)) + assertEquals(modes[1], PerfMode.selectMode(modes, current, 0, 90f, 120)) + assertEquals(modes[2], PerfMode.selectMode(modes, current, 0, Float.POSITIVE_INFINITY, 0)) + } + + @Test fun panelRatesListOnlyTheCurrentSizeWithinTheCap() { + val modes = arrayOf(mode(1, 60f), mode(2, 120f), mode(3, 144f), mode(4, 90f, 720), mode(5, 59.94f)) + assertEquals(listOf(60, 120, 144), PerfMode.panelRates(modes, modes[1], Float.POSITIVE_INFINITY).toList()) + assertEquals(listOf(60, 120), PerfMode.panelRates(modes, modes[1], 120f).toList()) + } + + @Test fun aPanelTheSystemHoldsOffersOnlyItsCurrentRate() { + val modes = arrayOf(mode(1, 60f), mode(2, 120f), mode(3, 185f)) + assertTrue(PerfMode.panelHeld(185f, 120f)) + assertTrue(PerfMode.panelHeld(60f, 120f)) + assertFalse(PerfMode.panelHeld(120f, 119.88f)) + assertFalse(PerfMode.panelHeld(0f, 120f)) + assertEquals(listOf(120), PerfMode.panelRates(modes, modes[1], Float.POSITIVE_INFINITY, true).toList()) + assertEquals(listOf(60, 120, 185), PerfMode.panelRates(modes, modes[1], Float.POSITIVE_INFINITY, false).toList()) + } + + @Test + fun aSteadyRateBelowAnUnconstrainingLimiterSetsThePace() { + assertEquals(30, PerfMode.pacedRate(30, 120, 120, 45)) + assertEquals(45, PerfMode.pacedRate(0, 0, 0, 45)) + assertEquals(40, PerfMode.pacedRate(0, 40, 120, 45)) + assertEquals(45, PerfMode.pacedRate(0, 120, 120, 45)) + assertEquals(120, PerfMode.pacedRate(0, 120, 120, 60)) + assertEquals(120, PerfMode.pacedRate(0, 120, 120, 0)) + assertEquals(60, PerfMode.pacedRate(0, 60, 0, 45)) + } } diff --git a/docs/progress-log.md b/docs/progress-log.md index 462affde2..5fcfa6070 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -1449,8 +1449,9 @@ State: **main = `90c7574`** (PR #14 merge), main build run 35895701784. No tag, - A runtime script must be named `bannerlator-*` or CI never packages it. - `gh release create --target` needs the full sha. - A proot bind is invisible to a program's "Computer" list; put what users need under home. -- The compositor decides its driver and its HDR gate once per app process - anything that changes - them applies after the app is fully closed, and the UI must say so. +- The compositor decides its driver once per app process - anything that changes it applies after + the app is fully closed, and the UI must say so. Its HDR gate follows what the device can present, + so the HDR setting itself switches during a session. - Bannerlator's File Manager ports mechanically (`port_fm.py` anchors) once the container hooks are cut; do not hand-edit 2,500 lines. - Deleting a release asset on GitHub can drop a sibling asset - re-list and restore. diff --git a/docs/settings-map.md b/docs/settings-map.md index cfbdf196d..8e19e9db8 100644 --- a/docs/settings-map.md +++ b/docs/settings-map.md @@ -94,7 +94,7 @@ Links of the form `droiddeck://settings/
` open a Settings section direc | Setting | Where | Also matches | | --- | --- | --- | -| Session display | Steam or Desktop options (swipe up) › Display | resolution, scaling, hdr, refresh | +| Session display | Steam or Desktop options (swipe up) › Display | resolution, scaling, hdr, refresh, zero-copy | | Graphics drivers | Steam or Desktop options (swipe up) › Display | turnip, driver, gpu, adreno, mali | | Offline mode | Steam or Desktop options (swipe up) › Steam | offline, steam | | Microphone | Steam or Desktop options (swipe up) › Audio | microphone, voice | diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 50ff42423..2a404c1c6 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -412,10 +412,10 @@ def pacing(adb: str, serial: str, seconds: float) -> dict: try: time.sleep(seconds) dump = run_adb(adb, serial, *timestats, "-dump", timeout=60) + elapsed = time.monotonic() - started except ControlError as exc: raise ControlError(str(exc), "PACING_FAILED") from exc finally: - elapsed = time.monotonic() - started try: disabled = run_adb(adb, serial, *timestats, "-disable").returncode == 0 except ControlError: diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index 953bab4a0..f5a569ddc 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -358,3 +358,51 @@ and clears the held flag. wlroots counts repeated presses of one button and send reaches zero, so a second finger touching before the first lifted left the button pressed in the seat for good: the game saw a held click, and later taps only raised and lowered the count. A finger now presses the button only when no earlier finger holds it. `tools/tests/test_gamescope_touch_click.py` compiles the rule from this patch. + +## 0135 Wayland backend: a limit on the planes handed to the host + +`wayland_overlay_planes` says how many planes above the base one the host compositor shows without composing them +itself. With more layers than that, gamescope composites them into one picture, as it already does for a scaler or +`composite_force`. -1, the default, keeps every layer on its own plane. The app sets it while a host that shows the +game picture directly cannot give an overlay a display layer of its own, so the overlay is drawn into the game +picture here and the frame still reaches the display without a copy. + +## 0136 rendervulkan, Wayland backend: composite only into output images the host has released + +The composite output images were used in a fixed rotation of three, with no check that the host compositor had +released the one about to be written. A host that puts the buffer on the display itself, without copying it, was +still reading that image when the next composite wrote into it. A backend framebuffer now says whether the host +holds it, the Wayland backend answers from the buffer's release event, and the composite takes the next image the +host does not hold. Backends that are not a session get five images instead of three, so one is free while the +host holds two and the last and deferred pictures stay intact. Session backends keep three images and their order. + +## 0137 Wayland backend: the host's refresh rates and the app's target + +A nested session had one refresh rate, the host's, so Steam offered no refresh control and a frame limit never moved +the display. The backend binds the host's `droiddeck_refresh_v1`, takes the list of rates the host display can switch +between and returns it as the connector's dynamic refresh rates, so the rates reach Steam with the rest of the +display state and are sent again when the list changes. On every present it tells the host the refresh rate the +frame limit resolves to and the limit itself; the host switches its display and the new rate comes back through +`wl_output`, which the nested refresh already follows. A host without the global leaves all of this as it was. + +## 0138 Frame limiter: a limit the refresh rate does not divide is spread evenly + +The limiter held a window for a whole number of refreshes, the refresh rate divided by the limit and rounded down. A +limit of 45 or 40 on a 60 Hz display rounded to one refresh per frame, so the limit did nothing, and each frame was +timed from the moment the previous one was shown, so a late frame pushed every frame after it. The limited cycle is +now the exact time between frames at the limit, and each window keeps the time its next frame is due on that line. +A frame is released on the refresh nearest its due time: 45 on 60 Hz shows frames for one, one and two refreshes in +turn, 40 for one and two, and a limit that divides the refresh rate is paced as before. A frame that arrives most of a +refresh late, or more than a refresh early, starts the line again from that frame, so a stall is not followed by a +burst. `tools/tests/test_gamescope_limiter_cadence.py` compiles the two rules from this patch and runs them across +refresh rates and limits. + +## 0139 HDR output can be switched while a session runs + +The Wayland backend read `hdr_enabled` once, when the host compositor described its output, and kept the answer: a +session started with HDR off told its clients the display had no HDR for as long as it ran, and its environment +carried `DXVK_HDR=0`. Whether the display can show HDR now comes from the host's output description alone, and +`hdr_enabled` decides only whether HDR is used, so setting it during a session takes effect on the next frame in +either direction. The 10-bit output format is chosen only while HDR is enabled, so an SDR session keeps the 8-bit +output it had, and the output images are made again in the other format when the setting changes. On a display that can show HDR, a session that starts with HDR off leaves `DXVK_HDR` unset instead of +forcing it to 0, so a game started after HDR is switched on finds it. diff --git a/tools/gamescope/patches/0135-wayland-overlay-plane-limit.patch b/tools/gamescope/patches/0135-wayland-overlay-plane-limit.patch new file mode 100644 index 000000000..7961ec505 --- /dev/null +++ b/tools/gamescope/patches/0135-wayland-overlay-plane-limit.patch @@ -0,0 +1,20 @@ +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index 372fc08..fe38c7d 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -126,6 +126,7 @@ namespace gamescope + gamescope::ConVar cv_wayland_mouse_warp_without_keyboard_focus( "wayland_mouse_warp_without_keyboard_focus", true, "Should we only forward mouse warps to the app when we have keyboard focus?" ); + gamescope::ConVar cv_wayland_mouse_relmotion_without_keyboard_focus( "wayland_mouse_relmotion_without_keyboard_focus", false, "Should we only forward mouse relative motion to the app when we have keyboard focus?" ); + gamescope::ConVar cv_wayland_use_modifiers( "wayland_use_modifiers", true, "Use DMA-BUF modifiers?" ); ++ gamescope::ConVar cv_wayland_overlay_planes( "wayland_overlay_planes", -1, "How many planes above the base one the host shows without composing them itself; more are composited here into one. -1 for no limit." ); + + gamescope::ConVar cv_wayland_hdr10_saturation_scale( "wayland_hdr10_saturation_scale", 1.0, "Saturation scale for HDR10 content by gamut expansion. 1.0 - 1.2 is a good range to play with." ); + +@@ -1102,6 +1103,7 @@ namespace gamescope + eLayer0Filter == GamescopeUpscaleFilter::PIXEL ) && !bLayer0ScreenSize; + + bNeedsFullComposite |= cv_composite_force; ++ bNeedsFullComposite |= cv_wayland_overlay_planes >= 0 && pFrameInfo->layers.count() > 1 + cv_wayland_overlay_planes; + bNeedsFullComposite |= pFrameInfo->useFSRLayer0; + bNeedsFullComposite |= pFrameInfo->useNISLayer0; + bNeedsFullComposite |= pFrameInfo->useSGSRLayer0; diff --git a/tools/gamescope/patches/0136-composite-into-released-output-images.patch b/tools/gamescope/patches/0136-composite-into-released-output-images.patch new file mode 100644 index 000000000..2f827f870 --- /dev/null +++ b/tools/gamescope/patches/0136-composite-into-released-output-images.patch @@ -0,0 +1,218 @@ +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index fe38c7d..be99e6d 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -503,6 +503,8 @@ namespace gamescope + wl_buffer *GetHostBuffer() const { return m_pHostBuffer; } + wlr_buffer *GetClientBuffer() const { return m_pClientBuffer; } + ++ bool HeldByHost() const override { return m_bCompositorAcquired; } ++ + void Wayland_Buffer_Release( wl_buffer *pBuffer ); + static const wl_buffer_listener s_BufferListener; + +diff --git a/src/backend.h b/src/backend.h +index fbfa7c7..30b42ca 100644 +--- a/src/backend.h ++++ b/src/backend.h +@@ -288,6 +288,8 @@ namespace gamescope + virtual void SetReleasePoint( std::shared_ptr pReleasePoint ) = 0; + + virtual IBackendFb *EnsureImported() = 0; ++ ++ virtual bool HeldByHost() const { return false; } + }; + + class IBackendPlane +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 0835bfe..42cc9c4 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -3644,15 +3644,12 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput ) + outputImageflags.bSampled = true; // for pipewire blits + outputImageflags.bOutputImage = true; + +- pOutput->outputImages.resize(3); // extra image for partial composition. +- pOutput->outputImagesPartialOverlay.resize(3); ++ const uint32_t uImageCount = GetBackend()->IsSessionBased() ? 3u : 5u; + +- pOutput->outputImages[0] = nullptr; +- pOutput->outputImages[1] = nullptr; +- pOutput->outputImages[2] = nullptr; +- pOutput->outputImagesPartialOverlay[0] = nullptr; +- pOutput->outputImagesPartialOverlay[1] = nullptr; +- pOutput->outputImagesPartialOverlay[2] = nullptr; ++ pOutput->outputImages.clear(); ++ pOutput->outputImagesPartialOverlay.clear(); ++ pOutput->outputImages.resize( uImageCount ); ++ pOutput->outputImagesPartialOverlay.resize( uImageCount ); + + uint32_t uDRMFormat = pOutput->uOutputFormat; + +@@ -3662,28 +3659,14 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput ) + if ( g_uOutputRotation & 1u ) + std::swap( uOutputWidth, uOutputHeight ); + +- pOutput->outputImages[0] = new CVulkanTexture(); +- bool bSuccess = pOutput->outputImages[0]->BInit( uOutputWidth, uOutputHeight, 1u, uDRMFormat, outputImageflags ); +- if ( bSuccess != true ) +- { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; +- } +- +- pOutput->outputImages[1] = new CVulkanTexture(); +- bSuccess = pOutput->outputImages[1]->BInit( uOutputWidth, uOutputHeight, 1u, uDRMFormat, outputImageflags ); +- if ( bSuccess != true ) ++ for ( uint32_t i = 0; i < uImageCount; i++ ) + { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; +- } +- +- pOutput->outputImages[2] = new CVulkanTexture(); +- bSuccess = pOutput->outputImages[2]->BInit( uOutputWidth, uOutputHeight, 1u, uDRMFormat, outputImageflags ); +- if ( bSuccess != true ) +- { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; ++ pOutput->outputImages[i] = new CVulkanTexture(); ++ if ( !pOutput->outputImages[i]->BInit( uOutputWidth, uOutputHeight, 1u, uDRMFormat, outputImageflags ) ) ++ { ++ vk_log.errorf( "failed to allocate buffer for KMS" ); ++ return false; ++ } + } + + // Oh no. +@@ -3696,28 +3679,14 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput ) + { + uint32_t uPartialDRMFormat = pOutput->uOutputFormatOverlay; + +- pOutput->outputImagesPartialOverlay[0] = new CVulkanTexture(); +- bool bSuccess = pOutput->outputImagesPartialOverlay[0]->BInit( uOutputWidth, uOutputHeight, 1u, uPartialDRMFormat, outputImageflags, nullptr, 0, 0, pOutput->outputImages[0].get() ); +- if ( bSuccess != true ) +- { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; +- } +- +- pOutput->outputImagesPartialOverlay[1] = new CVulkanTexture(); +- bSuccess = pOutput->outputImagesPartialOverlay[1]->BInit( uOutputWidth, uOutputHeight, 1u, uPartialDRMFormat, outputImageflags, nullptr, 0, 0, pOutput->outputImages[1].get() ); +- if ( bSuccess != true ) ++ for ( uint32_t i = 0; i < uImageCount; i++ ) + { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; +- } +- +- pOutput->outputImagesPartialOverlay[2] = new CVulkanTexture(); +- bSuccess = pOutput->outputImagesPartialOverlay[2]->BInit( uOutputWidth, uOutputHeight, 1u, uPartialDRMFormat, outputImageflags, nullptr, 0, 0, pOutput->outputImages[2].get() ); +- if ( bSuccess != true ) +- { +- vk_log.errorf( "failed to allocate buffer for KMS" ); +- return false; ++ pOutput->outputImagesPartialOverlay[i] = new CVulkanTexture(); ++ if ( !pOutput->outputImagesPartialOverlay[i]->BInit( uOutputWidth, uOutputHeight, 1u, uPartialDRMFormat, outputImageflags, nullptr, 0, 0, pOutput->outputImages[i].get() ) ) ++ { ++ vk_log.errorf( "failed to allocate buffer for KMS" ); ++ return false; ++ } + } + } + +@@ -3755,6 +3724,8 @@ bool vulkan_remake_output_images() + g_device.waitIdle(); + + pOutput->nOutImage = 0; ++ pOutput->nLastOutImage = 0; ++ pOutput->nDeferredOutImage = 0; + + // Delete screenshot/capture textures to be remade if needed + for (auto& pScreenshotTexture : pOutput->pScreenshotTextures) +@@ -4604,6 +4575,30 @@ namespace + + ReshadeEffectPipeline *g_pLastReshadeEffect = nullptr; + ++static bool vulkan_output_image_held( uint32_t nImage ) ++{ ++ for ( const auto &pImage : { g_output.outputImages[ nImage ], g_output.outputImagesPartialOverlay[ nImage ] } ) ++ { ++ if ( pImage != nullptr && pImage->GetBackendFb() != nullptr && pImage->GetBackendFb()->HeldByHost() ) ++ return true; ++ } ++ return false; ++} ++ ++static uint32_t vulkan_free_output_image( uint32_t nFirst ) ++{ ++ const uint32_t uCount = g_output.outputImages.size(); ++ for ( uint32_t i = 0; i < uCount; i++ ) ++ { ++ const uint32_t nImage = ( nFirst + i ) % uCount; ++ if ( uCount > 3 && ( nImage == g_output.nLastOutImage || nImage == g_output.nDeferredOutImage ) ) ++ continue; ++ if ( !vulkan_output_image_held( nImage ) ) ++ return nImage; ++ } ++ return nFirst; ++} ++ + std::optional vulkan_composite( struct FrameInfo_t *frameInfo, gamescope::Rc pPipewireTexture, bool partial, gamescope::Rc pOutputOverride, bool increment, std::unique_ptr pInCommandBuffer ) + { + EOTF outputTF = frameInfo->outputEncodingEOTF; +@@ -4643,6 +4638,9 @@ std::optional vulkan_composite( struct FrameInfo_t *frameInfo, gamesco + if ( !pOutputOverride && !vulkan_ensure_output_images() ) + return std::nullopt; + ++ if ( !pOutputOverride && !GetBackend()->UsesVulkanSwapchain() ) ++ g_output.nOutImage = vulkan_free_output_image( g_output.nOutImage ); ++ + gamescope::Rc compositeImage; + if ( pOutputOverride ) + compositeImage = pOutputOverride; +@@ -4877,7 +4875,9 @@ std::optional vulkan_composite( struct FrameInfo_t *frameInfo, gamesco + + if ( !GetBackend()->UsesVulkanSwapchain() && pOutputOverride == nullptr && increment ) + { +- g_output.nOutImage = ( g_output.nOutImage + 1 ) % 3; ++ g_output.nDeferredOutImage = g_output.nLastOutImage; ++ g_output.nLastOutImage = g_output.nOutImage; ++ g_output.nOutImage = ( g_output.nOutImage + 1 ) % g_output.outputImages.size(); + } + + return sequence; +@@ -4931,19 +4931,7 @@ bool vulkan_format_supports_features(VkFormat format, VkFormatFeatureFlags featu + + gamescope::Rc vulkan_get_last_output_image( bool partial, bool defer ) + { +- // Get previous image ( +2 ) +- // 1 2 3 +- // | +- // | +- uint32_t nRegularImage = ( g_output.nOutImage + 2 ) % 3; +- +- // Get previous previous image ( +1 ) +- // 1 2 3 +- // | +- // | +- uint32_t nDeferredImage = ( g_output.nOutImage + 1 ) % 3; +- +- uint32_t nOutImage = defer ? nDeferredImage : nRegularImage; ++ uint32_t nOutImage = defer ? g_output.nDeferredOutImage : g_output.nLastOutImage; + + if ( partial ) + { +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index e0ede11..8ae3b71 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -591,6 +591,8 @@ struct VulkanOutput_t + std::vector> presentationImages; + + uint32_t nOutImage; // swapchain index in nested mode, or ping/pong between two RTs ++ uint32_t nLastOutImage = 0; ++ uint32_t nDeferredOutImage = 0; + std::vector> outputImages; + std::vector> outputImagesPartialOverlay; + gamescope::OwningRc temporaryHackyBlankImage; diff --git a/tools/gamescope/patches/0137-wayland-backend-host-refresh-rates.patch b/tools/gamescope/patches/0137-wayland-backend-host-refresh-rates.patch new file mode 100644 index 000000000..04860928c --- /dev/null +++ b/tools/gamescope/patches/0137-wayland-backend-host-refresh-rates.patch @@ -0,0 +1,293 @@ +diff --git a/protocol/droiddeck-refresh-v1.xml b/protocol/droiddeck-refresh-v1.xml +new file mode 100644 +index 0000000..c4464a0 +--- /dev/null ++++ b/protocol/droiddeck-refresh-v1.xml +@@ -0,0 +1,81 @@ ++ ++ ++ ++ Copyright 2026 DroidDeck contributors ++ ++ Permission is hereby granted, free of charge, to any person obtaining a ++ copy of this software and associated documentation files (the "Software"), ++ to deal in the Software without restriction, including without limitation ++ the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ and/or sell copies of the Software, and to permit persons to whom the ++ Software is furnished to do so, subject to the following conditions: ++ ++ The above copyright notice and this permission notice (including the next ++ paragraph) shall be included in all copies or substantial portions of the ++ Software. ++ ++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ DEALINGS IN THE SOFTWARE. ++ ++ ++ ++ ++ A nested compositor paces its clients against the refresh rate of the ++ panel it is shown on. When its clients are held to a frame rate the ++ panel's current rate does not divide evenly, frames are shown for an ++ uneven number of refreshes. This interface lets the nested compositor ++ see every refresh rate the panel can run at its current size and ask ++ for the one that suits the frame rate it is pacing to. ++ ++ On bind the compositor sends one rate event per refresh rate, lowest ++ first, followed by done. The list is sent again, in full, whenever it ++ changes (a different panel, or a limit the user placed on the panel's ++ rate). The rate the panel is running at is still reported the standard ++ way, through wl_output.mode. ++ ++ A request is a preference, not a guarantee: the user, the platform or ++ another output mirroring the panel may hold the panel at another rate. ++ The client reads the result from wl_output.mode. ++ ++ ++ ++ ++ The preference set through this object is dropped. ++ ++ ++ ++ ++ ++ refresh is the panel rate the client would like, in Hz, taken from ++ the advertised list; 0 withdraws the preference. frame_rate is the ++ frame rate the client holds its content to, in frames per second, or ++ 0 when the content is not held to a rate. The compositor may multiply ++ the content's frame rate itself (generated frames); when it does, it ++ picks the advertised rate that the multiplied frame rate divides ++ evenly instead of the requested one. ++ ++ ++ ++ ++ ++ ++ ++ Sent once per rate, lowest first, in Hz rounded to the nearest whole ++ number. ++ ++ ++ ++ ++ ++ ++ Ends a list of rate events. The rates received since the previous ++ done replace the earlier list. ++ ++ ++ ++ +diff --git a/protocol/meson.build b/protocol/meson.build +index cf8fbd1..71fe31b 100644 +--- a/protocol/meson.build ++++ b/protocol/meson.build +@@ -43,6 +43,8 @@ protocols = [ + 'gamescope-private.xml', + 'gamescope-action-binding.xml', + ++ 'droiddeck-refresh-v1.xml', ++ + # wlroots protocols + 'wlr-layer-shell-unstable-v1.xml', + ] +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index be99e6d..9862641 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -38,6 +38,7 @@ + #include + #include + #include ++#include + #include "wlr_end.hpp" + + #include "drm_include.h" +@@ -705,6 +706,10 @@ namespace gamescope + virtual bool UsesVulkanSwapchain() const override; + + virtual bool IsSessionBased() const override; ++ virtual bool HackTemporarySetDynamicRefresh( int nRefresh ) override; ++ ++ std::span GetHostRefreshRates() const; ++ void SyncHostRefreshTarget(); + virtual bool SupportsExplicitSync() const override; + + virtual bool IsPaused() const override; +@@ -778,6 +783,10 @@ namespace gamescope + void Wayland_Output_Geometry( wl_output *pOutput, int32_t nX, int32_t nY, int32_t nPhysicalWidth, int32_t nPhysicalHeight, int32_t nSubpixel, const char *pMake, const char *pModel, int32_t nTransform ); + void Wayland_Output_Mode( wl_output *pOutput, uint32_t uFlags, int32_t nWidth, int32_t nHeight, int32_t nRefresh ); + void Wayland_Output_Done( wl_output *pOutput ); ++ ++ void Wayland_Refresh_Rate( droiddeck_refresh_v1 *pRefresh, uint32_t uRefresh ); ++ void Wayland_Refresh_Done( droiddeck_refresh_v1 *pRefresh ); ++ static const droiddeck_refresh_v1_listener s_RefreshListener; + void Wayland_Output_Scale( wl_output *pOutput, int32_t nFactor ); + void Wayland_Output_Name( wl_output *pOutput, const char *pName ); + void Wayland_Output_Description( wl_output *pOutput, const char *pDescription ); +@@ -829,6 +838,12 @@ namespace gamescope + OwningRc m_pOwnedBlackFb; + OwningRc m_pBlackTexture; + wp_presentation *m_pPresentation = nullptr; ++ droiddeck_refresh_v1 *m_pHostRefresh = nullptr; ++ std::array m_HostRefreshRates{}; ++ std::atomic m_uHostRefreshRateCount = { 0 }; ++ std::vector m_PendingHostRefreshRates; ++ int m_nSentHostRefresh = 0; ++ int m_nSentHostFrameRate = 0; + frog_color_management_factory_v1 *m_pFrogColorMgmtFactory = nullptr; + wp_color_manager_v1 *m_pWPColorManager = nullptr; + wp_image_description_v1 *m_pWPImageDescriptions[ GamescopeAppTextureColorspace_Count ]{}; +@@ -890,6 +905,11 @@ namespace gamescope + .global = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_Registry_Global ), + .global_remove = WAYLAND_NULL(), + }; ++ const droiddeck_refresh_v1_listener CWaylandBackend::s_RefreshListener = ++ { ++ .rate = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_Refresh_Rate ), ++ .done = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_Refresh_Done ), ++ }; + const wl_output_listener CWaylandBackend::s_OutputListener = + { + .geometry = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_Output_Geometry ), +@@ -1087,6 +1107,7 @@ namespace gamescope + { + droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputPresent ); + UpdateFullscreenState(); ++ m_pBackend->SyncHostRefreshTarget(); + + bool bNeedsFullComposite = false; + +@@ -1244,7 +1265,7 @@ namespace gamescope + } + std::span CWaylandConnector::GetValidDynamicRefreshRates() const + { +- return std::span{}; ++ return m_pBackend->GetHostRefreshRates(); + } + + void CWaylandConnector::GetNativeColorimetry( +@@ -2396,6 +2417,52 @@ namespace gamescope + return false; + } + ++ std::span CWaylandBackend::GetHostRefreshRates() const ++ { ++ const uint32_t uCount = m_uHostRefreshRateCount; ++ if ( uCount < 2 ) ++ return std::span{}; ++ return std::span{ m_HostRefreshRates.data(), uCount }; ++ } ++ ++ bool CWaylandBackend::HackTemporarySetDynamicRefresh( int nRefresh ) ++ { ++ if ( !m_pHostRefresh ) ++ return false; ++ SyncHostRefreshTarget(); ++ return true; ++ } ++ ++ void CWaylandBackend::SyncHostRefreshTarget() ++ { ++ if ( !m_pHostRefresh ) ++ return; ++ const int nFrameRate = steamcompmgr_get_app_target_fps(); ++ const int nRefresh = steamcompmgr_get_app_dynamic_refresh(); ++ if ( nRefresh == m_nSentHostRefresh && nFrameRate == m_nSentHostFrameRate ) ++ return; ++ xdg_log.infof( "Asking the host for %dhz at %dfps", nRefresh, nFrameRate ); ++ droiddeck_refresh_v1_set_target( m_pHostRefresh, nRefresh, nFrameRate ); ++ m_nSentHostRefresh = nRefresh; ++ m_nSentHostFrameRate = nFrameRate; ++ } ++ ++ void CWaylandBackend::Wayland_Refresh_Rate( droiddeck_refresh_v1 *pRefresh, uint32_t uRefresh ) ++ { ++ m_PendingHostRefreshRates.push_back( uRefresh ); ++ } ++ void CWaylandBackend::Wayland_Refresh_Done( droiddeck_refresh_v1 *pRefresh ) ++ { ++ std::sort( m_PendingHostRefreshRates.begin(), m_PendingHostRefreshRates.end() ); ++ const uint32_t uCount = std::min( m_PendingHostRefreshRates.size(), m_HostRefreshRates.size() ); ++ m_uHostRefreshRateCount = 0; ++ std::copy_n( m_PendingHostRefreshRates.begin(), uCount, m_HostRefreshRates.begin() ); ++ m_uHostRefreshRateCount = uCount; ++ m_PendingHostRefreshRates.clear(); ++ steamcompmgr_display_rates_changed(); ++ force_repaint(); ++ } ++ + bool CWaylandBackend::SupportsExplicitSync() const + { + // GAMESCOPE_DISABLE_EXPLICIT_SYNC=1: a kernel without DRM_IOCTL_SYNCOBJ_EVENTFD (before +@@ -2647,6 +2714,11 @@ namespace gamescope + wl_output_add_listener( pOutput , &s_OutputListener, this ); + m_pOutputs.emplace( std::make_pair( std::move( pOutput ), WaylandOutputInfo{} ) ); + } ++ else if ( !strcmp( pInterface, droiddeck_refresh_v1_interface.name ) ) ++ { ++ m_pHostRefresh = (droiddeck_refresh_v1 *)wl_registry_bind( pRegistry, uName, &droiddeck_refresh_v1_interface, 1u ); ++ droiddeck_refresh_v1_add_listener( m_pHostRefresh, &s_RefreshListener, this ); ++ } + else if ( !strcmp( pInterface, frog_color_management_factory_v1_interface.name ) ) + { + m_pFrogColorMgmtFactory = (frog_color_management_factory_v1 *)wl_registry_bind( pRegistry, uName, &frog_color_management_factory_v1_interface, 1u ); +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index 38b304b..d7d11b3 100644 +--- a/src/steamcompmgr.cpp ++++ b/src/steamcompmgr.cpp +@@ -1229,6 +1229,25 @@ static int g_nCombinedAppRefreshCycleOverride[gamescope::GAMESCOPE_SCREEN_TYPE_C + bool g_nCombinedAppRefreshCycleChangeRefresh[gamescope::GAMESCOPE_SCREEN_TYPE_COUNT] = { true, true }; + bool g_nCombinedAppRefreshCycleChangeFPS[gamescope::GAMESCOPE_SCREEN_TYPE_COUNT] = { true, true }; + ++int steamcompmgr_get_app_target_fps() ++{ ++ return g_nSteamCompMgrTargetFPS; ++} ++ ++int steamcompmgr_get_app_dynamic_refresh() ++{ ++ if ( !GetBackend()->GetCurrentConnector() ) ++ return 0; ++ return g_nDynamicRefreshRate[ GetBackend()->GetCurrentConnector()->GetScreenType() ]; ++} ++ ++static std::atomic g_bDisplayRatesChanged = { false }; ++ ++void steamcompmgr_display_rates_changed() ++{ ++ g_bDisplayRatesChanged = true; ++} ++ + static void _update_app_target_refresh_cycle() + { + if ( !GetBackend()->GetCurrentConnector() ) +@@ -9703,7 +9722,8 @@ void update_vrr_atoms(xwayland_ctx_t *root_ctx, bool force, bool* needs_flush = + *needs_flush = true; + } + +- if ( g_nOutputRefresh != g_nCurrentRefreshRate_CachedValue || force ) ++ const bool bDisplayRatesChanged = g_bDisplayRatesChanged.exchange( false ); ++ if ( g_nOutputRefresh != g_nCurrentRefreshRate_CachedValue || bDisplayRatesChanged || force ) + { + int32_t nRefresh = gamescope::ConvertmHzToHz( g_nOutputRefresh ); + XChangeProperty(root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeDisplayRefreshRateFeedback, XA_CARDINAL, 32, PropModeReplace, +diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp +index ff54d8e..9e0bb79 100644 +--- a/src/steamcompmgr.hpp ++++ b/src/steamcompmgr.hpp +@@ -202,4 +202,7 @@ MouseCursor *steamcompmgr_get_server_cursor(uint32_t serverId); + + extern gamescope::ConVar cv_tearing_enabled; + ++extern int steamcompmgr_get_app_target_fps(); ++extern int steamcompmgr_get_app_dynamic_refresh(); ++extern void steamcompmgr_display_rates_changed(); + extern void steamcompmgr_set_app_refresh_cycle_override( gamescope::GamescopeScreenType type, int override_fps, bool change_refresh, bool change_fps_cap ); diff --git a/tools/gamescope/patches/0138-limiter-even-cadence.patch b/tools/gamescope/patches/0138-limiter-even-cadence.patch new file mode 100644 index 000000000..429aa7893 --- /dev/null +++ b/tools/gamescope/patches/0138-limiter-even-cadence.patch @@ -0,0 +1,67 @@ +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index d7d11b3..cfec551 100644 +--- a/src/steamcompmgr.cpp ++++ b/src/steamcompmgr.cpp +@@ -7188,6 +7188,19 @@ init_runtime_info() + update_runtime_info(); + } + ++static uint64_t limiter_latch_target( uint64_t ulPreviousTarget, uint64_t ulLatched, uint64_t ulLimitedCycle, uint64_t ulRefreshCycle ) ++{ ++ const uint64_t ulTarget = ulPreviousTarget + ulLimitedCycle; ++ const bool bLate = ulTarget + ulRefreshCycle * 3 / 4 < ulLatched; ++ const bool bEarly = ulTarget > ulLatched + ulRefreshCycle; ++ return ( bLate || bEarly ) ? ulLatched : ulTarget; ++} ++ ++static bool limiter_holds_vblank( uint64_t ulTarget, uint64_t ulNow, uint64_t ulLimitedCycle, uint64_t ulRefreshCycle ) ++{ ++ return ulNow + ulRefreshCycle / 2 < ulTarget + ulLimitedCycle; ++} ++ + static void + steamcompmgr_flush_frame_done( steamcompmgr_win_t *w ) + { +@@ -7206,6 +7219,9 @@ steamcompmgr_flush_frame_done( steamcompmgr_win_t *w ) + + w->last_commit_first_latch_time = timespec_to_nanos(now); + ++ w->limiter_latch_target_time = limiter_latch_target( w->limiter_latch_target_time, w->last_commit_first_latch_time, ++ g_SteamCompMgrLimitedAppRefreshCycle, g_SteamCompMgrAppRefreshCycle ); ++ + // Acknowledge commit once. + wlserver_lock(); + +@@ -7258,8 +7274,7 @@ static bool steamcompmgr_should_vblank_window( bool bShouldLimitFPS, uint64_t vb + { + if ( w && now ) + { +- uint64_t schedule = w->last_commit_first_latch_time + g_SteamCompMgrLimitedAppRefreshCycle; +- if ( now + g_SteamCompMgrAppRefreshCycle / 2 < schedule ) ++ if ( limiter_holds_vblank( w->limiter_latch_target_time, now, g_SteamCompMgrLimitedAppRefreshCycle, g_SteamCompMgrAppRefreshCycle ) ) + bSendCallback = false; + } + else +@@ -11047,9 +11062,7 @@ steamcompmgr_main(int argc, char **argv) + } + else + { +- int nVblankDivisor = nRealRefreshHz / nTargetFPS; +- +- g_SteamCompMgrLimitedAppRefreshCycle = g_SteamCompMgrAppRefreshCycle * nVblankDivisor; ++ g_SteamCompMgrLimitedAppRefreshCycle = g_SteamCompMgrAppRefreshCycle * nRealRefreshHz / nTargetFPS; + } + } + } +diff --git a/src/steamcompmgr_shared.hpp b/src/steamcompmgr_shared.hpp +index 0fcc80b..3c74d62 100644 +--- a/src/steamcompmgr_shared.hpp ++++ b/src/steamcompmgr_shared.hpp +@@ -146,6 +146,7 @@ struct steamcompmgr_win_t { + bool outdatedInteractiveFocus = false; + + uint64_t last_commit_first_latch_time = 0; ++ uint64_t limiter_latch_target_time = 0; + uint64_t last_commit_present_time = 0; + + bool hasHwndStyle = false; diff --git a/tools/gamescope/patches/0139-hdr-switch-live.patch b/tools/gamescope/patches/0139-hdr-switch-live.patch new file mode 100644 index 000000000..3c1b83962 --- /dev/null +++ b/tools/gamescope/patches/0139-hdr-switch-live.patch @@ -0,0 +1,54 @@ +diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp +index 9862641..e9d2923 100644 +--- a/src/Backends/WaylandBackend.cpp ++++ b/src/Backends/WaylandBackend.cpp +@@ -1972,7 +1972,7 @@ namespace gamescope + { + auto *pHDRInfo = &m_pConnector->m_HDRInfo; + if (m_pBackend->SupportsColorManagement()) { +- pHDRInfo->bExposeHDRSupport = ( cv_hdr_enabled && m_pConnector->m_uMaxTargetLuminance > m_pConnector->m_uReferenceLuminance ); ++ pHDRInfo->bExposeHDRSupport = ( m_pConnector->m_uMaxTargetLuminance > m_pConnector->m_uReferenceLuminance ); + pHDRInfo->eOutputEncodingEOTF = pHDRInfo->bExposeHDRSupport ? EOTF_PQ : EOTF_Gamma22; + } + +@@ -2282,7 +2282,7 @@ namespace gamescope + + assert( u8BitFormat != DRM_FORMAT_INVALID ); + +- *pPrimaryPlaneFormat = u10BitFormat != DRM_FORMAT_INVALID ? u10BitFormat : u8BitFormat; ++ *pPrimaryPlaneFormat = ( cv_hdr_enabled && u10BitFormat != DRM_FORMAT_INVALID ) ? u10BitFormat : u8BitFormat; + *pOverlayPlaneFormat = u8BitFormat; + } + +@@ -2493,13 +2493,17 @@ namespace gamescope + + // XXX: We should do this a better way that handles per-window and appid stuff + // down the line +- if ( cv_hdr_enabled && GetCurrentConnector()->GetHDRInfo().bExposeHDRSupport ) ++ if ( !GetCurrentConnector()->GetHDRInfo().bExposeHDRSupport ) ++ { ++ setenv( "DXVK_HDR", "0", true ); ++ } ++ else if ( cv_hdr_enabled ) + { + setenv( "DXVK_HDR", "1", true ); + } + else + { +- setenv( "DXVK_HDR", "0", true ); ++ unsetenv( "DXVK_HDR" ); + } + + WritePatchedEdid( GetCurrentConnector()->GetRawEDID(), GetCurrentConnector()->GetHDRInfo(), false ); +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 42cc9c4..d0d21f0 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -3735,6 +3735,7 @@ bool vulkan_remake_output_images() + + if ( vulkan_defer_output_images() ) + { ++ GetBackend()->GetPreferredOutputFormat( &pOutput->uOutputFormat, &pOutput->uOutputFormatOverlay ); + pOutput->outputImages.clear(); + pOutput->outputImagesPartialOverlay.clear(); + pOutput->temporaryHackyBlankImage = vulkan_create_debug_blank_texture(); diff --git a/tools/gamescope/release.env b/tools/gamescope/release.env index bf5211b03..c2ff29348 100644 --- a/tools/gamescope/release.env +++ b/tools/gamescope/release.env @@ -1,3 +1,3 @@ GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components -GAMESCOPE_TAG=gamescope-3.16.29-p23 -GAMESCOPE_SHA256=f5f2b8f658234ad2910a1be53c238188db7e7b2a9079f8cc5fa9ea006bebbe7e +GAMESCOPE_TAG=gamescope-3.16.29-zerocopy-8df683f1-qa +GAMESCOPE_SHA256=609198c39b125094a65e1703ffcfd6538e88c9784a1a6596bf673f2e5dc7af80 diff --git a/tools/linuxfs/desktop/droiddeck-desktop b/tools/linuxfs/desktop/droiddeck-desktop index d063bab65..f715ad18d 100644 --- a/tools/linuxfs/desktop/droiddeck-desktop +++ b/tools/linuxfs/desktop/droiddeck-desktop @@ -24,7 +24,7 @@ if [ -n "${DD_DEBUG_DIR:-}" ]; then exec >>"$DD_DEBUG_DIR/desktop.log" 2>&1 echo "== droiddeck-desktop $(date -u '+%Y-%m-%d %H:%M:%S UTC') ${DD_WIDTH:-1280}x${DD_HEIGHT:-720}" fi -find "$XDG_RUNTIME_DIR" -mindepth 1 -maxdepth 1 ! -name 'wayland-0*' ! -name 'keymap.xkb' -exec rm -rf {} + 2>/dev/null +find "$XDG_RUNTIME_DIR" -mindepth 1 -maxdepth 1 ! -name 'wayland-0*' ! -name 'keymap.xkb' ! -name 'droiddeck-display-buffers' -exec rm -rf {} + 2>/dev/null chmod 700 "$XDG_RUNTIME_DIR" 2>/dev/null mkdir -p /tmp/.X11-unix /tmp/.ICE-unix && chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix 2>/dev/null export DD_DESKTOP=1 diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat index b39682bc2..32a9889b8 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat @@ -66,19 +66,32 @@ BRIGHTNESS_JS = r""" """.replace("__BINDING__", BRIGHTNESS_BINDING) +def control_request(name, text, directory): + path = os.path.join(directory, name) + with open(path + ".tmp", "w") as target: + target.write(text + "\n") + os.replace(path + ".tmp", path) + + def brightness_request(payload, directory=CONTROLS_DIR): try: value = float(payload) if not math.isfinite(value) or not 0 <= value <= 1: return - path = os.path.join(directory, "brightness.request") - with open(path + ".tmp", "w") as target: - target.write(str(value) + "\n") - os.replace(path + ".tmp", path) + control_request("brightness.request", str(value), directory) except (ValueError, TypeError, OSError): return +def hdr_request(payload, directory=CONTROLS_DIR): + if payload not in ("0", "1"): + return + try: + control_request("hdr.request", payload, directory) + except OSError: + return + + INSTALL_JS = r""" (() => { if (window.__droiddeckCompat) return "present"; @@ -256,6 +269,49 @@ TOUR_JS = r""" return "off"; })() """ +SET_SETTING_JS = r"""(field, value) => { + const bytes = []; + for (let n of [field * 8, value]) { + while (n > 127) { bytes.push((n & 127) | 128); n = Math.floor(n / 128); } + bytes.push(n); + } + return SteamClient.Settings.SetSetting(btoa(String.fromCharCode(...bytes))); + }""" +HDR_BINDING = "droiddeckHdrChanged" +HDR_JS = r""" +(() => { + if (window.__droiddeckHdr) return "present"; + const settings = window.settingsStore; + if (typeof settings?.clientSettings?.gamescope_hdr_enabled !== "boolean" || + typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable"; + const write = __SET_SETTING__; + const HOLD_MS = 3000; + const self = { known: settings.clientSettings.gamescope_hdr_enabled, pending: null, until: 0 }; + self.set = value => { + if (typeof value !== "boolean") return true; + self.known = value; + if (settings.clientSettings.gamescope_hdr_enabled === value && self.pending === null) return true; + self.pending = value; + self.until = performance.now() + HOLD_MS; + write(21015, value ? 1 : 0); + return true; + }; + self.check = () => { + const value = settings.clientSettings.gamescope_hdr_enabled; + if (typeof value !== "boolean") return; + if (self.pending !== null) { + if (value !== self.pending && performance.now() < self.until) return; + self.pending = null; + } + if (value === self.known) return; + self.known = value; + if (typeof window.__BINDING__ === "function") window.__BINDING__(value ? "1" : "0"); + }; + self.interval = setInterval(self.check, 500); + window.__droiddeckHdr = self; + return "installed"; +})() +""".replace("__BINDING__", HDR_BINDING).replace("__SET_SETTING__", SET_SETTING_JS) FRAME_LIMIT_JS = r""" (() => { if (window.__droiddeckFrameLimit) return "present"; @@ -281,14 +337,7 @@ FRAME_LIMIT_JS = r""" } if (!service || !settings?.clientSettings || typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable"; const self = { timer: null }; - const write = value => { - const bytes = []; - for (let n of [21002 * 8, value]) { - while (n > 127) { bytes.push((n & 127) | 128); n = Math.floor(n / 128); } - bytes.push(n); - } - return SteamClient.Settings.SetSetting(btoa(String.fromCharCode(...bytes))); - }; + const write = value => (__SET_SETTING__)(21002, value); self.check = async () => { let rates; try { @@ -316,7 +365,7 @@ FRAME_LIMIT_JS = r""" window.__droiddeckFrameLimit = self; return "installed"; })() -""" +""".replace("__SET_SETTING__", SET_SETTING_JS) WINDOW_BINDING = "droiddeckWindowAction" WINDOW_TARGET = "createflags=18" WINDOW_MOVES = {"nw": 0, "n": 1, "ne": 2, "e": 3, "se": 4, "s": 5, "sw": 6, "w": 7, "move": 8} @@ -923,6 +972,9 @@ class Helper: self.controls_installed = False self.frame_limit_state = None self.frame_limit_retry = 0 + self.hdr_state = None + self.hdr_installed = False + self.hdr_retry = 0 self.windows = {} self.windows_retry = 0 @@ -983,6 +1035,29 @@ class Helper: except (Closed, OSError, ValueError): del self.windows[ident] + def sync_hdr(self): + try: + with open(os.path.join(CONTROLS_DIR, "state.json")) as source: + value = json.load(source).get("hdr") + if not isinstance(value, bool): + return + if not self.hdr_installed: + if time.monotonic() < self.hdr_retry: + return + self.page.call("Runtime.addBinding", {"name": HDR_BINDING}) + self.hdr_installed = self.page.evaluate(HDR_JS) in ("installed", "present") + if not self.hdr_installed: + self.hdr_retry = time.monotonic() + 10 + return + if value != self.hdr_state: + if self.page.evaluate("window.__droiddeckHdr ? window.__droiddeckHdr.set(%s) : false" % json.dumps(value)) is True: + self.hdr_state = value + else: + self.hdr_state = None + self.hdr_installed = False + except (OSError, ValueError, TypeError, AttributeError): + pass + def sync_frame_limit(self): if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry: return @@ -1095,6 +1170,9 @@ class Helper: self.controls_installed = False self.frame_limit_state = None self.frame_limit_retry = 0 + self.hdr_state = None + self.hdr_installed = False + self.hdr_retry = 0 self.sync_controls() return True @@ -1231,6 +1309,8 @@ class Helper: for e in events: if called(e, BRIGHTNESS_BINDING): brightness_request(e.get("params", {}).get("payload")) + if called(e, HDR_BINDING): + hdr_request(e.get("params", {}).get("payload")) if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str): self.open_chooser(e["params"]["payload"]) return events @@ -1260,6 +1340,7 @@ class Helper: while True: self.sync_controls() self.sync_frame_limit() + self.sync_hdr() self.sync_windows() sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else []) sources += [page.ws for page in self.windows.values()] diff --git a/tools/tests/test_desktop_display_buffers.py b/tools/tests/test_desktop_display_buffers.py new file mode 100644 index 000000000..0c3defcb8 --- /dev/null +++ b/tools/tests/test_desktop_display_buffers.py @@ -0,0 +1,29 @@ +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] +DESKTOP = ROOT / "tools/linuxfs/desktop/droiddeck-desktop" +SOURCE = ROOT / "app/src/main/cpp/waylandcomp/src/display_buffers.c" + + +class DesktopDisplayBuffersTest(unittest.TestCase): + def test_clearing_the_runtime_directory_keeps_what_the_compositor_serves(self): + socket = re.search(r'#define DISPLAY_BUFFERS_SOCKET "([^"]+)"', SOURCE.read_text()).group(1) + lines = [line for line in DESKTOP.read_text().splitlines() if line.startswith('find "$XDG_RUNTIME_DIR"')] + self.assertEqual(len(lines), 1) + with tempfile.TemporaryDirectory() as directory: + runtime = Path(directory) / "runtime" + (runtime / "dbus-1").mkdir(parents=True) + kept = ["wayland-0", "wayland-0.lock", "keymap.xkb", socket] + for name in kept + ["wayland-1", "pipewire-0", "dbus-1/session"]: + (runtime / name).write_text("") + subprocess.run(["bash", "-c", lines[0]], env={"XDG_RUNTIME_DIR": str(runtime), "PATH": "/usr/bin:/bin"}, + check=True, timeout=20) + self.assertEqual(sorted(path.name for path in runtime.iterdir()), sorted(kept)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_effects_source_resolution.py b/tools/tests/test_effects_source_resolution.py index 92ae2d615..cd63c69d6 100644 --- a/tools/tests/test_effects_source_resolution.py +++ b/tools/tests/test_effects_source_resolution.py @@ -203,7 +203,7 @@ static struct { float kx, ky, off_x, off_y; int rx, ry, rw, rh; } g_map; static struct { VkImage img; int w, h; } g_scene; struct vkp_img_slot { VkImage img; int w, h; }; static struct vkp_img_slot g_hdrscene, g_fgscene; -static struct { int active, rw, rh; VkImage result; } g_pass; +static struct { int active, rw, rh, ngen; VkImage result; VkImage gens[VKP_FG_MAX_GENERATIONS]; } g_pass; static struct { int64_t present_ns, present_max_ns; unsigned presents; } g_perf; static int effects_active = 1, framegen, cardboard; struct fx_settings { int scaling, cas_on, cas_pct; }; @@ -368,7 +368,7 @@ static void run_path(int offscreen, const struct vkp_draw *draw, int n, const st assert(n > 0 && n <= 4); memcpy(before, draw, n * sizeof(*draw)); int rw = 0, rh = 0; - assert((offscreen ? pass_begin_impl(1920, 1080, draw, n, hdr, &rw, &rh) + assert((offscreen ? pass_begin_impl(1920, 1080, draw, n, hdr, 0, &rw, &rh) : render_impl(1920, 1080, draw, n, hdr, NULL)) == 0); assert(memcmp(draw, before, n * sizeof(*draw)) == 0); if (offscreen) assert(rw == (fail_effects ? effects_w : (int)g_extent.width) && @@ -393,7 +393,7 @@ static void check_path(int offscreen) { run_path(offscreen, &draw, 1, NULL); check_input(1280, 720); reset(); draw = fullscreen(); draw.dw = 1280; draw.dh = 720; int rw, rh; - assert((offscreen ? pass_begin_impl(1280, 720, &draw, 1, NULL, &rw, &rh) + assert((offscreen ? pass_begin_impl(1280, 720, &draw, 1, NULL, 0, &rw, &rh) : render_impl(1280, 720, &draw, 1, NULL, NULL)) == 0); check_input(1280, 720); } diff --git a/tools/tests/test_gamescope_limiter_cadence.py b/tools/tests/test_gamescope_limiter_cadence.py new file mode 100644 index 000000000..79a4319ad --- /dev/null +++ b/tools/tests/test_gamescope_limiter_cadence.py @@ -0,0 +1,118 @@ +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +PATCH = ROOT / "tools/gamescope/patches/0138-limiter-even-cadence.patch" + + +def added_source(): + return "\n".join(line[1:] for line in PATCH.read_text().splitlines() if line.startswith("+") and not line.startswith("+++")) + + +def block(text, start): + begin = text.index(start) + return text[begin:text.index("\n}", begin) + 3] + + +PREAMBLE = r''' +#include +#include +#include +#include +''' + +MAIN = r''' +struct Run { + std::vector gaps; + int frames = 0; +}; + +static Run run(int hz, int fps, int vblanks, uint64_t latency) { + const uint64_t cycle = 1000000000ull / hz; + const uint64_t limited = cycle * hz / fps; + uint64_t target = 0; + int last = -1; + Run r; + for (int i = 0; i < vblanks; i++) { + const uint64_t now = (1000ull + i) * cycle; + if (limiter_holds_vblank(target, now, limited, cycle)) continue; + target = limiter_latch_target(target, now + latency, limited, cycle); + if (last >= 0) r.gaps.push_back(i - last); + last = i; + r.frames++; + } + return r; +} + +static void check(int hz, int fps, uint64_t latency) { + const int vblanks = hz * 20; + const Run r = run(hz, fps, vblanks, latency); + const int low = hz / fps; + const int high = (hz + fps - 1) / fps; + for (int gap : r.gaps) { + if (gap != low && gap != high) { + std::printf("%d Hz at %d fps: a frame was held for %d refreshes\n", hz, fps, gap); + assert(false); + } + } + const int expected = fps * 20; + if (r.frames < expected - 1 || r.frames > expected + 1) { + std::printf("%d Hz at %d fps: %d frames, expected %d\n", hz, fps, r.frames, expected); + assert(false); + } +} + +int main() { + const int rates[] = {60, 90, 120, 144, 165}; + const int limits[] = {24, 30, 36, 40, 45, 48, 50, 60, 72, 80, 90, 100, 120, 144}; + for (int hz : rates) { + for (int fps : limits) { + if (fps > hz) continue; + check(hz, fps, 0); + check(hz, fps, 1000000000ull / hz / 4); + } + } + + const Run even = run(60, 30, 600, 0); + for (int gap : even.gaps) assert(gap == 2); + const Run full = run(120, 120, 600, 0); + for (int gap : full.gaps) assert(gap == 1); + const Run two_of_three = run(60, 40, 600, 0); + for (size_t i = 1; i < two_of_three.gaps.size(); i++) assert(two_of_three.gaps[i] != two_of_three.gaps[i - 1]); + + const uint64_t cycle = 16666666, limited = cycle * 60 / 45; + assert(limiter_latch_target(1000 * cycle, 1500 * cycle, limited, cycle) == 1500 * cycle); + assert(limiter_latch_target(1500 * cycle, 1000 * cycle, limited, cycle) == 1000 * cycle); + assert(limiter_latch_target(1000 * cycle, 1001 * cycle, limited, cycle) == 1000 * cycle + limited); + return 0; +} +''' + + +class GamescopeLimiterCadenceTest(unittest.TestCase): + def test_a_limit_the_refresh_rate_does_not_divide_is_spread_evenly(self): + compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++") + if not compiler: + self.skipTest("no C++ compiler") + added = added_source() + source = PREAMBLE + block(added, "static uint64_t limiter_latch_target") + block(added, "static bool limiter_holds_vblank") + MAIN + with tempfile.TemporaryDirectory() as tmp: + src = Path(tmp) / "limiter_cadence.cpp" + exe = Path(tmp) / "limiter_cadence" + src.write_text(source) + subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True) + subprocess.run([str(exe)], check=True) + + def test_the_limited_cycle_is_no_longer_a_whole_number_of_refreshes(self): + added = added_source() + self.assertIn("g_SteamCompMgrAppRefreshCycle * nRealRefreshHz / nTargetFPS", added) + removed = "\n".join(line[1:] for line in PATCH.read_text().splitlines() if line.startswith("-") and not line.startswith("---")) + self.assertIn("nVblankDivisor", removed) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_hdr_live_switch.py b/tools/tests/test_hdr_live_switch.py new file mode 100644 index 000000000..4468be504 --- /dev/null +++ b/tools/tests/test_hdr_live_switch.py @@ -0,0 +1,87 @@ +from pathlib import Path +import re +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +PATCH = ROOT / "tools/gamescope/patches/0139-hdr-switch-live.patch" +APP = ROOT / "app/src/main/java/com/droiddeck/launcher" +RES = ROOT / "app/src/main/res" + + +def lines(prefix): + return [line[1:] for line in PATCH.read_text().splitlines() + if line.startswith(prefix) and not line.startswith(prefix * 3)] + + +class HdrLiveSwitchTest(unittest.TestCase): + def test_display_capability_does_not_depend_on_the_setting(self): + added = [line for line in lines("+") if "bExposeHDRSupport =" in line] + self.assertEqual(len(added), 1) + self.assertNotIn("cv_hdr_enabled", added[0]) + self.assertIn("m_uMaxTargetLuminance > m_pConnector->m_uReferenceLuminance", added[0]) + + def test_sdr_keeps_the_8_bit_output(self): + added = [line for line in lines("+") if "*pPrimaryPlaneFormat" in line] + self.assertEqual(len(added), 1) + self.assertRegex(added[0], r"cv_hdr_enabled && u10BitFormat != DRM_FORMAT_INVALID \) \? u10BitFormat : u8BitFormat") + + def test_remade_output_images_pick_the_format_again(self): + text = PATCH.read_text() + hunk = text[text.index("src/rendervulkan.cpp"):] + added = [line[1:] for line in hunk.splitlines() if line.startswith("+") and not line.startswith("+++")] + self.assertEqual([line.strip() for line in added], + ["GetBackend()->GetPreferredOutputFormat( &pOutput->uOutputFormat, &pOutput->uOutputFormatOverlay );"]) + self.assertIn("if ( vulkan_defer_output_images() )", hunk[:hunk.index(added[0])]) + + def test_capable_display_does_not_force_dxvk_hdr_off(self): + added = "\n".join(lines("+")) + self.assertIn('unsetenv( "DXVK_HDR" )', added) + off = added.index('setenv( "DXVK_HDR", "0", true )') + self.assertIn("!GetCurrentConnector()->GetHDRInfo().bExposeHDRSupport", added[:off]) + + def test_the_gate_follows_the_display_not_the_setting(self): + text = (APP / "SessionActivity.kt").read_text() + start = text.index("val attached = CompositorHost.isStarted") + block = text[start:text.index("DriverSetupLog.write", start)] + request = block[block.index("nativeSetHdrRequest("):block.index("Log.i", block.index("nativeSetHdrRequest("))] + self.assertNotIn("SessionPrefs.hdr", block[:block.index("if (!SessionState.running)")]) + self.assertIn("capable, false", request) + self.assertIn("SessionState.hdrCapable && SessionPrefs.hdr(this, mode)", block) + + def test_both_switches_apply_to_the_running_session(self): + helper = (APP / "session/SessionHdr.kt").read_text() + self.assertIn('setGamescopeConvar(app, "hdr_enabled", if (on) 1 else 0)', helper) + self.assertIn("nativeSetHdrOutput(on)", helper) + self.assertIn("nativeSetZeroCopy(on || SessionPrefs.zeroCopy(context, mode))", helper) + self.assertIn("SessionPrefs.prefMode(SessionState.mode) != mode", helper) + for name in ("SessionActivity.kt", "FrontEndActivity.kt"): + text = (APP / name).read_text() + self.assertEqual(len(re.findall(r"onHdr = \{ on -> com\.droiddeck\.launcher\.session\.SessionHdr\.set\(", text)), 1, name) + self.assertNotIn("SessionPrefs.setHdr(", text, name) + + def test_a_saved_opt_out_applies_before_the_gate_opens(self): + native = (ROOT / "app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c").read_text() + switch = native[native.index("void droiddeck_color_set_output(int on)"):] + switch = switch[:switch.index("if (gate != 1)")] + self.assertLess(switch.index("pthread_mutex_lock(&g_output_mu)"), switch.index("atomic_store(&g_output_wanted, on)")) + self.assertLess(switch.index("atomic_exchange(&g_output_on, on)"), switch.index("pthread_mutex_unlock(&g_output_mu)")) + opened = native[native.index("atomic_store(&g_gate, 1);") - 40:] + opened = opened[:opened.index("pthread_mutex_unlock(&g_output_mu)")] + self.assertIn("pthread_mutex_lock(&g_output_mu)", opened) + self.assertIn("if (mode == 3 || !atomic_load(&g_output_wanted)) atomic_store(&g_output_on, 0);", opened) + text = (APP / "SessionActivity.kt").read_text() + self.assertNotIn("if (attached) WaylandCompositor.nativeSetHdrOutput", text) + + def test_retries_stay_with_the_session_that_asked(self): + helper = (APP / "session/SessionHdr.kt").read_text() + self.assertIn("val session = SessionState.sessionId", helper) + self.assertIn("SessionState.sessionId == session", helper) + + def test_no_restart_hint_is_left(self): + for path in list(RES.glob("values*/strings.xml")) + list(APP.rglob("*.kt")): + self.assertNotIn("mode_hdr_restart", path.read_text(), str(path)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_hdr_steam_sync.py b/tools/tests/test_hdr_steam_sync.py new file mode 100644 index 000000000..c550a892d --- /dev/null +++ b/tools/tests/test_hdr_steam_sync.py @@ -0,0 +1,185 @@ +import json +from pathlib import Path +import runpy +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] +BIN = ROOT / "tools/linuxfs/overlay/usr/local/bin" +APP = ROOT / "app/src/main/java/com/droiddeck/launcher" +LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat")) + +HARNESS = r""" +const assert = require('assert'); +globalThis.window = globalThis; +globalThis.btoa = text => Buffer.from(text, 'binary').toString('base64'); +let now = 0, tick = null; +Object.defineProperty(globalThis, 'performance', { value: { now: () => now }, configurable: true }); +globalThis.setInterval = callback => { tick = callback; return 1; }; +const varints = bytes => { const out = []; let value = 0, shift = 0; + for (const b of bytes) { value += (b & 127) * 2 ** shift; shift += 7; if (b < 128) { out.push(value); value = 0; shift = 0; } } + return out; }; +const writes = [], told = []; +let apply = true; +globalThis.settingsStore = { clientSettings: { gamescope_hdr_enabled: false } }; +globalThis.SteamClient = { Settings: { SetSetting(encoded) { + const [key, value] = varints([...Buffer.from(encoded, 'base64')]); + assert.strictEqual(key, 21015 * 8); + writes.push(value); + if (apply) settingsStore.clientSettings.gamescope_hdr_enabled = value === 1; +} } }; +window.droiddeckHdrChanged = value => told.push(value); +const script = require('fs').readFileSync(process.argv[2], 'utf8'); +assert.strictEqual(eval(script), 'installed'); +assert.strictEqual(eval(script), 'present'); +const bridge = window.__droiddeckHdr; +tick(); +assert.deepStrictEqual(told, [], 'an unchanged client setting is not reported'); +assert.strictEqual(bridge.set(true), true); +assert.deepStrictEqual(writes, [1]); +tick(); +assert.deepStrictEqual(told, [], 'a value the app set is not reported back to it'); +assert.strictEqual(bridge.set(true), true); +assert.deepStrictEqual(writes, [1], 'an equal value is not written again'); +settingsStore.clientSettings.gamescope_hdr_enabled = false; +tick(); +assert.deepStrictEqual(told, ['0'], 'a change made in the client reaches the app'); +tick(); +assert.deepStrictEqual(told, ['0']); +settingsStore.clientSettings.gamescope_hdr_enabled = true; +tick(); +assert.deepStrictEqual(told, ['0', '1']); +apply = false; +bridge.set(false); +assert.deepStrictEqual(writes, [1, 0]); +now += 500; tick(); +assert.deepStrictEqual(told, ['0', '1'], 'the old value is not reported while a write is settling'); +now += 3000; tick(); +assert.deepStrictEqual(told, ['0', '1', '1'], 'a write the client did not take is reported as its real value'); +assert.strictEqual(bridge.set('yes'), true); +assert.deepStrictEqual(writes, [1, 0]); +bridge.set(false); +bridge.set(true); +assert.deepStrictEqual(writes, [1, 0, 0, 1], 'a newer opposite value is written while the earlier write is settling'); +settingsStore.clientSettings.gamescope_hdr_enabled = false; +now += 500; tick(); +settingsStore.clientSettings.gamescope_hdr_enabled = true; +now += 500; tick(); +assert.deepStrictEqual(told, ['0', '1', '1'], 'the earlier write landing late is not reported to the app'); +delete globalThis.__droiddeckHdr; +delete settingsStore.clientSettings.gamescope_hdr_enabled; +assert.strictEqual(eval(script), 'unavailable'); +""" + + +class HdrSteamSyncTest(unittest.TestCase): + def test_bridge_keeps_the_client_setting_and_the_app_equal(self): + with tempfile.TemporaryDirectory() as directory: + script = Path(directory) / "bridge.js" + script.write_text(LIVE["HDR_JS"]) + test = Path(directory) / "test.js" + test.write_text(HARNESS) + result = subprocess.run(["node", str(test), str(script)], capture_output=True, text=True, timeout=20) + self.assertEqual(result.returncode, 0, result.stderr) + + def test_requests_accept_only_on_and_off(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "hdr.request" + for value in ["2", "true", "", None, 1]: + LIVE["hdr_request"](value, directory) + self.assertFalse(path.exists()) + LIVE["hdr_request"]("1", directory) + self.assertEqual(path.read_text(), "1\n") + LIVE["hdr_request"]("0", directory) + self.assertEqual(path.read_text(), "0\n") + + def helper(self, directory): + helper = LIVE["Helper"]("/steam", 0) + calls = [] + + class Page: + answer = True + + def call(self, method, params=None): + calls.append((method, params)) + + def evaluate(self, expression): + calls.append(expression) + return "installed" if expression == LIVE["HDR_JS"] else self.answer + + helper.page = Page() + return helper, calls + + def test_the_app_state_is_applied_once_per_change(self): + with tempfile.TemporaryDirectory() as directory: + globals_ = LIVE["Helper"].sync_hdr.__globals__ + previous = globals_["CONTROLS_DIR"] + try: + globals_["CONTROLS_DIR"] = directory + helper, calls = self.helper(directory) + path = Path(directory) / "state.json" + helper.sync_hdr() + path.write_text(json.dumps({"brightness": 0.5})) + helper.sync_hdr() + self.assertEqual(calls, [], "a session that cannot show HDR leaves the client setting alone") + path.write_text(json.dumps({"brightness": 0.5, "hdr": True})) + helper.sync_hdr() + helper.sync_hdr() + self.assertEqual(calls[0], ("Runtime.addBinding", {"name": LIVE["HDR_BINDING"]})) + self.assertEqual(calls[1], LIVE["HDR_JS"]) + self.assertEqual(calls[2:], ["window.__droiddeckHdr ? window.__droiddeckHdr.set(true) : false"]) + path.write_text(json.dumps({"brightness": 0.7, "hdr": True})) + helper.sync_hdr() + self.assertEqual(len(calls), 3) + path.write_text(json.dumps({"hdr": False})) + helper.sync_hdr() + self.assertEqual(calls[3], "window.__droiddeckHdr ? window.__droiddeckHdr.set(false) : false") + helper.page.answer = False + path.write_text(json.dumps({"hdr": True})) + helper.sync_hdr() + self.assertFalse(helper.hdr_installed) + self.assertIsNone(helper.hdr_state) + helper.page.answer = True + path.write_text(json.dumps({"hdr": False})) + helper.sync_hdr() + self.assertEqual(calls[-1], "window.__droiddeckHdr ? window.__droiddeckHdr.set(false) : false") + finally: + globals_["CONTROLS_DIR"] = previous + + def test_a_client_without_the_setting_is_left_alone(self): + with tempfile.TemporaryDirectory() as directory: + globals_ = LIVE["Helper"].sync_hdr.__globals__ + previous = globals_["CONTROLS_DIR"] + try: + globals_["CONTROLS_DIR"] = directory + helper, calls = self.helper(directory) + helper.page.evaluate = lambda expression: calls.append(expression) or "unavailable" + (Path(directory) / "state.json").write_text(json.dumps({"hdr": True})) + helper.sync_hdr() + self.assertEqual(calls, [("Runtime.addBinding", {"name": LIVE["HDR_BINDING"]}), LIVE["HDR_JS"]]) + self.assertFalse(helper.hdr_installed) + self.assertIsNone(helper.hdr_state) + helper.sync_hdr() + self.assertEqual(len(calls), 2, "a client without the setting is not asked again straight away") + finally: + globals_["CONTROLS_DIR"] = previous + + def test_the_app_publishes_and_takes_the_shared_value(self): + controls = (APP / "runtime/DeviceControlsComponent.kt").read_text() + self.assertIn('if (SessionState.hdrCapable) controls.put("hdr", SessionState.hdr)', controls) + self.assertIn('"hdr.request" -> if (text == "0" || text == "1")', controls) + self.assertIn('SessionHdr.set(context, SessionPrefs.prefMode(SessionState.mode), text == "1")', controls) + self.assertIn('"hdr.request")', controls[controls.index("REQUESTS = setOf"):]) + session = (APP / "SessionActivity.kt").read_text() + self.assertIn("if (key == SessionPrefs.hdrKey(hdrPrefMode()))", session) + self.assertIn("registerOnSharedPreferenceChangeListener(hdrPrefListener)", session) + self.assertIn("unregisterOnSharedPreferenceChangeListener(hdrPrefListener)", session) + + def test_frame_limit_writes_share_the_setting_writer(self): + self.assertIn("(21002, value)", LIVE["FRAME_LIMIT_JS"]) + self.assertNotIn("__SET_SETTING__", LIVE["FRAME_LIMIT_JS"] + LIVE["HDR_JS"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_output_refresh.py b/tools/tests/test_output_refresh.py index 8896d3e55..96817b2f4 100644 --- a/tools/tests/test_output_refresh.py +++ b/tools/tests/test_output_refresh.py @@ -44,10 +44,11 @@ static struct surface surface = { .xdg_toplevel = 1, .toplevel_committed = 1 }; static int g_input_pipe[2] = {-1, -1}; static atomic_int g_output_refresh_mhz = 60000; static atomic_int g_output_refresh_pending; +static atomic_int g_panel_rates_pending; static int g_output_announced_refresh_mhz = 60000; static int g_output_w = 1920, g_output_h = 1080; static int flushes, resizes, pointers, ticks; -static int scale_changes, scale_mode, scale_alignment, renders; +static int scale_changes, scale_mode, scale_alignment, renders, rate_notifies; static void *g_display; #define WL_OUTPUT_MODE_CURRENT 1 #define WL_OUTPUT_MODE_PREFERRED 2 @@ -77,6 +78,7 @@ static void vk_present_set_scale_mode(int mode, int alignment) { scale_changes++; scale_mode = mode; scale_alignment = alignment; } static void schedule_render(void) { renders++; } +static void refresh_notify_rates(void) { rate_notifies++; } ''' CHECKS = r''' @@ -138,6 +140,11 @@ int main(void) { droiddeck_wayland_set_output_refresh_rate(90000); drain(); expect(6, 90000, 1); assert(scale_changes == 2 && scale_mode == 1 && scale_alignment == 3 && renders == 2); + atomic_store(&g_panel_rates_pending, 1); + drain(); + assert(rate_notifies == 1 && !atomic_load(&g_panel_rates_pending)); + drain(); + assert(rate_notifies == 1); close(g_input_pipe[0]); close(g_input_pipe[1]); puts("PASS"); } diff --git a/tools/tests/test_render_on_commit.py b/tools/tests/test_render_on_commit.py index c0b8c436d..66abb89d7 100644 --- a/tools/tests/test_render_on_commit.py +++ b/tools/tests/test_render_on_commit.py @@ -26,7 +26,7 @@ static struct wl_event_source *g_render_idle, *g_fallback_timer; static int g_fallback_armed, g_dirty, g_hud_fresh, framegen; static void *g_hud_surface; static int64_t g_dirty_since_ns, g_last_vsync_ns, g_tick_vsync_ns, g_hud_last_ns, g_rendered_tick_ns; -static int g_tick_held; +static int g_tick_held, g_tick_spare, g_scene_queues; static int64_t g_hold_missed_ns; #define HOLD_RETRY_NS 1000000000LL static int64_t g_refresh_ns = 16666667; @@ -254,6 +254,15 @@ int main(void) { clock_ns += 200000000LL; schedule_render(); assert(idles_added == idles && g_fallback_armed == 1 && timers_armed == 1); + g_rendered_tick_ns = g_tick_vsync_ns; + g_tick_spare = 0; g_scene_queues = 1; + assert(!tick_takes_scene()); + g_tick_spare = 1; + assert(tick_takes_scene()); + g_scene_queues = 0; + assert(!tick_takes_scene()); + g_rendered_tick_ns = g_tick_vsync_ns - 1; + assert(tick_takes_scene()); puts("PASS"); return 0; } @@ -270,7 +279,7 @@ class RenderOnCommitTest(unittest.TestCase): render = extract_function(source, 'render_scene') self.assertIn('g_rendered_tick_ns = g_tick_vsync_ns;', render) self.assertIn('g_tick_held = 0;', render) - functions = ('scene_held_for_limit', 'commit_renders_on', 'render_on_commit', 'schedule_render', 'scene_waits_for_game', 'on_commit_idle', + functions = ('scene_held_for_limit', 'commit_renders_on', 'tick_takes_scene', 'render_on_commit', 'schedule_render', 'scene_waits_for_game', 'on_commit_idle', 'bfi_blocked', 'bfi_update', 'bfi_tick', 'on_vsync') harness = PREAMBLE + '\n'.join(extract_function(source, name) for name in functions) + CHECKS with tempfile.TemporaryDirectory(prefix='droiddeck-render-on-commit-') as folder: diff --git a/tools/tests/test_vk_linear_dmabuf.py b/tools/tests/test_vk_linear_dmabuf.py index 32f6a7f37..a91df519c 100644 --- a/tools/tests/test_vk_linear_dmabuf.py +++ b/tools/tests/test_vk_linear_dmabuf.py @@ -33,6 +33,7 @@ static const uint32_t g_qfam = 2; %(is_dmabuf)s %(width)s %(height)s +static int black_fill_below(const struct draw_list *dl, int n) { (void)dl; (void)n; return 0; } %(candidate)s static int candidate(struct vkp_image *img) { diff --git a/tools/tests/vk_terminal_callers_test.c b/tools/tests/vk_terminal_callers_test.c index 2398608bd..ebf8fbf09 100644 --- a/tools/tests/vk_terminal_callers_test.c +++ b/tools/tests/vk_terminal_callers_test.c @@ -110,7 +110,7 @@ struct damage_list { int n; }; struct surface { struct vkp_image *shm_img; struct wl_resource *resource; - int buf_w, buf_h, buf_alpha, has_content; + int buf_w, buf_h, buf_alpha, has_content, black_fill; /* Read by take_shm's game-frame detection; with no damage it stays off here. */ int src_set; float src[4]; struct damage_list damage_buf, damage_local;