diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-05-09 13:49:09 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-05-09 13:49:09 +0200 |
commit | 66feeb8de70291786499b3008ab8fded4043172a (patch) | |
tree | 4c2029d9f51b2471c7c8dc0c3be9311640831595 /src/render/renderers/opengl | |
parent | 7eb41022f19a57505c8eef3497ad6710fc92bd7d (diff) | |
parent | 15e863517ea37ca7ba6bcb75b078272eddbc5d37 (diff) |
Merge remote-tracking branch 'origin/5.11.0' into 5.11
Change-Id: I666d4ca1ad39f81e41a9b47a8828d1689ff2b33e
Diffstat (limited to 'src/render/renderers/opengl')
-rw-r--r-- | src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp | 3 | ||||
-rw-r--r-- | src/render/renderers/opengl/renderer/renderer.cpp | 59 | ||||
-rw-r--r-- | src/render/renderers/opengl/renderer/renderer_p.h | 3 |
3 files changed, 50 insertions, 15 deletions
diff --git a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp index cd082011b..4ec929b6e 100644 --- a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -887,7 +887,8 @@ int SubmissionContext::activateTexture(TextureScope scope, GLTexture *tex, int o // actually re-bind if required, the tex->dna on the unit not being the same // Note: tex->dna() could be 0 if the texture has not been created yet if (m_activeTextures[onUnit].texture != tex) { - QOpenGLTexture *glTex = tex->getOrCreateGLTexture(); + // Texture must have been created and updated at this point + QOpenGLTexture *glTex = tex->getGLTexture(); if (glTex == nullptr) return -1; glTex->bind(onUnit); diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp index bcc5fba80..b889799a3 100644 --- a/src/render/renderers/opengl/renderer/renderer.cpp +++ b/src/render/renderers/opengl/renderer/renderer.cpp @@ -128,6 +128,9 @@ QT_BEGIN_NAMESPACE +// Crashes on AMD Radeon drivers on Windows. Disable for now. +//#define SHADER_LOADING_IN_COMMAND_THREAD + using namespace Qt3DCore; namespace Qt3DRender { @@ -323,11 +326,17 @@ QOpenGLContext *Renderer::shareContext() const } // Executed in the command thread -void Renderer::loadShader(Shader *shader) const +void Renderer::loadShader(Shader *shader, HShader shaderHandle) { +#ifdef SHADER_LOADING_IN_COMMAND_THREAD + Q_UNUSED(shaderHandle); Profiling::GLTimeRecorder recorder(Profiling::ShaderUpload); LoadShaderCommand cmd(shader); m_commandThread->executeCommand(&cmd); +#else + Q_UNUSED(shader); + m_dirtyShaders.push_back(shaderHandle); +#endif } void Renderer::setOpenGLContext(QOpenGLContext *context) @@ -1123,7 +1132,7 @@ void Renderer::reloadDirtyShaders() shader->submitPendingNotifications(); // If the shader hasn't be loaded, load it if (shader != nullptr && !shader->isLoaded()) - loadShader(shader); + loadShader(shader, shaderHandle); } } } @@ -1147,14 +1156,37 @@ void Renderer::updateGLResources() } } +#ifndef SHADER_LOADING_IN_COMMAND_THREAD + { + Profiling::GLTimeRecorder recorder(Profiling::ShaderUpload); + const QVector<HShader> dirtyShaderHandles = std::move(m_dirtyShaders); + ShaderManager *shaderManager = m_nodesManager->shaderManager(); + for (const HShader &handle: dirtyShaderHandles) { + Shader *shader = shaderManager->data(handle); + // Compile shader + m_submissionContext->loadShader(shader, shaderManager); + } + } +#endif + { Profiling::GLTimeRecorder recorder(Profiling::TextureUpload); const QVector<HTexture> activeTextureHandles = std::move(m_dirtyTextures); for (const HTexture &handle: activeTextureHandles) { Texture *texture = m_nodesManager->textureManager()->data(handle); - // Upload/Update texture + // Update texture properties updateTexture(texture); } + // We want to upload textures data at this point as the SubmissionThread and + // AspectThread are locked ensuring no races between Texture/TextureImage and + // GLTexture + if (m_submissionContext != nullptr) { + GLTextureManager *glTextureManager = m_nodesManager->glTextureManager(); + const QVector<GLTexture *> glTextures = glTextureManager->activeResources(); + // Upload texture data + for (GLTexture *glTexture : glTextures) + glTexture->getOrCreateGLTexture(); + } } // When Textures are cleaned up, their id is saved // so that they can be cleaned up in the render thread @@ -1196,13 +1228,18 @@ void Renderer::updateTexture(Texture *texture) GLTextureManager *glTextureManager = m_nodesManager->glTextureManager(); GLTexture *glTexture = glTextureManager->lookupResource(texture->peerId()); - // No GLTexture associated yet -> create it - if (glTexture == nullptr) { + auto createOrUpdateGLTexture = [=] () { + GLTexture *newGLTexture = nullptr; if (isUnique) - glTextureManager->createUnique(texture); + newGLTexture = glTextureManager->createUnique(texture); else - glTextureManager->getOrCreateShared(texture); + newGLTexture = glTextureManager->getOrCreateShared(texture); texture->unsetDirty(); + }; + + // No GLTexture associated yet -> create it + if (glTexture == nullptr) { + createOrUpdateGLTexture(); return; } @@ -1210,12 +1247,8 @@ void Renderer::updateTexture(Texture *texture) // and abandon the old one if (glTextureManager->isShared(glTexture)) { glTextureManager->abandon(glTexture, texture); - // Check if a shared texture should become unique - if (isUnique) - glTextureManager->createUnique(texture); - else - glTextureManager->getOrCreateShared(texture); - texture->unsetDirty(); + // Note: if isUnique is true, a once shared texture will become unique + createOrUpdateGLTexture(); return; } diff --git a/src/render/renderers/opengl/renderer/renderer_p.h b/src/render/renderers/opengl/renderer/renderer_p.h index 1d459a15e..bf9554a54 100644 --- a/src/render/renderers/opengl/renderer/renderer_p.h +++ b/src/render/renderers/opengl/renderer/renderer_p.h @@ -226,7 +226,7 @@ public: // Executed in secondary GL thread - void loadShader(Shader *shader) const override; + void loadShader(Shader *shader, Qt3DRender::Render::HShader shaderHandle) override; void updateGLResources(); @@ -382,6 +382,7 @@ private: QVector<HBuffer> m_dirtyBuffers; QVector<HBuffer> m_downloadableBuffers; + QVector<HShader> m_dirtyShaders; QVector<HTexture> m_dirtyTextures; bool m_ownedContext; |