feat: validate Quest guest frame entrypoint

This commit is contained in:
XxJSONDeruloxX committed 2026-10-14 19:07:40 -04:00
1 parent 040d31c1ee
commit 2ef2d4b53d
13 files changed
+245 -45

No files matched your search

+7 -4
View File
@@ -425,10 +425,13 @@ public:
if (id_ == k_unTrackedDeviceIndexInvalid) return;
DriverPose_t pose{};
pose.qWorldFromDriverRotation.w = pose.qDriverFromHeadRotation.w = 1;
pose.qRotation = {hand.pose.orientation[3], hand.pose.orientation[0], hand.pose.orientation[1], hand.pose.orientation[2]};
for (int axis = 0; axis < 3; axis++) pose.vecPosition[axis] = hand.pose.position[axis];
pose.qRotation.w = 1;
pose.deviceIsConnected = hand.active;
pose.poseIsValid = hand.active && (hand.pose.flags & 3u) == 3u;
pose.poseIsValid = hand.active && XrTrackingFile::Tracked(hand.pose);
if (pose.poseIsValid) {
pose.qRotation = {hand.pose.orientation[3], hand.pose.orientation[0], hand.pose.orientation[1], hand.pose.orientation[2]};
for (int axis = 0; axis < 3; axis++) pose.vecPosition[axis] = hand.pose.position[axis];
}
pose.result = pose.poseIsValid ? TrackingResult_Running_OK : TrackingResult_Running_OutOfRange;
pose_ = pose;
VRServerDriverHost()->TrackedDevicePoseUpdated(id_, pose, sizeof(pose));
@@ -580,7 +583,7 @@ public:
bool freshXr = xr_.Read(&xr) && XrTrackingFile::Fresh(xr);
if (freshXr || xrMode_) {
p.deviceIsConnected = true;
p.poseIsValid = freshXr && (xr.head.flags & 3u) == 3u;
p.poseIsValid = freshXr && XrTrackingFile::Tracked(xr.head);
p.result = p.poseIsValid ? TrackingResult_Running_OK : TrackingResult_Running_OutOfRange;
if (p.poseIsValid) {
p.qRotation = {xr.head.orientation[3], xr.head.orientation[0], xr.head.orientation[1], xr.head.orientation[2]};
+7 -3
View File
@@ -183,7 +183,8 @@ private:
started_ = true;
thread_ = std::thread([this] {
try { Run(); }
catch (const std::exception &error) { Log("presenter: %s", error.what()); Fail(); }
catch (const std::exception &error) { Log("presenter: %s", error.what()); }
Cleanup(); Fail();
});
}
}
@@ -240,6 +241,9 @@ private:
lastLog = now;
}
}
}
void Cleanup() {
if (dev_) vk_.DeviceWaitIdle(dev_);
DestroyCapture();
while (!textures_.empty()) Forget(textures_.back().handle);
@@ -253,7 +257,7 @@ private:
}
if (surface_) vk_.DestroySurfaceKHR(inst_, surface_, nullptr);
if (inst_) vk_.DestroyInstance(inst_, nullptr);
Fail();
surface_ = VK_NULL_HANDLE; inst_ = VK_NULL_HANDLE;
}
std::chrono::microseconds guard_{4000};
@@ -360,7 +364,7 @@ private:
VK_GLOBAL(X)
#undef X
const char *iexts[] = {"VK_KHR_surface", wayland_ ? "VK_KHR_wayland_surface" : "VK_KHR_xlib_surface"};
VkApplicationInfo app = {VK_STRUCTURE_TYPE_APPLICATION_INFO, nullptr, "droiddeck-vr-presenter", 1, nullptr, 0, VK_API_VERSION_1_1};
VkApplicationInfo app = {VK_STRUCTURE_TYPE_APPLICATION_INFO, nullptr, "droiddeck-vr-presenter", 1, nullptr, 0, VK_API_VERSION_1_2};
VkInstanceCreateInfo ici = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, nullptr, 0, &app, 0, nullptr,
frameChannel_ ? 0u : 2u, frameChannel_ ? nullptr : iexts};
VkResult r = vk_.CreateInstance(&ici, nullptr, &inst_);
+11
View File
@@ -1,6 +1,7 @@
#pragma once
#include "xr_tracking.h"
#include <cstring>
#include <cmath>
#include <mutex>
#include <string>
#include <fcntl.h>
@@ -47,6 +48,16 @@ public:
&& packet.period_ns <= 50000000LL && packet.eyes[0].width > 0 && packet.eyes[0].width <= 8192
&& packet.eyes[0].height > 0 && packet.eyes[0].height <= 8192;
}
static bool Tracked(const DroidDeckXrPose &pose) {
if ((pose.flags & 15u) != 15u) return false;
float lengthSquared = 0;
for (float value : pose.orientation) {
if (!std::isfinite(value)) return false;
lengthSquared += value * value;
}
for (float value : pose.position) if (!std::isfinite(value)) return false;
return std::abs(lengthSquared - 1.f) < 0.01f;
}
private:
DroidDeckXrTracking *mapping_ = nullptr;
std::mutex mutex_;
+11 -2
View File
@@ -1,9 +1,11 @@
#include "../src/xr_tracking_file.h"
#include <cassert>
#include <cstdio>
#include <limits>
int main() {
char filename[] = "/tmp/droiddeck-xr-test-XXXXXX";
int main(int argc, char **argv) {
char filename[256];
std::snprintf(filename, sizeof(filename), "%s/droiddeck-xr-test-XXXXXX", argc > 1 ? argv[1] : "/tmp");
int descriptor = mkstemp(filename);
assert(descriptor >= 0);
assert(ftruncate(descriptor, sizeof(DroidDeckXrTracking)) == 0);
@@ -20,6 +22,13 @@ int main() {
writer->head.orientation[3] = 1; writer->head.position[1] = 1.6f; writer->head.flags = 15;
assert(reader.Read(&packet)); assert(XrTrackingFile::Fresh(packet));
assert(packet.head.position[1] == 1.6f);
assert(XrTrackingFile::Tracked(packet.head));
auto invalidPose = packet.head; invalidPose.flags = 7;
assert(!XrTrackingFile::Tracked(invalidPose));
invalidPose = packet.head; invalidPose.orientation[3] = 0;
assert(!XrTrackingFile::Tracked(invalidPose));
invalidPose = packet.head; invalidPose.position[0] = std::numeric_limits<float>::quiet_NaN();
assert(!XrTrackingFile::Tracked(invalidPose));
__atomic_store_n(&writer->seq, 1u, __ATOMIC_RELEASE);
assert(!reader.Read(&packet));
__atomic_store_n(&writer->seq, 2u, __ATOMIC_RELEASE);