Skip to content

Commit

Permalink
mesa-chimeraos 23.3.3-chos2
Browse files Browse the repository at this point in the history
  • Loading branch information
BoukeHaarsma23 committed Jan 20, 2024
1 parent 572755c commit 1e9cb8a
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 6 deletions.
200 changes: 200 additions & 0 deletions common/0006-STEAMOS-Dynamic-swapchain-override-for-gamescope-lim.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
From cac15ce38523769c72f1c6f8458516ea1dc9f1d8 Mon Sep 17 00:00:00 2001
From: Bas Nieuwenhuizen <[email protected]>
Date: Mon, 21 Feb 2022 18:43:54 +0100
Subject: [PATCH 6/6] STEAMOS: Dynamic swapchain override for gamescope limiter

---
src/loader/loader_dri3_helper.c | 42 +++++++++++++++++++++++++++++++--
src/loader/loader_dri3_helper.h | 1 +
src/loader/meson.build | 2 +-
src/vulkan/wsi/wsi_common_x11.c | 38 +++++++++++++++++++++++++++++
4 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
index 2631a9e2fd5..dbf6db349c6 100644
--- a/src/loader/loader_dri3_helper.c
+++ b/src/loader/loader_dri3_helper.c
@@ -289,6 +289,30 @@ dri3_update_max_num_back(struct loader_dri3_drawable *draw)
}
}

+static unsigned
+gamescope_swapchain_override()
+{
+ const char *path = getenv("GAMESCOPE_LIMITER_FILE");
+ if (!path)
+ return 0;
+
+ static simple_mtx_t mtx = SIMPLE_MTX_INITIALIZER;
+ static int fd = -1;
+
+ simple_mtx_lock(&mtx);
+ if (fd < 0) {
+ fd = open(path, O_RDONLY);
+ }
+ simple_mtx_unlock(&mtx);
+
+ if (fd < 0)
+ return 0;
+
+ uint32_t override_value = 0;
+ pread(fd, &override_value, sizeof(override_value), 0);
+ return override_value;
+}
+
void
loader_dri3_set_swap_interval(struct loader_dri3_drawable *draw, int interval)
{
@@ -303,10 +327,12 @@ loader_dri3_set_swap_interval(struct loader_dri3_drawable *draw, int interval)
* PS. changing from value A to B and A < B won't cause swap out of order but
* may still gets wrong target_msc value at the beginning.
*/
- if (draw->swap_interval != interval)
+ if (draw->orig_swap_interval != interval)
loader_dri3_swapbuffer_barrier(draw);

- draw->swap_interval = interval;
+ draw->orig_swap_interval = interval;
+ if (gamescope_swapchain_override() != 1)
+ draw->swap_interval = interval;
}

static void
@@ -438,6 +464,12 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
draw->swap_interval = dri_get_initial_swap_interval(draw->dri_screen_render_gpu,
draw->ext->config);

+ draw->orig_swap_interval = draw->swap_interval;
+
+ unsigned gamescope_override = gamescope_swapchain_override();
+ if (gamescope_override == 1)
+ draw->swap_interval = 1;
+
dri3_update_max_num_back(draw);

/* Create a new drawable */
@@ -1085,6 +1117,12 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw,
if (draw->type == LOADER_DRI3_DRAWABLE_WINDOW) {
dri3_fence_reset(draw->conn, back);

+ unsigned gamescope_override = gamescope_swapchain_override();
+ if (gamescope_override == 1)
+ draw->swap_interval = 1;
+ else
+ draw->swap_interval = draw->orig_swap_interval;
+
/* Compute when we want the frame shown by taking the last known
* successful MSC and adding in a swap interval for each outstanding swap
* request. target_msc=divisor=remainder=0 means "Use glXSwapBuffers()
diff --git a/src/loader/loader_dri3_helper.h b/src/loader/loader_dri3_helper.h
index cc2362dd599..fe73b3f329c 100644
--- a/src/loader/loader_dri3_helper.h
+++ b/src/loader/loader_dri3_helper.h
@@ -178,6 +178,7 @@ struct loader_dri3_drawable {
bool block_on_depleted_buffers;
bool queries_buffer_age;
int swap_interval;
+ int orig_swap_interval;

struct loader_dri3_extensions *ext;
const struct loader_dri3_vtable *vtable;
diff --git a/src/loader/meson.build b/src/loader/meson.build
index 35f9991ba2f..154cf809a69 100644
--- a/src/loader/meson.build
+++ b/src/loader/meson.build
@@ -29,7 +29,7 @@ if with_platform_x11 and with_dri3
dependencies : [
idep_mesautil,
dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence,
- dep_xcb_xfixes,
+ dep_xcb_xfixes, dep_xcb_xrandr, idep_mesautil
],
build_by_default : false,
)
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index cba1d1c5e7c..6d66387d5be 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -48,6 +48,7 @@
#include "util/hash_table.h"
#include "util/os_file.h"
#include "util/os_time.h"
+#include "util/simple_mtx.h"
#include "util/u_debug.h"
#include "util/u_thread.h"
#include "util/xmlconfig.h"
@@ -219,6 +220,30 @@ wsi_x11_detect_xwayland(xcb_connection_t *conn,
return is_xwayland;
}

+static unsigned
+gamescope_swapchain_override()
+{
+ const char *path = getenv("GAMESCOPE_LIMITER_FILE");
+ if (!path)
+ return 0;
+
+ static simple_mtx_t mtx = SIMPLE_MTX_INITIALIZER;
+ static int fd = -1;
+
+ simple_mtx_lock(&mtx);
+ if (fd < 0) {
+ fd = open(path, O_RDONLY);
+ }
+ simple_mtx_unlock(&mtx);
+
+ if (fd < 0)
+ return 0;
+
+ uint32_t override_value = 0;
+ pread(fd, &override_value, sizeof(override_value), 0);
+ return override_value;
+}
+
static struct wsi_x11_connection *
wsi_x11_connection_create(struct wsi_device *wsi_dev,
xcb_connection_t *conn)
@@ -1107,6 +1132,8 @@ struct x11_swapchain {
/* Total number of images returned to application in AcquireNextImage. */
uint64_t present_poll_acquire_count;

+ VkPresentModeKHR orig_present_mode;
+
struct x11_image images[0];
};
VK_DEFINE_NONDISP_HANDLE_CASTS(x11_swapchain, base.base, VkSwapchainKHR,
@@ -1857,6 +1884,12 @@ x11_queue_present(struct wsi_swapchain *anv_chain,
if (chain->status < 0)
return chain->status;

+ unsigned gamescope_override = gamescope_swapchain_override();
+ if ((gamescope_override == 1 && chain->base.present_mode != VK_PRESENT_MODE_FIFO_KHR) ||
+ (gamescope_override != 1 && chain->base.present_mode != chain->orig_present_mode)) {
+ return x11_swapchain_result(chain, VK_ERROR_OUT_OF_DATE_KHR);
+ }
+
if (damage && damage->pRectangles && damage->rectangleCount > 0 &&
damage->rectangleCount <= MAX_DAMAGE_RECTS) {
xcb_rectangle_t rects[MAX_DAMAGE_RECTS];
@@ -2615,6 +2648,10 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
xcb_void_cookie_t cookie;
VkResult result;
VkPresentModeKHR present_mode = wsi_swapchain_get_present_mode(wsi_device, pCreateInfo);
+ VkPresentModeKHR orig_present_mode = present_mode;
+
+ if (gamescope_swapchain_override() == 1)
+ present_mode = VK_PRESENT_MODE_FIFO_KHR;

assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR);

@@ -2727,6 +2764,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
chain->base.wait_for_present = x11_wait_for_present;
chain->base.release_images = x11_release_images;
chain->base.present_mode = present_mode;
+ chain->orig_present_mode = orig_present_mode;
chain->base.image_count = num_images;
chain->conn = conn;
chain->window = window;
--
2.43.0

9 changes: 6 additions & 3 deletions lib32-mesa/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkgname=(
'lib32-mesa'
)
_mesaver=23.3.3
pkgver=${_mesaver//-/.}.chos1
pkgver=${_mesaver//-/.}.chos2
pkgrel=1
epoch=1
pkgdesc="An open-source implementation of the OpenGL specification (32-bit)"
Expand Down Expand Up @@ -71,6 +71,7 @@ source=(
0003-vulkan-wsi-wayland-Use-commit_timing-commit_queue-pr.patch
0004-hack-rip-out-commit-timing-v1.patch
0005-wsi-Use-vendored-gamescope-commit-queue-v1-protocol.patch
0006-STEAMOS-Dynamic-swapchain-override-for-gamescope-lim.patch
)
sha256sums=('518307c0057fa3cee8b58df78be431d4df5aafa7edc60d09278b2d7a0a80f3b4'
'SKIP'
Expand All @@ -79,15 +80,17 @@ sha256sums=('518307c0057fa3cee8b58df78be431d4df5aafa7edc60d09278b2d7a0a80f3b4'
'97fc2fddd9afbc91e4dde5be3c1ddcbbcc433ae0d57b2c952c5ac73a372f52c3'
'21ff1a220c8741891fee77c766f6688da518c2ee0a9039b4d7310cef35b644ed'
'b0f51fc9cbd68850a73b858619e3fc4147e75484b80e98f9c854c246864ba68c'
'621a6da07df923d84a89633c122c037f46f579cda6e3c779678c5e85f5c1b272')
'621a6da07df923d84a89633c122c037f46f579cda6e3c779678c5e85f5c1b272'
'40172839bad90eae4be3a94c0e826e7ac9dd6e6bf6b44e266ef603cf02edf1bf')
b2sums=('6b57e99356abccf398c5fb84953fc1490ddf516dbeed1feca8d16344a04c1c15183325752717447a34a61dd4cdda897147e3194f869d8dbadfa5c45a0c95dab5'
'SKIP'
'1ecf007b82260710a7bf5048f47dd5d600c168824c02c595af654632326536a6527fbe0738670ee7b921dd85a70425108e0f471ba85a8e1ca47d294ad74b4adb'
'5a6b6ba26692f4cd3cbec42597e35accde45cae99690017ec2f9ac8ce75ae9cc7a812179cd2e68c0fb324568e5f8ee1fff4d718f109ea655cec6ad67abc203ac'
'e6c37a0c0ba91b2dd4c7242c945166b5cb56834c846ab68598e198e31c9b80db0de70121e6452ed9bbd841e25eb59845c30557d2ac60021c070bc1f7fd0dd6ea'
'bd51d6af44e913ce225c26920418e1ff1768876a916fea94954958eb18375e48aa9f01ef4a486f26c75b7d6ab4b7b83059885acd3ec6867c6b15764436bd919b'
'd48a86ac7470fba6b71f4d523a4a909dc550456dec4bb60b0e81be99c437355339ec5b9bca39a5ef5ec1d3a6956f56e24111befa5955682b88bf570f388f415c'
'b153e21177d4b4a3fb31df7e0adda3a499234884fada8f85e8346439429123499050efa347809745474aac9b1043fb14539404dbebe7f81cb46d14d332fcdfc5')
'b153e21177d4b4a3fb31df7e0adda3a499234884fada8f85e8346439429123499050efa347809745474aac9b1043fb14539404dbebe7f81cb46d14d332fcdfc5'
'acd1fa5cdded4726a84c4d777a04309f71444237e175f66a2bd2cb2a1a45a298b68fa15f385769425b577fb0d0468b81d3ecd90d024940e41d9ceb76adbe388d')
validpgpkeys=('8703B6700E7EE06D7A39B8D6EDAE37B02CEB490D' # Emil Velikov <[email protected]>
'946D09B5E4C9845E63075FF1D961C596A7203456' # Andres Gomez <[email protected]>
'E3E8F480C52ADD73B278EE78E1ECBE07D7D70895' # Juan Antonio Suárez Romero (Igalia, S.L.) <[email protected]>
Expand Down
9 changes: 6 additions & 3 deletions mesa/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkgname=(
'mesa'
)
_mesaver=23.3.3
pkgver=${_mesaver//-/.}.chos1
pkgver=${_mesaver//-/.}.chos2
pkgrel=1
epoch=1
pkgdesc="An open-source implementation of the OpenGL specification"
Expand Down Expand Up @@ -80,6 +80,7 @@ source=(
0003-vulkan-wsi-wayland-Use-commit_timing-commit_queue-pr.patch
0004-hack-rip-out-commit-timing-v1.patch
0005-wsi-Use-vendored-gamescope-commit-queue-v1-protocol.patch
0006-STEAMOS-Dynamic-swapchain-override-for-gamescope-lim.patch
)
sha256sums=('518307c0057fa3cee8b58df78be431d4df5aafa7edc60d09278b2d7a0a80f3b4'
'SKIP'
Expand All @@ -88,15 +89,17 @@ sha256sums=('518307c0057fa3cee8b58df78be431d4df5aafa7edc60d09278b2d7a0a80f3b4'
'97fc2fddd9afbc91e4dde5be3c1ddcbbcc433ae0d57b2c952c5ac73a372f52c3'
'21ff1a220c8741891fee77c766f6688da518c2ee0a9039b4d7310cef35b644ed'
'b0f51fc9cbd68850a73b858619e3fc4147e75484b80e98f9c854c246864ba68c'
'621a6da07df923d84a89633c122c037f46f579cda6e3c779678c5e85f5c1b272')
'621a6da07df923d84a89633c122c037f46f579cda6e3c779678c5e85f5c1b272'
'40172839bad90eae4be3a94c0e826e7ac9dd6e6bf6b44e266ef603cf02edf1bf')
b2sums=('6b57e99356abccf398c5fb84953fc1490ddf516dbeed1feca8d16344a04c1c15183325752717447a34a61dd4cdda897147e3194f869d8dbadfa5c45a0c95dab5'
'SKIP'
'1ecf007b82260710a7bf5048f47dd5d600c168824c02c595af654632326536a6527fbe0738670ee7b921dd85a70425108e0f471ba85a8e1ca47d294ad74b4adb'
'5a6b6ba26692f4cd3cbec42597e35accde45cae99690017ec2f9ac8ce75ae9cc7a812179cd2e68c0fb324568e5f8ee1fff4d718f109ea655cec6ad67abc203ac'
'e6c37a0c0ba91b2dd4c7242c945166b5cb56834c846ab68598e198e31c9b80db0de70121e6452ed9bbd841e25eb59845c30557d2ac60021c070bc1f7fd0dd6ea'
'bd51d6af44e913ce225c26920418e1ff1768876a916fea94954958eb18375e48aa9f01ef4a486f26c75b7d6ab4b7b83059885acd3ec6867c6b15764436bd919b'
'd48a86ac7470fba6b71f4d523a4a909dc550456dec4bb60b0e81be99c437355339ec5b9bca39a5ef5ec1d3a6956f56e24111befa5955682b88bf570f388f415c'
'b153e21177d4b4a3fb31df7e0adda3a499234884fada8f85e8346439429123499050efa347809745474aac9b1043fb14539404dbebe7f81cb46d14d332fcdfc5')
'b153e21177d4b4a3fb31df7e0adda3a499234884fada8f85e8346439429123499050efa347809745474aac9b1043fb14539404dbebe7f81cb46d14d332fcdfc5'
'acd1fa5cdded4726a84c4d777a04309f71444237e175f66a2bd2cb2a1a45a298b68fa15f385769425b577fb0d0468b81d3ecd90d024940e41d9ceb76adbe388d')
validpgpkeys=('8703B6700E7EE06D7A39B8D6EDAE37B02CEB490D' # Emil Velikov <[email protected]>
'946D09B5E4C9845E63075FF1D961C596A7203456' # Andres Gomez <[email protected]>
'E3E8F480C52ADD73B278EE78E1ECBE07D7D70895' # Juan Antonio Suárez Romero (Igalia, S.L.) <[email protected]>
Expand Down

0 comments on commit 1e9cb8a

Please sign in to comment.