From 872966f3205682ecc8c1e9353b64c04c59adf0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 30 Jun 2020 08:32:59 +0200 Subject: rhi: replace QVector by std::vector wherever possible Change-Id: I0020df0a0ce3b53e62dd9e4e5faad92583f9dbcc Reviewed-by: Mike Krus --- src/core/vector_helper_p.h | 14 + .../rhi/graphicshelpers/submissioncontext.cpp | 20 +- .../rhi/jobs/filtercompatibletechniquejob.cpp | 2 +- .../rhi/jobs/materialparametergathererjob_p.h | 6 +- .../renderers/rhi/jobs/renderviewjobutils.cpp | 14 +- .../renderers/rhi/jobs/renderviewjobutils_p.h | 8 +- .../renderers/rhi/renderer/commandexecuter.cpp | 4 +- .../renderers/rhi/renderer/commandexecuter_p.h | 6 +- .../renderers/rhi/renderer/rendercommand_p.h | 2 +- src/plugins/renderers/rhi/renderer/renderer.cpp | 287 ++++++++------------- src/plugins/renderers/rhi/renderer/renderer_p.h | 31 +-- src/plugins/renderers/rhi/renderer/renderqueue.cpp | 2 +- src/plugins/renderers/rhi/renderer/renderqueue_p.h | 6 +- src/plugins/renderers/rhi/renderer/renderview.cpp | 8 +- src/plugins/renderers/rhi/renderer/renderview_p.h | 14 +- src/plugins/renderers/rhi/renderer/rhishader.cpp | 96 +++---- src/plugins/renderers/rhi/renderer/rhishader_p.h | 100 +++---- .../renderers/rhi/renderer/shaderparameterpack_p.h | 2 +- src/plugins/renderers/rhi/textures/texture.cpp | 11 +- src/plugins/renderers/rhi/textures/texture_p.h | 14 +- 20 files changed, 299 insertions(+), 348 deletions(-) diff --git a/src/core/vector_helper_p.h b/src/core/vector_helper_p.h index 9274a11ca..77cfd9a52 100644 --- a/src/core/vector_helper_p.h +++ b/src/core/vector_helper_p.h @@ -54,6 +54,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -67,6 +68,19 @@ void moveAtEnd(std::vector& destination, std::vector&& source) std::make_move_iterator(source.end())); } +template +void append(std::vector& destination, const U& source) +{ + destination.insert(destination.end(), + source.cbegin(), + source.cend()); +} + +template +bool contains(const std::vector& destination, const U& element) noexcept +{ + return std::find(destination.begin(), destination.end(), element) != destination.end(); +} } // namespace Qt3DCore QT_END_NAMESPACE diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp index 50bfd02f0..3af1be523 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -967,7 +967,7 @@ void SubmissionContext::activateDrawBuffers(const AttachmentPack &attachments) { Q_UNUSED(attachments); RHI_UNIMPLEMENTED; - //* const QVector activeDrawBuffers = attachments.getGlDrawBuffers(); + //* const std::vector activeDrawBuffers = attachments.getGlDrawBuffers(); //* //* if (m_glHelper->checkFrameBufferComplete()) { //* if (activeDrawBuffers.size() > 1) {// We need MRT @@ -1167,18 +1167,18 @@ void SubmissionContext::applyStateSet(const RenderStateSet *ss, graphicsPipeline->setTargetBlends({blend}); - const QVector statesToSet = ss->states(); + const auto &statesToSet = ss->states(); for (const StateVariant &ds : statesToSet) applyState(ds, graphicsPipeline); } StateVariant *SubmissionContext::getState(RenderStateSet *ss, StateMask type) const { - const QVector &statesToSet = ss->states(); + const auto &statesToSet = ss->states(); for (int i = 0, m = statesToSet.size(); i < m; ++i) { const StateVariant &ds = statesToSet.at(i); if (ds.type == type) - return ss->states().begin() + i; + return ss->states().data() + i; } return nullptr; } @@ -1337,7 +1337,7 @@ bool SubmissionContext::setParameters(ShaderParameterPack ¶meterPack, RHISha // Update uniforms in the Default Uniform Block const PackUniformHash& values = parameterPack.uniforms(); const auto &activeUniformsIndices = parameterPack.submissionUniformIndices(); - const QVector &shaderUniforms = shader->uniforms(); + const std::vector &shaderUniforms = shader->uniforms(); for (const int shaderUniformIndex : activeUniformsIndices) { const ShaderUniform &uniform = shaderUniforms[shaderUniformIndex]; @@ -1428,7 +1428,7 @@ void SubmissionContext::uploadDataToRHIBuffer(Buffer *buffer, RHIBuffer *b, bool // Note: we are only storing the updates data CPU side at this point // actually upload will be performed when the buffer will be bound // as we would otherwise need to know the usage type of the buffer - QVector updates = std::move(buffer->pendingBufferUpdates()); + auto updates = std::move(buffer->pendingBufferUpdates()); for (auto it = updates.begin(); it != updates.end(); ++it) { auto update = it; // We have a partial update @@ -1583,7 +1583,7 @@ constexpr int getFirstAvailableBit(const std::bitset &bits) return -1; } // This function ensures that the shader stages all have the same bindings -void preprocessRHIShader(QVector &shaderCodes) +void preprocessRHIShader(std::vector &shaderCodes) { // Map the variable names to bindings std::map bindings; @@ -1750,11 +1750,13 @@ void SubmissionContext::loadShader(Shader *shaderNode, ShaderManager *shaderMana // We create or adopt an already created rhiShader rhiShader = rhiShaderManager->createOrAdoptExisting(shaderNode); - const QVector sharedShaderIds = + const std::vector &sharedShaderIds = rhiShaderManager->shaderIdsForProgram(rhiShader); if (sharedShaderIds.size() == 1) { // Shader in the cache hasn't been loaded yet - QVector shaderCodes = shaderNode->shaderCode(); + // We want a copy of the QByteArray as preprocessRHIShader will + // modify them + std::vector shaderCodes = shaderNode->shaderCode(); preprocessRHIShader(shaderCodes); rhiShader->setShaderCode(shaderCodes); diff --git a/src/plugins/renderers/rhi/jobs/filtercompatibletechniquejob.cpp b/src/plugins/renderers/rhi/jobs/filtercompatibletechniquejob.cpp index 657e5eea7..9c8a6dcbf 100644 --- a/src/plugins/renderers/rhi/jobs/filtercompatibletechniquejob.cpp +++ b/src/plugins/renderers/rhi/jobs/filtercompatibletechniquejob.cpp @@ -81,7 +81,7 @@ void FilterCompatibleTechniqueJob::run() Q_ASSERT(m_manager != nullptr && m_renderer != nullptr); Q_ASSERT(m_renderer->isRunning() && m_renderer->submissionContext()->isInitialized()); - const QVector dirtyTechniqueIds = m_manager->takeDirtyTechniques(); + const auto& dirtyTechniqueIds = m_manager->takeDirtyTechniques(); for (const Qt3DCore::QNodeId techniqueId : dirtyTechniqueIds) { Technique *technique = m_manager->lookupResource(techniqueId); if (Q_LIKELY(technique != nullptr)) diff --git a/src/plugins/renderers/rhi/jobs/materialparametergathererjob_p.h b/src/plugins/renderers/rhi/jobs/materialparametergathererjob_p.h index f635755d7..eb7f17a66 100644 --- a/src/plugins/renderers/rhi/jobs/materialparametergathererjob_p.h +++ b/src/plugins/renderers/rhi/jobs/materialparametergathererjob_p.h @@ -86,12 +86,12 @@ public: { m_renderPassFilter = renderPassFilter; } - inline const QHash> & + inline const QHash> & materialToPassAndParameter() Q_DECL_NOTHROW { return m_parameters; } - inline void setHandles(const QVector &handles) Q_DECL_NOTHROW + inline void setHandles(const std::vector &handles) Q_DECL_NOTHROW { m_handles = handles; } @@ -108,7 +108,7 @@ private: // Material id to array of RenderPasse with parameters MaterialParameterGathererData m_parameters; - QVector m_handles; + std::vector m_handles; }; typedef QSharedPointer MaterialParameterGathererJobPtr; diff --git a/src/plugins/renderers/rhi/jobs/renderviewjobutils.cpp b/src/plugins/renderers/rhi/jobs/renderviewjobutils.cpp index ee3fc3ca4..595811026 100644 --- a/src/plugins/renderers/rhi/jobs/renderviewjobutils.cpp +++ b/src/plugins/renderers/rhi/jobs/renderviewjobutils.cpp @@ -320,7 +320,7 @@ Technique *findTechniqueForEffect(NodeManagers *manager, const TechniqueFilter * if (!effect) return nullptr; - QVector matchingTechniques; + std::vector matchingTechniques; const bool hasInvalidTechniqueFilter = (techniqueFilter == nullptr || techniqueFilter->filters().isEmpty()); @@ -337,17 +337,17 @@ Technique *findTechniqueForEffect(NodeManagers *manager, const TechniqueFilter * if (technique->isCompatibleWithRenderer() && (hasInvalidTechniqueFilter || technique->isCompatibleWithFilters(techniqueFilter->filters()))) - matchingTechniques.append(technique); + matchingTechniques.push_back(technique); } if (matchingTechniques.size() == 0) // We failed to find a suitable technique to use :( return nullptr; if (matchingTechniques.size() == 1) - return matchingTechniques.first(); + return matchingTechniques.front(); // Several compatible techniques, return technique with highest major and minor version - Technique *highest = matchingTechniques.first(); + Technique *highest = matchingTechniques.front(); GraphicsApiFilterData filter = *highest->graphicsApiFilter(); for (auto it = matchingTechniques.cbegin() + 1; it < matchingTechniques.cend(); ++it) { if (filter < *(*it)->graphicsApiFilter()) { @@ -467,7 +467,7 @@ const int qNodeIdTypeId = qMetaTypeId(); } UniformBlockValueBuilder::UniformBlockValueBuilder( - const QVector &uniformNamesIds, + const std::vector &uniformNamesIds, ShaderDataManager *shaderDataManager, TextureManager *textureManager, const Matrix4x4 &matrix) @@ -505,7 +505,7 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper( } } } else { // Array of scalar/vec qmlPropertyName[0] - if (m_uniformNamesIds.contains(propertyInBlockNameId)) { + if (Qt3DCore::contains(m_uniformNamesIds, propertyInBlockNameId)) { activeUniformNamesToValue.insert(propertyInBlockNameId, value->value); } } @@ -520,7 +520,7 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper( activeUniformNamesToValue.insert(propertyInBlockNameId, value->value); } } else { // Scalar / Vec - if (m_uniformNamesIds.contains(propertyInBlockNameId)) { + if (Qt3DCore::contains(m_uniformNamesIds, propertyInBlockNameId)) { // If the property needs to be transformed, we transform it here as // the shaderdata cannot hold transformed properties for multiple // thread contexts at once diff --git a/src/plugins/renderers/rhi/jobs/renderviewjobutils_p.h b/src/plugins/renderers/rhi/jobs/renderviewjobutils_p.h index 54c079625..e61b76baf 100644 --- a/src/plugins/renderers/rhi/jobs/renderviewjobutils_p.h +++ b/src/plugins/renderers/rhi/jobs/renderviewjobutils_p.h @@ -122,7 +122,7 @@ struct ParameterInfo bool operator<(const int otherNameId) const Q_DECL_NOEXCEPT; bool operator<(const ParameterInfo &other) const Q_DECL_NOEXCEPT; }; -typedef QVector ParameterInfoList; +typedef std::vector ParameterInfoList; struct RenderPassParameterData { @@ -131,7 +131,7 @@ struct RenderPassParameterData }; QT3D_DECLARE_TYPEINFO_3(Qt3DRender, Render, Rhi, RenderPassParameterData, Q_MOVABLE_TYPE) -using MaterialParameterGathererData = QHash>; +using MaterialParameterGathererData = QHash>; Q_AUTOTEST_EXPORT void parametersFromMaterialEffectTechnique(ParameterInfoList *infoList, ParameterManager *manager, @@ -159,7 +159,7 @@ typedef QHash UniformBlockValueBuilderHash; struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder { - explicit UniformBlockValueBuilder(const QVector &uniformNamesIds, + explicit UniformBlockValueBuilder(const std::vector &uniformNamesIds, ShaderDataManager *shaderDataManager, TextureManager *textureManager, const Matrix4x4 &matrix); @@ -177,7 +177,7 @@ struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder UniformBlockValueBuilderHash activeUniformNamesToValue; private: - const QVector &m_uniformNamesIds; + const std::vector &m_uniformNamesIds; ShaderDataManager *m_shaderDataManager = nullptr; TextureManager *m_textureManager = nullptr; const Matrix4x4 &m_viewMatrix; diff --git a/src/plugins/renderers/rhi/renderer/commandexecuter.cpp b/src/plugins/renderers/rhi/renderer/commandexecuter.cpp index d4fdf3a6d..d29fae5de 100644 --- a/src/plugins/renderers/rhi/renderer/commandexecuter.cpp +++ b/src/plugins/renderers/rhi/renderer/commandexecuter.cpp @@ -301,12 +301,12 @@ CommandExecuter::CommandExecuter(Render::Rhi::Renderer *renderer) : m_renderer(r // Render thread void CommandExecuter::performAsynchronousCommandExecution( - const QVector &views) + const std::vector &views) { Q_UNUSED(views); RHI_UNIMPLEMENTED; //* QMutexLocker lock(&m_pendingCommandsMutex); - //* const QVector shellCommands = + //* const std::vector shellCommands = //std::move(m_pendingCommands); //* lock.unlock(); //* diff --git a/src/plugins/renderers/rhi/renderer/commandexecuter_p.h b/src/plugins/renderers/rhi/renderer/commandexecuter_p.h index 924930a49..74f83c082 100644 --- a/src/plugins/renderers/rhi/renderer/commandexecuter_p.h +++ b/src/plugins/renderers/rhi/renderer/commandexecuter_p.h @@ -49,7 +49,7 @@ // We mean it. // -#include +#include #include #include @@ -79,13 +79,13 @@ class CommandExecuter public: explicit CommandExecuter(Render::Rhi::Renderer *renderer); - void performAsynchronousCommandExecution(const QVector &views); + void performAsynchronousCommandExecution(const std::vector &views); QVariant executeCommand(const QStringList &args); private: Render::Rhi::Renderer *m_renderer; - QVector m_pendingCommands; + std::vector m_pendingCommands; QMutex m_pendingCommandsMutex; }; diff --git a/src/plugins/renderers/rhi/renderer/rendercommand_p.h b/src/plugins/renderers/rhi/renderer/rendercommand_p.h index 421ea2b8d..704e79c32 100644 --- a/src/plugins/renderers/rhi/renderer/rendercommand_p.h +++ b/src/plugins/renderers/rhi/renderer/rendercommand_p.h @@ -128,7 +128,7 @@ public: // A QAttribute pack might be interesting // This is a temporary fix in the meantime, to remove the hacked methods in Technique - QVector m_activeAttributes; + std::vector m_activeAttributes; float m_depth; int m_changeCost; diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index b99ae427f..f05164671 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -202,7 +202,7 @@ private: int locationForAttribute(Attribute *attr, RHIShader *shader) noexcept { - const QVector attribInfo = shader->attributes(); + const std::vector &attribInfo = shader->attributes(); const auto it = std::find_if( attribInfo.begin(), attribInfo.end(), [attr](const ShaderAttribute &sAttr) { return attr->nameId() == sAttr.m_nameId; }); @@ -389,7 +389,7 @@ QOpenGLContext *Renderer::shareContext() const void Renderer::loadShader(Shader *shader, HShader shaderHandle) { Q_UNUSED(shader); - if (!m_dirtyShaders.contains(shaderHandle)) + if (!Qt3DCore::contains(m_dirtyShaders, shaderHandle)) m_dirtyShaders.push_back(shaderHandle); } @@ -554,7 +554,7 @@ void Renderer::releaseGraphicsResources() //{ //* //* // Clean up the graphics context and any resources - //* const QVector activeTexturesHandles = + //* const std::vector activeTexturesHandles = //m_RHIResourceManagers->rhiTextureManager()->activeHandles(); //* for (const HRHITexture &textureHandle : activeTexturesHandles) { //* RHITexture *tex = m_RHIResourceManagers->rhiTextureManager()->data(textureHandle); @@ -562,7 +562,7 @@ void Renderer::releaseGraphicsResources() //* } //* //* // Do the same thing with buffers - //* const QVector activeBuffers = + //* const std::vector activeBuffers = //m_RHIResourceManagers->rhiBufferManager()->activeHandles(); //* for (const HRHIBuffer &bufferHandle : activeBuffers) { //* RHIBuffer *buffer = m_RHIResourceManagers->rhiBufferManager()->data(bufferHandle); @@ -570,7 +570,7 @@ void Renderer::releaseGraphicsResources() //* } //* //* // Do the same thing with shaders - //* const QVector shaders = + //* const std::vector shaders = //m_RHIResourceManagers->rhiShaderManager()->takeActiveResources(); //* qDeleteAll(shaders); //* @@ -638,60 +638,29 @@ RenderSettings *Renderer::settings() const return m_settings; } -void Renderer::render() -{ - // Traversing the framegraph tree from root to lead node - // Allows us to define the rendering set up - // Camera, RenderTarget ... - - // Utimately the renderer should be a framework - // For the processing of the list of renderviews - - // Matrice update, bounding volumes computation ... - // Should be jobs - - // namespace Qt3DCore has 2 distincts node trees - // One scene description - // One framegraph description - - while (m_running.loadRelaxed() > 0) { - doRender(); - // TO DO: Restore windows exposed detection - // Probably needs to happens some place else though - } -} - -// Either called by render if Qt3D is in charge of the RenderThread -// or by QRenderAspectPrivate::renderSynchronous (for Scene3D) -void Renderer::doRender(bool swapBuffers) +// Either called by render if Qt3D is in charge of rendering (in the mainthread) +// or by QRenderAspectPrivate::render (for Scene3D, potentially from a RenderThread) +// This will wait until renderQueue is ready or shutdown was requested +void Renderer::render(bool swapBuffers) { Renderer::ViewSubmissionResultData submissionData; - bool hasCleanedQueueAndProceeded = false; - bool preprocessingComplete = false; bool beganDrawing = false; // Blocking until RenderQueue is full - const bool canSubmit = isReadyToSubmit(); - m_shouldSwapBuffers = swapBuffers; + const bool canSubmit = waitUntilReadyToSubmit(); - // Lock the mutex to protect access to the renderQueue while we look for its state - QMutexLocker locker(m_renderQueue->mutex()); - const bool queueIsComplete = m_renderQueue->isFrameQueueComplete(); + // If it returns false -> we are shutting down + if (!canSubmit) + return; + + m_shouldSwapBuffers = swapBuffers; + const std::vector &renderViews = m_renderQueue->nextFrameQueue(); const bool queueIsEmpty = m_renderQueue->targetRenderViewCount() == 0; bool mustCleanResources = false; - // When using synchronous rendering (QtQuick) - // We are not sure that the frame queue is actually complete - // Since a call to render may not be synched with the completions - // of the RenderViewJobs - // In such a case we return early, waiting for a next call with - // the frame queue complete at this point - // RenderQueue is complete (but that means it may be of size 0) - if (canSubmit && (queueIsComplete && !queueIsEmpty)) { - const QVector renderViews = m_renderQueue->nextFrameQueue(); - + if (!queueIsEmpty) { QTaskLogger submissionStatsPart1(m_services->systemInformation(), { JobTypes::FrameSubmissionPart1, 0 }, QTaskLogger::Submission); @@ -699,77 +668,69 @@ void Renderer::doRender(bool swapBuffers) { JobTypes::FrameSubmissionPart2, 0 }, QTaskLogger::Submission); - QVector rhiPassesInfo; + std::vector rhiPassesInfo; - if (canRender()) { - QSurface *surface = nullptr; - for (const RenderView *rv : renderViews) { - surface = rv->surface(); - if (surface) - break; - } + QSurface *surface = nullptr; + for (const RenderView *rv : renderViews) { + surface = rv->surface(); + if (surface) + break; + } - // In case we did not draw because e.g. there wase no swapchain, - // we keep the resource updates from the previous frame. - if (!m_submissionContext->m_currentUpdates) { - m_submissionContext->m_currentUpdates = - m_submissionContext->rhi()->nextResourceUpdateBatch(); - } + // In case we did not draw because e.g. there wase no swapchain, + // we keep the resource updates from the previous frame. + if (!m_submissionContext->m_currentUpdates) { + m_submissionContext->m_currentUpdates = + m_submissionContext->rhi()->nextResourceUpdateBatch(); + } - // 1) Execute commands for buffer uploads, texture updates, shader loading first - updateResources(); + // 1) Execute commands for buffer uploads, texture updates, shader loading first + updateResources(); - rhiPassesInfo = prepareCommandsSubmission(renderViews); - // 2) Update Pipelines and copy data into commands to allow concurrent submission - preprocessingComplete = true; + rhiPassesInfo = prepareCommandsSubmission(renderViews); + // 2) Update Pipelines and copy data into commands to allow concurrent submission - bool hasCommands = false; - for (const RenderView *rv : renderViews) { - // TODO find a way to break earlier with this pattern. - rv->forEachCommand([&] (const RenderCommand &cmd) { - hasCommands |= cmd.isValid(); - }); - if (hasCommands) - break; - } + bool hasCommands = false; + for (const RenderView *rv : renderViews) { + // TODO find a way to break earlier with this pattern. + rv->forEachCommand([&] (const RenderCommand &cmd) { + hasCommands |= cmd.isValid(); + }); + if (hasCommands) + break; + } - if (hasCommands) { - // Scoped to destroy surfaceLock - SurfaceLocker surfaceLock(surface); - const bool surfaceIsValid = (surface && surfaceLock.isSurfaceValid()); - if (surfaceIsValid) { - beganDrawing = m_submissionContext->beginDrawing(surface); - if (beganDrawing) { - // Purge shader which aren't used any longer - static int callCount = 0; - ++callCount; - const int shaderPurgePeriod = 600; - if (callCount % shaderPurgePeriod == 0) - m_RHIResourceManagers->rhiShaderManager()->purge(); - } + if (hasCommands) { + // Scoped to destroy surfaceLock + SurfaceLocker surfaceLock(surface); + const bool surfaceIsValid = (surface && surfaceLock.isSurfaceValid()); + if (surfaceIsValid) { + beganDrawing = m_submissionContext->beginDrawing(surface); + if (beganDrawing) { + // Purge shader which aren't used any longer + static int callCount = 0; + ++callCount; + const int shaderPurgePeriod = 600; + if (callCount % shaderPurgePeriod == 0) + m_RHIResourceManagers->rhiShaderManager()->purge(); } } - // 2) Proceed to next frame and start preparing frame n + 1 - m_renderQueue->reset(); - locker.unlock(); // Done protecting RenderQueue - m_vsyncFrameAdvanceService->proceedToNextFrame(); - hasCleanedQueueAndProceeded = true; - - // Only try to submit the RenderViews if the preprocessing was successful - // This part of the submission is happening in parallel to the RV building for the next - // frame - if (beganDrawing) { - submissionStatsPart1.end(submissionStatsPart2.restart()); - - // 3) Submit the render commands for frame n (making sure we never reference - // something that could be changing) Render using current device state and renderer - // configuration - submissionData = submitRenderViews(rhiPassesInfo); - - // Perform any required cleanup of the Graphics resources (Buffers deleted, Shader - // deleted...) - mustCleanResources = true; - } + } + + // Only try to submit the RenderViews if the preprocessing was successful + // This part of the submission is happening in parallel to the RV building for the next + // frame + if (beganDrawing) { + submissionStatsPart1.end(submissionStatsPart2.restart()); + + // 3) Submit the render commands for frame n (making sure we never reference + // something that could be changing) Render using current device state and renderer + // configuration + submissionData = submitRenderViews(rhiPassesInfo); + + // Perform any required cleanup of the Graphics resources (Buffers deleted, Shader + // deleted...) + mustCleanResources = true; } // Execute the pending shell commands @@ -777,27 +738,6 @@ void Renderer::doRender(bool swapBuffers) // Delete all the RenderViews which will clear the allocators // that were used for their allocation - qDeleteAll(renderViews); - } - - // If hasCleanedQueueAndProceeded isn't true this implies that something went wrong - // with the rendering and/or the renderqueue is incomplete from some reason - // or alternatively it could be complete but empty (RenderQueue of size 0) - - if (!hasCleanedQueueAndProceeded) { - // RenderQueue was full but something bad happened when - // trying to render it and therefore proceedToNextFrame was not called - // Note: in this case the renderQueue mutex is still locked - - // Reset the m_renderQueue so that we won't try to render - // with a queue used by a previous frame with corrupted content - // if the current queue was correctly submitted - m_renderQueue->reset(); - - // We allow the RenderTickClock service to proceed to the next frame - // In turn this will allow the aspect manager to request a new set of jobs - // to be performed for each aspect - m_vsyncFrameAdvanceService->proceedToNextFrame(); } // Perform the last swapBuffers calls after the proceedToNextFrame @@ -816,6 +756,15 @@ void Renderer::doRender(bool swapBuffers) if (mustCleanResources) cleanGraphicsResources(); } + + // Reset RenderQueue and destroy the renderViews + m_renderQueue->reset(); + qDeleteAll(renderViews); + + // We allow the RenderTickClock service to proceed to the next frame + // In turn this will allow the aspect manager to request a new set of jobs + // to be performed for each aspect + m_vsyncFrameAdvanceService->proceedToNextFrame(); } // Called by RenderViewJobs @@ -825,7 +774,7 @@ void Renderer::enqueueRenderView(RenderView *renderView, int submitOrder) { QMutexLocker locker(m_renderQueue->mutex()); // Prevent out of order execution // We cannot use a lock free primitive here because: - // - QVector is not thread safe + // - std::vector is not thread safe // - Even if the insert is made correctly, the isFrameComplete call // could be invalid since depending on the order of execution // the counter could be complete but the renderview not yet added to the @@ -837,17 +786,7 @@ void Renderer::enqueueRenderView(RenderView *renderView, int submitOrder) } } -bool Renderer::canRender() const -{ - - // TO DO: Check if all surfaces have been destroyed... - // It may be better if the last window to be closed trigger a call to shutdown - // Rather than having checks for the surface everywhere - - return true; -} - -bool Renderer::isReadyToSubmit() +bool Renderer::waitUntilReadyToSubmit() { // Make sure that we've been told to render before rendering // Prevent ouf of order execution @@ -1008,20 +947,22 @@ void Renderer::updateGraphicsPipeline(RenderCommand &cmd, RenderView *rv, int re return onFailure(); } - QVector uboBindings; - uboBindings << QRhiShaderResourceBinding::uniformBuffer( - 0, - QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, - rvUBO) - << QRhiShaderResourceBinding::uniformBuffer( - 1, - QRhiShaderResourceBinding::VertexStage - | QRhiShaderResourceBinding::FragmentStage, - commandUBO); + std::vector uboBindings; + uboBindings.push_back( + QRhiShaderResourceBinding::uniformBuffer( + 0, + QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, + rvUBO)); + + uboBindings.push_back( + QRhiShaderResourceBinding::uniformBuffer( + 1, + QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, + commandUBO)); // Create additional empty UBO Buffer for UBO with binding point > 1 (since we assume 0 and // 1 and for Qt3D standard values) - const QVector uniformBlocks = cmd.m_rhiShader->uniformBlocks(); + const std::vector &uniformBlocks = cmd.m_rhiShader->uniformBlocks(); QHash uboBuffers; for (const ShaderUniformBlock &block : uniformBlocks) { if (block.m_binding > 1) { @@ -1032,11 +973,11 @@ void Renderer::updateGraphicsPipeline(RenderCommand &cmd, RenderView *rv, int re ubo->allocate(m_submissionContext.data(), rawData, true); ok = ubo->bind(m_submissionContext.data(), RHIBuffer::UniformBuffer); uboBuffers[block.m_binding] = { handle, ubo }; - uboBindings << QRhiShaderResourceBinding::uniformBuffer( + uboBindings.push_back(QRhiShaderResourceBinding::uniformBuffer( block.m_binding, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, - ubo->rhiBuffer()); + ubo->rhiBuffer())); } } graphicsPipeline->setUBOs(uboBuffers); @@ -1101,7 +1042,7 @@ void Renderer::updateGraphicsPipeline(RenderCommand &cmd, RenderView *rv, int re QRhiVertexInputBinding::Classification classification; uint attributeDivisor; }; - QVector uniqueBindings; + std::vector uniqueBindings; // QRhiVertexInputBinding -> specifies the stride of an attribute, whether it's per vertex @@ -1355,8 +1296,8 @@ bool Renderer::setupRenderTarget(RenderView *rv, RHIGraphicsPipeline *graphicsPi } } // When this function is called, we must not be processing the commands for frame n+1 -QVector -Renderer::prepareCommandsSubmission(const QVector &renderViews) +std::vector +Renderer::prepareCommandsSubmission(const std::vector &renderViews) { // TO DO: Find a central place to initialize RHI resources const int renderViewCount = renderViews.size(); @@ -1365,11 +1306,11 @@ Renderer::prepareCommandsSubmission(const QVector &renderViews) // as creating the pass clears the buffers // 1) We need to find all adjacents RenderViews that have the same renderTarget // and submit all of these as part of the same RHI pass - QVector rhiPassesInfo; + std::vector rhiPassesInfo; for (int i = 0; i < renderViewCount;) { - QVector sameRenderTargetRVs; - QVector rvUbos; + std::vector sameRenderTargetRVs; + std::vector rvUbos; RenderView *refRV = renderViews.at(i); sameRenderTargetRVs.push_back(refRV); @@ -1605,7 +1546,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) // Executed in a job (in main thread when jobs are done) void Renderer::sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager) { - const QVector> + const std::vector> updateTextureProperties = std::move(m_updatedTextureProperties); for (const auto &pair : updateTextureProperties) { const Qt3DCore::QNodeIdVector targetIds = pair.second; @@ -1678,7 +1619,7 @@ void Renderer::sendDisablesToFrontend(Qt3DCore::QAspectManager *manager) void Renderer::updateResources() { { - const QVector dirtyBufferHandles = std::move(m_dirtyBuffers); + const std::vector dirtyBufferHandles = std::move(m_dirtyBuffers); for (const HBuffer &handle : dirtyBufferHandles) { Buffer *buffer = m_nodesManager->bufferManager()->data(handle); @@ -1698,7 +1639,7 @@ void Renderer::updateResources() #ifndef SHADER_LOADING_IN_COMMAND_THREAD { - const QVector dirtyShaderHandles = std::move(m_dirtyShaders); + const std::vector dirtyShaderHandles = std::move(m_dirtyShaders); ShaderManager *shaderManager = m_nodesManager->shaderManager(); for (const HShader &handle : dirtyShaderHandles) { Shader *shader = shaderManager->data(handle); @@ -1715,7 +1656,7 @@ void Renderer::updateResources() #endif { - const QVector activeTextureHandles = std::move(m_dirtyTextures); + const std::vector activeTextureHandles = std::move(m_dirtyTextures); for (const HTexture &handle : activeTextureHandles) { Texture *texture = m_nodesManager->textureManager()->data(handle); @@ -1807,7 +1748,7 @@ void Renderer::updateTexture(Texture *texture) // Will make the texture requestUpload if (dirtyFlags.testFlag(Texture::DirtyImageGenerators)) { const QNodeIdVector textureImageIds = texture->textureImageIds(); - QVector images; + std::vector images; images.reserve(textureImageIds.size()); // TODO: Move this into RHITexture directly for (const QNodeId textureImageId : textureImageIds) { @@ -1869,7 +1810,7 @@ void Renderer::cleanupRenderTarget(const RenderTarget *renderTarget) // Called by SubmitRenderView void Renderer::downloadGLBuffers() { - const QVector downloadableHandles = std::move(m_downloadableBuffers); + const std::vector downloadableHandles = std::move(m_downloadableBuffers); for (const Qt3DCore::QNodeId &bufferId : downloadableHandles) { BufferManager *bufferManager = m_nodesManager->bufferManager(); BufferManager::ReadLocker locker(const_cast(bufferManager)); @@ -1887,7 +1828,7 @@ void Renderer::downloadGLBuffers() // Happens in RenderThread context when all RenderViewJobs are done // Returns the id of the last bound FBO Renderer::ViewSubmissionResultData -Renderer::submitRenderViews(const QVector &rhiPassesInfo) +Renderer::submitRenderViews(const std::vector &rhiPassesInfo) { QElapsedTimer timer; quint64 queueElapsed = 0; @@ -2091,7 +2032,7 @@ void Renderer::jobsDone(Qt3DCore::QAspectManager *manager) // called in main thread once all jobs are done running // sync captured renders to frontend - const QVector pendingCaptureIds = + const std::vector pendingCaptureIds = std::move(m_pendingRenderCaptureSendRequests); for (const Qt3DCore::QNodeId &id : qAsConst(pendingCaptureIds)) { auto *backend = static_cast( @@ -2498,7 +2439,7 @@ bool Renderer::uploadUBOsForCommand(QRhiCommandBuffer *cb, const RenderView *rv, if (!shader) return true; - const QVector &uboMembers = shader->uboMembers(); + const std::vector &uboMembers = shader->uboMembers(); const QHash &uboBuffers = pipeline->ubos(); const ShaderParameterPack ¶meterPack = command.m_parameterPack; const PackUniformHash &uniforms = parameterPack.uniforms(); @@ -2574,7 +2515,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) { bool allCommandsIssued = true; - const QVector &renderViews = passInfo.rvs; + const std::vector &renderViews = passInfo.rvs; QColor clearColor; QRhiDepthStencilClearValue clearDepthStencil; diff --git a/src/plugins/renderers/rhi/renderer/renderer_p.h b/src/plugins/renderers/rhi/renderer/renderer_p.h index d810e0edd..8a0046d93 100644 --- a/src/plugins/renderers/rhi/renderer/renderer_p.h +++ b/src/plugins/renderers/rhi/renderer/renderer_p.h @@ -185,8 +185,7 @@ public: void shutdown() override; void releaseGraphicsResources() override; - void render() override; - void doRender(bool swapBuffers = true) override; + void render(bool swapBuffers = true) override; void cleanGraphicsResources() override; bool isRunning() const override { return m_running.loadRelaxed(); } @@ -257,13 +256,13 @@ public: struct RHIPassInfo { - QVector rvs; + std::vector rvs; QSurface *surface = nullptr; Qt3DCore::QNodeId renderTargetId; AttachmentPack attachmentPack; }; - QVector prepareCommandsSubmission(const QVector &renderViews); + std::vector prepareCommandsSubmission(const std::vector &renderViews); bool executeCommandsSubmission(const RHIPassInfo &passInfo); // For Scene2D rendering @@ -281,7 +280,7 @@ public: QList pendingKeyEvents() const; void enqueueRenderView(RenderView *renderView, int submitOrder); - bool isReadyToSubmit(); + bool waitUntilReadyToSubmit(); QVariant executeCommand(const QStringList &args) override; void setOffscreenSurfaceHelper(OffscreenSurfaceHelper *helper) override; @@ -294,7 +293,7 @@ public: QSurface *surface; }; - ViewSubmissionResultData submitRenderViews(const QVector &rhiPassesInfo); + ViewSubmissionResultData submitRenderViews(const std::vector &rhiPassesInfo); RendererCache *cache() { return &m_cache; } void setScreen(QScreen *scr) override; @@ -308,8 +307,6 @@ public: private: #endif - bool canRender() const; - Qt3DCore::QServiceLocator *m_services; QRenderAspect *m_aspect; NodeManagers *m_nodesManager; @@ -335,8 +332,8 @@ private: QAtomicInt m_running; - QVector m_dirtyAttributes; - QVector m_dirtyGeometry; + std::vector m_dirtyAttributes; + std::vector m_dirtyGeometry; QAtomicInt m_exposed; struct DirtyBits @@ -361,7 +358,7 @@ private: RenderableEntityFilterPtr m_renderableEntityFilterJob; ComputableEntityFilterPtr m_computableEntityFilterJob; - QVector m_pendingRenderCaptureSendRequests; + std::vector m_pendingRenderCaptureSendRequests; void performDraw(RenderCommand *command); void performCompute(const RenderView *rv, RenderCommand *command); @@ -379,12 +376,12 @@ private: void sendSetFenceHandlesToFrontend(); void sendDisablesToFrontend(Qt3DCore::QAspectManager *manager); - QVector m_dirtyBuffers; - QVector m_downloadableBuffers; - QVector m_dirtyShaders; - QVector m_dirtyTextures; - QVector> m_updatedTextureProperties; - QVector m_updatedDisableSubtreeEnablers; + std::vector m_dirtyBuffers; + std::vector m_downloadableBuffers; + std::vector m_dirtyShaders; + std::vector m_dirtyTextures; + std::vector> m_updatedTextureProperties; + std::vector m_updatedDisableSubtreeEnablers; Qt3DCore::QNodeIdVector m_textureIdsToCleanup; std::vector m_shaderBuilderUpdates; diff --git a/src/plugins/renderers/rhi/renderer/renderqueue.cpp b/src/plugins/renderers/rhi/renderer/renderqueue.cpp index 39eaddc9a..463e4cad8 100644 --- a/src/plugins/renderers/rhi/renderer/renderqueue.cpp +++ b/src/plugins/renderers/rhi/renderer/renderqueue.cpp @@ -101,7 +101,7 @@ bool RenderQueue::queueRenderView(RenderView *renderView, uint submissionOrderIn * A call to reset is required after rendering of the frame. Otherwise under some * conditions the current but then invalidated frame queue could be reused. */ -QVector RenderQueue::nextFrameQueue() +const std::vector &RenderQueue::nextFrameQueue() { return m_currentWorkQueue; } diff --git a/src/plugins/renderers/rhi/renderer/renderqueue_p.h b/src/plugins/renderers/rhi/renderer/renderqueue_p.h index 3b6eec13d..515c1ce3e 100644 --- a/src/plugins/renderers/rhi/renderer/renderqueue_p.h +++ b/src/plugins/renderers/rhi/renderer/renderqueue_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include +#include #include #include @@ -76,7 +76,7 @@ public: bool isFrameQueueComplete() const; bool queueRenderView(RenderView *renderView, uint submissionOrderIndex); - QVector nextFrameQueue(); + const std::vector &nextFrameQueue(); void reset(); void setNoRender(); @@ -91,7 +91,7 @@ private: bool m_wasReset; int m_targetRenderViewCount; int m_currentRenderViewCount; - QVector m_currentWorkQueue; + std::vector m_currentWorkQueue; QMutex m_mutex; }; diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp index 12f8d01a5..bab5fecfb 100644 --- a/src/plugins/renderers/rhi/renderer/renderview.cpp +++ b/src/plugins/renderers/rhi/renderer/renderview.cpp @@ -408,7 +408,7 @@ void sortByMaterial(EntityRenderCommandDataView *view, int begin, const int end) } void sortCommandRange(EntityRenderCommandDataView *view, int begin, int end, const int level, - const QVector &sortingTypes) + const std::vector &sortingTypes) { if (level >= sortingTypes.size()) return; @@ -461,7 +461,7 @@ void RenderView::sort() // We compute the adjacent change cost // Only perform uniform minimization if we explicitly asked for it - if (!m_sortingTypes.contains(QSortPolicy::Uniform)) + if (!Qt3DCore::contains(m_sortingTypes, QSortPolicy::Uniform)) return; // Minimize uniform changes @@ -584,7 +584,7 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit const Qt3DCore::QNodeId materialComponentId = entity->componentUuid(); const HMaterial materialHandle = entity->componentHandle(); - const QVector renderPassData = + const std::vector renderPassData = m_parameters.value(materialComponentId); HGeometry geometryHandle = @@ -729,7 +729,7 @@ EntityRenderCommandData RenderView::buildComputeRenderCommands(const Entity **en && computeJob->isEnabled()) { const Qt3DCore::QNodeId materialComponentId = entity->componentUuid(); - const QVector &renderPassData = + const std::vector &renderPassData = m_parameters.value(materialComponentId); // 1 RenderCommand per RenderPass pass on an Entity with a Mesh diff --git a/src/plugins/renderers/rhi/renderer/renderview_p.h b/src/plugins/renderers/rhi/renderer/renderview_p.h index 172c330a4..9cdca9a3d 100644 --- a/src/plugins/renderers/rhi/renderer/renderview_p.h +++ b/src/plugins/renderers/rhi/renderer/renderview_p.h @@ -73,7 +73,7 @@ // TODO: Move out once this is all refactored #include -#include +#include #include #include #include @@ -185,10 +185,6 @@ public: inline void appendProximityFilterId(const Qt3DCore::QNodeId proximityFilterId) { m_proximityFilterIds.push_back(proximityFilterId); } inline Qt3DCore::QNodeIdVector proximityFilterIds() const { return m_proximityFilterIds; } - inline void appendInsertFenceId(const Qt3DCore::QNodeId setFenceId) { m_insertFenceIds.push_back(setFenceId); } - // We prefix with get to avoid confusion when it is called - inline Qt3DCore::QNodeIdVector insertFenceIds() const { return m_insertFenceIds; } - inline void setRenderPassFilter(const RenderPassFilter *rpFilter) Q_DECL_NOTHROW { m_passFilter = rpFilter; } inline const RenderPassFilter *renderPassFilter() const Q_DECL_NOTHROW { return m_passFilter; } @@ -252,7 +248,7 @@ public: void setRenderTargetId(Qt3DCore::QNodeId renderTargetId) Q_DECL_NOTHROW { m_renderTarget = renderTargetId; } Qt3DCore::QNodeId renderTargetId() const Q_DECL_NOTHROW { return m_renderTarget; } - void addSortType(const QVector &sortTypes) { m_sortingTypes.append(sortTypes); } + void addSortType(const QVector &sortTypes) { Qt3DCore::append(m_sortingTypes, sortTypes); } void setSurface(QSurface *surface) { m_surface = surface; } QSurface *surface() const { return m_surface; } @@ -267,8 +263,6 @@ public: inline void setRenderCaptureRequest(const QRenderCaptureRequest& request) Q_DECL_NOTHROW { m_renderCaptureRequest = request; } inline const QRenderCaptureRequest renderCaptureRequest() const Q_DECL_NOTHROW { return m_renderCaptureRequest; } - void setMemoryBarrier(QMemoryBarrier::Operations barrier) Q_DECL_NOTHROW { m_memoryBarrier = barrier; } - QMemoryBarrier::Operations memoryBarrier() const Q_DECL_NOTHROW { return m_memoryBarrier; } bool isDownloadBuffersEnable() const; void setIsDownloadBuffersEnable(bool isDownloadBuffersEnable); @@ -341,9 +335,7 @@ private: bool m_frustumCulling = false; bool m_showDebugOverlay = false; int m_workGroups[3] = { 1, 1, 1}; - QMemoryBarrier::Operations m_memoryBarrier = QMemoryBarrier::None; - QVector m_insertFenceIds; - QVector m_sortingTypes; + std::vector m_sortingTypes; Qt3DCore::QNodeIdVector m_proximityFilterIds; Qt3DCore::QNodeIdVector m_layerFilterIds; Matrix4x4 m_viewMatrix; diff --git a/src/plugins/renderers/rhi/renderer/rhishader.cpp b/src/plugins/renderers/rhi/renderer/rhishader.cpp index acc16bba3..268d2fa75 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader.cpp +++ b/src/plugins/renderers/rhi/renderer/rhishader.cpp @@ -39,6 +39,7 @@ #include "rhishader_p.h" #include +#include #include #include #include @@ -57,37 +58,37 @@ RHIShader::RHIShader() : m_isLoaded(false) m_shaderCode.resize(static_cast(QShaderProgram::Compute) + 1); } -QVector RHIShader::uniformsNames() const +const std::vector &RHIShader::uniformsNames() const { return m_uniformsNames; } -QVector RHIShader::attributesNames() const +const std::vector &RHIShader::attributesNames() const { return m_attributesNames; } -QVector RHIShader::uniformBlockNames() const +const std::vector &RHIShader::uniformBlockNames() const { return m_uniformBlockNames; } -QVector RHIShader::storageBlockNames() const +const std::vector &RHIShader::storageBlockNames() const { return m_shaderStorageBlockNames; } -QVector RHIShader::samplerNames() const +const std::vector &RHIShader::samplerNames() const { return m_samplerNames; } -QVector RHIShader::imagesNames() const +const std::vector &RHIShader::imagesNames() const { return m_imageNames; } -QVector RHIShader::shaderCode() const +const std::vector &RHIShader::shaderCode() const { return m_shaderCode; } @@ -258,9 +259,9 @@ static constexpr int rhiTypeSize(QShaderDescription::VariableType type) } template -QVector stableRemoveDuplicates(QVector in, Pred predicate) +std::vector stableRemoveDuplicates(std::vector in, Pred predicate) { - QVector out; + std::vector out; for (const auto &element : in) { if (std::none_of(out.begin(), out.end(), [&](T &other) { return predicate(element, other); })) @@ -335,8 +336,8 @@ void RHIShader::recordAllUniforms(const QShaderDescription::BlockVariable &membe m_unqualifiedUniformNames << fullMemberName; if (isStruct && !isArray) { - m_structNames << fullMemberName; - m_structNamesIds << StringToInt::lookupId(fullMemberName); + m_structNames.push_back(fullMemberName); + m_structNamesIds.push_back(StringToInt::lookupId(fullMemberName)); for (const QShaderDescription::BlockVariable& bv : member.structMembers) { // recordAllUniforms("baz", "foo.bar.") @@ -354,8 +355,8 @@ void RHIShader::recordAllUniforms(const QShaderDescription::BlockVariable &membe else if (isStruct && isArray) { // Record the struct names forEachArrayAccessor(member.arrayDims, [&] (const QString& str) { - m_structNames << (fullMemberName + str); - m_structNamesIds << StringToInt::lookupId(m_structNames.back()); + m_structNames.push_back(fullMemberName + str); + m_structNamesIds.push_back(StringToInt::lookupId(m_structNames.back())); }); // Record the struct members @@ -387,14 +388,14 @@ bool isGeneratedUBOName(const QByteArray& arr) void RHIShader::introspect() { - QVector rhiUBO; - QVector rhiSSBO; + std::vector rhiUBO; + std::vector rhiSSBO; - QVector uniformBlocks; - QVector storageBlocks; - QVector attributes; - QVector samplers; - QVector images; + std::vector uniformBlocks; + std::vector storageBlocks; + std::vector attributes; + std::vector samplers; + std::vector images; // Introspect shader vertex input if (m_stages[QShader::VertexStage].isValid()) { @@ -406,8 +407,8 @@ void RHIShader::introspect() input.location }); } - rhiUBO += vtx.uniformBlocks(); - rhiSSBO += vtx.storageBlocks(); + Qt3DCore::append(rhiUBO, vtx.uniformBlocks()); + Qt3DCore::append(rhiSSBO, vtx.storageBlocks()); } // Introspect shader uniforms @@ -425,8 +426,8 @@ void RHIShader::introspect() image.binding }); } - rhiUBO += frag.uniformBlocks(); - rhiSSBO += frag.storageBlocks(); + Qt3DCore::append(rhiUBO, frag.uniformBlocks()); + Qt3DCore::append(rhiSSBO, frag.storageBlocks()); } rhiUBO = stableRemoveDuplicates(rhiUBO, @@ -448,19 +449,15 @@ void RHIShader::introspect() // Parse Uniform Block members so that we can later on map a Parameter name to an actual // member - const QVector members = ubo.members; + m_uniformsNamesIds.reserve(m_uniformsNamesIds.size() + ubo.members.size()); - QVector namesIds; - namesIds.reserve(members.size()); - - for (const QShaderDescription::BlockVariable &member : members) { - namesIds << StringToInt::lookupId(member.name); + for (const QShaderDescription::BlockVariable &member : qAsConst(ubo.members)) { + m_uniformsNamesIds.push_back(StringToInt::lookupId(member.name)); if (addUnqualifiedUniforms) { recordAllUniforms(member, QStringLiteral("")); } } - m_uniformsNamesIds += namesIds; - m_uboMembers.push_back({ uniformBlocks.last(), members }); + m_uboMembers.push_back(UBO_Member{ uniformBlocks.back(), ubo.members }); } for (const QShaderDescription::StorageBlock &ssbo : rhiSSBO) { @@ -538,20 +535,20 @@ ShaderStorageBlock RHIShader::storageBlockForBlockName(const QString &blockName) RHIShader::ParameterKind RHIShader::categorizeVariable(int nameId) const noexcept { - if (m_uniformsNamesIds.contains(nameId)) + if (Qt3DCore::contains(m_uniformsNamesIds, nameId)) return ParameterKind::Uniform; - else if (m_uniformBlockNamesIds.contains(nameId)) + else if (Qt3DCore::contains(m_uniformBlockNamesIds, nameId)) return ParameterKind::UBO; - else if (m_shaderStorageBlockNamesIds.contains(nameId)) + else if (Qt3DCore::contains(m_shaderStorageBlockNamesIds, nameId)) return ParameterKind::SSBO; - else if (m_structNamesIds.contains(nameId)) + else if (Qt3DCore::contains(m_structNamesIds, nameId)) return ParameterKind::Struct; return ParameterKind::Uniform; } bool RHIShader::hasUniform(int nameId) const noexcept { - return m_uniformsNamesIds.contains(nameId); + return Qt3DCore::contains(m_uniformsNamesIds, nameId); } bool RHIShader::hasActiveVariables() const noexcept @@ -560,8 +557,15 @@ bool RHIShader::hasActiveVariables() const noexcept || !m_uniformBlockNamesIds.empty() || !m_shaderStorageBlockNamesIds.empty(); } +void RHIShader::setShaderCode(const std::vector &shaderCode) +{ + m_shaderCode.clear(); + Qt3DCore::append(m_shaderCode, shaderCode); +} + void RHIShader::prepareUniforms(ShaderParameterPack &pack) { + const PackUniformHash &values = pack.uniforms(); auto it = values.keys.cbegin(); @@ -600,7 +604,7 @@ const QHash RHIShader::fragOutputs() const return m_fragOutputs; } -void RHIShader::initializeAttributes(const QVector &attributesDescription) +void RHIShader::initializeAttributes(const std::vector &attributesDescription) { m_attributes = attributesDescription; m_attributesNames.resize(attributesDescription.size()); @@ -613,7 +617,7 @@ void RHIShader::initializeAttributes(const QVector &attributesD } } -void RHIShader::initializeSamplers(const QVector &samplersDescription) +void RHIShader::initializeSamplers(const std::vector &samplersDescription) { m_samplers = samplersDescription; m_samplerNames.resize(samplersDescription.size()); @@ -626,7 +630,7 @@ void RHIShader::initializeSamplers(const QVector &samplersDescr } } -void RHIShader::initializeImages(const QVector &imagesDescription) +void RHIShader::initializeImages(const std::vector &imagesDescription) { m_images = imagesDescription; m_imageNames.resize(imagesDescription.size()); @@ -639,7 +643,7 @@ void RHIShader::initializeImages(const QVector &imagesDescripti } } -void RHIShader::initializeUniformBlocks(const QVector &uniformBlockDescription) +void RHIShader::initializeUniformBlocks(const std::vector &uniformBlockDescription) { m_uniformBlocks = uniformBlockDescription; m_uniformBlockNames.resize(uniformBlockDescription.size()); @@ -651,11 +655,11 @@ void RHIShader::initializeUniformBlocks(const QVector &unifo qCDebug(Shaders) << "Initializing Uniform Block {" << m_uniformBlockNames[i] << "}"; // Find all active uniforms for the shader block - QVector::const_iterator uniformsIt = m_uniforms.cbegin(); - const QVector::const_iterator uniformsEnd = m_uniforms.cend(); + std::vector::const_iterator uniformsIt = m_uniforms.cbegin(); + const std::vector::const_iterator uniformsEnd = m_uniforms.cend(); - QVector::const_iterator uniformNamesIt = m_uniformsNames.cbegin(); - const QVector::const_iterator uniformNamesEnd = m_attributesNames.cend(); + std::vector::const_iterator uniformNamesIt = m_uniformsNames.cbegin(); + const std::vector::const_iterator uniformNamesEnd = m_attributesNames.cend(); QHash activeUniformsInBlock; @@ -679,7 +683,7 @@ void RHIShader::initializeUniformBlocks(const QVector &unifo } void RHIShader::initializeShaderStorageBlocks( - const QVector &shaderStorageBlockDescription) + const std::vector &shaderStorageBlockDescription) { m_shaderStorageBlocks = shaderStorageBlockDescription; m_shaderStorageBlockNames.resize(shaderStorageBlockDescription.size()); diff --git a/src/plugins/renderers/rhi/renderer/rhishader_p.h b/src/plugins/renderers/rhi/renderer/rhishader_p.h index 774dcbdb0..ba2b3293c 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader_p.h +++ b/src/plugins/renderers/rhi/renderer/rhishader_p.h @@ -85,25 +85,25 @@ public: void setFragOutputs(const QHash &fragOutputs); const QHash fragOutputs() const; - inline QVector uniformsNamesIds() const { return m_uniformsNamesIds; } - inline QVector standardUniformNameIds() const { return m_standardUniformNamesIds; } - inline QVector uniformBlockNamesIds() const { return m_uniformBlockNamesIds; } - inline QVector storageBlockNamesIds() const { return m_shaderStorageBlockNamesIds; } - inline QVector attributeNamesIds() const { return m_attributeNamesIds; } - - QVector uniformsNames() const; - QVector attributesNames() const; - QVector uniformBlockNames() const; - QVector storageBlockNames() const; - QVector samplerNames() const; - QVector imagesNames() const; - - inline QVector uniforms() const { return m_uniforms; } - inline QVector attributes() const { return m_attributes; } - inline QVector uniformBlocks() const { return m_uniformBlocks; } - inline QVector storageBlocks() const { return m_shaderStorageBlocks; } - inline QVector samplers() const { return m_samplers; } - inline QVector images() const { return m_images; } + inline const std::vector &uniformsNamesIds() const { return m_uniformsNamesIds; } + inline const std::vector &standardUniformNameIds() const { return m_standardUniformNamesIds; } + inline const std::vector &uniformBlockNamesIds() const { return m_uniformBlockNamesIds; } + inline const std::vector &storageBlockNamesIds() const { return m_shaderStorageBlockNamesIds; } + inline const std::vector &attributeNamesIds() const { return m_attributeNamesIds; } + + const std::vector &uniformsNames() const; + const std::vector &attributesNames() const; + const std::vector &uniformBlockNames() const; + const std::vector &storageBlockNames() const; + const std::vector &samplerNames() const; + const std::vector &imagesNames() const; + + inline const std::vector &uniforms() const { return m_uniforms; } + inline const std::vector &attributes() const { return m_attributes; } + inline const std::vector &uniformBlocks() const { return m_uniformBlocks; } + inline const std::vector &storageBlocks() const { return m_shaderStorageBlocks; } + inline const std::vector &samplers() const { return m_samplers; } + inline const std::vector &images() const { return m_images; } QHash activeUniformsForUniformBlock(int blockIndex) const; @@ -121,11 +121,11 @@ public: bool hasUniform(int nameId) const noexcept; bool hasActiveVariables() const noexcept; - void setShaderCode(const QVector shaderCode) { m_shaderCode = shaderCode; } - QVector shaderCode() const; + void setShaderCode(const std::vector &shaderCode); + const std::vector &shaderCode() const; const QShader &shaderStage(QShader::Stage stage) const noexcept { return m_stages[stage]; } - QVector uboMembers() const { return m_uboMembers; } + std::vector uboMembers() const { return m_uboMembers; } const QSet &unqualifiedUniformNames() const noexcept { @@ -138,50 +138,50 @@ private: bool m_isLoaded; QShader m_stages[6]; - QVector m_uniformsNames; - QVector m_uniformsNamesIds; - QVector m_standardUniformNamesIds; - QVector m_uniforms; + std::vector m_uniformsNames; + std::vector m_uniformsNamesIds; + std::vector m_standardUniformNamesIds; + std::vector m_uniforms; - QVector m_attributesNames; - QVector m_attributeNamesIds; - QVector m_attributes; + std::vector m_attributesNames; + std::vector m_attributeNamesIds; + std::vector m_attributes; - QVector m_uniformBlockNames; - QVector m_uniformBlockNamesIds; - QVector m_uniformBlocks; + std::vector m_uniformBlockNames; + std::vector m_uniformBlockNamesIds; + std::vector m_uniformBlocks; QHash> m_uniformBlockIndexToShaderUniforms; QSet m_unqualifiedUniformNames; - QVector m_shaderStorageBlockNames; - QVector m_shaderStorageBlockNamesIds; - QVector m_shaderStorageBlocks; + std::vector m_shaderStorageBlockNames; + std::vector m_shaderStorageBlockNamesIds; + std::vector m_shaderStorageBlocks; - QVector m_samplerNames; - QVector m_samplerIds; - QVector m_samplers; + std::vector m_samplerNames; + std::vector m_samplerIds; + std::vector m_samplers; - QVector m_imageNames; - QVector m_imageIds; - QVector m_images; + std::vector m_imageNames; + std::vector m_imageIds; + std::vector m_images; - QVector m_structNames; - QVector m_structNamesIds; + std::vector m_structNames; + std::vector m_structNamesIds; QHash m_fragOutputs; - QVector m_shaderCode; + std::vector m_shaderCode; // Private so that only SubmissionContext can call it friend class SubmissionContext; - void initializeAttributes(const QVector &attributesDescription); - void initializeUniformBlocks(const QVector &uniformBlockDescription); + void initializeAttributes(const std::vector &attributesDescription); + void initializeUniformBlocks(const std::vector &uniformBlockDescription); void - initializeShaderStorageBlocks(const QVector &shaderStorageBlockDescription); - void initializeSamplers(const QVector &samplerDescription); - void initializeImages(const QVector &imageDescription); + initializeShaderStorageBlocks(const std::vector &shaderStorageBlockDescription); + void initializeSamplers(const std::vector &samplerDescription); + void initializeImages(const std::vector &imageDescription); void recordAllUniforms(const QShaderDescription::BlockVariable &ubo, QString parentName); - QVector m_uboMembers; + std::vector m_uboMembers; mutable QMutex m_mutex; QMetaObject::Connection m_contextConnection; diff --git a/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h b/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h index e285551b7..bd4798072 100644 --- a/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h +++ b/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/plugins/renderers/rhi/textures/texture.cpp b/src/plugins/renderers/rhi/textures/texture.cpp index a3606f369..2270d1ba6 100644 --- a/src/plugins/renderers/rhi/textures/texture.cpp +++ b/src/plugins/renderers/rhi/textures/texture.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -355,7 +356,7 @@ bool RHITexture::loadTextureDataFromGenerator() m_properties.layers = m_textureData->layers(); m_properties.format = m_textureData->format(); - const QVector imageData = m_textureData->imageData(); + const QVector &imageData = m_textureData->imageData(); if (!imageData.empty()) { // Set the mips level based on the first image if autoMipMapGeneration is disabled @@ -581,7 +582,7 @@ void RHITexture::setProperties(const TextureProperties &props) } } -void RHITexture::setImages(const QVector &images) +void RHITexture::setImages(const std::vector &images) { // check if something has changed at all bool same = (images.size() == m_images.size()); @@ -618,7 +619,7 @@ void RHITexture::setSharedTextureId(int textureId) void RHITexture::addTextureDataUpdates(const QVector &updates) { - m_pendingTextureDataUpdates += updates; + Qt3DCore::append(m_pendingTextureDataUpdates, updates); requestUpload(); } @@ -685,7 +686,7 @@ void RHITexture::uploadRhiTextureData(SubmissionContext *ctx) // Upload all QTexImageData set by the QTextureGenerator if (m_textureData) { - const QVector &imgData = m_textureData->imageData(); + const auto &imgData = m_textureData->imageData(); for (const QTextureImageDataPtr &data : imgData) { const int mipLevels = data->mipLevels(); @@ -722,7 +723,7 @@ void RHITexture::uploadRhiTextureData(SubmissionContext *ctx) m_imageData.clear(); // Update data from TextureUpdates - const QVector textureDataUpdates = std::move(m_pendingTextureDataUpdates); + const std::vector textureDataUpdates = std::move(m_pendingTextureDataUpdates); for (const QTextureDataUpdate &update : textureDataUpdates) { const QTextureImageDataPtr imgData = update.data(); diff --git a/src/plugins/renderers/rhi/textures/texture_p.h b/src/plugins/renderers/rhi/textures/texture_p.h index c78bc1c1b..e2378e42b 100644 --- a/src/plugins/renderers/rhi/textures/texture_p.h +++ b/src/plugins/renderers/rhi/textures/texture_p.h @@ -137,7 +137,7 @@ public: inline TextureParameters parameters() const { return m_parameters; } inline QTextureGeneratorPtr textureGenerator() const { return m_dataFunctor; } inline int sharedTextureId() const { return m_sharedTextureId; } - inline QVector images() const { return m_images; } + inline const std::vector &images() const { return m_images; } inline QSize size() const { return QSize(m_properties.width, m_properties.height); } inline QRhiTexture *getRhiTexture() const { return m_rhi; } @@ -176,7 +176,7 @@ public: bool isDirty() const { return m_dirtyFlags != None; } bool hasTextureData() const { return !m_textureData.isNull(); } - bool hasImagesData() const { return !m_imageData.isEmpty(); } + bool hasImagesData() const { return !m_imageData.empty(); } QFlags dirtyFlags() const { return m_dirtyFlags; } @@ -191,12 +191,12 @@ public: void setParameters(const TextureParameters ¶ms); void setProperties(const TextureProperties &props); - void setImages(const QVector &images); + void setImages(const std::vector &images); void setGenerator(const QTextureGeneratorPtr &generator); void setSharedTextureId(int textureId); void addTextureDataUpdates(const QVector &updates); - QVector textureDataUpdates() const { return m_pendingTextureDataUpdates; } + const std::vector &textureDataUpdates() const { return m_pendingTextureDataUpdates; } QTextureGeneratorPtr dataGenerator() const { return m_dataFunctor; } private: @@ -228,12 +228,12 @@ private: QTextureGeneratorPtr m_dataFunctor; QTextureGenerator *m_pendingDataFunctor; - QVector m_images; + std::vector m_images; // cache actual image data generated by the functors QTextureDataPtr m_textureData; - QVector m_imageData; - QVector m_pendingTextureDataUpdates; + std::vector m_imageData; + std::vector m_pendingTextureDataUpdates; int m_sharedTextureId; bool m_externalRendering; -- cgit v1.2.3