History

Merge pull request #8325 from jherico/deferred_batches_threaded

Threaded rendering

samcake committed 10 years ago

Commit 8d12a232 parents 8c7f89c 438205b141 files · +4020 −2962Browse files

Showing the changes to interface/src/Application.cpp (1 of 141 files). Show all

Unified · Split

interface/src/Application.cpp+38−74
@@ -257,7 +257,10 @@ public: · 256 unmodified lines
257257 void run() override {
258258 while (!_quit) {
259259 QThread::sleep(HEARTBEAT_UPDATE_INTERVAL_SECS);
260−
260+ // Don't do heartbeat detection under nsight
261+ if (nsightActive()) {
262+ continue;
263+ }
261264 uint64_t lastHeartbeat = _heartbeat; // sample atomic _heartbeat, because we could context switch away and have it updated on us
262265 uint64_t now = usecTimestampNow();
263266 auto lastHeartbeatAge = (now > lastHeartbeat) ? now - lastHeartbeat : 0;
@@ -305,8 +308,6 @@ public: · 41 unmodified lines
305308 // Don't actually crash in debug builds, in case this apparent deadlock is simply from
306309 // the developer actively debugging code
307310 #ifdef NDEBUG
308−
309−
310311 deadlockDetectionCrash();
311312 #endif
312313 }
@@ -779,16 +780,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 466 unmodified lines
779780 _glWidget->makeCurrent();
780781 _glWidget->initializeGL();
781782
782− _chromiumShareContext = new OffscreenGLCanvas();
783− _chromiumShareContext->create(_glWidget->context()->contextHandle());
784− _chromiumShareContext->makeCurrent();
785− qt_gl_set_global_share_context(_chromiumShareContext->getContext());
786−
787− _offscreenContext = new OffscreenGLCanvas();
788− _offscreenContext->create(_glWidget->context()->contextHandle());
789− _offscreenContext->makeCurrent();
790783 initializeGL();
791− _offscreenContext->makeCurrent();
792784 // Make sure we don't time out during slow operations at startup
793785 updateHeartbeat();
794786
@@ -1498,11 +1490,18 @@ void Application::initializeGL() { · 703 unmodified lines
14981490 _isGLInitialized = true;
14991491 }
15001492
1493+ _glWidget->makeCurrent();
1494+ _chromiumShareContext = new OffscreenGLCanvas();
1495+ _chromiumShareContext->create(_glWidget->context()->contextHandle());
1496+ _chromiumShareContext->makeCurrent();
1497+ qt_gl_set_global_share_context(_chromiumShareContext->getContext());
1498+
1499+ _glWidget->makeCurrent();
15011500 gpu::Context::init<gpu::gl::GLBackend>();
15021501 _gpuContext = std::make_shared<gpu::Context>();
15031502 // The gpu context can make child contexts for transfers, so
15041503 // we need to restore primary rendering context
1505− _offscreenContext->makeCurrent();
1504+ _glWidget->makeCurrent();
15061505
15071506 initDisplay();
15081507 qCDebug(interfaceapp, "Initialized Display.");
@@ -1521,7 +1520,8 @@ void Application::initializeGL() { · 12 unmodified lines
15211520 // Needs to happen AFTER the render engine initialization to access its configuration
15221521 initializeUi();
15231522 qCDebug(interfaceapp, "Initialized Offscreen UI.");
1524− _offscreenContext->makeCurrent();
1523+ _glWidget->makeCurrent();
1524+
15251525
15261526 // call Menu getInstance static method to set up the menu
15271527 // Needs to happen AFTER the QML UI initialization
@@ -1537,8 +1537,13 @@ void Application::initializeGL() { · 9 unmodified lines
15371537
15381538 _idleLoopStdev.reset();
15391539
1540+ _offscreenContext = new OffscreenGLCanvas();
1541+ _offscreenContext->create(_glWidget->context()->contextHandle());
1542+ _offscreenContext->makeCurrent();
1543+
15401544 // update before the first render
15411545 update(0);
1546+
15421547 }
15431548
15441549 FrameTimingsScriptingInterface _frameTimingsScriptingInterface;
@@ -1555,7 +1560,7 @@ void Application::initializeUi() { · 10 unmodified lines
15551560
15561561
15571562 auto offscreenUi = DependencyManager::get<OffscreenUi>();
1558− offscreenUi->create(_offscreenContext->getContext());
1563+ offscreenUi->create(_glWidget->context()->contextHandle());
15591564
15601565 auto rootContext = offscreenUi->getRootContext();
15611566
@@ -1726,17 +1731,7 @@ void Application::paintGL() { · 164 unmodified lines
17261731 PerformanceWarning warn(showWarnings, "Application::paintGL()");
17271732 resizeGL();
17281733
1729− // Before anything else, let's sync up the gpuContext with the true glcontext used in case anything happened
1730− {
1731− PerformanceTimer perfTimer("syncCache");
1732− renderArgs._context->syncCache();
1733− }
1734−
1735− auto framebufferCache = DependencyManager::get<FramebufferCache>();
1736− // Final framebuffer that will be handled to the display-plugin
1737− auto finalFramebuffer = framebufferCache->getFramebuffer();
1738−
1739− _gpuContext->beginFrame(finalFramebuffer, getHMDSensorPose());
1734+ _gpuContext->beginFrame(getHMDSensorPose());
17401735 // Reset the gpu::Context Stages
17411736 // Back to the default framebuffer;
17421737 gpu::doInBatch(_gpuContext, [&](gpu::Batch& batch) {
@@ -1866,7 +1861,10 @@ void Application::paintGL() { · 123 unmodified lines
18661861 getApplicationCompositor().setFrameInfo(_frameCount, _myCamera.getTransform());
18671862
18681863 // Primary rendering pass
1864+ auto framebufferCache = DependencyManager::get<FramebufferCache>();
18691865 const QSize size = framebufferCache->getFrameBufferSize();
1866+ // Final framebuffer that will be handled to the display-plugin
1867+ auto finalFramebuffer = framebufferCache->getFramebuffer();
18701868
18711869 {
18721870 PROFILE_RANGE(__FUNCTION__ "/mainRender");
@@ -1891,7 +1889,6 @@ void Application::paintGL() { · 18 unmodified lines
18911889 auto baseProjection = renderArgs.getViewFrustum().getProjection();
18921890 auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
18931891 float IPDScale = hmdInterface->getIPDScale();
1894− mat4 headPose = displayPlugin->getHeadPose();
18951892
18961893 // FIXME we probably don't need to set the projection matrix every frame,
18971894 // only when the display plugin changes (or in non-HMD modes when the user
@@ -1907,13 +1904,6 @@ void Application::paintGL() { · 9 unmodified lines
19071904 // Apply IPD scaling
19081905 mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
19091906 eyeOffsets[eye] = eyeOffsetTransform;
1910−
1911− // Tell the plugin what pose we're using to render. In this case we're just using the
1912− // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1913− // for rotational timewarp. If we move to support positonal timewarp, we need to
1914− // ensure this contains the full pose composed with the eye offsets.
1915− displayPlugin->setEyeRenderPose(_frameCount, eye, headPose * glm::inverse(eyeOffsetTransform));
1916−
19171907 eyeProjections[eye] = displayPlugin->getEyeProjection(eye, baseProjection);
19181908 });
19191909 renderArgs._context->setStereoProjections(eyeProjections);
@@ -1921,36 +1911,26 @@ void Application::paintGL() { · 1 unmodified line
19211911 }
19221912 renderArgs._blitFramebuffer = finalFramebuffer;
19231913 displaySide(&renderArgs, _myCamera);
1924−
1925− renderArgs._blitFramebuffer.reset();
1926− renderArgs._context->enableStereo(false);
1927− }
1928−
1929− _gpuContext->endFrame();
1930−
1931− gpu::TexturePointer overlayTexture = _applicationOverlay.acquireOverlay();
1932− if (overlayTexture) {
1933− displayPlugin->submitOverlayTexture(overlayTexture);
19341914 }
19351915
1936− // deliver final composited scene to the display plugin
1916+ auto frame = _gpuContext->endFrame();
1917+ frame->frameIndex = _frameCount;
1918+ frame->framebuffer = finalFramebuffer;
1919+ frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer){
1920+ DependencyManager::get<FramebufferCache>()->releaseFramebuffer(framebuffer);
1921+ };
1922+ frame->overlay = _applicationOverlay.getOverlayTexture();
1923+ // deliver final scene rendering commands to the display plugin
19371924 {
19381925 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
19391926 PerformanceTimer perfTimer("pluginOutput");
1940−
1941− auto finalTexture = finalFramebuffer->getRenderBuffer(0);
1942− Q_ASSERT(!_lockedFramebufferMap.contains(finalTexture));
1943− _lockedFramebufferMap[finalTexture] = finalFramebuffer;
1944−
1945− Q_ASSERT(isCurrentContext(_offscreenContext->getContext()));
1946− {
1947− PROFILE_RANGE(__FUNCTION__ "/pluginSubmitScene");
1948− PerformanceTimer perfTimer("pluginSubmitScene");
1949− displayPlugin->submitSceneTexture(_frameCount, finalTexture);
1950− }
1951− Q_ASSERT(isCurrentContext(_offscreenContext->getContext()));
1927+ displayPlugin->submitFrame(frame);
19521928 }
19531929
1930+ // Reset the framebuffer and stereo state
1931+ renderArgs._blitFramebuffer.reset();
1932+ renderArgs._context->enableStereo(false);
1933+
19541934 {
19551935 Stats::getInstance()->setRenderDetails(renderArgs._details);
19561936 }
@@ -5405,6 +5385,7 @@ void Application::updateDisplayMode() { · 3448 unmodified lines
54055385 DisplayPluginList advanced;
54065386 DisplayPluginList developer;
54075387 foreach(auto displayPlugin, displayPlugins) {
5388+ displayPlugin->setContext(_gpuContext);
54085389 auto grouping = displayPlugin->getGrouping();
54095390 switch (grouping) {
54105391 case Plugin::ADVANCED:
@@ -5474,9 +5455,6 @@ void Application::updateDisplayMode() { · 63 unmodified lines
54745455 _displayPlugin->deactivate();
54755456 }
54765457
5477− // FIXME probably excessive and useless context switching
5478− _offscreenContext->makeCurrent();
5479−
54805458 bool active = newDisplayPlugin->activate();
54815459
54825460 if (!active) {
@@ -5621,20 +5599,6 @@ bool Application::makeRenderingContextCurrent() { · 138 unmodified lines
56215599 return _offscreenContext->makeCurrent();
56225600 }
56235601
5624−void Application::releaseSceneTexture(const gpu::TexturePointer& texture) {
5625− Q_ASSERT(QThread::currentThread() == thread());
5626− auto& framebufferMap = _lockedFramebufferMap;
5627− Q_ASSERT(framebufferMap.contains(texture));
5628− auto framebufferPointer = framebufferMap[texture];
5629− framebufferMap.remove(texture);
5630− auto framebufferCache = DependencyManager::get<FramebufferCache>();
5631− framebufferCache->releaseFramebuffer(framebufferPointer);
5632−}
5633−
5634−void Application::releaseOverlayTexture(const gpu::TexturePointer& texture) {
5635− _applicationOverlay.releaseOverlay(texture);
5636−}
5637−
56385602 bool Application::isForeground() const {
56395603 return _isForeground && !_window->isMinimized();
56405604 }