Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-fix(server_openvr): Add timewarped compositing to Windows OpenVR compositor #2472

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions alvr/server_openvr/cpp/alvr_server/HMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ void Hmd::SetViewsConfig(FfiViewsConfig config) {

this->views_config = config;

// The OpenXR spec defines the HMD position as the midpoint
// between the eyes, so conversion to this is handled by the
// client.
auto left_transform = MATRIX_IDENTITY;
left_transform.m[0][3] = -config.ipd_m / 2.0;
auto right_transform = MATRIX_IDENTITY;
Expand All @@ -318,6 +321,12 @@ void Hmd::SetViewsConfig(FfiViewsConfig config) {

vr::VRServerDriverHost()->SetDisplayProjectionRaw(object_id, left_proj, right_proj);

#ifdef _WIN32
if (m_encoder) {
m_encoder->SetViewsConfig(left_proj, left_transform, right_proj, right_transform);
}
#endif

// todo: check if this is still needed
vr::VRServerDriverHost()->VendorSpecificEvent(
object_id, vr::VREvent_LensDistortionChanged, {}, 0
Expand Down
14 changes: 13 additions & 1 deletion alvr/server_openvr/cpp/platform/win32/CEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,19 @@ void CEncoder::Initialize(std::shared_ptr<CD3DRender> d3dRender) {
#endif
}

void CEncoder::SetViewsConfig(
vr::HmdRect2_t projLeft,
vr::HmdMatrix34_t eyeToHeadLeft,
vr::HmdRect2_t projRight,
vr::HmdMatrix34_t eyeToHeadRight
) {
m_FrameRender->SetViewsConfig(projLeft, eyeToHeadLeft, projRight, eyeToHeadRight);
}

bool CEncoder::CopyToStaging(
ID3D11Texture2D* pTexture[][2],
vr::VRTextureBounds_t bounds[][2],
vr::HmdMatrix34_t poses[],
int layerCount,
bool recentering,
uint64_t presentationTime,
Expand All @@ -91,7 +101,9 @@ bool CEncoder::CopyToStaging(
m_targetTimestampNs = targetTimestampNs;
m_FrameRender->Startup();

m_FrameRender->RenderFrame(pTexture, bounds, layerCount, recentering, message, debugText);
m_FrameRender->RenderFrame(
pTexture, bounds, poses, layerCount, recentering, message, debugText
);
return true;
}

Expand Down
8 changes: 8 additions & 0 deletions alvr/server_openvr/cpp/platform/win32/CEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ class CEncoder : public CThread {

void Initialize(std::shared_ptr<CD3DRender> d3dRender);

void SetViewsConfig(
vr::HmdRect2_t projLeft,
vr::HmdMatrix34_t eyeToHeadLeft,
vr::HmdRect2_t projRight,
vr::HmdMatrix34_t eyeToHeadRight
);

bool CopyToStaging(
ID3D11Texture2D* pTexture[][2],
vr::VRTextureBounds_t bounds[][2],
vr::HmdMatrix34_t poses[],
int layerCount,
bool recentering,
uint64_t presentationTime,
Expand Down
Loading
Loading