Skip to content

Commit

Permalink
[XR/XrSession] Requesting frame rendering returns whether it has been
Browse files Browse the repository at this point in the history
- This is used afterward to avoid copying the frame to the window

- It happens for the first few frames, notably when the session hasn't been started yet (the RenderSystem is updated while the XrSystem still hasn't been)
  • Loading branch information
Razakhel committed Nov 13, 2024
1 parent a5b512f commit 8bd98cb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/RaZ/XR/XrSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class XrSession {

void begin(unsigned int viewConfigType);
void end();
void renderFrame(const std::vector<XrViewConfigurationView>& viewConfigViews,
bool renderFrame(const std::vector<XrViewConfigurationView>& viewConfigViews,
unsigned int viewConfigType,
unsigned int environmentBlendMode,
const ViewRenderFunc& viewRenderFunc);
Expand Down
2 changes: 1 addition & 1 deletion include/RaZ/XR/XrSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class XrSystem final : public System {

private:
Vec2u recoverOptimalViewSize() const;
void renderFrame(const ViewRenderFunc& viewRenderFunc);
bool renderFrame(const ViewRenderFunc& viewRenderFunc);

void recoverViewConfigurations();
void recoverEnvironmentBlendModes();
Expand Down
5 changes: 4 additions & 1 deletion src/RaZ/Render/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void RenderSystem::renderXrFrame() {
ZoneScopedN("RenderSystem::renderXrFrame");
TracyGpuZone("RenderSystem::renderXrFrame")

m_xrSystem->renderFrame([this] (Vec3f position, Quaternionf rotation, ViewFov viewFov) {
const bool hasRendered = m_xrSystem->renderFrame([this] (Vec3f position, Quaternionf rotation, ViewFov viewFov) {
if (m_cameraEntity) {
const auto& camTransform = m_cameraEntity->getComponent<Transform>();
position = camTransform.getRotation() * position + camTransform.getPosition();
Expand Down Expand Up @@ -342,6 +342,9 @@ void RenderSystem::renderXrFrame() {
});

#if !defined(RAZ_NO_WINDOW)
if (!hasRendered)
return;

// TODO: the copied color buffer must be the one from the render pass executed last
const Framebuffer& geomFramebuffer = m_renderGraph.m_geometryPass.getFramebuffer();
copyToWindow(geomFramebuffer.getColorBuffer(0), geomFramebuffer.getDepthBuffer(), m_window->getWidth(), m_window->getHeight());
Expand Down
6 changes: 4 additions & 2 deletions src/RaZ/XR/XrSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ void XrSession::end() {
Logger::debug("[XrSession] Ended session");
}

void XrSession::renderFrame(const std::vector<XrViewConfigurationView>& viewConfigViews,
bool XrSession::renderFrame(const std::vector<XrViewConfigurationView>& viewConfigViews,
unsigned int viewConfigType,
unsigned int environmentBlendMode,
const ViewRenderFunc& viewRenderFunc) {
ZoneScopedN("XrSession::renderFrame");

if (!m_isRunning)
return;
return false;

XrFrameWaitInfo frameWaitInfo {};
frameWaitInfo.type = XR_TYPE_FRAME_WAIT_INFO;
Expand Down Expand Up @@ -275,6 +275,8 @@ void XrSession::renderFrame(const std::vector<XrViewConfigurationView>& viewConf
frameEndInfo.layers = renderLayerInfo.layers.data();
checkLog(xrEndFrame(m_handle, &frameEndInfo), "Failed to end the XR frame", m_instance);
}

return !renderLayerInfo.layers.empty();
}

XrSession::~XrSession() {
Expand Down
4 changes: 2 additions & 2 deletions src/RaZ/XR/XrSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Vec2u XrSystem::recoverOptimalViewSize() const {
return optimalViewSize;
}

void XrSystem::renderFrame(const ViewRenderFunc& viewRenderFunc) {
m_session.renderFrame(m_viewConfigViews, m_viewConfigType, m_environmentBlendMode, viewRenderFunc);
bool XrSystem::renderFrame(const ViewRenderFunc& viewRenderFunc) {
return m_session.renderFrame(m_viewConfigViews, m_viewConfigType, m_environmentBlendMode, viewRenderFunc);
}

void XrSystem::recoverViewConfigurations() {
Expand Down

0 comments on commit 8bd98cb

Please sign in to comment.