Skip to content

Commit

Permalink
layer: identify 32-bit and 64-bit layer logs
Browse files Browse the repository at this point in the history
Leave some breadcrumbs to figure out whether the logs we're getting come
from the 32-bit or 64-bit layer. ARM/aarch64 and FreeBSD logs will appear
without a bit suffix.
  • Loading branch information
matte-schwartz committed Feb 2, 2025
1 parent ec4e002 commit 8cf6164
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 47 deletions.
93 changes: 53 additions & 40 deletions layer/VkLayer_FROG_gamescope_wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@

#include "../src/messagey.h"

// For layer logging.
#if __linux__
#if __x86_64__
#define WSI_LAYER_INFO "[Gamescope WSI 64-bit] "
#elif __i386__
#define WSI_LAYER_INFO "[Gamescope WSI 32-bit] "
#else
#define WSI_LAYER_INFO "[Gamescope WSI] "
#endif
#else
#define WSI_LAYER_INFO "[Gamescope WSI] "
#endif

using namespace std::literals;

namespace GamescopeWSILayer {
Expand Down Expand Up @@ -150,17 +163,17 @@ namespace GamescopeWSILayer {
static uint32_t getMinImageCount() {
static uint32_t s_minImageCount = []() -> uint32_t {
if (auto minCount = parseEnv<uint32_t>("GAMESCOPE_WSI_MIN_IMAGE_COUNT")) {
fprintf(stderr, "[Gamescope WSI] minImageCount overridden by GAMESCOPE_WSI_MIN_IMAGE_COUNT: %u\n", *minCount);
fprintf(stderr, WSI_LAYER_INFO "minImageCount overridden by GAMESCOPE_WSI_MIN_IMAGE_COUNT: %u\n", *minCount);
return *minCount;
}

if (auto minCount = parseEnv<uint32_t>("vk_wsi_override_min_image_count")) {
fprintf(stderr, "[Gamescope WSI] minImageCount overridden by vk_wsi_override_min_image_count: %u\n", *minCount);
fprintf(stderr, WSI_LAYER_INFO "minImageCount overridden by vk_wsi_override_min_image_count: %u\n", *minCount);
return *minCount;
}

if (auto minCount = parseEnv<uint32_t>("vk_x11_override_min_image_count")) {
fprintf(stderr, "[Gamescope WSI] minImageCount overridden by vk_x11_override_min_image_count: %u\n", *minCount);
fprintf(stderr, WSI_LAYER_INFO "minImageCount overridden by vk_x11_override_min_image_count: %u\n", *minCount);
return *minCount;
}

Expand Down Expand Up @@ -233,13 +246,13 @@ namespace GamescopeWSILayer {
{
const char *mesaExecutableEnv = getenv("MESA_DRICONF_EXECUTABLE_OVERRIDE");
if (mesaExecutableEnv && *mesaExecutableEnv) {
fprintf(stderr, "[Gamescope WSI] Executable name overriden by MESA_DRICONF_EXECUTABLE_OVERRIDE: %s\n", mesaExecutableEnv);
fprintf(stderr, WSI_LAYER_INFO "Executable name overriden by MESA_DRICONF_EXECUTABLE_OVERRIDE: %s\n", mesaExecutableEnv);
return mesaExecutableEnv;
}

const char *mesaProcessName = getenv("MESA_PROCESS_NAME");
if (mesaProcessName && *mesaProcessName) {
fprintf(stderr, "[Gamescope WSI] Executable name overriden by MESA_PROCESS_NAME: %s\n", mesaExecutableEnv);
fprintf(stderr, WSI_LAYER_INFO "Executable name overriden by MESA_PROCESS_NAME: %s\n", mesaExecutableEnv);
return mesaProcessName;
}

Expand All @@ -250,7 +263,7 @@ namespace GamescopeWSILayer {
free(programNameCStr);
}

fprintf(stderr, "[Gamescope WSI] Executable name: %s\n", name.c_str());
fprintf(stderr, WSI_LAYER_INFO "Executable name: %s\n", name.c_str());
return name;
}();

Expand Down Expand Up @@ -435,15 +448,15 @@ namespace GamescopeWSILayer {
auto largestObscuringWindowSize = xcb::getLargestObscuringChildWindowSize(connection, window);
auto toplevelWindow = xcb::getToplevelWindow(connection, window);
if (!rect || !largestObscuringWindowSize || !toplevelWindow) {
fprintf(stderr, "[Gamescope WSI] canBypassXWayland: failed to get window info for window 0x%x.\n", window);
fprintf(stderr, WSI_LAYER_INFO "canBypassXWayland: failed to get window info for window 0x%x.\n", window);
return false;
}

cachedWindowRect = *rect;

auto toplevelRect = xcb::getWindowRect(connection, *toplevelWindow);
if (!toplevelRect) {
fprintf(stderr, "[Gamescope WSI] canBypassXWayland: failed to get window info for window 0x%x.\n", window);
fprintf(stderr, WSI_LAYER_INFO "canBypassXWayland: failed to get window info for window 0x%x.\n", window);
return false;
}

Expand All @@ -459,7 +472,7 @@ namespace GamescopeWSILayer {
// (There can be dummy composite redirect windows and whatever.)
if (largestObscuringWindowSize->width > 1 || largestObscuringWindowSize->height > 1) {
#if GAMESCOPE_WSI_BYPASS_DEBUG
fprintf(stderr, "[Gamescope WSI] Largest obscuring window size: %u %u\n", largestObscuringWindowSize->width, largestObscuringWindowSize->height);
fprintf(stderr, WSI_LAYER_INFO "Largest obscuring window size: %u %u\n", largestObscuringWindowSize->width, largestObscuringWindowSize->height);
#endif
return false;
}
Expand All @@ -475,7 +488,7 @@ namespace GamescopeWSILayer {
iabs(int32_t(toplevelRect->extent.width) - int32_t(rect->extent.width)) > 2 ||
iabs(int32_t(toplevelRect->extent.height) - int32_t(rect->extent.height)) > 2) {
#if GAMESCOPE_WSI_BYPASS_DEBUG
fprintf(stderr, "[Gamescope WSI] Not within 1px margin of error. Offset: %d %d Extent: %u %u vs %u %u\n",
fprintf(stderr, WSI_LAYER_INFO "Not within 1px margin of error. Offset: %d %d Extent: %u %u vs %u %u\n",
rect->offset.x, rect->offset.y,
toplevelRect->extent.width, toplevelRect->extent.height,
rect->extent.width, rect->extent.height);
Expand Down Expand Up @@ -547,7 +560,7 @@ namespace GamescopeWSILayer {
std::unique_lock lock(*swapchain->presentTimingMutex);
swapchain->refreshCycle = (uint64_t(refresh_cycle_hi) << 32) | refresh_cycle_lo;
}
fprintf(stderr, "[Gamescope WSI] Swapchain recieved new refresh cycle: %.2fms\n", swapchain->refreshCycle / 1'000'000.0);
fprintf(stderr, WSI_LAYER_INFO "Swapchain recieved new refresh cycle: %.2fms\n", swapchain->refreshCycle / 1'000'000.0);
},

.retired = [](
Expand All @@ -557,7 +570,7 @@ namespace GamescopeWSILayer {
{
swapchain->retired = true;
}
fprintf(stderr, "[Gamescope WSI] Swapchain retired\n");
fprintf(stderr, WSI_LAYER_INFO "Swapchain retired\n");
},
};

Expand Down Expand Up @@ -596,20 +609,20 @@ namespace GamescopeWSILayer {

wl_display *display = wl_display_connect(gamescopeWaylandSocket());
if (!display) {
fprintf(stderr, "[Gamescope WSI] Failed to connect to gamescope socket: %s. Bypass layer will be unavailable.\n", gamescopeWaylandSocket());
fprintf(stderr, WSI_LAYER_INFO "Failed to connect to gamescope socket: %s. Bypass layer will be unavailable.\n", gamescopeWaylandSocket());
return result;
}

{
if (pCreateInfo->pApplicationInfo) {
fprintf(stderr, "[Gamescope WSI] Application info:\n");
fprintf(stderr, WSI_LAYER_INFO "Application info:\n");
fprintf(stderr, " pApplicationName: %s\n", pCreateInfo->pApplicationInfo->pApplicationName);
fprintf(stderr, " applicationVersion: %u\n", pCreateInfo->pApplicationInfo->applicationVersion);
fprintf(stderr, " pEngineName: %s\n", pCreateInfo->pApplicationInfo->pEngineName);
fprintf(stderr, " engineVersion: %u\n", pCreateInfo->pApplicationInfo->engineVersion);
fprintf(stderr, " apiVersion: %u\n", pCreateInfo->pApplicationInfo->apiVersion);
} else {
fprintf(stderr, "[Gamescope WSI] No application info given.\n");
fprintf(stderr, WSI_LAYER_INFO "No application info given.\n");
}
}

Expand Down Expand Up @@ -663,7 +676,7 @@ namespace GamescopeWSILayer {
vkroots::ChainPatcher<VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT>
maintenance1Patcher(&deviceCreateInfo, [&](VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT *pMaintenance1)
{
fprintf(stderr, "[Gamescope WSI] Forcing on VK_EXT_swapchain_maintenance1.\n");
fprintf(stderr, WSI_LAYER_INFO "Forcing on VK_EXT_swapchain_maintenance1.\n");
pMaintenance1->swapchainMaintenance1 = VK_TRUE;
return true;
});
Expand Down Expand Up @@ -735,7 +748,7 @@ namespace GamescopeWSILayer {

GamescopeWaylandObjects waylandObjects = GamescopeWaylandObjects::get(pCreateInfo->display);
if (!waylandObjects.valid()) {
fprintf(stderr, "[Gamescope WSI] Failed to get Wayland objects\n");
fprintf(stderr, WSI_LAYER_INFO "Failed to get Wayland objects\n");
return VK_ERROR_SURFACE_LOST_KHR;
}

Expand Down Expand Up @@ -975,17 +988,17 @@ namespace GamescopeWSILayer {
xcb_window_t window,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
fprintf(stderr, "[Gamescope WSI] Creating Gamescope surface: xid: 0x%x\n", window);
fprintf(stderr, WSI_LAYER_INFO "Creating Gamescope surface: xid: 0x%x\n", window);

GamescopeWaylandObjects waylandObjects = GamescopeWaylandObjects::get(gamescopeInstance->display);
if (!waylandObjects.valid()) {
fprintf(stderr, "[Gamescope WSI] Failed to get Wayland objects\n");
fprintf(stderr, WSI_LAYER_INFO "Failed to get Wayland objects\n");
return VK_ERROR_SURFACE_LOST_KHR;
}

wl_surface* waylandSurface = wl_compositor_create_surface(waylandObjects.compositor);
if (!waylandSurface) {
fprintf(stderr, "[Gamescope WSI] Failed to create wayland surface - xid: 0x%x\n", window);
fprintf(stderr, WSI_LAYER_INFO "Failed to create wayland surface - xid: 0x%x\n", window);
return VK_ERROR_SURFACE_LOST_KHR;
}

Expand All @@ -1009,7 +1022,7 @@ namespace GamescopeWSILayer {

VkResult result = pDispatch->CreateWaylandSurfaceKHR(instance, &waylandCreateInfo, pAllocator, pSurface);
if (result != VK_SUCCESS) {
fprintf(stderr, "[Gamescope WSI] Failed to create Vulkan wayland surface - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), window);
fprintf(stderr, WSI_LAYER_INFO "Failed to create Vulkan wayland surface - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), window);
return result;
}

Expand All @@ -1023,11 +1036,11 @@ namespace GamescopeWSILayer {
VkSurfaceKHR fallbackSurface = VK_NULL_HANDLE;
result = pDispatch->CreateXcbSurfaceKHR(instance, &xcbCreateInfo, pAllocator, &fallbackSurface);
if (result != VK_SUCCESS) {
fprintf(stderr, "[Gamescope WSI] Failed to create Vulkan xcb (fallback) surface - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), window);
fprintf(stderr, WSI_LAYER_INFO "Failed to create Vulkan xcb (fallback) surface - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), window);
return result;
}

fprintf(stderr, "[Gamescope WSI] Made gamescope surface for xid: 0x%x\n", window);
fprintf(stderr, WSI_LAYER_INFO "Made gamescope surface for xid: 0x%x\n", window);
auto gamescopeSurface = GamescopeSurface::create(*pSurface, GamescopeSurfaceData {
.instance = instance,
.display = gamescopeInstance->display,
Expand All @@ -1046,7 +1059,7 @@ namespace GamescopeWSILayer {
}

static void DumpGamescopeSurfaceState(GamescopeInstance& instance, GamescopeSurface& surface) {
fprintf(stderr, "[Gamescope WSI] Surface state:\n");
fprintf(stderr, WSI_LAYER_INFO "Surface state:\n");
fprintf(stderr, " steam app id: %u\n", instance->appId);
fprintf(stderr, " window xid: 0x%x\n", surface->window);
fprintf(stderr, " wayland surface res id: %u\n", wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(surface->surface)));
Expand Down Expand Up @@ -1076,9 +1089,9 @@ namespace GamescopeWSILayer {
gamescope_swapchain_destroy(state->object);
}
GamescopeSwapchain::remove(swapchain);
fprintf(stderr, "[Gamescope WSI] Destroying swapchain: %p\n", reinterpret_cast<void*>(swapchain));
fprintf(stderr, WSI_LAYER_INFO "Destroying swapchain: %p\n", reinterpret_cast<void*>(swapchain));
pDispatch->DestroySwapchainKHR(device, swapchain, pAllocator);
fprintf(stderr, "[Gamescope WSI] Destroyed swapchain: %p\n", reinterpret_cast<void*>(swapchain));
fprintf(stderr, WSI_LAYER_INFO "Destroyed swapchain: %p\n", reinterpret_cast<void*>(swapchain));
}

static VkResult CreateSwapchainKHR(
Expand Down Expand Up @@ -1158,7 +1171,7 @@ namespace GamescopeWSILayer {
minImageCount = std::max(getMinImageCount(), minImageCount);
swapchainInfo.minImageCount = minImageCount;

fprintf(stderr, "[Gamescope WSI] Creating swapchain for xid: 0x%0x - oldSwapchain: %p - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
fprintf(stderr, WSI_LAYER_INFO "Creating swapchain for xid: 0x%0x - oldSwapchain: %p - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
gamescopeSurface->window,
reinterpret_cast<void*>(pCreateInfo->oldSwapchain),
pCreateInfo->minImageCount,
Expand All @@ -1183,7 +1196,7 @@ namespace GamescopeWSILayer {
&VkSurfaceFormatKHR::format) ;

if (!supportedSwapchainFormat) {
fprintf(stderr, "[Gamescope WSI] Refusing to make swapchain (unsupported VkFormat) for xid: 0x%0x - format: %s - colorspace: %s - flip: %s\n",
fprintf(stderr, WSI_LAYER_INFO "Refusing to make swapchain (unsupported VkFormat) for xid: 0x%0x - format: %s - colorspace: %s - flip: %s\n",
gamescopeSurface->window,
vkroots::helpers::enumString(pCreateInfo->imageFormat),
vkroots::helpers::enumString(pCreateInfo->imageColorSpace),
Expand All @@ -1197,21 +1210,21 @@ namespace GamescopeWSILayer {
if (!gamescopeSurface->isWayland()) {
auto oServerId = xcb::getPropertyValue<uint32_t>(gamescopeSurface->connection, "GAMESCOPE_XWAYLAND_SERVER_ID"sv);
if (!oServerId) {
fprintf(stderr, "[Gamescope WSI] Failed to get Xwayland server id. Failing swapchain creation.\n");
fprintf(stderr, WSI_LAYER_INFO "Failed to get Xwayland server id. Failing swapchain creation.\n");
return VK_ERROR_SURFACE_LOST_KHR;
}
serverId = *oServerId;
}

auto gamescopeInstance = GamescopeInstance::get(gamescopeSurface->instance);
if (!gamescopeInstance) {
fprintf(stderr, "[Gamescope WSI] CreateSwapchainKHR: Instance for swapchain was already destroyed. (App use after free).\n");
fprintf(stderr, WSI_LAYER_INFO "CreateSwapchainKHR: Instance for swapchain was already destroyed. (App use after free).\n");
return VK_ERROR_SURFACE_LOST_KHR;
}

VkResult result = pDispatch->CreateSwapchainKHR(device, &swapchainInfo, pAllocator, pSwapchain);
if (result != VK_SUCCESS) {
fprintf(stderr, "[Gamescope WSI] Failed to create swapchain - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), gamescopeSurface->window);
fprintf(stderr, WSI_LAYER_INFO "Failed to create swapchain - vr: %s xid: 0x%x\n", vkroots::helpers::enumString(result), gamescopeSurface->window);
return result;
}

Expand Down Expand Up @@ -1239,7 +1252,7 @@ namespace GamescopeWSILayer {
uint32_t imageCount = 0;
pDispatch->GetSwapchainImagesKHR(device, *pSwapchain, &imageCount, nullptr);

fprintf(stderr, "[Gamescope WSI] Created swapchain for xid: 0x%0x swapchain: %p - imageCount: %u\n",
fprintf(stderr, WSI_LAYER_INFO "Created swapchain for xid: 0x%0x swapchain: %p - imageCount: %u\n",
gamescopeSurface->window,
reinterpret_cast<void*>(*pSwapchain),
imageCount);
Expand Down Expand Up @@ -1310,7 +1323,7 @@ namespace GamescopeWSILayer {
assert(pPresentTimes->swapchainCount == presentInfo.swapchainCount);

#if GAMESCOPE_WSI_DISPLAY_TIMING_DEBUG
fprintf(stderr, "[Gamescope WSI] QueuePresentKHR: presentID: %u - desiredPresentTime: %lu - now: %lu\n", pPresentTimes->pTimes[i].presentID, pPresentTimes->pTimes[i].desiredPresentTime, getTimeMonotonic());
fprintf(stderr, WSI_LAYER_INFO "QueuePresentKHR: presentID: %u - desiredPresentTime: %lu - now: %lu\n", pPresentTimes->pTimes[i].presentID, pPresentTimes->pTimes[i].desiredPresentTime, getTimeMonotonic());
#endif
gamescope_swapchain_set_present_time(
gamescopeSwapchain->object,
Expand Down Expand Up @@ -1408,13 +1421,13 @@ namespace GamescopeWSILayer {
// exposed as supported in order for them to handle presentation latency like they
// would as in FIFO mode.
if (frameLimiterAware && gamescopeSwapchain->forceFifo != forceFifo) {
fprintf(stderr, "[Gamescope WSI] Forcing swapchain recreation as frame limiter changed, and we want the app to know the exposed modes changed.\n");
fprintf(stderr, WSI_LAYER_INFO "Forcing swapchain recreation as frame limiter changed, and we want the app to know the exposed modes changed.\n");
UpdateSwapchainResult(VK_ERROR_OUT_OF_DATE_KHR);
}

auto gamescopeSurface = GamescopeSurface::get(gamescopeSwapchain->surface);
if (!gamescopeSurface) {
fprintf(stderr, "[Gamescope WSI] QueuePresentKHR: Surface for swapchain %u was already destroyed. (App use after free).\n", i);
fprintf(stderr, WSI_LAYER_INFO "QueuePresentKHR: Surface for swapchain %u was already destroyed. (App use after free).\n", i);
abort();
continue;
}
Expand All @@ -1438,7 +1451,7 @@ namespace GamescopeWSILayer {
if (windowSizeChanged)
UpdateSwapchainResult(VK_ERROR_OUT_OF_DATE_KHR);
} else {
fprintf(stderr, "[Gamescope WSI] QueuePresentKHR: Failed to get cached window size for swapchain %u\n", i);
fprintf(stderr, WSI_LAYER_INFO "QueuePresentKHR: Failed to get cached window size for swapchain %u\n", i);
}
}
}
Expand All @@ -1456,7 +1469,7 @@ namespace GamescopeWSILayer {
for (uint32_t i = 0; i < swapchainCount; i++) {
auto gamescopeSwapchain = GamescopeSwapchain::get(pSwapchains[i]);
if (!gamescopeSwapchain) {
fprintf(stderr, "[Gamescope WSI] SetHdrMetadataEXT: Swapchain %u does not support HDR.\n", i);
fprintf(stderr, WSI_LAYER_INFO "SetHdrMetadataEXT: Swapchain %u does not support HDR.\n", i);
continue;
}

Expand All @@ -1476,7 +1489,7 @@ namespace GamescopeWSILayer {
nits_to_u16(metadata.maxContentLightLevel),
nits_to_u16(metadata.maxFrameAverageLightLevel));

fprintf(stderr, "[Gamescope WSI] VkHdrMetadataEXT: display primaries:\n");
fprintf(stderr, WSI_LAYER_INFO "VkHdrMetadataEXT: display primaries:\n");
fprintf(stderr, " r: %.4g %.4g\n", metadata.displayPrimaryRed.x, metadata.displayPrimaryRed.y);
fprintf(stderr, " g: %.4g %.4g\n", metadata.displayPrimaryGreen.x, metadata.displayPrimaryGreen.y);
fprintf(stderr, " b: %.4g %.4g\n", metadata.displayPrimaryBlue.x, metadata.displayPrimaryBlue.y);
Expand All @@ -1495,7 +1508,7 @@ namespace GamescopeWSILayer {
VkPastPresentationTimingGOOGLE* pPresentationTimings) {
auto gamescopeSwapchain = GamescopeSwapchain::get(swapchain);
if (!gamescopeSwapchain) {
fprintf(stderr, "[Gamescope WSI] GetPastPresentationTimingGOOGLE: Not a gamescope swapchain.\n");
fprintf(stderr, WSI_LAYER_INFO "GetPastPresentationTimingGOOGLE: Not a gamescope swapchain.\n");
return VK_ERROR_SURFACE_LOST_KHR;
}

Expand All @@ -1522,7 +1535,7 @@ namespace GamescopeWSILayer {
VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) {
auto gamescopeSwapchain = GamescopeSwapchain::get(swapchain);
if (!gamescopeSwapchain) {
fprintf(stderr, "[Gamescope WSI] GetRefreshCycleDurationGOOGLE: Not a gamescope swapchain.\n");
fprintf(stderr, WSI_LAYER_INFO "GetRefreshCycleDurationGOOGLE: Not a gamescope swapchain.\n");
return VK_ERROR_SURFACE_LOST_KHR;
}

Expand Down
Loading

0 comments on commit 8cf6164

Please sign in to comment.