From 49512c95d753aaf94209c551354c48b548d76490 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 26 Sep 2017 16:17:59 -0700 Subject: [PATCH 1/2] possibly fix threading crashes, mirror and fade --- interface/src/SecondaryCamera.cpp | 39 +++++++++---------- interface/src/SecondaryCamera.h | 19 +++++---- .../src/model-networking/TextureCache.cpp | 16 +++++--- .../src/model-networking/TextureCache.h | 9 +++-- libraries/render-utils/src/FadeEffect.cpp | 9 +++-- libraries/render-utils/src/FadeEffect.h | 2 +- 6 files changed, 51 insertions(+), 43 deletions(-) diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index 56b8b3ef85..9d19b8fb0f 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -18,7 +18,6 @@ using RenderArgsPointer = std::shared_ptr; void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) { - task.addJob("RenderShadowTask", cullFunctor); const auto items = task.addJob("FetchCullSort", cullFunctor); assert(items.canCast()); @@ -30,14 +29,6 @@ void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render } class SecondaryCameraJob { // Changes renderContext for our framebuffer and view. - QUuid _attachedEntityId{}; - glm::vec3 _position{}; - glm::quat _orientation{}; - float _vFoV{}; - float _nearClipPlaneDistance{}; - float _farClipPlaneDistance{}; - EntityPropertyFlags _attachedEntityPropertyFlags; - QSharedPointer _entityScriptingInterface; public: using Config = SecondaryCameraJobConfig; using JobModel = render::Job::ModelO; @@ -55,13 +46,15 @@ public: _vFoV = config.vFoV; _nearClipPlaneDistance = config.nearClipPlaneDistance; _farClipPlaneDistance = config.farClipPlaneDistance; + _textureWidth = config.textureWidth; + _textureHeight = config.textureHeight; } void run(const render::RenderContextPointer& renderContext, RenderArgsPointer& cachedArgs) { auto args = renderContext->args; auto textureCache = DependencyManager::get(); gpu::FramebufferPointer destFramebuffer; - destFramebuffer = textureCache->getSpectatorCameraFramebuffer(); // FIXME: Change the destination based on some unimplemented config var + destFramebuffer = textureCache->getSpectatorCameraFramebuffer(_textureWidth, _textureHeight); // FIXME: Change the destination based on some unimplemented config var if (destFramebuffer) { _cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer; _cachedArgsPointer->_viewport = args->_viewport; @@ -98,6 +91,18 @@ public: protected: RenderArgs _cachedArgs; RenderArgsPointer _cachedArgsPointer; + +private: + QUuid _attachedEntityId; + glm::vec3 _position; + glm::quat _orientation; + float _vFoV; + float _nearClipPlaneDistance; + float _farClipPlaneDistance; + int _textureWidth; + int _textureHeight; + EntityPropertyFlags _attachedEntityPropertyFlags; + QSharedPointer _entityScriptingInterface; }; void SecondaryCameraJobConfig::setPosition(glm::vec3 pos) { @@ -123,16 +128,10 @@ void SecondaryCameraJobConfig::enableSecondaryCameraRenderConfigs(bool enabled) setEnabled(enabled); } -void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { // Carefully adjust the framebuffer / texture. - qApp->getRenderEngine()->getConfiguration()->getConfig()->resetSize(width, height); -} - -void SecondaryCameraRenderTaskConfig::resetSize(int width, int height) { // FIXME: Add an arg here for "destinationFramebuffer" - bool wasEnabled = isEnabled(); - setEnabled(false); - auto textureCache = DependencyManager::get(); - textureCache->resetSpectatorCameraFramebuffer(width, height); // FIXME: Call the correct reset function based on the "destinationFramebuffer" arg - setEnabled(wasEnabled); +void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { + textureWidth = width; + textureHeight = height; + emit dirty(); } class EndSecondaryCameraFrame { // Restores renderContext. diff --git a/interface/src/SecondaryCamera.h b/interface/src/SecondaryCamera.h index 0941959c0a..a9b438ec6f 100644 --- a/interface/src/SecondaryCamera.h +++ b/interface/src/SecondaryCamera.h @@ -18,7 +18,6 @@ #include #include - class MainRenderTask { public: using JobModel = render::Task::Model; @@ -37,12 +36,15 @@ class SecondaryCameraJobConfig : public render::Task::Config { // Exposes second Q_PROPERTY(float nearClipPlaneDistance MEMBER nearClipPlaneDistance NOTIFY dirty) // Secondary camera's near clip plane distance. In meters. Q_PROPERTY(float farClipPlaneDistance MEMBER farClipPlaneDistance NOTIFY dirty) // Secondary camera's far clip plane distance. In meters. public: - QUuid attachedEntityId{}; - glm::vec3 position{}; - glm::quat orientation{}; - float vFoV{ DEFAULT_FIELD_OF_VIEW_DEGREES }; - float nearClipPlaneDistance{ DEFAULT_NEAR_CLIP }; - float farClipPlaneDistance{ DEFAULT_FAR_CLIP }; + QUuid attachedEntityId; + glm::vec3 position; + glm::quat orientation; + float vFoV { DEFAULT_FIELD_OF_VIEW_DEGREES }; + float nearClipPlaneDistance { DEFAULT_NEAR_CLIP }; + float farClipPlaneDistance { DEFAULT_FAR_CLIP }; + int textureWidth { TextureCache::DEFAULT_SPECTATOR_CAM_WIDTH }; + int textureHeight { TextureCache::DEFAULT_SPECTATOR_CAM_HEIGHT }; + SecondaryCameraJobConfig() : render::Task::Config(false) {} signals: void dirty(); @@ -59,9 +61,6 @@ class SecondaryCameraRenderTaskConfig : public render::Task::Config { Q_OBJECT public: SecondaryCameraRenderTaskConfig() : render::Task::Config(false) {} - void resetSize(int width, int height); -signals: - void dirty(); }; class SecondaryCameraRenderTask { diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index a4ce892521..5d8f840c85 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -1003,6 +1003,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl) if (_spectatorCameraFramebuffer) { texture = _spectatorCameraFramebuffer->getRenderBuffer(0); if (texture) { + texture->setSource(SPECTATOR_CAMERA_FRAME_URL.toString().toStdString()); _spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); return _spectatorCameraNetworkTexture; } @@ -1016,6 +1017,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl) if (_hmdPreviewFramebuffer) { texture = _hmdPreviewFramebuffer->getRenderBuffer(0); if (texture) { + texture->setSource(HMD_PREVIEW_FRAME_URL.toString().toStdString()); _hmdPreviewNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); return _hmdPreviewNetworkTexture; } @@ -1033,14 +1035,18 @@ const gpu::FramebufferPointer& TextureCache::getHmdPreviewFramebuffer(int width, } const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer() { + // If we're taking a screenshot and the spectator cam buffer hasn't been created yet, reset to the default size if (!_spectatorCameraFramebuffer) { - resetSpectatorCameraFramebuffer(2048, 1024); + return getSpectatorCameraFramebuffer(DEFAULT_SPECTATOR_CAM_WIDTH, DEFAULT_SPECTATOR_CAM_HEIGHT); } return _spectatorCameraFramebuffer; } -void TextureCache::resetSpectatorCameraFramebuffer(int width, int height) { - _spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height)); - _spectatorCameraNetworkTexture.reset(); - emit spectatorCameraFramebufferReset(); +const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer(int width, int height) { + // If we aren't taking a screenshot, we might need to resize or create the camera buffer + if (!_spectatorCameraFramebuffer || _spectatorCameraFramebuffer->getWidth() != width || _spectatorCameraFramebuffer->getHeight() != height) { + _spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height)); + emit spectatorCameraFramebufferReset(); + } + return _spectatorCameraFramebuffer; } diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 5bc5aa7d96..1102694f86 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -167,12 +167,13 @@ public: gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); - - /// SpectatorCamera rendering targets. NetworkTexturePointer getResourceTexture(QUrl resourceTextureUrl); - const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(); - void resetSpectatorCameraFramebuffer(int width, int height); const gpu::FramebufferPointer& getHmdPreviewFramebuffer(int width, int height); + const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(); + const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height); + + static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 }; + static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 }; signals: void spectatorCameraFramebufferReset(); diff --git a/libraries/render-utils/src/FadeEffect.cpp b/libraries/render-utils/src/FadeEffect.cpp index c94fe717f1..418d02a4e7 100644 --- a/libraries/render-utils/src/FadeEffect.cpp +++ b/libraries/render-utils/src/FadeEffect.cpp @@ -16,8 +16,7 @@ #include FadeEffect::FadeEffect() { - auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png"; - _maskMap = DependencyManager::get()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE); + } void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& editableItems) { @@ -29,11 +28,15 @@ void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& edi task.addJob("FadeEdit", fadeEditInput); } -render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() const { +render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() { return [this](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) { auto program = shapePipeline.pipeline->getProgram(); auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap"); auto bufferLocation = program->getUniformBuffers().findLocation("fadeParametersBuffer"); + if (!_maskMap) { + auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png"; + _maskMap = DependencyManager::get()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE); + } batch.setResourceTexture(maskMapLocation, _maskMap); batch.setUniformBuffer(bufferLocation, _configurations); }; diff --git a/libraries/render-utils/src/FadeEffect.h b/libraries/render-utils/src/FadeEffect.h index 4b4e401332..9827f67a7f 100644 --- a/libraries/render-utils/src/FadeEffect.h +++ b/libraries/render-utils/src/FadeEffect.h @@ -21,7 +21,7 @@ public: void build(render::Task::TaskConcept& task, const task::Varying& editableItems); - render::ShapePipeline::BatchSetter getBatchSetter() const; + render::ShapePipeline::BatchSetter getBatchSetter(); render::ShapePipeline::ItemSetter getItemUniformSetter() const; render::ShapePipeline::ItemSetter getItemStoredSetter(); From 553829f7ab94acbd08c5dc97d255b0bede8cd77d Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 27 Sep 2017 11:57:20 -0700 Subject: [PATCH 2/2] make sure FadeEffect dependency is created early --- interface/src/Application.cpp | 4 ++++ libraries/render-utils/src/FadeEffect.cpp | 9 +++------ libraries/render-utils/src/FadeEffect.h | 2 +- libraries/render-utils/src/RenderDeferredTask.cpp | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e1c3af1939..369e4848d1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -198,6 +198,8 @@ #include #include +#include + #include "commerce/Ledger.h" #include "commerce/Wallet.h" #include "commerce/QmlCommerce.h" @@ -682,6 +684,8 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); diff --git a/libraries/render-utils/src/FadeEffect.cpp b/libraries/render-utils/src/FadeEffect.cpp index 418d02a4e7..c94fe717f1 100644 --- a/libraries/render-utils/src/FadeEffect.cpp +++ b/libraries/render-utils/src/FadeEffect.cpp @@ -16,7 +16,8 @@ #include FadeEffect::FadeEffect() { - + auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png"; + _maskMap = DependencyManager::get()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE); } void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& editableItems) { @@ -28,15 +29,11 @@ void FadeEffect::build(render::Task::TaskConcept& task, const task::Varying& edi task.addJob("FadeEdit", fadeEditInput); } -render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() { +render::ShapePipeline::BatchSetter FadeEffect::getBatchSetter() const { return [this](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args*) { auto program = shapePipeline.pipeline->getProgram(); auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap"); auto bufferLocation = program->getUniformBuffers().findLocation("fadeParametersBuffer"); - if (!_maskMap) { - auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png"; - _maskMap = DependencyManager::get()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE); - } batch.setResourceTexture(maskMapLocation, _maskMap); batch.setUniformBuffer(bufferLocation, _configurations); }; diff --git a/libraries/render-utils/src/FadeEffect.h b/libraries/render-utils/src/FadeEffect.h index 9827f67a7f..4b4e401332 100644 --- a/libraries/render-utils/src/FadeEffect.h +++ b/libraries/render-utils/src/FadeEffect.h @@ -21,7 +21,7 @@ public: void build(render::Task::TaskConcept& task, const task::Varying& editableItems); - render::ShapePipeline::BatchSetter getBatchSetter(); + render::ShapePipeline::BatchSetter getBatchSetter() const; render::ShapePipeline::ItemSetter getItemUniformSetter() const; render::ShapePipeline::ItemSetter getItemStoredSetter(); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index c67a1c7875..85df1ee8de 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -49,8 +49,8 @@ using namespace render; extern void initOverlay3DPipelines(render::ShapePlumber& plumber, bool depthTest = false); extern void initDeferredPipelines(render::ShapePlumber& plumber, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); -RenderDeferredTask::RenderDeferredTask() { - DependencyManager::set(); +RenderDeferredTask::RenderDeferredTask() +{ } void RenderDeferredTask::configure(const Config& config)