mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
cleanup (#764)
This commit is contained in:
1 parent
4163b31b02
commit
83ec5708ed
852 files changed
+4844
-46144
No files matched your search
@@ -1,14 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# Builds Cardboard mode's SteamVR pieces for the guest (glibc aarch64):
|
||||
# <out>/droiddeck the SteamVR driver: driver_droiddeck.so, its manifest and default settings
|
||||
# <out>/layer VK_LAYER_DROIDDECK_vr, the Vulkan layer SteamVR's compositor needs on Turnip/KGSL
|
||||
#
|
||||
# tools/vr/build.sh [OUT] in the local cross image (default OUT: tools/vr/out)
|
||||
# tools/vr/build.sh --native OUT with aarch64-linux-gnu-gcc/g++ on PATH (CI, or inside the image)
|
||||
#
|
||||
# Vulkan headers: VK_INCLUDE (a directory holding vulkan/), else the NDK's (ANDROID_NDK_HOME, the
|
||||
# runner's latest NDK, or the newest under ANDROID_HOME). Only vulkan/ is copied out of it: the rest of
|
||||
# the NDK sysroot is Android's libc, not the guest's.
|
||||
set -euo pipefail
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
repo=$(cd "$here/../.." && pwd)
|
||||
@@ -29,8 +19,6 @@ if [ -z "$vkinc" ]; then
|
||||
fi
|
||||
[ -n "$vkinc" ] && [ -f "$vkinc/vulkan/vulkan_core.h" ] || { echo "tools/vr/build.sh: no Vulkan headers (set VK_INCLUDE)" >&2; exit 1; }
|
||||
|
||||
# Everything the compilers read sits under the repo, so the cross image (which mounts only the repo)
|
||||
# sees it too.
|
||||
work="$repo/build/vr"
|
||||
rm -rf "$work" && mkdir -p "$work/include"
|
||||
cp -R "$vkinc/vulkan" "$work/include/"
|
||||
@@ -40,7 +28,6 @@ mkdir -p "$work/out/droiddeck/bin/linuxarm64" "$work/out/layer"
|
||||
compile() {
|
||||
local cmd=(sh -c '
|
||||
set -e
|
||||
# libwayland-client: linked against a stub with its soname (the guest has the real one).
|
||||
mkdir -p build/vr/stub
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wl,-soname,libwayland-client.so.0 -Itools/vr/third_party/wayland \
|
||||
-o build/vr/stub/libwayland-client.so tools/vr/src/wayland_client_stub.c
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
// SteamVR driver for DroidDeck's Cardboard mode: one 3DoF HMD whose pose is the phone's rotation
|
||||
// sensor, read from the head pose file the app shares with the guest
|
||||
// (app/src/main/cpp/waylandcomp/src/headpose_shm.h, /run/droiddeck/droiddeck-headpose).
|
||||
//
|
||||
// The HMD renders an undistorted side-by-side pair: the app's Cardboard pass, in its side-by-side
|
||||
// mode, does the lens distortion for the viewer the user picked. So the projection here is exactly
|
||||
// the frustum that pass samples (tan_half_fov, eye_aspect from the pose file), and the distortion is
|
||||
// the identity.
|
||||
//
|
||||
// How the frames reach the screen is the open question this driver is for: see docs/cardboard-vr.md.
|
||||
// It exposes IVRDisplayComponent with the display "on the desktop" (extended mode) at the session's
|
||||
// size, and logs what vrserver / vrcompositor ask of it.
|
||||
#include "openvr_driver.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -50,7 +38,6 @@ void Log(const char *fmt, ...) {
|
||||
fprintf(stderr, "[droiddeck] %s\n", buf);
|
||||
}
|
||||
|
||||
// The shared pose file, mapped read-only; reads follow the seqlock in headpose_shm.h.
|
||||
class PoseFile {
|
||||
public:
|
||||
bool Read(droiddeck_headpose *out) {
|
||||
@@ -82,7 +69,6 @@ private:
|
||||
};
|
||||
|
||||
HmdQuaternion_t QuatFromMatrix(const float m[9]) {
|
||||
// Row-major rotation -> quaternion (Shepperd's method).
|
||||
HmdQuaternion_t q;
|
||||
float tr = m[0] + m[4] + m[8];
|
||||
if (tr > 0.0f) {
|
||||
@@ -101,8 +87,6 @@ HmdQuaternion_t QuatFromMatrix(const float m[9]) {
|
||||
return q;
|
||||
}
|
||||
|
||||
// IVRVirtualDisplay: the compositor renders the final frame into its own backbuffer and hands it
|
||||
// here instead of scanning it out. What the handle is on Linux is what this logs (experiment).
|
||||
class VirtualDisplay : public IVRVirtualDisplay {
|
||||
public:
|
||||
void Present(const PresentInfo_t *info, uint32_t size) override {
|
||||
@@ -115,7 +99,6 @@ public:
|
||||
}
|
||||
void WaitForPresent() override {}
|
||||
bool GetTimeSinceLastVsync(float *seconds, uint64_t *counter) override {
|
||||
// A free-running 60 Hz vsync.
|
||||
using namespace std::chrono;
|
||||
double t = duration<double>(steady_clock::now().time_since_epoch()).count();
|
||||
double period = 1.0 / 60.0;
|
||||
@@ -129,8 +112,6 @@ private:
|
||||
std::chrono::steady_clock::time_point last_;
|
||||
};
|
||||
|
||||
// The vsync grid SteamVR paces against in driver-direct mode (Prop_DriverDirectModeSendsVsyncEvents):
|
||||
// a free-running 60 Hz tick, declared a little ahead of time (ALVR's announcer, alvr/server_openvr/src/vsync.rs).
|
||||
class Vsync {
|
||||
public:
|
||||
static constexpr std::chrono::nanoseconds kInterval{16666667};
|
||||
@@ -172,10 +153,6 @@ private:
|
||||
static inline std::chrono::steady_clock::time_point last_{};
|
||||
};
|
||||
|
||||
// IVRDriverDirectModeComponent: SteamVR renders each eye into textures this driver allocates
|
||||
// (shared Vulkan images from SteamVR's IPC resource manager, dmabufs on Linux) and hands them
|
||||
// over per frame. This is how ALVR gets frames on Linux; it avoids the compositor's own direct mode,
|
||||
// which needs VK_KHR_display - something Turnip on KGSL refuses outright.
|
||||
class DirectMode : public IVRDriverDirectModeComponent {
|
||||
public:
|
||||
struct Set {
|
||||
@@ -190,8 +167,8 @@ public:
|
||||
Set set;
|
||||
set.pid = pid;
|
||||
set.desc = *d;
|
||||
const uint32_t usage = 0x1 /* TRANSFER_SRC */ | 0x4 /* SAMPLED */ | 0x80 /* INPUT_ATTACHMENT */;
|
||||
const uint32_t create = 0x8 /* MUTABLE_FORMAT */;
|
||||
const uint32_t usage = 0x1 | 0x4 | 0x80 ;
|
||||
const uint32_t create = 0x8 ;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
SharedTextureHandle_t h = 0;
|
||||
if (!VRIPCResourceManager()->NewSharedVulkanImage(d->nFormat, d->nWidth, d->nHeight, true, false, true, 1, 1,
|
||||
@@ -245,7 +222,6 @@ public:
|
||||
|
||||
void SubmitLayer(const SubmitLayerPerEye_t (&eyes)[2]) override {
|
||||
layers_++;
|
||||
// The first layer of a frame is the compositor's own picture; overlays after it are not drawn yet.
|
||||
if (layerInFrame_++ == 0) {
|
||||
for (int e = 0; e < 2; e++) {
|
||||
frame_.texture[e] = eyes[e].hTexture;
|
||||
@@ -274,7 +250,6 @@ public:
|
||||
}
|
||||
|
||||
void PostPresent(const Throttling_t *t) override {
|
||||
// Hold until the tick after the last one declared (ALVR's pacing): a slow frame costs one frame.
|
||||
auto last = Vsync::LastTick();
|
||||
auto until = last + Vsync::kInterval * (1 + (t ? t->nFramesToThrottle : 0));
|
||||
if (until > std::chrono::steady_clock::now()) std::this_thread::sleep_until(until);
|
||||
@@ -304,12 +279,9 @@ private:
|
||||
droiddeck::EyeFrame frame_{};
|
||||
};
|
||||
|
||||
// The session's game pad, as the app publishes it for the guest: the absolute-state snapshot at the
|
||||
// head of fake input ring 0 (app/src/main/cpp/fakeinput_steam.cpp, FakeInputRingHeader), under a
|
||||
// seqlock. FAKE_EVDEV_MEMFD_PATHS names the rings in every session process's environment.
|
||||
struct PadState {
|
||||
uint32_t buttons = 0; // bit order of FakeInputWriter.BUTTON_MAP; bit 11 = the QAM button
|
||||
int16_t axes[8] = {}; // X, Y, RX, RY (+-32767), GAS = right trigger, BRAKE = left (0..255), HAT0X, HAT0Y
|
||||
uint32_t buttons = 0;
|
||||
int16_t axes[8] = {};
|
||||
};
|
||||
enum : uint32_t {
|
||||
PAD_A = 1u << 0, PAD_B = 1u << 1, PAD_X = 1u << 2, PAD_Y = 1u << 3, PAD_LB = 1u << 4, PAD_RB = 1u << 5,
|
||||
@@ -340,7 +312,7 @@ private:
|
||||
std::string path;
|
||||
if (const char *env = getenv("DROIDDECK_VR_PAD_RING")) path = env;
|
||||
if (path.empty()) {
|
||||
const char *paths = getenv("FAKE_EVDEV_MEMFD_PATHS"); // "0=/path;1=/path;..."
|
||||
const char *paths = getenv("FAKE_EVDEV_MEMFD_PATHS");
|
||||
if (paths && !strncmp(paths, "0=", 2)) path.assign(paths + 2, strcspn(paths + 2, ";"));
|
||||
}
|
||||
if (path.empty()) {
|
||||
@@ -363,10 +335,6 @@ private:
|
||||
std::chrono::steady_clock::time_point retry_{};
|
||||
};
|
||||
|
||||
// One hand: a Vive-profile controller driven by the game pad. 3DoF, so it is a gaze pointer: it sits
|
||||
// low in front of its side of the body and points where the head looks, and SteamVR's laser follows the
|
||||
// view. Right hand: right stick = trackpad, A = trackpad click, RT = trigger, RB = grip, Start = menu,
|
||||
// the Steam/guide button = system. Left: left stick, X, LT, LB, Select.
|
||||
class CardboardController : public ITrackedDeviceServerDriver {
|
||||
public:
|
||||
explicit CardboardController(bool right) : right_(right) {}
|
||||
@@ -404,14 +372,12 @@ public:
|
||||
|
||||
DriverPose_t GetPose() override { return pose_; }
|
||||
|
||||
// From the driver's pose thread: the head's orientation and the pad.
|
||||
void Update(const HmdQuaternion_t &head, const PadState *pad) {
|
||||
if (id_ == k_unTrackedDeviceIndexInvalid) return;
|
||||
DriverPose_t p = {};
|
||||
p.qWorldFromDriverRotation.w = 1;
|
||||
p.qDriverFromHeadRotation.w = 1;
|
||||
p.qRotation = head;
|
||||
// Low and in front of its side, in head space, then into the room with the head's rotation.
|
||||
const double off[3] = {right_ ? 0.18 : -0.18, -0.35, -0.30};
|
||||
double m[3][3];
|
||||
const double w = head.w, x = head.x, y = head.y, z = head.z;
|
||||
@@ -460,7 +426,6 @@ public:
|
||||
if (height_ <= 0) height_ = 1080;
|
||||
float hz = VRSettings()->GetFloat(kSettingsSection, "displayFrequency");
|
||||
if (hz <= 0.0f) hz = 60.0f;
|
||||
// Until the app has drawn an eye: the Cardboard pass's defaults for a 1920x1080 panel.
|
||||
tanHalf_ = 1.0f;
|
||||
eyeAspect_ = (width_ * 0.5f) / height_;
|
||||
droiddeck_headpose hp;
|
||||
@@ -476,8 +441,6 @@ public:
|
||||
VRProperties()->SetFloatProperty(c, Prop_DisplayFrequency_Float, hz);
|
||||
VRProperties()->SetFloatProperty(c, Prop_SecondsFromVsyncToPhotons_Float, 0.011f);
|
||||
VRProperties()->SetUint64Property(c, Prop_CurrentUniverseId_Uint64, 2);
|
||||
// Off the desktop: with a direct mode component that sends SteamVR's compositor down the
|
||||
// driver-direct path; on it, the compositor opens its own direct mode window (VK_KHR_display).
|
||||
VRProperties()->SetBoolProperty(c, Prop_IsOnDesktop_Bool, false);
|
||||
VRProperties()->SetBoolProperty(c, Prop_DisplayDebugMode_Bool, false);
|
||||
directMode_ = VRSettings()->GetBool(kSettingsSection, "directMode");
|
||||
@@ -489,9 +452,6 @@ public:
|
||||
VRProperties()->SetBoolProperty(c, Prop_HasDisplayComponent_Bool, true);
|
||||
virtualDisplay_ = VRSettings()->GetBool(kSettingsSection, "virtualDisplay");
|
||||
VRProperties()->SetBoolProperty(c, Prop_HasVirtualDisplayComponent_Bool, virtualDisplay_);
|
||||
// A proximity sensor that reads "worn" while Cardboard mode is on: otherwise SteamVR sees a headset
|
||||
// lying still (a phone on a table between sessions) and puts the display in standby, after which
|
||||
// the compositor submits no layers at all.
|
||||
VRProperties()->SetBoolProperty(c, Prop_ContainsProximitySensor_Bool, true);
|
||||
VRDriverInput()->CreateBooleanComponent(c, "/proximity", &proximity_);
|
||||
VRDriverInput()->UpdateBooleanComponent(proximity_, true, 0);
|
||||
@@ -528,7 +488,7 @@ public:
|
||||
p.qWorldFromDriverRotation.w = 1;
|
||||
p.qDriverFromHeadRotation.w = 1;
|
||||
p.qRotation.w = 1;
|
||||
p.vecPosition[1] = 1.6; // standing eye height: 3DoF, the head never moves
|
||||
p.vecPosition[1] = 1.6;
|
||||
droiddeck_headpose hp;
|
||||
bool ok = pose_.Read(&hp);
|
||||
if (ok) {
|
||||
@@ -543,14 +503,12 @@ public:
|
||||
return p;
|
||||
}
|
||||
|
||||
// ---- IVRDisplayComponent
|
||||
void GetWindowBounds(int32_t *x, int32_t *y, uint32_t *w, uint32_t *h) override {
|
||||
*x = 0; *y = 0; *w = (uint32_t)width_; *h = (uint32_t)height_;
|
||||
}
|
||||
bool IsDisplayOnDesktop() override { return !directMode_; }
|
||||
bool IsDisplayRealDisplay() override { return false; }
|
||||
void GetRecommendedRenderTargetSize(uint32_t *w, uint32_t *h) override {
|
||||
// Rendered a little larger than the panel: the lens pass magnifies the middle.
|
||||
*w = (uint32_t)(width_ / 2 * 1.4f);
|
||||
*h = (uint32_t)(height_ * 1.4f);
|
||||
}
|
||||
@@ -559,7 +517,6 @@ public:
|
||||
*x = eye == Eye_Left ? 0 : (uint32_t)width_ / 2;
|
||||
}
|
||||
void GetProjectionRaw(EVREye, float *left, float *right, float *top, float *bottom) override {
|
||||
// Exactly what the Cardboard pass samples from each half of a side-by-side frame.
|
||||
*left = -tanHalf_ * eyeAspect_; *right = tanHalf_ * eyeAspect_;
|
||||
*top = -tanHalf_; *bottom = tanHalf_;
|
||||
}
|
||||
@@ -582,7 +539,6 @@ private:
|
||||
droiddeck_headpose hp;
|
||||
bool fresh = pose_.Read(&hp) && hp.seq != lastSeq;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
// A new sample, or a heartbeat so SteamVR never thinks the HMD went away.
|
||||
PadState pad;
|
||||
const bool havePad = pad_.Read(&pad);
|
||||
const bool padChanged = havePad && (pad.buttons != lastPad_.buttons || memcmp(pad.axes, lastPad_.axes, sizeof(pad.axes)));
|
||||
@@ -657,7 +613,7 @@ private:
|
||||
|
||||
Provider g_provider;
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
DD_EXPORT void *HmdDriverFactory(const char *interfaceName, int *returnCode) {
|
||||
if (!strcmp(interfaceName, IServerTrackedDeviceProvider_Version)) return &g_provider;
|
||||
|
||||
+366
-970
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,3 @@
|
||||
// See presenter.h.
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include <vulkan/vulkan_core.h>
|
||||
typedef struct _XDisplay Display;
|
||||
@@ -41,7 +40,6 @@ void Log(const char *fmt, ...) {
|
||||
fprintf(stderr, "[droiddeck] %s\n", buf);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Xlib, loaded at runtime
|
||||
|
||||
struct X11 {
|
||||
void *lib = nullptr;
|
||||
@@ -68,7 +66,6 @@ struct X11 {
|
||||
}
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------- Vulkan, loaded at runtime
|
||||
|
||||
#define VK_GLOBAL(X) X(CreateInstance)
|
||||
#define VK_INSTANCE(X) \
|
||||
@@ -124,7 +121,7 @@ public:
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (fds[i] < 0) continue;
|
||||
int fd = dup(fds[i]); // the import owns its fd; the driver keeps its own
|
||||
int fd = dup(fds[i]);
|
||||
if (fd >= 0) pending_.push_back({handles[i], fd, format, w, h});
|
||||
}
|
||||
EnsureThread();
|
||||
@@ -163,7 +160,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ the presenting thread
|
||||
|
||||
void Run() {
|
||||
const char *mode = getenv("DROIDDECK_VR_PRESENT");
|
||||
@@ -198,9 +194,6 @@ private:
|
||||
if (wl_) { wl_display_dispatch_pending(wl_); wl_display_flush(wl_); }
|
||||
for (auto &p : imports) Import(p);
|
||||
for (auto h : removals) Forget(h);
|
||||
// SteamVR hands the textures over at Present with no fence the driver can wait on: give the
|
||||
// compositor's GPU work a moment to land before copying, as ALVR does (a torn or half-drawn
|
||||
// frame otherwise).
|
||||
if (f.texture[0]) std::this_thread::sleep_until(at + guard_);
|
||||
if (f.texture[0] && Draw(f)) shown++;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
@@ -216,10 +209,6 @@ private:
|
||||
|
||||
std::chrono::microseconds guard_{4000};
|
||||
|
||||
// ------------------------------------------------------------ Wayland: straight to DroidDeck's compositor
|
||||
// The compositor the app runs (wayland-0 in the session's runtime dir, beside gamescope's socket)
|
||||
// takes a fullscreen toplevel at the panel's size: one hop and one scale fewer than the X11 overlay
|
||||
// through gamescope, whose output is the session's (often smaller) resolution.
|
||||
struct wl_display *wl_ = nullptr;
|
||||
struct wl_compositor *wlComp_ = nullptr;
|
||||
struct xdg_wm_base *wm_ = nullptr;
|
||||
@@ -272,9 +261,6 @@ private:
|
||||
xdg_toplevel_set_fullscreen(toplevel_, nullptr);
|
||||
wl_surface_commit(wlSurf_);
|
||||
for (int i = 0; i < 20 && !configured_; i++) wl_display_roundtrip(wl_);
|
||||
// The size: the panel the Cardboard pass draws (two eyes, from the shared pose file), so nothing
|
||||
// scales the picture down on the way. The compositor's configure carries the session's output
|
||||
// size, which is often smaller; it is the fallback.
|
||||
width_ = height_ = 0;
|
||||
int fd = open("/run/droiddeck/droiddeck-headpose", O_RDONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
@@ -291,8 +277,6 @@ private:
|
||||
bool InitWindow() {
|
||||
if (const char *g = getenv("DROIDDECK_VR_PRESENT_GUARD_MS")) guard_ = std::chrono::microseconds((long)(atof(g) * 1000));
|
||||
if (!x_.Load()) { Log("presenter: no libX11"); return false; }
|
||||
// gamescope's first Xwayland (:0) is where its overlays (mangoapp, Steam's) live; SteamVR's
|
||||
// processes inherit the games' display (:1), so it is not taken from DISPLAY.
|
||||
const char *name = getenv("DROIDDECK_VR_DISPLAY");
|
||||
if (!name || !*name) name = ":0";
|
||||
dpy_ = x_.OpenDisplay(name);
|
||||
@@ -302,14 +286,11 @@ private:
|
||||
height_ = (uint32_t)x_.DisplayHeight(dpy_, scr);
|
||||
win_ = x_.CreateSimpleWindow(dpy_, x_.DefaultRootWindow(dpy_), 0, 0, width_, height_, 0, 0, 0);
|
||||
x_.StoreName(dpy_, win_, "DroidDeck Cardboard VR");
|
||||
// gamescope shows an external overlay above whatever has focus (mangoapp is one).
|
||||
// gamescope composites one external overlay (mangoapp, the perf HUD, usually holds it) and one Steam
|
||||
// overlay; the Steam overlay slot is free while nothing is shown over a game.
|
||||
const char *atom = getenv("DROIDDECK_VR_OVERLAY_ATOM");
|
||||
if (!atom || !*atom) atom = "STEAM_OVERLAY";
|
||||
unsigned long cardinal = 6; // XA_CARDINAL
|
||||
unsigned long one = 1; // format 32 properties are longs in Xlib
|
||||
x_.ChangeProperty(dpy_, win_, x_.InternAtom(dpy_, atom, 0), cardinal, 32, 0 /* PropModeReplace */,
|
||||
unsigned long cardinal = 6;
|
||||
unsigned long one = 1;
|
||||
x_.ChangeProperty(dpy_, win_, x_.InternAtom(dpy_, atom, 0), cardinal, 32, 0 ,
|
||||
(const unsigned char *)&one, 1);
|
||||
x_.MapWindow(dpy_, win_);
|
||||
x_.Flush(dpy_);
|
||||
@@ -438,15 +419,10 @@ private:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Imports one of SteamVR's shared images with the parameters it was made with (ALVR's recipe):
|
||||
// optimal tiling, mutable format (which keeps it uncompressed), opaque fd, dedicated memory. UNORM so a
|
||||
// blit copies the bytes rather than decoding sRGB.
|
||||
void Import(const PendingImport &p) {
|
||||
Imported im{p.handle};
|
||||
im.width = p.width;
|
||||
im.height = p.height;
|
||||
// The same format list SteamVR's mutable sRGB images carry: with it Turnip keeps UBWC compression on,
|
||||
// and the import has to agree on that or it reads compressed data as plain pixels.
|
||||
const char *fl = getenv("DROIDDECK_VR_IMPORT_FORMAT_LIST");
|
||||
const bool formatList = !fl || strcmp(fl, "0") != 0;
|
||||
VkFormat formats[2] = {(VkFormat)p.format, UnormOf(p.format)};
|
||||
@@ -516,8 +492,6 @@ private:
|
||||
VkCommandBufferBeginInfo bi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
vk_.BeginCommandBuffer(cmd_, &bi);
|
||||
VkImage dst = images_[idx];
|
||||
// The eye textures come from SteamVR's compositor (another process): take them from the external
|
||||
// queue family as they are (GENERAL keeps the contents; they are uncompressed).
|
||||
VkImageMemoryBarrier pre[3] = {
|
||||
Barrier(dst, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, VK_ACCESS_TRANSFER_WRITE_BIT),
|
||||
Barrier(eye[0]->image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_TRANSFER_READ_BIT,
|
||||
@@ -597,11 +571,11 @@ private:
|
||||
std::vector<Imported> textures_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
void Presenter::AddTextures(const uint64_t h[3], const int fds[3], uint32_t f, uint32_t w, uint32_t hh) { Impl::Get().Add(h, fds, f, w, hh); }
|
||||
void Presenter::RemoveTexture(uint64_t h) { Impl::Get().Remove(h); }
|
||||
void Presenter::Submit(const EyeFrame &f) { Impl::Get().Submit(f); }
|
||||
void Presenter::Shutdown() { Impl::Get().Shutdown(); }
|
||||
|
||||
} // namespace droiddeck
|
||||
}
|
||||
@@ -1,34 +1,19 @@
|
||||
// Puts SteamVR's eye textures on the screen for the Cardboard driver (driver_droiddeck.cpp).
|
||||
//
|
||||
// The driver-direct component hands each frame over as two eye textures: shared Vulkan images,
|
||||
// dmabufs on Linux. The presenter imports them into a Vulkan device of its own and draws them side by
|
||||
// side into a fullscreen X11 window on gamescope's Xwayland, marked as an external overlay so gamescope
|
||||
// shows it above whatever app has focus. DroidDeck's compositor, in Cardboard mode with a
|
||||
// side-by-side source, then puts the lens distortion on it for the viewer.
|
||||
//
|
||||
// SteamVR compositor -> eye textures -> [presenter: blit L|R] -> X11 overlay -> gamescope
|
||||
// -> DroidDeck compositor -> Cardboard lens pass -> panel
|
||||
//
|
||||
// Everything is loaded at runtime (libvulkan.so.1, libX11.so.6): the driver links against nothing
|
||||
// the cross build image lacks.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace droiddeck {
|
||||
|
||||
struct EyeFrame {
|
||||
uint64_t texture[2]; // SharedTextureHandle_t per eye
|
||||
float bounds[2][4]; // uMin, vMin, uMax, vMax per eye
|
||||
uint64_t texture[2];
|
||||
float bounds[2][4];
|
||||
};
|
||||
|
||||
class Presenter {
|
||||
public:
|
||||
// Called from CreateSwapTextureSet: the three images of one set, as SteamVR made them.
|
||||
static void AddTextures(const uint64_t handles[3], const int fds[3], uint32_t vkFormat, uint32_t width, uint32_t height);
|
||||
static void RemoveTexture(uint64_t handle);
|
||||
// Called from Present: the frame's eye textures; returns at once (a thread of its own presents).
|
||||
static void Submit(const EyeFrame &frame);
|
||||
static void Shutdown();
|
||||
};
|
||||
|
||||
} // namespace droiddeck
|
||||
}
|
||||
@@ -1,33 +1,4 @@
|
||||
#define _GNU_SOURCE
|
||||
/*
|
||||
* VK_LAYER_DROIDDECK_vr: lets SteamVR's vrcompositor create its Vulkan instance on Turnip/KGSL.
|
||||
*
|
||||
* vrcompositor always asks for VK_KHR_display and the direct-mode extensions around it (it opens a
|
||||
* direct mode window even when a driver-direct-mode driver - tools/vr/src/driver_droiddeck.cpp -
|
||||
* will receive the frames). Turnip's KGSL backend has no displays and refuses to enumerate any GPU
|
||||
* on an instance with VK_KHR_display enabled. This layer takes those extensions out of the instance
|
||||
* it creates below itself and answers the display queries on its own: there are no displays.
|
||||
*
|
||||
* Shared semaphores: SteamVR shares a timeline semaphore with every image it shares between its
|
||||
* processes, exported as an opaque fd. Turnip/KGSL cannot export one. Such a semaphore is created
|
||||
* unshared here instead, its "fd" is a placeholder (a memfd named droiddeck-detached-sem), and a
|
||||
* process importing a placeholder keeps a detached semaphore whose GPU waits are dropped and whose
|
||||
* host waits return at once. Each process still orders its own work; what is lost is only the GPU
|
||||
* ordering between processes, which SteamVR's own IPC (one frame at a time) mostly covers.
|
||||
*
|
||||
* Where it runs: droiddeck-steamvr enables it explicitly in SteamVR's own processes (VK_INSTANCE_LAYERS
|
||||
* + VK_LAYER_PATH). It is also an implicit layer for the whole session, because processes SteamVR did
|
||||
* not start share textures with it too: Steam's web helper draws its in-VR overlay through SteamVR,
|
||||
* needs the exportable semaphores, and without them crashes until Steam quits. As an implicit layer
|
||||
* it stays out of the way:
|
||||
* - the display stand-in (taking display extensions off, the fake display) happens only while
|
||||
* SteamVR runs (droiddeck-steamvr's marker file) or where the layer was enabled by name, never in
|
||||
* an ordinary session: gamescope and games see the driver's extensions unchanged;
|
||||
* - the semaphore bridge is active in those same processes, and in Steam's web helper once SteamVR
|
||||
* is installed (its GPU process outlives SteamVR runs);
|
||||
* - everything else - every process of a session without SteamVR installed - gets the next layer's
|
||||
* functions untouched.
|
||||
*/
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vk_layer.h>
|
||||
|
||||
@@ -51,10 +22,7 @@ static void say(const char *fmt, const char *arg) {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ crash trace (debug) */
|
||||
|
||||
/* DROIDDECK_VR_CRASHTRACE=1: print a backtrace on a fatal signal. vrcompositor's launcher drops
|
||||
* LD_PRELOAD, but this layer is loaded into it, so this is the way to see where it dies. */
|
||||
#include <dlfcn.h>
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
@@ -86,7 +54,6 @@ static void crash_trace_install(void) {
|
||||
static int done;
|
||||
if (done++) return;
|
||||
if (!getenv("DROIDDECK_VR_CRASHTRACE")) {
|
||||
/* Or a marker beside droiddeck-steamvr's, for processes whose environment is not ours (Steam). */
|
||||
const char *rt = getenv("XDG_RUNTIME_DIR");
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/droiddeck-steamvr/crashtrace", rt && *rt ? rt : "/run/droiddeck");
|
||||
@@ -100,33 +67,28 @@ static void crash_trace_install(void) {
|
||||
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
|
||||
int sigs[] = {SIGSEGV, SIGABRT, SIGBUS, SIGILL, SIGFPE};
|
||||
for (unsigned i = 0; i < sizeof(sigs) / sizeof(*sigs); i++) {
|
||||
/* Only where nothing handles the signal yet: Wine and FEX (Proton games) take SIGSEGV as part
|
||||
* of their normal work, and replacing their handler crashes the game. */
|
||||
struct sigaction old;
|
||||
if (sigaction(sigs[i], NULL, &old) == 0 && !(old.sa_flags & SA_SIGINFO) && old.sa_handler == SIG_DFL)
|
||||
sigaction(sigs[i], &sa, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ dispatch */
|
||||
|
||||
struct inst {
|
||||
VkInstance handle;
|
||||
PFN_vkGetInstanceProcAddr gipa;
|
||||
PFN_vkDestroyInstance destroy;
|
||||
int stripped; /* the app asked for display extensions we took out */
|
||||
int active; /* see the top of the file */
|
||||
int stripped;
|
||||
int active;
|
||||
};
|
||||
struct dev {
|
||||
VkDevice handle;
|
||||
PFN_vkGetDeviceProcAddr gdpa;
|
||||
PFN_vkDestroyDevice destroy;
|
||||
int active;
|
||||
int display; /* its instance has the pretend display */
|
||||
int display;
|
||||
};
|
||||
|
||||
/* SteamVR is running (droiddeck-steamvr start/stop keeps this file), or the layer was asked for by
|
||||
* name. Only then does the layer stand in for a display. */
|
||||
static int steamvr_running(void) {
|
||||
const char *layers = getenv("VK_INSTANCE_LAYERS");
|
||||
if (layers && strstr(layers, "VK_LAYER_DROIDDECK_vr")) return 1;
|
||||
@@ -137,10 +99,6 @@ static int steamvr_running(void) {
|
||||
return access(path, F_OK) == 0;
|
||||
}
|
||||
|
||||
/* Whether an instance gets the semaphore bridge. Steam's web helper shares its in-VR overlays with
|
||||
* SteamVR, and its GPU process lives across SteamVR runs: one created before SteamVR started crashes
|
||||
* once SteamVR shows the overlay, and after a few of those Steam quits. So it is bridged whenever
|
||||
* SteamVR is installed, not only while it runs. */
|
||||
static int bridge_wanted(void) {
|
||||
if (steamvr_running()) return 1;
|
||||
if (strcmp(program_invocation_short_name, "steamwebhelper")) return 0;
|
||||
@@ -155,7 +113,6 @@ static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct inst g_inst[MAX_OBJS];
|
||||
static struct dev g_dev[MAX_OBJS];
|
||||
|
||||
/* The dispatch key: the loader's dispatch table pointer at the start of every dispatchable object. */
|
||||
static void *key(const void *obj) { return *(void **)obj; }
|
||||
|
||||
static struct inst *inst_for(const void *obj) {
|
||||
@@ -178,7 +135,6 @@ static struct dev *dev_for(const void *obj) {
|
||||
#define NEXT(dev, fn) ((PFN_vk##fn)dev_for(dev)->gdpa(dev, "vk" #fn))
|
||||
#define HOOK_AS(str, fn) if (!strcmp(name, str)) return (PFN_vkVoidFunction)fn;
|
||||
|
||||
/* Extensions this layer takes off the instance and stands in for. */
|
||||
static const char *const DISPLAY_EXTS[] = {
|
||||
"VK_KHR_display", "VK_EXT_direct_mode_display", "VK_EXT_display_surface_counter",
|
||||
"VK_KHR_get_display_properties2", "VK_EXT_acquire_xlib_display", "VK_EXT_acquire_drm_display",
|
||||
@@ -189,7 +145,6 @@ static int is_display_ext(const char *name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ instance */
|
||||
|
||||
static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *ci, const VkAllocationCallbacks *alloc,
|
||||
VkInstance *out) {
|
||||
@@ -203,7 +158,6 @@ static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *ci, const
|
||||
PFN_vkCreateInstance next_create = (PFN_vkCreateInstance)next_gipa(VK_NULL_HANDLE, "vkCreateInstance");
|
||||
if (!next_create) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
|
||||
/* Outside SteamVR the instance is created exactly as asked: display extensions stay on. */
|
||||
const int vr = steamvr_running();
|
||||
VkInstanceCreateInfo mine = *ci;
|
||||
const char **names = calloc(ci->enabledExtensionCount + 1, sizeof(*names));
|
||||
@@ -216,7 +170,6 @@ static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *ci, const
|
||||
if (stripped) {
|
||||
int have = 0;
|
||||
for (uint32_t i = 0; i < n; i++) have |= !strcmp(names[i], "VK_EXT_headless_surface");
|
||||
/* The pretend display's surface is a headless one; it needs VK_KHR_surface too. */
|
||||
const char *more[] = {"VK_EXT_headless_surface", "VK_KHR_surface"};
|
||||
names = realloc(names, (n + 3) * sizeof(*names));
|
||||
if (!have) names[n++] = more[0];
|
||||
@@ -253,7 +206,6 @@ static void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCa
|
||||
if (d) d(instance, alloc);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ device */
|
||||
|
||||
static VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice pd, const VkDeviceCreateInfo *ci,
|
||||
const VkAllocationCallbacks *alloc, VkDevice *out) {
|
||||
@@ -270,7 +222,6 @@ static VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice pd, const VkDeviceCreat
|
||||
const int active = in && in->active;
|
||||
const int display = in && in->stripped;
|
||||
|
||||
/* VK_EXT_display_control (vblank events on a display) goes too: there is no display. */
|
||||
VkDeviceCreateInfo mine = *ci;
|
||||
const char **names = calloc(ci->enabledExtensionCount + 1, sizeof(*names));
|
||||
uint32_t n = 0;
|
||||
@@ -307,13 +258,6 @@ static void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallback
|
||||
if (f) f(device, alloc);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ the display stand-in
|
||||
*
|
||||
* One pretend display with one mode and one plane. vrcompositor keeps a direct mode window on it even
|
||||
* when a driver-direct driver takes the frames, and waits on that window's presents, so the display
|
||||
* needs a working swapchain: its surface is a headless one (VK_EXT_headless_surface, Mesa's WSI).
|
||||
* The vblank side of VK_EXT_display_control is a 60 Hz clock. Size and rate:
|
||||
* DROIDDECK_VR_DISPLAY_MODE=WIDTHxHEIGHT@HZ (default 1920x1080@60). */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
@@ -452,8 +396,6 @@ static VkResult VKAPI_CALL GetRandROutputDisplayEXT(VkPhysicalDevice pd, void *d
|
||||
*d = FAKE_DISPLAY; return VK_SUCCESS;
|
||||
}
|
||||
|
||||
/* VK_EXT_display_control on the device: a 60 Hz clock. A vblank event's fence comes back signalled
|
||||
* once the next tick has passed (the caller's vblank thread waits right after registering). */
|
||||
static VkResult VKAPI_CALL DisplayPowerControlEXT(VkDevice d, VkDisplayKHR disp, const VkDisplayPowerInfoEXT *info) { return VK_SUCCESS; }
|
||||
static VkResult signalled_fence(VkDevice d, const VkAllocationCallbacks *a, VkFence *fence) {
|
||||
VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, NULL, VK_FENCE_CREATE_SIGNALED_BIT};
|
||||
@@ -477,14 +419,10 @@ static VkResult VKAPI_CALL GetSwapchainCounterEXT(VkDevice d, VkSwapchainKHR sc,
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
/* The pretend display's swapchain, on the headless surface: no swapchain counter (that belongs to
|
||||
* VK_EXT_display_control, which the device does not have), and a request the headless WSI accepts. */
|
||||
static VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice d, const VkSwapchainCreateInfoKHR *ci, const VkAllocationCallbacks *a,
|
||||
VkSwapchainKHR *out) {
|
||||
PFN_vkCreateSwapchainKHR next = NEXT(d, CreateSwapchainKHR);
|
||||
VkSwapchainCreateInfoKHR sized = *ci;
|
||||
/* A headless surface has no size of its own (UINT32_MAX), and SteamVR passes that through: the
|
||||
* pretend display's mode is the size. */
|
||||
mode_init();
|
||||
if (sized.imageExtent.width == UINT32_MAX || sized.imageExtent.height == UINT32_MAX)
|
||||
sized.imageExtent = (VkExtent2D){g_mode_w, g_mode_h};
|
||||
@@ -498,13 +436,12 @@ static VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice d, const VkSwapchainCreat
|
||||
for (const VkBaseInStructure *p = ci->pNext; p && n < (int)sizeof(line) - 16; p = p->pNext) n += snprintf(line + n, sizeof(line) - n, " %d", p->sType);
|
||||
say("vkCreateSwapchainKHR refused (%s); retrying for the headless surface", line);
|
||||
VkSwapchainCreateInfoKHR mine = *ci;
|
||||
mine.pNext = NULL; /* drops VkSwapchainCounterCreateInfoEXT and friends */
|
||||
mine.pNext = NULL;
|
||||
mine.presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
mine.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
if (mine.minImageCount < 2) mine.minImageCount = 2;
|
||||
r = next(d, &mine, a, out);
|
||||
if (r != VK_SUCCESS) {
|
||||
/* Last resort: the plainest swapchain the surface can take. */
|
||||
mine.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||
mine.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
mine.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
@@ -524,16 +461,6 @@ static PFN_vkVoidFunction display_device_hook(const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ bridged shared semaphores
|
||||
*
|
||||
* SteamVR shares a timeline semaphore with every image it shares between processes, exported as an
|
||||
* opaque fd; Turnip/KGSL cannot export one. Here such a semaphore is created unshared, and its "fd" is
|
||||
* a memfd (named droiddeck-shared-sem) holding a 64-bit counter. Every process that has the semaphore -
|
||||
* the creator and each importer - keeps its own real timeline semaphore, and a poller thread in each
|
||||
* process carries values both ways: a value reached locally goes up into the counter, a value the
|
||||
* counter shows (another process got there) is signalled locally from the host. GPU waits then work
|
||||
* as written, about a poll period late. A binary semaphore cannot be bridged that way; GPU waits on an
|
||||
* imported binary one are dropped (each process still orders its own work). */
|
||||
|
||||
#include <sched.h>
|
||||
#include <stdatomic.h>
|
||||
@@ -547,14 +474,14 @@ struct bridged {
|
||||
VkSemaphore sem;
|
||||
VkDevice dev;
|
||||
_Atomic uint64_t *counter;
|
||||
int fd; /* the memfd, kept by the creator so every export can dup it; -1 for an importer */
|
||||
int timeline; /* 0: binary, bridged only by dropping its waits */
|
||||
unsigned long ino; /* the memfd's inode, which names the semaphore across processes in traces */
|
||||
uint64_t submitted; /* the highest value this process has queued a signal of */
|
||||
int fd;
|
||||
int timeline;
|
||||
unsigned long ino;
|
||||
uint64_t submitted;
|
||||
};
|
||||
static pthread_mutex_t g_br_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct bridged g_br[MAX_SEMS];
|
||||
static VkSemaphore g_timeline_sems[MAX_TYPED]; /* every timeline semaphore this process made */
|
||||
static VkSemaphore g_timeline_sems[MAX_TYPED];
|
||||
static pthread_t g_poller;
|
||||
static int g_poller_started;
|
||||
|
||||
@@ -573,7 +500,6 @@ static void timeline_note(VkSemaphore s, int add) {
|
||||
pthread_mutex_unlock(&g_br_lock);
|
||||
}
|
||||
|
||||
/* Under g_br_lock. */
|
||||
static struct bridged *bridged_find(VkSemaphore s) {
|
||||
for (int i = 0; i < MAX_SEMS; i++) if (g_br[i].sem == s) return &g_br[i];
|
||||
return NULL;
|
||||
@@ -585,7 +511,6 @@ static void bridged_drop(struct bridged *b) {
|
||||
b->fd = -1;
|
||||
}
|
||||
|
||||
/* A `semtrace` file beside droiddeck-steamvr's marker: log every bridged semaphore every 2 s. */
|
||||
static int sem_trace_on(void) {
|
||||
static int checked, on;
|
||||
if (!checked++) {
|
||||
@@ -673,7 +598,6 @@ static VkResult VKAPI_CALL CreateSemaphore(VkDevice d, const VkSemaphoreCreateIn
|
||||
return r;
|
||||
}
|
||||
if (!export_info) return r;
|
||||
/* Rebuild the chain without the export request. */
|
||||
VkSemaphoreTypeCreateInfo type = {0};
|
||||
VkSemaphoreCreateInfo mine = *ci;
|
||||
mine.pNext = NULL;
|
||||
@@ -688,7 +612,7 @@ static VkResult VKAPI_CALL CreateSemaphore(VkDevice d, const VkSemaphoreCreateIn
|
||||
int fd = memfd_create(SHARED_NAME, MFD_CLOEXEC);
|
||||
_Atomic uint64_t *counter = NULL;
|
||||
if (fd >= 0 && ftruncate(fd, 4096) == 0) counter = map_counter(fd);
|
||||
if (!counter) { if (fd >= 0) close(fd); return r; } /* unshared, unbridged */
|
||||
if (!counter) { if (fd >= 0) close(fd); return r; }
|
||||
atomic_store(counter, timeline ? type_info->initialValue : 0);
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
struct bridged *slot = bridged_find(VK_NULL_HANDLE);
|
||||
@@ -732,7 +656,7 @@ static VkResult VKAPI_CALL ImportSemaphoreFdKHR(VkDevice d, const VkImportSemaph
|
||||
if (info->fd < 0 || !is_shared_counter(info->fd)) return NEXT(d, ImportSemaphoreFdKHR)(d, info);
|
||||
_Atomic uint64_t *counter = map_counter(info->fd);
|
||||
const unsigned long ino = fd_ino(info->fd);
|
||||
close(info->fd); /* a successful import owns the fd */
|
||||
close(info->fd);
|
||||
const int timeline = timeline_known(info->semaphore);
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
struct bridged *b = bridged_find(info->semaphore);
|
||||
@@ -748,7 +672,6 @@ static VkResult VKAPI_CALL ImportSemaphoreFdKHR(VkDevice d, const VkImportSemaph
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
/* An imported binary one: nothing here will ever signal it. */
|
||||
static int drop_wait(VkSemaphore s) {
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
struct bridged *b = bridged_find(s);
|
||||
@@ -763,17 +686,8 @@ static uint64_t now_us(void) {
|
||||
return (uint64_t)ts.tv_sec * 1000000u + (uint64_t)ts.tv_nsec / 1000u;
|
||||
}
|
||||
|
||||
/* How long a submit may wait for another process to reach a shared value before the wait is dropped. */
|
||||
#define SUBMIT_GRACE_US 3000
|
||||
|
||||
/* Whether a submit should drop its GPU wait on s for value.
|
||||
*
|
||||
* Turnip on KGSL does not defer a submit that waits on a timeline value nobody has signalled yet ("wait
|
||||
* before signal"): vkQueueSubmit blocks the calling thread until the value is signalled. SteamVR's
|
||||
* client waits on a value of the compositor's that the compositor signals only after the client has
|
||||
* submitted and told it so, which on Turnip deadlocks the client before its first frame (helloxr's
|
||||
* acquire, DXVK's submit thread in Proton games). For an imported timeline semaphore whose value is
|
||||
* neither reached nor queued here, the counter gets a short grace period, then the wait goes. */
|
||||
static int submit_drop_wait(VkSemaphore s, uint64_t value) {
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
struct bridged *b = bridged_find(s);
|
||||
@@ -787,7 +701,6 @@ static int submit_drop_wait(VkSemaphore s, uint64_t value) {
|
||||
if (!imported || !value || value <= queued) return 0;
|
||||
struct dev *d = dev_for(dev);
|
||||
if (!d) return 0;
|
||||
/* A Vulkan 1.0 device (SteamVR's client interop) has only the KHR names. */
|
||||
PFN_vkGetSemaphoreCounterValue get = (PFN_vkGetSemaphoreCounterValue)d->gdpa(dev, "vkGetSemaphoreCounterValue");
|
||||
if (!get) get = (PFN_vkGetSemaphoreCounterValue)d->gdpa(dev, "vkGetSemaphoreCounterValueKHR");
|
||||
PFN_vkSignalSemaphore sig = (PFN_vkSignalSemaphore)d->gdpa(dev, "vkSignalSemaphore");
|
||||
@@ -812,7 +725,6 @@ static int submit_drop_wait(VkSemaphore s, uint64_t value) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Notes the values this process queues signals of, so its own later waits on them are kept. */
|
||||
static void note_signal(VkSemaphore s, uint64_t value) {
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
struct bridged *b = bridged_find(s);
|
||||
@@ -836,7 +748,6 @@ static void note_submit2_signals(uint32_t count, const VkSubmitInfo2 *submits) {
|
||||
note_signal(submits[i].pSignalSemaphoreInfos[j].semaphore, submits[i].pSignalSemaphoreInfos[j].value);
|
||||
}
|
||||
|
||||
/* Drops waits on detached semaphores from a list; returns the new count. */
|
||||
static uint32_t keep_waits(const VkSemaphore *in, const VkPipelineStageFlags *stages, const uint64_t *values, uint32_t n,
|
||||
VkSemaphore *out, VkPipelineStageFlags *out_stages, uint64_t *out_values) {
|
||||
uint32_t k = 0;
|
||||
@@ -850,7 +761,6 @@ static uint32_t keep_waits(const VkSemaphore *in, const VkPipelineStageFlags *st
|
||||
return k;
|
||||
}
|
||||
|
||||
/* semtrace: the first wait and the first signal of each shared semaphore, and its first few values. */
|
||||
static void trace_sem(const char *what, VkSemaphore sem, uint64_t value) {
|
||||
if (!sem_trace_on() || value > 3) return;
|
||||
pthread_mutex_lock(&g_br_lock);
|
||||
@@ -876,8 +786,6 @@ static VkResult VKAPI_CALL QueueSubmit(VkQueue q, uint32_t count, const VkSubmit
|
||||
for (uint32_t j = 0; j < submits[i].signalSemaphoreCount; j++)
|
||||
trace_sem("signals", submits[i].pSignalSemaphores[j], t && j < t->signalSemaphoreValueCount ? t->pSignalSemaphoreValues[j] : 0);
|
||||
}
|
||||
/* Waits are judged before this submit's own signals count as queued: an acquire may wait on one
|
||||
* value and signal the next on the same semaphore. */
|
||||
int any = 0;
|
||||
for (uint32_t i = 0; i < count && !any; i++) {
|
||||
const VkTimelineSemaphoreSubmitInfo *t = NULL;
|
||||
@@ -911,7 +819,6 @@ static VkResult VKAPI_CALL QueueSubmit(VkQueue q, uint32_t count, const VkSubmit
|
||||
copy[i].pWaitSemaphores = sems;
|
||||
copy[i].pWaitDstStageMask = stages;
|
||||
if (t) {
|
||||
/* Only this struct is replaced; the rest of the chain is kept behind it. */
|
||||
tl[i] = *t;
|
||||
tl[i].waitSemaphoreValueCount = t->waitSemaphoreValueCount ? k : 0;
|
||||
tl[i].pWaitSemaphoreValues = vals;
|
||||
@@ -920,7 +827,7 @@ static VkResult VKAPI_CALL QueueSubmit(VkQueue q, uint32_t count, const VkSubmit
|
||||
for (const VkBaseInStructure *p = submits[i].pNext; p; prev = p, p = p->pNext) if (p == (const void *)t) { rest = p->pNext; break; }
|
||||
(void)prev;
|
||||
tl[i].pNext = rest;
|
||||
copy[i].pNext = &tl[i]; /* other structs before it are dropped: SteamVR chains only this one */
|
||||
copy[i].pNext = &tl[i];
|
||||
}
|
||||
}
|
||||
VkResult r = next(q, count, copy, fence);
|
||||
@@ -989,7 +896,6 @@ static VkResult VKAPI_CALL GetSemaphoreCounterValue(VkDevice d, VkSemaphore s, u
|
||||
return next(d, s, value);
|
||||
}
|
||||
|
||||
/* semtrace also logs how shared (external memory) images are created, to compare both sides. */
|
||||
static VkResult VKAPI_CALL CreateImage(VkDevice d, const VkImageCreateInfo *ci, const VkAllocationCallbacks *a, VkImage *out) {
|
||||
VkResult r = NEXT(d, CreateImage)(d, ci, a, out);
|
||||
if (!sem_trace_on()) return r;
|
||||
@@ -1026,7 +932,6 @@ static PFN_vkVoidFunction semaphore_hook(const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ proc addr */
|
||||
|
||||
#define HOOK(fn) if (!strcmp(name, "vk" #fn)) return (PFN_vkVoidFunction)fn;
|
||||
|
||||
@@ -1085,7 +990,6 @@ EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVr_GetDeviceProcAddr(Vk
|
||||
if (f) return f;
|
||||
}
|
||||
if (d) {
|
||||
/* Only where the driver has the function: the hooks call through to it. */
|
||||
PFN_vkVoidFunction mine = semaphore_hook(name);
|
||||
if (mine && d->gdpa(device, name)) return mine;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* Link-time stand-in for libwayland-client.so.0 (tools/vr/build.sh): the symbols the presenter uses, so
|
||||
* the driver links with -z defs against a library the build machine does not have. Never loaded: the
|
||||
* runtime's real libwayland-client.so.0 satisfies the dependency on the device. */
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "wayland-util.h"
|
||||
|
||||
@@ -36,94 +36,12 @@ extern "C" {
|
||||
|
||||
struct timespec;
|
||||
|
||||
/** \class wl_proxy
|
||||
*
|
||||
* \brief Represents a protocol object on the client side.
|
||||
*
|
||||
* A wl_proxy acts as a client side proxy to an object existing in the
|
||||
* compositor. The proxy is responsible for converting requests made by the
|
||||
* clients with \ref wl_proxy_marshal() into Wayland's wire format. Events
|
||||
* coming from the compositor are also handled by the proxy, which will in
|
||||
* turn call the handler set with \ref wl_proxy_add_listener().
|
||||
*
|
||||
* \note With the exception of function \ref wl_proxy_set_queue(), functions
|
||||
* accessing a wl_proxy are not normally used by client code. Clients
|
||||
* should normally use the higher level interface generated by the scanner to
|
||||
* interact with compositor objects.
|
||||
*
|
||||
*/
|
||||
struct wl_proxy;
|
||||
|
||||
/** \class wl_display
|
||||
*
|
||||
* \brief Represents a connection to the compositor and acts as a proxy to
|
||||
* the wl_display singleton object.
|
||||
*
|
||||
* A wl_display object represents a client connection to a Wayland
|
||||
* compositor. It is created with either \ref wl_display_connect() or
|
||||
* \ref wl_display_connect_to_fd(). A connection is terminated using
|
||||
* \ref wl_display_disconnect().
|
||||
*
|
||||
* A wl_display is also used as the \ref wl_proxy for the wl_display
|
||||
* singleton object on the compositor side.
|
||||
*
|
||||
* A wl_display object handles all the data sent from and to the
|
||||
* compositor. When a \ref wl_proxy marshals a request, it will write its wire
|
||||
* representation to the display's write buffer. The data is sent to the
|
||||
* compositor when the client calls \ref wl_display_flush().
|
||||
*
|
||||
* Incoming data is handled in two steps: queueing and dispatching. In the
|
||||
* queue step, the data coming from the display fd is interpreted and
|
||||
* added to a queue. On the dispatch step, the handler for the incoming
|
||||
* event set by the client on the corresponding \ref wl_proxy is called.
|
||||
*
|
||||
* A wl_display has at least one event queue, called the <em>default
|
||||
* queue</em>. Clients can create additional event queues with \ref
|
||||
* wl_display_create_queue() and assign \ref wl_proxy's to it. Events
|
||||
* occurring in a particular proxy are always queued in its assigned queue.
|
||||
* A client can ensure that a certain assumption, such as holding a lock
|
||||
* or running from a given thread, is true when a proxy event handler is
|
||||
* called by assigning that proxy to an event queue and making sure that
|
||||
* this queue is only dispatched when the assumption holds.
|
||||
*
|
||||
* The default queue is dispatched by calling \ref wl_display_dispatch().
|
||||
* This will dispatch any events queued on the default queue and attempt
|
||||
* to read from the display fd if it's empty. Events read are then queued
|
||||
* on the appropriate queues according to the proxy assignment.
|
||||
*
|
||||
* A user created queue is dispatched with \ref wl_display_dispatch_queue().
|
||||
* This function behaves exactly the same as wl_display_dispatch()
|
||||
* but it dispatches given queue instead of the default queue.
|
||||
*
|
||||
* A real world example of event queue usage is Mesa's implementation of
|
||||
* eglSwapBuffers() for the Wayland platform. This function might need
|
||||
* to block until a frame callback is received, but dispatching the default
|
||||
* queue could cause an event handler on the client to start drawing
|
||||
* again. This problem is solved using another event queue, so that only
|
||||
* the events handled by the EGL code are dispatched during the block.
|
||||
*
|
||||
* This creates a problem where a thread dispatches a non-default
|
||||
* queue, reading all the data from the display fd. If the application
|
||||
* would call \em poll(2) after that it would block, even though there
|
||||
* might be events queued on the default queue. Those events should be
|
||||
* dispatched with \ref wl_display_dispatch_pending() or \ref
|
||||
* wl_display_dispatch_queue_pending() before flushing and blocking.
|
||||
*/
|
||||
struct wl_display;
|
||||
|
||||
/** \class wl_event_queue
|
||||
*
|
||||
* \brief A queue for \ref wl_proxy object events.
|
||||
*
|
||||
* Event queues allows the events on a display to be handled in a thread-safe
|
||||
* manner. See \ref wl_display for details.
|
||||
*
|
||||
*/
|
||||
struct wl_event_queue;
|
||||
|
||||
/** Destroy proxy after marshalling
|
||||
* \relates wl_proxy
|
||||
*/
|
||||
#define WL_MARSHAL_FLAG_DESTROY (1 << 0)
|
||||
|
||||
void
|
||||
|
||||
+56
-4535
File diff suppressed because it is too large.
Load diff
@@ -23,15 +23,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* \brief Include the client API and protocol C API.
|
||||
*
|
||||
* \warning Use of this header file is discouraged. Prefer including
|
||||
* wayland-client-core.h instead, which does not include the
|
||||
* client protocol header and as such only defines the library
|
||||
* API.
|
||||
*/
|
||||
|
||||
#ifndef WAYLAND_CLIENT_H
|
||||
#define WAYLAND_CLIENT_H
|
||||
|
||||
+8
-565
@@ -23,10 +23,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/** \file wayland-util.h
|
||||
*
|
||||
* \brief Utility classes, functions, and macros.
|
||||
*/
|
||||
|
||||
#ifndef WAYLAND_UTIL_H
|
||||
#define WAYLAND_UTIL_H
|
||||
@@ -40,14 +36,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Visibility attribute */
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define WL_EXPORT __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define WL_EXPORT
|
||||
#endif
|
||||
|
||||
/** Deprecated attribute */
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201402L)
|
||||
#define WL_DEPRECATED [[deprecated]]
|
||||
#elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
@@ -56,14 +50,6 @@ extern "C" {
|
||||
#define WL_DEPRECATED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Printf-style argument attribute
|
||||
*
|
||||
* \param x Ordinality of the format string argument
|
||||
* \param y Ordinality of the argument to check against the format string
|
||||
*
|
||||
* \sa https://gcc.gnu.org/onlinedocs/gcc-3.2.1/gcc/Function-Attributes.html
|
||||
*/
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
|
||||
#else
|
||||
@@ -76,405 +62,57 @@ extern "C" {
|
||||
#define WL_TYPEOF(expr) __typeof__(expr)
|
||||
#endif
|
||||
|
||||
/** \class wl_object
|
||||
*
|
||||
* \brief A protocol object.
|
||||
*
|
||||
* A `wl_object` is an opaque struct identifying the protocol object
|
||||
* underlying a `wl_proxy` or `wl_resource`.
|
||||
*
|
||||
* \note Functions accessing a `wl_object` are not normally used by client code.
|
||||
* Clients should normally use the higher level interface generated by the
|
||||
* scanner to interact with compositor objects.
|
||||
*
|
||||
*/
|
||||
struct wl_object;
|
||||
|
||||
/**
|
||||
* The maximum size of a protocol message.
|
||||
*
|
||||
* If a message size exceeds this value, the connection will be dropped.
|
||||
* Servers will send an invalid_method error before disconnecting.
|
||||
*/
|
||||
#define WL_MAX_MESSAGE_SIZE 4096
|
||||
|
||||
/**
|
||||
* Protocol message signature
|
||||
*
|
||||
* A wl_message describes the signature of an actual protocol message, such as a
|
||||
* request or event, that adheres to the Wayland protocol wire format. The
|
||||
* protocol implementation uses a wl_message within its demarshal machinery for
|
||||
* decoding messages between a compositor and its clients. In a sense, a
|
||||
* wl_message is to a protocol message like a class is to an object.
|
||||
*
|
||||
* The `name` of a wl_message is the name of the corresponding protocol message.
|
||||
*
|
||||
* The `signature` is an ordered list of symbols representing the data types
|
||||
* of message arguments and, optionally, a protocol version and indicators for
|
||||
* nullability. A leading integer in the `signature` indicates the _since_
|
||||
* version of the protocol message. A `?` preceding a data type symbol indicates
|
||||
* that the following argument type is nullable. While it is a protocol violation
|
||||
* to send messages with non-nullable arguments set to `NULL`, event handlers in
|
||||
* clients might still get called with non-nullable object arguments set to
|
||||
* `NULL`. This can happen when the client destroyed the object being used as
|
||||
* argument on its side and an event referencing that object was sent before the
|
||||
* server knew about its destruction. As this race cannot be prevented, clients
|
||||
* should - as a general rule - program their event handlers such that they can
|
||||
* handle object arguments declared non-nullable being `NULL` gracefully.
|
||||
*
|
||||
* When no arguments accompany a message, `signature` is an empty string.
|
||||
*
|
||||
* Symbols:
|
||||
*
|
||||
* * `i`: int
|
||||
* * `u`: uint
|
||||
* * `f`: fixed
|
||||
* * `s`: string
|
||||
* * `o`: object
|
||||
* * `n`: new_id
|
||||
* * `a`: array
|
||||
* * `h`: fd
|
||||
* * `?`: following argument (`o` or `s`) is nullable
|
||||
*
|
||||
* While demarshaling primitive arguments is straightforward, when demarshaling
|
||||
* messages containing `object` or `new_id` arguments, the protocol
|
||||
* implementation often must determine the type of the object. The `types` of a
|
||||
* wl_message is an array of wl_interface references that correspond to `o` and
|
||||
* `n` arguments in `signature`, with `NULL` placeholders for arguments with
|
||||
* non-object types.
|
||||
*
|
||||
* Consider the protocol event wl_display `delete_id` that has a single `uint`
|
||||
* argument. The wl_message is:
|
||||
*
|
||||
* \code
|
||||
* { "delete_id", "u", [NULL] }
|
||||
* \endcode
|
||||
*
|
||||
* Here, the message `name` is `"delete_id"`, the `signature` is `"u"`, and the
|
||||
* argument `types` is `[NULL]`, indicating that the `uint` argument has no
|
||||
* corresponding wl_interface since it is a primitive argument.
|
||||
*
|
||||
* In contrast, consider a `wl_foo` interface supporting protocol request `bar`
|
||||
* that has existed since version 2, and has two arguments: a `uint` and an
|
||||
* object of type `wl_baz_interface` that may be `NULL`. Such a `wl_message`
|
||||
* might be:
|
||||
*
|
||||
* \code
|
||||
* { "bar", "2u?o", [NULL, &wl_baz_interface] }
|
||||
* \endcode
|
||||
*
|
||||
* Here, the message `name` is `"bar"`, and the `signature` is `"2u?o"`. Notice
|
||||
* how the `2` indicates the protocol version, the `u` indicates the first
|
||||
* argument type is `uint`, and the `?o` indicates that the second argument
|
||||
* is an object that may be `NULL`. Lastly, the argument `types` array indicates
|
||||
* that no wl_interface corresponds to the first argument, while the type
|
||||
* `wl_baz_interface` corresponds to the second argument.
|
||||
*
|
||||
* \sa wl_argument
|
||||
* \sa wl_interface
|
||||
* \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Wire-Format">Wire Format</a>
|
||||
*/
|
||||
struct wl_message {
|
||||
/** Message name */
|
||||
const char *name;
|
||||
/** Message signature */
|
||||
const char *signature;
|
||||
/** Object argument interfaces */
|
||||
const struct wl_interface **types;
|
||||
};
|
||||
|
||||
/**
|
||||
* Protocol object interface
|
||||
*
|
||||
* A wl_interface describes the API of a protocol object defined in the Wayland
|
||||
* protocol specification. The protocol implementation uses a wl_interface
|
||||
* within its marshalling machinery for encoding client requests.
|
||||
*
|
||||
* The `name` of a wl_interface is the name of the corresponding protocol
|
||||
* interface, and `version` represents the version of the interface. The members
|
||||
* `method_count` and `event_count` represent the number of `methods` (requests)
|
||||
* and `events` in the respective wl_message members.
|
||||
*
|
||||
* For example, consider a protocol interface `foo`, marked as version `1`, with
|
||||
* two requests and one event.
|
||||
*
|
||||
* \code{.xml}
|
||||
* <interface name="foo" version="1">
|
||||
* <request name="a"></request>
|
||||
* <request name="b"></request>
|
||||
* <event name="c"></event>
|
||||
* </interface>
|
||||
* \endcode
|
||||
*
|
||||
* Given two wl_message arrays `foo_requests` and `foo_events`, a wl_interface
|
||||
* for `foo` might be:
|
||||
*
|
||||
* \code
|
||||
* struct wl_interface foo_interface = {
|
||||
* "foo", 1,
|
||||
* 2, foo_requests,
|
||||
* 1, foo_events
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \note The server side of the protocol may define interface <em>implementation
|
||||
* types</em> that incorporate the term `interface` in their name. Take
|
||||
* care to not confuse these server-side `struct`s with a wl_interface
|
||||
* variable whose name also ends in `interface`. For example, while the
|
||||
* server may define a type `struct wl_foo_interface`, the client may
|
||||
* define a `struct wl_interface wl_foo_interface`.
|
||||
*
|
||||
* \sa wl_message
|
||||
* \sa wl_proxy
|
||||
* \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Interfaces">Interfaces</a>
|
||||
* \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Versioning">Versioning</a>
|
||||
*/
|
||||
struct wl_interface {
|
||||
/** Interface name */
|
||||
const char *name;
|
||||
/** Interface version */
|
||||
int version;
|
||||
/** Number of methods (requests) */
|
||||
int method_count;
|
||||
/** Method (request) signatures */
|
||||
const struct wl_message *methods;
|
||||
/** Number of events */
|
||||
int event_count;
|
||||
/** Event signatures */
|
||||
const struct wl_message *events;
|
||||
};
|
||||
|
||||
/** \class wl_list
|
||||
*
|
||||
* \brief Doubly-linked list
|
||||
*
|
||||
* On its own, an instance of `struct wl_list` represents the sentinel head of
|
||||
* a doubly-linked list, and must be initialized using wl_list_init().
|
||||
* When empty, the list head's `next` and `prev` members point to the list head
|
||||
* itself, otherwise `next` references the first element in the list, and `prev`
|
||||
* refers to the last element in the list.
|
||||
*
|
||||
* Use the `struct wl_list` type to represent both the list head and the links
|
||||
* between elements within the list. Use wl_list_empty() to determine if the
|
||||
* list is empty in O(1).
|
||||
*
|
||||
* All elements in the list must be of the same type. The element type must have
|
||||
* a `struct wl_list` member, often named `link` by convention. Prior to
|
||||
* insertion, there is no need to initialize an element's `link` - invoking
|
||||
* wl_list_init() on an individual list element's `struct wl_list` member is
|
||||
* unnecessary if the very next operation is wl_list_insert(). However, a
|
||||
* common idiom is to initialize an element's `link` prior to removal - ensure
|
||||
* safety by invoking wl_list_init() before wl_list_remove().
|
||||
*
|
||||
* Consider a list reference `struct wl_list foo_list`, an element type as
|
||||
* `struct element`, and an element's link member as `struct wl_list link`.
|
||||
*
|
||||
* The following code initializes a list and adds three elements to it.
|
||||
*
|
||||
* \code
|
||||
* struct wl_list foo_list;
|
||||
*
|
||||
* struct element {
|
||||
* int foo;
|
||||
* struct wl_list link;
|
||||
* };
|
||||
* struct element e1, e2, e3;
|
||||
*
|
||||
* wl_list_init(&foo_list);
|
||||
* wl_list_insert(&foo_list, &e1.link); // e1 is the first element
|
||||
* wl_list_insert(&foo_list, &e2.link); // e2 is now the first element
|
||||
* wl_list_insert(&e2.link, &e3.link); // insert e3 after e2
|
||||
* \endcode
|
||||
*
|
||||
* The list now looks like <em>[e2, e3, e1]</em>.
|
||||
*
|
||||
* The `wl_list` API provides some iterator macros. For example, to iterate
|
||||
* a list in ascending order:
|
||||
*
|
||||
* \code
|
||||
* struct element *e;
|
||||
* wl_list_for_each(e, foo_list, link) {
|
||||
* do_something_with_element(e);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* See the documentation of each iterator for details.
|
||||
* \sa http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h
|
||||
*/
|
||||
struct wl_list {
|
||||
/** Previous list element */
|
||||
struct wl_list *prev;
|
||||
/** Next list element */
|
||||
struct wl_list *next;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the list.
|
||||
*
|
||||
* \param list List to initialize
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
void
|
||||
wl_list_init(struct wl_list *list);
|
||||
|
||||
/**
|
||||
* Inserts an element into the list, after the element represented by \p list.
|
||||
* When \p list is a reference to the list itself (the head), set the containing
|
||||
* struct of \p elm as the first element in the list.
|
||||
*
|
||||
* \note If \p elm is already part of a list, inserting it again will lead to
|
||||
* list corruption.
|
||||
*
|
||||
* \param list List element after which the new element is inserted
|
||||
* \param elm Link of the containing struct to insert into the list
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
void
|
||||
wl_list_insert(struct wl_list *list, struct wl_list *elm);
|
||||
|
||||
/**
|
||||
* Removes an element from the list.
|
||||
*
|
||||
* \note This operation leaves \p elm in an invalid state.
|
||||
*
|
||||
* \param elm Link of the containing struct to remove from the list
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
void
|
||||
wl_list_remove(struct wl_list *elm);
|
||||
|
||||
/**
|
||||
* Determines the length of the list.
|
||||
*
|
||||
* \note This is an O(n) operation.
|
||||
*
|
||||
* \param list List whose length is to be determined
|
||||
*
|
||||
* \return Number of elements in the list
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
int
|
||||
wl_list_length(const struct wl_list *list);
|
||||
|
||||
/**
|
||||
* Determines if the list is empty.
|
||||
*
|
||||
* \param list List whose emptiness is to be determined
|
||||
*
|
||||
* \return 1 if empty, or 0 if not empty
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
int
|
||||
wl_list_empty(const struct wl_list *list);
|
||||
|
||||
/**
|
||||
* Inserts all of the elements of one list into another, after the element
|
||||
* represented by \p list.
|
||||
*
|
||||
* \note This leaves \p other in an invalid state.
|
||||
*
|
||||
* \param list List element after which the other list elements will be inserted
|
||||
* \param other List of elements to insert
|
||||
*
|
||||
* \memberof wl_list
|
||||
*/
|
||||
void
|
||||
wl_list_insert_list(struct wl_list *list, struct wl_list *other);
|
||||
|
||||
/**
|
||||
* Retrieves a pointer to a containing struct, given a member name.
|
||||
*
|
||||
* This macro allows "conversion" from a pointer to a member to its containing
|
||||
* struct. This is useful if you have a contained item like a wl_list,
|
||||
* wl_listener, or wl_signal, provided via a callback or other means, and would
|
||||
* like to retrieve the struct that contains it.
|
||||
*
|
||||
* To demonstrate, the following example retrieves a pointer to
|
||||
* `example_container` given only its `destroy_listener` member:
|
||||
*
|
||||
* \code
|
||||
* struct example_container {
|
||||
* struct wl_listener destroy_listener;
|
||||
* // other members...
|
||||
* };
|
||||
*
|
||||
* void example_container_destroy(struct wl_listener *listener, void *data)
|
||||
* {
|
||||
* struct example_container *ctr;
|
||||
*
|
||||
* ctr = wl_container_of(listener, ctr, destroy_listener);
|
||||
* // destroy ctr...
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \note `sample` need not be a valid pointer. A null or uninitialised pointer
|
||||
* is sufficient.
|
||||
*
|
||||
* \param ptr Valid pointer to the contained member
|
||||
* \param sample Pointer to a struct whose type contains \p ptr
|
||||
* \param member Named location of \p ptr within the \p sample type
|
||||
*
|
||||
* \return The container for the specified pointer
|
||||
*/
|
||||
#define wl_container_of(ptr, sample, member) \
|
||||
(WL_TYPEOF(sample))((char *)(ptr) - \
|
||||
offsetof(WL_TYPEOF(*sample), member))
|
||||
|
||||
/**
|
||||
* Iterates over a list.
|
||||
*
|
||||
* This macro expresses a for-each iterator for wl_list. Given a list and
|
||||
* wl_list link member name (often named `link` by convention), this macro
|
||||
* assigns each element in the list to \p pos, which can then be referenced in
|
||||
* a trailing code block. For example, given a wl_list of `struct message`
|
||||
* elements:
|
||||
*
|
||||
* \code
|
||||
* struct message {
|
||||
* char *contents;
|
||||
* wl_list link;
|
||||
* };
|
||||
*
|
||||
* struct wl_list *message_list;
|
||||
* // Assume message_list now "contains" many messages
|
||||
*
|
||||
* struct message *m;
|
||||
* wl_list_for_each(m, message_list, link) {
|
||||
* do_something_with_message(m);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \param pos Cursor that each list element will be assigned to
|
||||
* \param head Head of the list to iterate over
|
||||
* \param member Name of the link member within the element struct
|
||||
*
|
||||
* \relates wl_list
|
||||
*/
|
||||
#define wl_list_for_each(pos, head, member) \
|
||||
for (pos = wl_container_of((head)->next, pos, member); \
|
||||
&pos->member != (head); \
|
||||
pos = wl_container_of(pos->member.next, pos, member))
|
||||
|
||||
/**
|
||||
* Iterates over a list, safe against removal of the list element.
|
||||
*
|
||||
* \note Only removal of the current element, \p pos, is safe. Removing
|
||||
* any other element during traversal may lead to a loop malfunction.
|
||||
*
|
||||
* \sa wl_list_for_each()
|
||||
*
|
||||
* \param pos Cursor that each list element will be assigned to
|
||||
* \param tmp Temporary pointer of the same type as \p pos
|
||||
* \param head Head of the list to iterate over
|
||||
* \param member Name of the link member within the element struct
|
||||
*
|
||||
* \relates wl_list
|
||||
*/
|
||||
#define wl_list_for_each_safe(pos, tmp, head, member) \
|
||||
for (pos = wl_container_of((head)->next, pos, member), \
|
||||
tmp = wl_container_of((pos)->member.next, tmp, member); \
|
||||
@@ -482,37 +120,11 @@ wl_list_insert_list(struct wl_list *list, struct wl_list *other);
|
||||
pos = tmp, \
|
||||
tmp = wl_container_of(pos->member.next, tmp, member))
|
||||
|
||||
/**
|
||||
* Iterates backwards over a list.
|
||||
*
|
||||
* \sa wl_list_for_each()
|
||||
*
|
||||
* \param pos Cursor that each list element will be assigned to
|
||||
* \param head Head of the list to iterate over
|
||||
* \param member Name of the link member within the element struct
|
||||
*
|
||||
* \relates wl_list
|
||||
*/
|
||||
#define wl_list_for_each_reverse(pos, head, member) \
|
||||
for (pos = wl_container_of((head)->prev, pos, member); \
|
||||
&pos->member != (head); \
|
||||
pos = wl_container_of(pos->member.prev, pos, member))
|
||||
|
||||
/**
|
||||
* Iterates backwards over a list, safe against removal of the list element.
|
||||
*
|
||||
* \note Only removal of the current element, \p pos, is safe. Removing
|
||||
* any other element during traversal may lead to a loop malfunction.
|
||||
*
|
||||
* \sa wl_list_for_each()
|
||||
*
|
||||
* \param pos Cursor that each list element will be assigned to
|
||||
* \param tmp Temporary pointer of the same type as \p pos
|
||||
* \param head Head of the list to iterate over
|
||||
* \param member Name of the link member within the element struct
|
||||
*
|
||||
* \relates wl_list
|
||||
*/
|
||||
#define wl_list_for_each_reverse_safe(pos, tmp, head, member) \
|
||||
for (pos = wl_container_of((head)->prev, pos, member), \
|
||||
tmp = wl_container_of((pos)->member.prev, tmp, member); \
|
||||
@@ -520,244 +132,75 @@ wl_list_insert_list(struct wl_list *list, struct wl_list *other);
|
||||
pos = tmp, \
|
||||
tmp = wl_container_of(pos->member.prev, tmp, member))
|
||||
|
||||
/**
|
||||
* \class wl_array
|
||||
*
|
||||
* Dynamic array
|
||||
*
|
||||
* A wl_array is a dynamic array that can only grow until released. It is
|
||||
* intended for relatively small allocations whose size is variable or not known
|
||||
* in advance. While construction of a wl_array does not require all elements to
|
||||
* be of the same size, wl_array_for_each() does require all elements to have
|
||||
* the same type and size.
|
||||
*
|
||||
*/
|
||||
struct wl_array {
|
||||
/** Array size */
|
||||
size_t size;
|
||||
/** Allocated space */
|
||||
size_t alloc;
|
||||
/** Array data */
|
||||
void *data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the array.
|
||||
*
|
||||
* \param array Array to initialize
|
||||
*
|
||||
* \memberof wl_array
|
||||
*/
|
||||
void
|
||||
wl_array_init(struct wl_array *array);
|
||||
|
||||
/**
|
||||
* Releases the array data.
|
||||
*
|
||||
* \note Leaves the array in an invalid state.
|
||||
*
|
||||
* \param array Array whose data is to be released
|
||||
*
|
||||
* \memberof wl_array
|
||||
*/
|
||||
void
|
||||
wl_array_release(struct wl_array *array);
|
||||
|
||||
/**
|
||||
* Increases the size of the array by \p size bytes.
|
||||
*
|
||||
* \param array Array whose size is to be increased
|
||||
* \param size Number of bytes to increase the size of the array by
|
||||
*
|
||||
* \return A pointer to the beginning of the newly appended space, or NULL when
|
||||
* resizing fails.
|
||||
*
|
||||
* \memberof wl_array
|
||||
*/
|
||||
void *
|
||||
wl_array_add(struct wl_array *array, size_t size);
|
||||
|
||||
/**
|
||||
* Copies the contents of \p source to \p array.
|
||||
*
|
||||
* \param array Destination array to copy to
|
||||
* \param source Source array to copy from
|
||||
*
|
||||
* \return 0 on success, or -1 on failure
|
||||
*
|
||||
* \memberof wl_array
|
||||
*/
|
||||
int
|
||||
wl_array_copy(struct wl_array *array, struct wl_array *source);
|
||||
|
||||
/**
|
||||
* Iterates over an array.
|
||||
*
|
||||
* This macro expresses a for-each iterator for wl_array. It assigns each
|
||||
* element in the array to \p pos, which can then be referenced in a trailing
|
||||
* code block. \p pos must be a pointer to the array element type, and all
|
||||
* array elements must be of the same type and size.
|
||||
*
|
||||
* \param pos Cursor that each array element will be assigned to
|
||||
* \param array Array to iterate over
|
||||
*
|
||||
* \relates wl_array
|
||||
* \sa wl_list_for_each()
|
||||
*/
|
||||
#define wl_array_for_each(pos, array) \
|
||||
for (pos = (array)->data; \
|
||||
(array)->size != 0 && \
|
||||
(const char *) pos < ((const char *) (array)->data + (array)->size); \
|
||||
(pos)++)
|
||||
|
||||
/**
|
||||
* Fixed-point number
|
||||
*
|
||||
* A `wl_fixed_t` is a 24.8 signed fixed-point number with a sign bit, 23 bits
|
||||
* of integer precision and 8 bits of decimal precision. Consider `wl_fixed_t`
|
||||
* as an opaque struct with methods that facilitate conversion to and from
|
||||
* `double` and `int` types.
|
||||
*/
|
||||
typedef int32_t wl_fixed_t;
|
||||
|
||||
/**
|
||||
* Converts a fixed-point number to a floating-point number.
|
||||
*
|
||||
* \param f Fixed-point number to convert
|
||||
*
|
||||
* \return Floating-point representation of the fixed-point argument
|
||||
*/
|
||||
static inline double
|
||||
wl_fixed_to_double(wl_fixed_t f)
|
||||
{
|
||||
return f / 256.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a floating-point number to a fixed-point number.
|
||||
*
|
||||
* \param d Floating-point number to convert
|
||||
*
|
||||
* \return Fixed-point representation of the floating-point argument
|
||||
*/
|
||||
static inline wl_fixed_t
|
||||
wl_fixed_from_double(double d)
|
||||
{
|
||||
return (wl_fixed_t) (round(d * 256.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a fixed-point number to an integer.
|
||||
*
|
||||
* \param f Fixed-point number to convert
|
||||
*
|
||||
* \return Integer component of the fixed-point argument
|
||||
*/
|
||||
static inline int
|
||||
wl_fixed_to_int(wl_fixed_t f)
|
||||
{
|
||||
return f / 256;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a fixed-point number.
|
||||
*
|
||||
* \param i Integer to convert
|
||||
*
|
||||
* \return Fixed-point representation of the integer argument
|
||||
*/
|
||||
static inline wl_fixed_t
|
||||
wl_fixed_from_int(int i)
|
||||
{
|
||||
return i * 256;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protocol message argument data types
|
||||
*
|
||||
* This union represents all of the argument types in the Wayland protocol wire
|
||||
* format. The protocol implementation uses wl_argument within its marshalling
|
||||
* machinery for dispatching messages between a client and a compositor.
|
||||
*
|
||||
* \sa wl_message
|
||||
* \sa wl_interface
|
||||
* \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-wire-Format">Wire Format</a>
|
||||
*/
|
||||
union wl_argument {
|
||||
int32_t i; /**< `int` */
|
||||
uint32_t u; /**< `uint` */
|
||||
wl_fixed_t f; /**< `fixed` */
|
||||
const char *s; /**< `string` */
|
||||
struct wl_object *o; /**< `object` */
|
||||
uint32_t n; /**< `new_id` */
|
||||
struct wl_array *a; /**< `array` */
|
||||
int32_t h; /**< `fd` */
|
||||
int32_t i;
|
||||
uint32_t u;
|
||||
wl_fixed_t f;
|
||||
const char *s;
|
||||
struct wl_object *o;
|
||||
uint32_t n;
|
||||
struct wl_array *a;
|
||||
int32_t h;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatcher function type alias
|
||||
*
|
||||
* A dispatcher is a function that handles the emitting of callbacks in client
|
||||
* code. For programs directly using the C library, this is done by using
|
||||
* libffi to call function pointers. When binding to languages other than C,
|
||||
* dispatchers provide a way to abstract the function calling process to be
|
||||
* friendlier to other function calling systems.
|
||||
*
|
||||
* A dispatcher takes five arguments: The first is the dispatcher-specific
|
||||
* implementation associated with the target object. The second is the object
|
||||
* upon which the callback is being invoked (either wl_proxy or wl_resource).
|
||||
* The third and fourth arguments are the opcode and the wl_message
|
||||
* corresponding to the callback. The final argument is an array of arguments
|
||||
* received from the other process via the wire protocol.
|
||||
*
|
||||
* \param user_data Dispatcher-specific implementation data
|
||||
* \param target Callback invocation target (wl_proxy or `wl_resource`)
|
||||
* \param opcode Callback opcode
|
||||
* \param msg Callback message signature
|
||||
* \param args Array of received arguments
|
||||
*
|
||||
* \return 0 on success, or -1 on failure
|
||||
*/
|
||||
typedef int (*wl_dispatcher_func_t)(const void *user_data, void *target,
|
||||
uint32_t opcode, const struct wl_message *msg,
|
||||
union wl_argument *args);
|
||||
|
||||
/**
|
||||
* Log function type alias
|
||||
*
|
||||
* The C implementation of the Wayland protocol abstracts the details of
|
||||
* logging. Users may customize the logging behavior, with a function conforming
|
||||
* to the `wl_log_func_t` type, via `wl_log_set_handler_client` and
|
||||
* `wl_log_set_handler_server`.
|
||||
*
|
||||
* A `wl_log_func_t` must conform to the expectations of `vprintf`, and
|
||||
* expects two arguments: a string to write and a corresponding variable
|
||||
* argument list. While the string to write may contain format specifiers and
|
||||
* use values in the variable argument list, the behavior of any `wl_log_func_t`
|
||||
* depends on the implementation.
|
||||
*
|
||||
* \note Take care to not confuse this with `wl_protocol_logger_func_t`, which
|
||||
* is a specific server-side logger for requests and events.
|
||||
*
|
||||
* \param fmt String to write to the log, containing optional format
|
||||
* specifiers
|
||||
* \param args Variable argument list
|
||||
*
|
||||
* \sa wl_log_set_handler_client
|
||||
* \sa wl_log_set_handler_server
|
||||
*/
|
||||
typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0);
|
||||
|
||||
/**
|
||||
* Return value of an iterator function
|
||||
*
|
||||
* \sa wl_client_for_each_resource_iterator_func_t
|
||||
* \sa wl_client_for_each_resource
|
||||
*/
|
||||
enum wl_iterator_result {
|
||||
/** Stop the iteration */
|
||||
WL_ITERATOR_STOP,
|
||||
/** Continue the iteration */
|
||||
WL_ITERATOR_CONTINUE
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user