-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontent_renderer.cpp
More file actions
700 lines (625 loc) · 23 KB
/
content_renderer.cpp
File metadata and controls
700 lines (625 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#include <chrono>
#include <runtime/content.hpp>
#include <runtime/constellation.hpp>
#include <xr/device.hpp>
#include <xr/session.hpp>
#include <common/command_buffers/details/buffer.hpp>
#include <common/command_buffers/details/states.hpp>
#include <common/command_buffers/webgl_constants.hpp>
#include "./content_renderer.hpp"
#include "./render_api.hpp"
namespace renderer
{
using namespace std;
inline string GetContentRendererId(shared_ptr<TrContentRuntime> content,
uint8_t contextId,
optional<string> suffix = nullopt)
{
auto id = "content_renderer#" +
to_string(content->id) + "." + to_string(contextId) +
(suffix.has_value() ? suffix.value() : "");
return id;
}
TrBackupGLContextScope::TrBackupGLContextScope(TrContentRenderer *contentRenderer)
: contentRenderer(contentRenderer)
{
assert(contentRenderer != nullptr && contentRenderer->glContext != nullptr);
string contextName = contentRenderer->glContext->name();
contentRenderer->glContextForBackup = make_unique<ContextGLApp>(contextName + "~backup",
contentRenderer->glContext.get());
// Switch the current pass to cached XR frame pass.
previousPass = contentRenderer->currentPass;
contentRenderer->currentPass = ExecutingPassType::kCachedXRFrame;
}
TrBackupGLContextScope::~TrBackupGLContextScope()
{
contentRenderer->currentPass = previousPass;
}
TrContentRenderer::TrContentRenderer(shared_ptr<TrContentRuntime> content, uint8_t contextId, TrConstellation *constellation)
: content(weak_ptr<TrContentRuntime>(content))
, contentId(content->id)
, contextId(contextId)
, constellation(constellation)
, xrDevice(constellation->xrDevice.get())
, targetFrameRate(constellation->renderer->clientDefaultFrameRate)
, glContext(nullptr)
, glContextForBackup(nullptr)
{
assert(xrDevice != nullptr);
stereoFrameForBackup = make_unique<xr::StereoRenderingFrame>(true, 0xf);
}
TrContentRenderer::~TrContentRenderer()
{
xrDevice = nullptr;
{
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
// Clear the `defaultCommandBufferRequests`.
for (auto commandBufferReq : defaultCommandBufferRequests)
{
if (commandBufferReq != nullptr)
delete commandBufferReq;
}
defaultCommandBufferRequests.clear();
// Clear the stereo frames list
// TODO(yorkie): use smart pointer to manage the stereo frames list?
for (auto it = stereoFramesList.begin(); it != stereoFramesList.end();)
{
auto frame = *it;
it = stereoFramesList.erase(it);
delete frame;
}
}
}
void TrContentRenderer::onCommandBuffersExecuting()
{
lastFrameHasOutOfMemoryError = false;
lastFrameErrorsCount = 0;
auto contentRef = getContent();
if (contentRef != nullptr)
contentRef->onCommandBuffersExecuting();
}
void TrContentRenderer::onCommandBuffersExecuted()
{
getContent()->onCommandBuffersExecuted();
// FIXME(yorkie): dispose this content once there is OOM or too many(>=20) graphic errors in a frame.
if (lastFrameHasOutOfMemoryError || lastFrameErrorsCount > 20) [[unlikely]]
{
DEBUG(LOG_TAG_ERROR,
"Disposing the content(%d) due to the frame OOM or occurred errors(%d) > 10",
getContent()->id,
lastFrameErrorsCount);
getContent()->dispose();
}
}
bool TrContentRenderer::sendCommandBufferResponse(TrCommandBufferResponse &res)
{
auto contentRef = getContent();
assert(contentRef != nullptr);
return contentRef->sendCommandBufferResponse(res);
}
ContextGLApp *TrContentRenderer::getContextGL() const
{
if (currentPass == ExecutingPassType::kCachedXRFrame)
return glContextForBackup.get();
else if (currentPass == ExecutingPassType::kOffscreenPass)
{
if (glContextOnOffscreenPass.has_value())
return const_cast<ContextGLApp *>(&glContextOnOffscreenPass.value());
else
return nullptr;
}
else
{
return glContext.get();
}
}
pid_t TrContentRenderer::getContentPid() const
{
auto contentRef = getContent();
return contentRef == nullptr
? INVALID_PID
: contentRef->pid.load();
}
TrRenderer &TrContentRenderer::getRendererRef() const
{
assert(constellation != nullptr && constellation->renderer != nullptr &&
"The constellation or renderer is not initialized.");
return *constellation->renderer;
}
void TrContentRenderer::resetOffscreenPassGLContext(std::optional<GLuint> framebuffer)
{
if (framebuffer == std::nullopt)
{
glContextOnOffscreenPass = std::nullopt;
}
else
{
std::string contextName = GetContentRendererId(getContent(), contextId) + "~offscreen";
glContextOnOffscreenPass = ContextGLApp(contextName, getContextGL(), framebuffer);
}
}
void TrContentRenderer::scheduleCommandBufferAtOffscreenPass(TrCommandBufferBase *req)
{
if (req == nullptr) [[unlikely]]
return;
commandBuffersOnOffscreenPass.push_back(req);
}
RenderPassType TrContentRenderer::determineRenderPassType(TrCommandBufferBase *req) const
{
if (req == nullptr) [[unlikely]]
{
return RenderPassType::kOpaque;
}
auto commandType = req->type;
// Check if this is a framebuffer bind operation
if (commandType == COMMAND_BUFFER_BIND_FRAMEBUFFER_REQ)
{
auto bindFbReq = dynamic_cast<const commandbuffers::BindFramebufferCommandBufferRequest *>(req);
if (bindFbReq != nullptr)
{
// If binding to a non-default framebuffer, route to offscreen pass
if (!bindFbReq->isBindToDefault())
{
return RenderPassType::kOffscreen;
}
}
}
// Check if the current framebuffer binding is not the default render target
if (currentBoundFramebuffer_.has_value())
{
auto glContext = getContextGL();
if (glContext != nullptr)
{
GLuint currentDefault = glContext->currentDefaultRenderTarget();
if (currentBoundFramebuffer_.value() != currentDefault && currentBoundFramebuffer_.value() != 0)
{
// Currently bound to a non-default framebuffer, route to offscreen
return RenderPassType::kOffscreen;
}
}
}
// If blending is enabled and this is a draw call, route to transparent pass
// Only check for actual draw commands, not all framebuffer-dependent commands
if (isBlendingEnabled_)
{
switch (commandType)
{
case COMMAND_BUFFER_DRAW_ARRAYS_REQ:
case COMMAND_BUFFER_DRAW_ELEMENTS_REQ:
case COMMAND_BUFFER_DRAW_ARRAYS_INSTANCED_REQ:
case COMMAND_BUFFER_DRAW_ELEMENTS_INSTANCED_REQ:
case COMMAND_BUFFER_DRAW_RANGE_ELEMENTS_REQ:
return RenderPassType::kTransparent;
default:
break;
}
}
// Default to opaque pass
return RenderPassType::kOpaque;
}
// The `req` argument is a pointer to `TrCommandBufferBase` in the heap, it will be stored in the corresponding queues
// such as `defaultCommandBufferRequests` or `stereoFramesList`, otherwise it will be deleted in this function.
void TrContentRenderer::onCommandBufferRequestReceived(TrCommandBufferBase *req)
{
if (!req->renderingInfo.isValid() && !commandbuffers::CommandTypes::IsXRFrameControl(req->type))
{
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
defaultCommandBufferRequests.push_back(req);
// We need to pending the execution of all command buffers util the default command queue is finished.
isDefaultCommandQueuePending = true;
defaultCommandQueueSkipTimes = 3;
return;
}
// Release the default command queue pending state once incoming request is not a default command.
isDefaultCommandQueuePending = false;
int stereoId;
int viewIndex;
if (req->type == COMMAND_BUFFER_XRFRAME_START_REQ)
{
auto xrFrameStartReq = dynamic_cast<XRFrameStartCommandBufferRequest *>(req);
stereoId = xrFrameStartReq->stereoId;
viewIndex = xrFrameStartReq->viewIndex;
}
else if (req->type == COMMAND_BUFFER_XRFRAME_FLUSH_REQ)
{
auto xrFrameFlushReq = dynamic_cast<XRFrameFlushCommandBufferRequest *>(req);
stereoId = xrFrameFlushReq->stereoId;
viewIndex = xrFrameFlushReq->viewIndex;
}
else if (req->type == COMMAND_BUFFER_XRFRAME_END_REQ)
{
auto xrFrameEndReq = dynamic_cast<XRFrameEndCommandBufferRequest *>(req);
stereoId = xrFrameEndReq->stereoId;
viewIndex = xrFrameEndReq->viewIndex;
}
else
{
stereoId = req->renderingInfo.stereoId;
viewIndex = req->renderingInfo.viewIndex;
}
xr::StereoRenderingFrame *frame = nullptr;
if (req->type == COMMAND_BUFFER_XRFRAME_START_REQ && viewIndex == 0)
{
frame = xrDevice->createStereoRenderingFrame(stereoId);
{
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
frame->available(true);
stereoFramesList.push_back(frame);
}
}
else
{
shared_lock<shared_mutex> lock(commandBufferRequestsMutex);
for (auto stereoFrame : stereoFramesList)
{
if (stereoFrame->getId() == stereoId)
{
frame = stereoFrame;
break;
}
}
if (frame == nullptr)
{
DEBUG(LOG_TAG_ERROR, "The stereo frame(%d) is not found for the viewIndex(%d)", stereoId, viewIndex);
delete req;
return;
}
}
{
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
if (req->type == COMMAND_BUFFER_XRFRAME_START_REQ)
frame->startFrame(viewIndex), delete req;
else if (req->type == COMMAND_BUFFER_XRFRAME_FLUSH_REQ)
frame->flushFrame(viewIndex), delete req;
else if (req->type == COMMAND_BUFFER_XRFRAME_END_REQ)
frame->endFrame(viewIndex), delete req;
else
{
if (frame->ended(viewIndex))
{
DEBUG(LOG_TAG_ERROR,
"The command buffer(%d) has been ignored due to the stereo frame(%d) is ended.",
req->type,
stereoId);
delete req;
}
else
{
frame->addCommandBuffer(req, viewIndex);
}
}
}
}
void TrContentRenderer::onOpaquesRenderPass(chrono::time_point<chrono::high_resolution_clock> time)
{
// Check and initialize the graphics contexts on host frame.
initializeGraphicsContextsOnce();
/**
* Execute the content's command buffers.
*/
onStartFrame();
{
// Execute the default command buffers first.
executeCommandBuffersAtDefaultFrame();
// Skip the XR frame in the following conditions:
bool shouldSkipXRFrame = false;
// If the default command queue is pending, we consider this time of XR frame might be skipped.
if (isDefaultCommandQueuePending == true)
{
// `defaultCommandQueueSkipTimes` is updated to a positive value such as +2 when there is a default command
// received.
//
// If the skip times is greater than 0, this time of XR frame must be skipped to wait for the default command
// queue to be executed, this is a method to ensure the default command queue should be executed completely.
if (defaultCommandQueueSkipTimes > 0)
{
shouldSkipXRFrame = true;
// Decrement the skip times, if it reaches 0, we will not skip the XR frame anymore.
defaultCommandQueueSkipTimes--;
}
// If the skip times is 0, we will reset the pending state and skip times, this is used to ensure the XR frame
// will not be suspended if there is default commands is received in multiple frames.
//
// In client-side, the XR frame updater will check the pending stere frames length, if there is too much (>=2)
// pending frames, it won't dispatch frame callback to wait for the pending frames to be executed. To resolve
// the deadlock, the skip times is introduced to make sure the pending stereo frames must be executed even
// though the default command queue is pending.
else
{
isDefaultCommandQueuePending = false;
shouldSkipXRFrame = false;
}
}
// If the default command queue is not pending, we will not skip the XR frame.
else
{
shouldSkipXRFrame = false;
}
if (!shouldSkipXRFrame && getContent()->used && xrDevice->enabled())
{
currentPass = ExecutingPassType::kXRFrame;
// Execute the XR frame
switch (xrDevice->getStereoRenderingMode())
{
case xr::TrStereoRenderingMode::MultiPass:
{
executeCommandBuffersAtXRFrame(xrDevice->getActiveEyeId());
break;
}
case xr::TrStereoRenderingMode::SinglePass:
case xr::TrStereoRenderingMode::SinglePassInstanced:
case xr::TrStereoRenderingMode::SinglePassMultiview:
{
executeCommandBuffersAtXRFrame(0);
executeCommandBuffersAtXRFrame(1);
break;
}
default:
break;
}
}
}
onEndFrame();
}
void TrContentRenderer::onTransparentsRenderPass(chrono::time_point<chrono::high_resolution_clock> time)
{
// Execute command buffers that have been routed to the transparent render pass.
// These are typically draw calls that have blending enabled.
auto *transparentPass = renderPassCollection_.getTransparentPass();
if (transparentPass != nullptr && transparentPass->hasCommandBuffers())
{
// Note: We use kXRFrame pass type for transparent rendering because it indicates
// a regular rendering frame (as opposed to initialization or offscreen). The
// transparent pass executes draw calls with blending, which are still part of
// the main XR/rendering frame.
currentPass = ExecutingPassType::kXRFrame;
transparentPass->begin();
{
auto &commandBuffers = transparentPass->getCommandBuffers();
constellation->renderer->executeCommandBuffers(commandBuffers,
this,
ExecutingPassType::kXRFrame);
}
transparentPass->end();
transparentPass->clearCommandBuffers();
}
}
void TrContentRenderer::onOffscreenRenderPass()
{
currentPass = ExecutingPassType::kOffscreenPass;
// Get the offscreen render pass from the collection
auto *offscreenPass = renderPassCollection_.getOffscreenPass();
// Execute command buffers from both the legacy storage and the new render pass collection
// This maintains backward compatibility while transitioning to the new system
if (commandBuffersOnOffscreenPass.size() > 0)
{
assert(glContextOnOffscreenPass.has_value() &&
"The offscreen pass context is not initialized, please call `initializeGraphicsContextsOnce()` first.");
offscreenPass->begin();
glContextOnOffscreenPass->restore();
constellation->renderer->executeCommandBuffers(commandBuffersOnOffscreenPass,
this,
ExecutingPassType::kOffscreenPass);
for (auto commandbuffer : commandBuffersOnOffscreenPass)
{
if (commandbuffer != nullptr) [[likely]]
delete commandbuffer;
}
commandBuffersOnOffscreenPass.clear();
glContextOnOffscreenPass = nullopt;
offscreenPass->end();
}
// Also check the render pass collection for any additional offscreen commands
if (offscreenPass->hasCommandBuffers())
{
offscreenPass->begin();
{
auto &commandBuffers = offscreenPass->getCommandBuffers();
constellation->renderer->executeCommandBuffers(commandBuffers,
this,
ExecutingPassType::kOffscreenPass);
}
offscreenPass->end();
offscreenPass->clearCommandBuffers();
}
currentPass = ExecutingPassType::kDefaultFrame;
}
void TrContentRenderer::onStartFrame()
{
frameStartTime = chrono::system_clock::now();
currentPass = ExecutingPassType::kDefaultFrame;
// Reset the render pass collection for a new frame
renderPassCollection_.resetForNewFrame();
// Reset blending and framebuffer state tracking
isBlendingEnabled_ = false;
currentBoundFramebuffer_ = std::nullopt;
// Update the pending stereo frames count for each WebXR session if the WebXR device is enabled.
if (xrDevice->enabled()) [[likely]]
{
size_t pendings = getPendingStereoFramesCount();
for (auto session : getContent()->getXRSessions())
session->setPendingStereoFramesCount(pendings);
}
// ContextApp: onStart
glContext->onFrameWillStart(constellation->renderer->glHostContext);
if (constellation->renderer->isAppContextSummaryEnabled)
glContext->print();
// Reset frame states
drawCallsPerFrame = 0;
drawCallsCountPerFrame = 0;
}
void TrContentRenderer::onEndFrame()
{
glContext->onFrameEnded(constellation->renderer->glHostContext);
frameEndTime = chrono::system_clock::now();
frameDuration = chrono::duration_cast<chrono::milliseconds>(frameEndTime - frameStartTime);
maxFrameDuration = max(maxFrameDuration, frameDuration);
currentPass = ExecutingPassType::kDefaultFrame;
}
void TrContentRenderer::initializeGraphicsContextsOnce()
{
if (isGraphicsContextsInitialized) [[likely]]
return;
auto idStrBase = GetContentRendererId(getContent(), contextId);
glContext = make_unique<ContextGLApp>(idStrBase, shared_from_this());
glContext->initializeContext(constellation->renderer->glHostContext);
glContextForBackup = make_unique<ContextGLApp>(idStrBase + "~backup", shared_from_this());
isGraphicsContextsInitialized = true;
}
void TrContentRenderer::executeCommandBuffersAtDefaultFrame()
{
if (getContent() == nullptr) [[unlikely]]
return;
vector<commandbuffers::TrCommandBufferBase *> list;
{
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
if (defaultCommandBufferRequests.size() > 0)
{
list = defaultCommandBufferRequests;
defaultCommandBufferRequests.clear();
}
}
if (list.size() > 0)
{
constellation->renderer->executeCommandBuffers(list, this, ExecutingPassType::kDefaultFrame);
for (auto req : list)
delete req;
}
}
void TrContentRenderer::executeCommandBuffersAtXRFrame(int viewIndex)
{
if (getContent() == nullptr) [[unlikely]]
return;
unique_lock<shared_mutex> lock(commandBufferRequestsMutex);
executeStereoFrame(viewIndex);
}
bool TrContentRenderer::executeStereoFrame(int viewIndex)
{
auto renderer = constellation->renderer;
bool called = false;
for (auto it = stereoFramesList.begin(); it != stereoFramesList.end();)
{
auto frame = *it;
if (
!frame->available() /** Remove this frame when frame is still inavialble when executing */
)
{
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "The stereo frame(%d) is to be removed due to it's unavailable.", frame->getId());
#endif
it = stereoFramesList.erase(it);
delete frame;
continue;
}
/** Just skip the non-ended frames. */
if (!frame->ended())
{
/** Check there is a flush command buffers */
if (frame->needFlush(viewIndex))
{
if (
viewIndex == 0 ||
(viewIndex == 1 && frame->ended(0)))
{
auto &list = frame->getCommandBuffers(viewIndex);
renderer->executeCommandBuffers(list, this, ExecutingPassType::kXRFrame);
frame->clearCommandBuffers(viewIndex);
frame->resetFlush(viewIndex);
}
}
it++;
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "Skipping the stereo frame(%d) due to it's not ended.", frame->getId());
#endif
continue;
}
/** If an ended frame is empty, it's needed to be removed here. */
if (frame->empty())
{
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "The stereo frame(%d) is to be removed due to it's empty.", frame->getId());
#endif
it = stereoFramesList.erase(it);
delete frame;
continue;
}
/**
* When we are going to render right(1) eye, we can't render the frame which left frame is not finished.
* Such as, the frame is ended before the native loop is going to render the right eye, thus the left eye
* in this frame will be skipped.
*/
if (viewIndex == 1 && !frame->finished(0))
{
it++;
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "The stereo frame(%d) is not finished for the left eye, it's skipped.", frame->getId());
#endif
continue;
}
auto &list = frame->getCommandBuffers(viewIndex);
bool isStateChanged = renderer->executeCommandBuffers(list, this, ExecutingPassType::kXRFrame);
frame->idempotent(viewIndex, !isStateChanged);
frame->finishPass(viewIndex);
if (viewIndex == 1)
{
if (frame->idempotent())
{
// FIXME(yorkie): this will move the command buffers to the backup frame.
frame->moveCommandBuffersTo(*stereoFrameForBackup);
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "The stereo frame(%d) is idempotent, the backup frame is copied.", contentId);
#endif
}
else
{
stereoFrameForBackup->clearCommandBuffers();
#ifdef TR_RENDERER_ENABLE_VERBOSE
DEBUG(LOG_TAG_RENDERER, "The stereo frame(%d) is not idempotent, the backup frame is cleared.", contentId);
#endif
}
}
/**
* After rendering the right eye, we need to remove the frame.
*/
if (viewIndex == 1)
{
assert(frame->finished(0));
it = stereoFramesList.erase(it);
delete frame;
}
else
{
it++;
}
/**
* We only need to render the frame one by one, this avoids the rendering order is not correct.
*/
called = true;
break;
}
// When the `called` is false, it means the current frames are not ended, so we need to render by the last frame.
if (called == false)
executeBackupFrame(viewIndex);
return called;
}
void TrContentRenderer::executeBackupFrame(int viewIndex)
{
auto &list = stereoFrameForBackup->getCommandBuffers(viewIndex);
if (list.size() > 0) [[likely]]
{
TrBackupGLContextScope contextScopeForBackup(this);
constellation->renderer->executeCommandBuffers(list, this, ExecutingPassType::kCachedXRFrame);
}
}
size_t TrContentRenderer::getPendingStereoFramesCount()
{
shared_lock<shared_mutex> lock(commandBufferRequestsMutex);
size_t count = 0;
for (auto frame : stereoFramesList)
{
if (frame->ended())
count++;
}
return count;
}
}