Keep Steam alive with SteamVR registered, run SteamVR at the glasses' rate, keep the glasses lip on top

This commit is contained in:
maxjivi05 committed 2026-10-13 11:24:01 -04:00
1 parent c8c62960f6
commit a746d56dc8
5 files changed
+130 -21

No files matched your search

+19 -7
View File
@@ -464,6 +464,7 @@ public:
EVRInitError Activate(uint32_t unObjectId) override {
id_ = unObjectId;
PropertyContainerHandle_t c = VRProperties()->TrackedDeviceToPropertyContainer(id_);
container_ = c;
width_ = VRSettings()->GetInt32(kSettingsSection, "windowWidth");
height_ = VRSettings()->GetInt32(kSettingsSection, "windowHeight");
if (width_ <= 0) width_ = 1920;
@@ -480,6 +481,7 @@ public:
}
if (pose_.Read(&hp) && hp.display_hz >= 24.0f) hz = hp.display_hz;
Vsync::SetRate(hz);
sentHz_ = hz;
sentTan_ = tanHalf_;
sentAspect_ = eyeAspect_;
VRProperties()->SetStringProperty(c, Prop_ModelNumber_String, "DroidDeck Cardboard");
@@ -509,7 +511,7 @@ public:
VRProperties()->SetBoolProperty(c, Prop_ContainsProximitySensor_Bool, true);
VRDriverInput()->CreateBooleanComponent(c, "/proximity", &proximity_);
VRDriverInput()->UpdateBooleanComponent(proximity_, true, 0);
Log("HMD activated: %dx%d at %.0f Hz, eye tan(half fov) %.3f, eye aspect %.3f", width_, height_, hz, tanHalf_, eyeAspect_);
Log("HMD activated: %dx%d at %.0f Hz, eye tan(half fov) %.3f, eye aspect %.3f", width_, height_, hz, tanHalf_.load(), eyeAspect_.load());
running_ = true;
thread_ = std::thread([this] { PoseLoop(); });
@@ -565,8 +567,9 @@ public:
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)(height_ * 1.4f * eyeAspect_);
*h = (uint32_t)(height_ * 1.4f);
const float scale = renderScale_;
*w = (uint32_t)(height_ * scale * eyeAspect_);
*h = (uint32_t)(height_ * scale);
}
void GetEyeOutputViewport(EVREye eye, uint32_t *x, uint32_t *y, uint32_t *w, uint32_t *h) override {
*y = 0; *w = (uint32_t)width_ / 2; *h = (uint32_t)height_;
@@ -592,6 +595,7 @@ private:
void UpdateEye(const droiddeck_headpose &hp) {
sentTan_ = tanHalf_ = hp.tan_half_fov;
sentAspect_ = eyeAspect_ = hp.eye_aspect;
renderScale_ = (hp.flags & DROIDDECK_HEADPOSE_MONO) ? 1.0f : 1.4f;
HmdRect2_t r;
r.vTopLeft.v[0] = -tanHalf_ * eyeAspect_;
r.vTopLeft.v[1] = -tanHalf_;
@@ -601,10 +605,17 @@ private:
uint32_t w = 0, h = 0;
GetRecommendedRenderTargetSize(&w, &h);
VRServerDriverHost()->SetRecommendedRenderTargetSize(id_, w, h);
Log("eye now tan(half fov) %.3f, aspect %.3f (%ux%u eye%s), render %ux%u", tanHalf_, eyeAspect_, hp.eye_w, hp.eye_h,
Log("eye now tan(half fov) %.3f, aspect %.3f (%ux%u eye%s), render %ux%u", tanHalf_.load(), eyeAspect_.load(), hp.eye_w, hp.eye_h,
(hp.flags & DROIDDECK_HEADPOSE_MONO) ? ", one eye shown" : "", w, h);
}
void UpdateRate(float hz) {
sentHz_ = hz;
Vsync::SetRate(hz);
VRProperties()->SetFloatProperty(container_, Prop_DisplayFrequency_Float, hz);
Log("panel now %.0f Hz", hz);
}
void PoseLoop() {
uint32_t lastSeq = 0;
auto lastSent = std::chrono::steady_clock::now();
@@ -622,7 +633,7 @@ private:
if (hp.eye_w > 0 && hp.tan_half_fov > 0.0f && hp.eye_aspect > 0.0f &&
(fabsf(hp.tan_half_fov - sentTan_) > 1e-3f || fabsf(hp.eye_aspect - sentAspect_) > 1e-3f))
UpdateEye(hp);
if (hp.display_hz >= 24.0f) Vsync::SetRate(hp.display_hz);
if (hp.display_hz >= 24.0f && fabsf(hp.display_hz - sentHz_) > 0.5f) UpdateRate(hp.display_hz);
const bool worn = (hp.flags & DROIDDECK_HEADPOSE_ENABLED) != 0;
if (worn != worn_) {
worn_ = worn;
@@ -642,8 +653,9 @@ private:
uint32_t id_ = k_unTrackedDeviceIndexInvalid;
int32_t width_ = 1920, height_ = 1080;
float tanHalf_ = 1.0f, eyeAspect_ = 0.889f;
float sentTan_ = 0.0f, sentAspect_ = 0.0f;
std::atomic<float> tanHalf_{1.0f}, eyeAspect_{0.889f}, renderScale_{1.4f};
float sentTan_ = 0.0f, sentAspect_ = 0.0f, sentHz_ = 0.0f;
PropertyContainerHandle_t container_ = k_ulInvalidPropertyContainer;
public:
void SetHands(CardboardController *left, CardboardController *right) { hands_[0] = left; hands_[1] = right; }
+43 -6
View File
@@ -312,21 +312,25 @@ static void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallback
* 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). */
* The vblank side of VK_EXT_display_control is a clock at the panel's rate. Size and rate:
* DROIDDECK_VR_DISPLAY_MODE=WIDTHxHEIGHT@HZ (default 1920x1080, at the head pose file's rate, else 60). */
#include <fcntl.h>
#include <stdatomic.h>
#include <time.h>
#include "../../../app/src/main/cpp/waylandcomp/src/headpose_shm.h"
#define FAKE_DISPLAY ((VkDisplayKHR)(uintptr_t)0xdd0001)
#define FAKE_MODE ((VkDisplayModeKHR)(uintptr_t)0xdd0002)
static uint32_t g_mode_w = 1920, g_mode_h = 1080, g_mode_mhz = 60000;
static int g_mode_fixed;
static void mode_init(void) {
static int done;
if (done++) return;
const char *m = getenv("DROIDDECK_VR_DISPLAY_MODE");
unsigned w, h, hz;
if (m && sscanf(m, "%ux%u@%u", &w, &h, &hz) == 3 && w && h && hz) { g_mode_w = w; g_mode_h = h; g_mode_mhz = hz * 1000; }
if (m && sscanf(m, "%ux%u@%u", &w, &h, &hz) == 3 && w && h && hz) { g_mode_w = w; g_mode_h = h; g_mode_mhz = hz * 1000; g_mode_fixed = 1; }
}
static uint64_t now_ns(void) {
@@ -334,7 +338,40 @@ static uint64_t now_ns(void) {
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
}
static uint64_t frame_ns(void) { return 1000000000000ull / g_mode_mhz; }
static _Atomic(const struct droiddeck_headpose *) g_pose;
static _Atomic uint64_t g_pose_tried;
static const struct droiddeck_headpose *pose_map(void) {
const struct droiddeck_headpose *p = atomic_load(&g_pose);
if (p) return p;
uint64_t t = now_ns(), last = atomic_load(&g_pose_tried);
if (last && t - last < 1000000000ull) return NULL;
atomic_store(&g_pose_tried, t);
int fd = open("/run/droiddeck/" DROIDDECK_HEADPOSE_FILE, O_RDONLY | O_CLOEXEC);
if (fd < 0) return NULL;
void *m = mmap(NULL, sizeof(struct droiddeck_headpose), PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if (m == MAP_FAILED) return NULL;
const struct droiddeck_headpose *expected = NULL;
if (!atomic_compare_exchange_strong(&g_pose, &expected, (const struct droiddeck_headpose *)m)) {
munmap(m, sizeof(struct droiddeck_headpose));
return expected;
}
return m;
}
static uint32_t mode_mhz(void) {
mode_init();
if (g_mode_fixed) return g_mode_mhz;
const struct droiddeck_headpose *p = pose_map();
if (!p || __atomic_load_n(&p->magic, __ATOMIC_RELAXED) != DROIDDECK_HEADPOSE_MAGIC) return g_mode_mhz;
uint32_t bits = __atomic_load_n((const uint32_t *)&p->display_hz, __ATOMIC_RELAXED);
float hz;
memcpy(&hz, &bits, sizeof(hz));
return hz >= 24.0f && hz <= 240.0f ? (uint32_t)(hz * 1000.0f + 0.5f) : g_mode_mhz;
}
static uint64_t frame_ns(void) { return 1000000000000ull / mode_mhz(); }
static VkDisplayPropertiesKHR display_props(void) {
mode_init();
@@ -384,7 +421,7 @@ static VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice
}
static VkDisplayModePropertiesKHR mode_props(void) {
mode_init();
VkDisplayModePropertiesKHR m = {FAKE_MODE, {{g_mode_w, g_mode_h}, g_mode_mhz}};
VkDisplayModePropertiesKHR m = {FAKE_MODE, {{g_mode_w, g_mode_h}, mode_mhz()}};
return m;
}
static VkResult VKAPI_CALL GetDisplayModePropertiesKHR(VkPhysicalDevice pd, VkDisplayKHR d, uint32_t *count, VkDisplayModePropertiesKHR *p) {
@@ -452,7 +489,7 @@ 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
/* VK_EXT_display_control on the device: a clock at the panel's rate. 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) {