diff options
Diffstat (limited to 'src/plugins/renderers/rhi/renderer')
24 files changed, 388 insertions, 1100 deletions
diff --git a/src/plugins/renderers/rhi/renderer/commandexecuter.cpp b/src/plugins/renderers/rhi/renderer/commandexecuter.cpp index 359e377bc..eaceb270a 100644 --- a/src/plugins/renderers/rhi/renderer/commandexecuter.cpp +++ b/src/plugins/renderers/rhi/renderer/commandexecuter.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com> -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "commandexecuter_p.h" @@ -304,7 +268,9 @@ QJsonObject parameterPackToJson(const Render::Rhi::ShaderParameterPack &pack) no } // anonymous -CommandExecuter::CommandExecuter(Render::Rhi::Renderer *renderer) : m_renderer(renderer) { } +CommandExecuter::CommandExecuter(Render::Rhi::Renderer *renderer) : m_renderer(renderer) { + Q_UNUSED(m_renderer) +} // Render thread void CommandExecuter::performAsynchronousCommandExecution( diff --git a/src/plugins/renderers/rhi/renderer/commandexecuter_p.h b/src/plugins/renderers/rhi/renderer/commandexecuter_p.h index e683253a7..1ee60afe3 100644 --- a/src/plugins/renderers/rhi/renderer/commandexecuter_p.h +++ b/src/plugins/renderers/rhi/renderer/commandexecuter_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com> -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_DEBUG_COMMANDEXECUTER_H #define QT3DRENDER_DEBUG_COMMANDEXECUTER_H diff --git a/src/plugins/renderers/rhi/renderer/logging.cpp b/src/plugins/renderers/rhi/renderer/logging.cpp index 1aaa68208..265a48bca 100644 --- a/src/plugins/renderers/rhi/renderer/logging.cpp +++ b/src/plugins/renderers/rhi/renderer/logging.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "logging_p.h" diff --git a/src/plugins/renderers/rhi/renderer/logging_p.h b/src/plugins/renderers/rhi/renderer/logging_p.h index 45d63978d..295181685 100644 --- a/src/plugins/renderers/rhi/renderer/logging_p.h +++ b/src/plugins/renderers/rhi/renderer/logging_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RENDERLOGGING_P_H #define QT3DRENDER_RENDER_RHI_RENDERLOGGING_P_H diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp index ce53de1ab..8cffaac4f 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "pipelineuboset_p.h" #include <rendercommand_p.h> @@ -46,7 +10,7 @@ #include <rhigraphicspipeline_p.h> #include <rhiresourcemanagers_p.h> #include <submissioncontext_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <Qt3DRender/private/nodemanagers_p.h> #include <Qt3DRender/private/buffermanager_p.h> #include <Qt3DRender/private/stringtoint_p.h> @@ -220,14 +184,14 @@ std::vector<QRhiCommandBuffer::DynamicOffset> PipelineUBOSet::offsets(const Rend const size_t dToCmd = distanceToCommand(cmd); { // Compute offset relative to the select UBO in the subset - const size_t localOffset = m_commandsUBO.localOffsetInBufferForCommand(dToCmd); - offsets.push_back({1, localOffset}); + const auto localOffset = m_commandsUBO.localOffsetInBufferForCommand(dToCmd); + offsets.push_back({1, quint32(localOffset)}); } for (const MultiUBOBufferWithBindingAndBlockSize &materialUBO : m_materialsUBOs) { // Compute offset relative to the select UBO in the subset const size_t localOffset = materialUBO.localOffsetInBufferForCommand(dToCmd); - offsets.push_back({materialUBO.binding, localOffset}); + offsets.push_back({materialUBO.binding, quint32(localOffset)}); } return offsets; @@ -279,7 +243,7 @@ std::vector<QRhiShaderResourceBinding> PipelineUBOSet::resourceBindings(const Re { RHITextureManager *textureManager = m_resourceManagers->rhiTextureManager(); RHIShader *shader = command.m_rhiShader; - const QRhiShaderResourceBinding::StageFlags stages = QRhiShaderResourceBinding::VertexStage|QRhiShaderResourceBinding::FragmentStage; + const QRhiShaderResourceBinding::StageFlags stages = QRhiShaderResourceBinding::ComputeStage|QRhiShaderResourceBinding::VertexStage|QRhiShaderResourceBinding::FragmentStage; std::vector<QRhiShaderResourceBinding> bindings = { QRhiShaderResourceBinding::uniformBuffer(0, stages, m_rvUBO.buffer->rhiBuffer()), }; @@ -359,9 +323,10 @@ std::vector<QRhiShaderResourceBinding> PipelineUBOSet::resourceBindings(const Re for (const BlockToSSBO &ssbo : command.m_parameterPack.shaderStorageBuffers()) { RHIBuffer *buffer = m_resourceManagers->rhiBufferManager()->lookupResource(ssbo.m_bufferID); if (buffer) { + Q_ASSERT(stages & QRhiShaderResourceBinding::ComputeStage); bindings.push_back(QRhiShaderResourceBinding::bufferLoadStore( ssbo.m_bindingIndex, - stages|QRhiShaderResourceBinding::ComputeStage, + stages, buffer->rhiBuffer())); } } @@ -618,31 +583,36 @@ void PipelineUBOSet::uploadUBOsForCommand(const RenderCommand &command, if (ubo == nullptr) continue; - for (const RHIShader::UBO_Member &member : qAsConst(uboBlock.members)) { + for (const RHIShader::UBO_Member &member : std::as_const(uboBlock.members)) { const QShaderDescription::BlockVariable &blockVariable = member.blockVariable; + + // Array if (!blockVariable.arrayDims.empty()) { - if (!blockVariable.structMembers.empty()) { - const int arr0 = blockVariable.arrayDims[0]; - for (int i = 0; i < arr0; i++) { - for (const RHIShader::UBO_Member &structMember : member.structMembers) { + if (!blockVariable.structMembers.empty()) { // Array of structs + // we treat structMembers as arrayMembers when we are dealing with an array of structs´ + const size_t arr0 = size_t(blockVariable.arrayDims[0]); + const size_t m = std::max(arr0, member.structMembers.size()); + for (size_t i = 0; i < m; ++i) { + const RHIShader::UBO_Member &arrayMember = member.structMembers[i]; + for (const RHIShader::UBO_Member &arrayStructMember : arrayMember.structMembers) { uploadUniform(uniforms, ubo, - structMember, + arrayStructMember, distanceToCommand, - i * blockVariable.size / arr0); + int(i * blockVariable.size / arr0)); } } - } else { + } else { // Array of scalars uploadUniform(uniforms, ubo, member, distanceToCommand); } } else { - if (!blockVariable.structMembers.empty()) { + if (!blockVariable.structMembers.empty()) { // Struct for (const RHIShader::UBO_Member &structMember : member.structMembers) { uploadUniform(uniforms, ubo, structMember, distanceToCommand); } - } else { + } else { // Scalar uploadUniform(uniforms, ubo, member, distanceToCommand); } @@ -692,7 +662,7 @@ void PipelineUBOSet::uploadUBOsForCommand(const RenderCommand &command, continue; // Upload ShaderData property that match members of each UBO block instance - for (const RHIShader::UBO_Member &uboInstance : qAsConst(block->members)) { + for (const RHIShader::UBO_Member &uboInstance : std::as_const(block->members)) { uploadShaderDataProperty(shaderData, materialsUBO, uboInstance, distanceToCommand); } diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h index e3902a5c6..55c3bbb60 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_PIPELINEUBOSET_H #define QT3DRENDER_RENDER_RHI_PIPELINEUBOSET_H @@ -52,7 +16,7 @@ // #include <rhihandle_types_p.h> -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <shadervariables_p.h> #include <rhishader_p.h> diff --git a/src/plugins/renderers/rhi/renderer/rendercommand.cpp b/src/plugins/renderers/rhi/renderer/rendercommand.cpp index 06fb3bec0..e9ef1e99b 100644 --- a/src/plugins/renderers/rhi/renderer/rendercommand.cpp +++ b/src/plugins/renderers/rhi/renderer/rendercommand.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "rendercommand_p.h" #include "rhigraphicspipeline_p.h" @@ -95,6 +59,12 @@ RenderCommand::RenderCommand() m_workGroups[2] = 0; } +RenderCommand::~RenderCommand() +{ + if (shaderResourceBindings) + shaderResourceBindings->deleteLater(); +} + bool RenderCommand::isValid() const noexcept { return m_isValid && m_rhiShader && pipeline.isValid(); diff --git a/src/plugins/renderers/rhi/renderer/rendercommand_p.h b/src/plugins/renderers/rhi/renderer/rendercommand_p.h index 9e2585588..392650385 100644 --- a/src/plugins/renderers/rhi/renderer/rendercommand_p.h +++ b/src/plugins/renderers/rhi/renderer/rendercommand_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RENDERCOMMAND_H #define QT3DRENDER_RENDER_RHI_RENDERCOMMAND_H @@ -62,7 +26,7 @@ #include <QOpenGLShaderProgram> #include <QOpenGLTexture> #include <QMatrix4x4> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <Qt3DCore/qattribute.h> #include <variant> @@ -93,8 +57,9 @@ struct CommandUBO float mvp[16]; float inverseModelViewProjectionMatrix[16]; float modelViewNormalMatrix[12]; + float skinningPalette[100 * 16]; }; -static_assert(sizeof(CommandUBO) == 6 * (16 * sizeof(float)) + 2 * (12 * sizeof(float)), +static_assert(sizeof(CommandUBO) == 6 * (16 * sizeof(float)) + 2 * (12 * sizeof(float)) + 100 * (16 * sizeof(float)), "UBO doesn't match std140"); struct Q_AUTOTEST_EXPORT AttributeInfo @@ -113,6 +78,7 @@ class Q_AUTOTEST_EXPORT RenderCommand { public: RenderCommand(); + ~RenderCommand(); bool isValid() const noexcept; diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index 7774c91fe..4a25bb464 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "renderer_p.h" #include "rhirendertarget_p.h" @@ -129,8 +93,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { @@ -372,7 +334,7 @@ void Renderer::setNodeManagers(NodeManagers *managers) m_computableEntityFilterJob->setManager(m_nodesManager->renderNodesManager()); } -void Renderer::setServices(QServiceLocator *services) +void Renderer::setServices(Qt3DCore::QServiceLocator *services) { m_services = services; @@ -649,12 +611,12 @@ void Renderer::render(bool swapBuffers) // RenderQueue is complete (but that means it may be of size 0) if (!queueIsEmpty) { - QTaskLogger submissionStatsPart1(m_services->systemInformation(), - { JobTypes::FrameSubmissionPart1, 0 }, - QTaskLogger::Submission); - QTaskLogger submissionStatsPart2(m_services->systemInformation(), - { JobTypes::FrameSubmissionPart2, 0 }, - QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart1(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart1, 0 }, + Qt3DCore::QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart2(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart2, 0 }, + Qt3DCore::QTaskLogger::Submission); std::vector<RHIPassInfo> rhiPassesInfo; @@ -795,8 +757,8 @@ QSurfaceFormat Renderer::format() namespace { std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr) { switch (attr->vertexBaseType()) { - case QAttribute::Byte: - case QAttribute::UnsignedByte: { + case Qt3DCore::QAttribute::Byte: + case Qt3DCore::QAttribute::UnsignedByte: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::UNormByte; if (attr->vertexSize() == 2) @@ -805,7 +767,18 @@ std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr return QRhiVertexInputAttribute::UNormByte4; break; } - case QAttribute::UnsignedInt: { + case Qt3DCore::QAttribute::Int: { + if (attr->vertexSize() == 1) + return QRhiVertexInputAttribute::SInt; + if (attr->vertexSize() == 2) + return QRhiVertexInputAttribute::SInt2; + if (attr->vertexSize() == 3) + return QRhiVertexInputAttribute::SInt3; + if (attr->vertexSize() == 4) + return QRhiVertexInputAttribute::SInt4; + break; + } + case Qt3DCore::QAttribute::UnsignedInt: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::UInt; if (attr->vertexSize() == 2) @@ -816,7 +789,18 @@ std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr return QRhiVertexInputAttribute::UInt4; break; } - case QAttribute::Float: { + case Qt3DCore::QAttribute::HalfFloat: { + if (attr->vertexSize() == 1) + return QRhiVertexInputAttribute::Half; + if (attr->vertexSize() == 2) + return QRhiVertexInputAttribute::Half2; + if (attr->vertexSize() == 3) + return QRhiVertexInputAttribute::Half3; + if (attr->vertexSize() >= 4) + return QRhiVertexInputAttribute::Half4; + break; + } + case Qt3DCore::QAttribute::Float: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::Float; if (attr->vertexSize() == 2) @@ -1179,16 +1163,24 @@ void Renderer::createRenderTarget(RenderTarget *target) } }; + RHIRenderTarget::BackBuffer backBuffer = RHIRenderTarget::BackBuffer::None; + // Look up attachments to populate the RT description // Attachments are sorted by attachment point (Color0 is first) for (const Attachment &attachment : pack.attachments()) { + + if (attachment.m_point == QRenderTargetOutput::Left || attachment.m_point == QRenderTargetOutput::Right) { + backBuffer = attachment.m_point == QRenderTargetOutput::Left ? RHIRenderTarget::BackBuffer::Left : RHIRenderTarget::BackBuffer::Right; + break; + } + RHITexture *tex = texman->lookupResource(attachment.m_textureUuid); if (tex && tex->getRhiTexture()) { - auto rhiTex = tex->getRhiTexture(); if (!rhiTex->flags().testFlag(QRhiTexture::RenderTarget) || !rhiTex->flags().testFlag(QRhiTexture::UsedAsTransferSource)) { // UsedAsTransferSource is required if we ever want to read back from the texture + rhiTex->destroy(); rhiTex->setFlags(rhiTex->flags() | QRhiTexture::RenderTarget|QRhiTexture::UsedAsTransferSource); rhiTex->create(); } @@ -1221,6 +1213,12 @@ void Renderer::createRenderTarget(RenderTarget *target) } } + rhiTarget->backBuffer = backBuffer; + // If we are targeting one of the back buffers directly, don't create an offscreen RT + if (backBuffer != RHIRenderTarget::BackBuffer::None) + return; + + // Otherwise, create QRhiRenderBuffer and associated resources if (targetSize.width() <= 0 || targetSize.height() <= 0) { cleanAllocatedResources(); return; @@ -1270,6 +1268,12 @@ bool Renderer::setupRenderTarget(RenderView *rv, const auto &managers = *nodeManagers(); auto &renderTargetManager = *managers.renderTargetManager(); + auto useSwapchainForPipeline = [&]() { + Q_ASSERT(swapchain); + rhiPipeline->setRenderPassDescriptor(swapchain->renderPassDescriptor()); + rhiPipeline->setSampleCount(swapchain->sampleCount()); + }; + auto *renderTarget = renderTargetManager.lookupResource(rv->renderTargetId()); if (renderTarget) { // Render to texture @@ -1277,14 +1281,25 @@ bool Renderer::setupRenderTarget(RenderView *rv, RHIRenderTargetManager *rhiRenderTargetManager = m_RHIResourceManagers->rhiRenderTargetManager(); RHIRenderTarget *rhiTarget = rhiRenderTargetManager->lookupResource(renderTargetId); - if (!rhiTarget || !rhiTarget->renderTarget) { + if (!rhiTarget) { qWarning(Backend) << "Invalid RenderTarget " << renderTargetId << " for Pipeline"; return false; } - rhiPipeline->setRenderPassDescriptor(rhiTarget->renderPassDescriptor); - rhiPipeline->setSampleCount(rhiTarget->renderTarget->sampleCount()); + // The RenderTarget we reference might actually be referencing a swapchain back buffer + if (rhiTarget->backBuffer != RHIRenderTarget::BackBuffer::None) { + // Render to the default framebuffer on our swapchain + useSwapchainForPipeline(); + } else { + if (!rhiTarget->renderTarget) { + qWarning(Backend) << "Invalid RenderTarget " << renderTargetId << " for Pipeline"; + return false; + } + rhiPipeline->setRenderPassDescriptor(rhiTarget->renderPassDescriptor); + rhiPipeline->setSampleCount(rhiTarget->renderTarget->sampleCount()); + } return true; + } else if (m_submissionContext->defaultRenderTarget()) { // Use default RenderTarget if set Default FBO set by Scene3D QRhiRenderTarget *defaultTarget = m_submissionContext->defaultRenderTarget();; @@ -1292,10 +1307,8 @@ bool Renderer::setupRenderTarget(RenderView *rv, rhiPipeline->setSampleCount(defaultTarget->sampleCount()); return true; } else { - Q_ASSERT(swapchain); // Render to the default framebuffer on our swapchain - rhiPipeline->setRenderPassDescriptor(swapchain->renderPassDescriptor()); - rhiPipeline->setSampleCount(swapchain->sampleCount()); + useSwapchainForPipeline(); return true; } } @@ -1422,11 +1435,11 @@ Renderer::prepareCommandsSubmission(const std::vector<RenderView *> &renderViews // Note: we cannot do it in the loop above as we want to be sure that all // the VAO which reference the geometry/attributes are properly updated RHI_UNIMPLEMENTED; - for (Attribute *attribute : qAsConst(m_dirtyAttributes)) + for (Attribute *attribute : std::as_const(m_dirtyAttributes)) attribute->unsetDirty(); m_dirtyAttributes.clear(); - for (Geometry *geometry : qAsConst(m_dirtyGeometry)) + for (Geometry *geometry : std::as_const(m_dirtyGeometry)) geometry->unsetDirty(); m_dirtyGeometry.clear(); @@ -1478,10 +1491,10 @@ void Renderer::lookForDirtyTextures() const std::vector<HTexture> &activeTextureHandles = textureManager->activeHandles(); for (const HTexture &handle : activeTextureHandles) { Texture *texture = textureManager->data(handle); - const QNodeIdVector imageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector imageIds = texture->textureImageIds(); // Does the texture reference any of the dirty texture images? - for (const QNodeId &imageId : imageIds) { + for (const Qt3DCore::QNodeId &imageId : imageIds) { if (dirtyImageIds.contains(imageId)) { texture->addDirtyFlag(Texture::DirtyImageGenerators); break; @@ -1511,7 +1524,7 @@ void Renderer::reloadDirtyShaders() // If api of the renderer matches the one from the technique if (technique->isCompatibleWithRenderer()) { const auto passIds = technique->renderPasses(); - for (const QNodeId &passId : passIds) { + for (const Qt3DCore::QNodeId &passId : passIds) { RenderPass *renderPass = m_nodesManager->renderPassManager()->lookupResource(passId); HShader shaderHandle = @@ -1564,12 +1577,15 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) const std::vector<HShader> &activeShaders = m_nodesManager->shaderManager()->activeHandles(); for (const HShader &handle : activeShaders) { Shader *s = m_nodesManager->shaderManager()->data(handle); + if (!s) + continue; + if (s->requiresFrontendSync()) { QShaderProgram *frontend = static_cast<decltype(frontend)>(manager->lookupNode(s->peerId())); if (frontend) { QShaderProgramPrivate *dFrontend = - static_cast<decltype(dFrontend)>(QNodePrivate::get(frontend)); + static_cast<decltype(dFrontend)>(Qt3DCore::QNodePrivate::get(frontend)); dFrontend->setStatus(s->status()); dFrontend->setLog(s->log()); s->unsetRequiresFrontendSync(); @@ -1581,8 +1597,11 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) for (const ShaderBuilderUpdate &update : m_shaderBuilderUpdates) { QShaderProgramBuilder *builder = static_cast<decltype(builder)>(manager->lookupNode(update.builderId)); + if (!builder) + continue; + QShaderProgramBuilderPrivate *dBuilder = - static_cast<decltype(dBuilder)>(QNodePrivate::get(builder)); + static_cast<decltype(dBuilder)>(Qt3DCore::QNodePrivate::get(builder)); dBuilder->setShaderCode(update.shaderCode, update.shaderType); } m_shaderBuilderUpdates.clear(); @@ -1618,8 +1637,7 @@ void Renderer::sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager) texture->blockNotifications(blocked); QAbstractTexturePrivate *dTexture = - static_cast<QAbstractTexturePrivate *>(QNodePrivate::get(texture)); - + static_cast<QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(texture)); dTexture->setStatus(properties.status); dTexture->setHandleType(pair.first.handleType); dTexture->setHandle(pair.first.handle); @@ -1657,7 +1675,7 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS QHash<int, int> &attributeNameToBinding) { // shader requires no attributes - if (shader->attributes().size() == 0) + if (shader->attributes().empty()) return true; // QRhiVertexInputBinding -> specifies the stride of an attribute, @@ -1679,7 +1697,7 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS for (Qt3DCore::QNodeId attribute_id : attributesIds) { Attribute *attrib = m_nodesManager->attributeManager()->lookupResource(attribute_id); - if (attrib->attributeType() != QAttribute::VertexAttribute) + if (attrib->attributeType() != Qt3DCore::QAttribute::VertexAttribute) continue; const int location = locationForAttribute(attrib, shader); // In case the shader doesn't use the attribute, we would get no @@ -1693,20 +1711,20 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS ? QRhiVertexInputBinding::PerInstance : QRhiVertexInputBinding::PerVertex; - auto getAttributeByteSize = [] (const QAttribute::VertexBaseType type) { + auto getAttributeByteSize = [](const Qt3DCore::QAttribute::VertexBaseType type) { switch (type) { - case QAttribute::Byte: - case QAttribute::UnsignedByte: + case Qt3DCore::QAttribute::Byte: + case Qt3DCore::QAttribute::UnsignedByte: return 1; - case QAttribute::Short: - case QAttribute::UnsignedShort: - case QAttribute::HalfFloat: + case Qt3DCore::QAttribute::Short: + case Qt3DCore::QAttribute::UnsignedShort: + case Qt3DCore::QAttribute::HalfFloat: return 2; - case QAttribute::Int: - case QAttribute::UnsignedInt: - case QAttribute::Float: + case Qt3DCore::QAttribute::Int: + case Qt3DCore::QAttribute::UnsignedInt: + case Qt3DCore::QAttribute::Float: return 4; - case QAttribute::Double: + case Qt3DCore::QAttribute::Double: return 8; } return 0; @@ -1773,7 +1791,7 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS //*/ inputBindings[i] = QRhiVertexInputBinding{ binding.stride, binding.classification, - int(binding.attributeDivisor) }; + binding.attributeDivisor }; } return true; @@ -1834,6 +1852,12 @@ void Renderer::updateResources() } } + std::vector<RHITexture *> updatedRHITextures; + + // Create/Update textures. We record the update info to later fill + // m_updatedTextureProperties once we are use the RHITextures have been + // fully created (as creating the RenderTargets below could change existing + // RHITextures) { const std::vector<HTexture> activeTextureHandles = Qt3DCore::moveAndClear(m_dirtyTextures); for (const HTexture &handle : activeTextureHandles) { @@ -1852,31 +1876,29 @@ void Renderer::updateResources() // RHITexture if (m_submissionContext != nullptr) { RHITextureManager *rhiTextureManager = m_RHIResourceManagers->rhiTextureManager(); - const std::vector<HRHITexture> &glTextureHandles = rhiTextureManager->activeHandles(); + const std::vector<HRHITexture> &rhiTextureHandles = rhiTextureManager->activeHandles(); // Upload texture data - for (const HRHITexture &glTextureHandle : glTextureHandles) { + for (const HRHITexture &rhiTextureHandle : rhiTextureHandles) { RHI_UNIMPLEMENTED; - RHITexture *glTexture = rhiTextureManager->data(glTextureHandle); + RHITexture *rhiTexture = rhiTextureManager->data(rhiTextureHandle); - // We create/update the actual GL texture using the GL context at this point + // We create/update the actual RHI texture using the RHI context at this point const RHITexture::TextureUpdateInfo info = - glTexture->createOrUpdateRhiTexture(m_submissionContext.data()); - - // RHITexture creation provides us width/height/format ... information - // for textures which had not initially specified these information - // (TargetAutomatic...) Gather these information and store them to be distributed by - // a change next frame - const QNodeIdVector referenceTextureIds = { - rhiTextureManager->texNodeIdForRHITexture.value(glTexture) - }; - // Store properties and referenceTextureIds + rhiTexture->createOrUpdateRhiTexture(m_submissionContext.data()); + if (info.wasUpdated) { + // RHITexture creation provides us width/height/format ... information + // for textures which had not initially specified these information + // (TargetAutomatic...) Gather these information and store them to be distributed by + // a change next frame + const Qt3DCore::QNodeIdVector referenceTextureIds = { rhiTextureManager->texNodeIdForRHITexture.value(rhiTexture) }; + // Store properties and referenceTextureIds Texture::TextureUpdateInfo updateInfo; updateInfo.properties = info.properties; - updateInfo.handleType = QAbstractTexture::OpenGLTextureId; - // updateInfo.handle = info.texture ? - // QVariant(info.texture->textureId()) : QVariant(); + // Record texture updates to notify frontend (we are sure at this stage + // that the internal QRHITexture won't be updated further for this frame m_updatedTextureProperties.push_back({ updateInfo, referenceTextureIds }); + updatedRHITextures.push_back(rhiTexture); } } } @@ -1890,6 +1912,10 @@ void Renderer::updateResources() // -> attachments added/removed // -> attachments textures updated (new dimensions, format ...) // -> destroy pipelines associated with dirty renderTargets + + // Note: we might end up recreating some of the internal textures when + // creating the RenderTarget as those might have been created above without + // the proper RenderTarget/TransformSource flags { RHIRenderTargetManager *rhiRenderTargetManager = m_RHIResourceManagers->rhiRenderTargetManager(); RenderTargetManager *renderTargetManager = m_nodesManager->renderTargetManager(); @@ -1930,6 +1956,22 @@ void Renderer::updateResources() } } + + // Note: we can only retrieve the internal QRhiResource handle to set on + // the frontend nodes after we are sure we are no going to modify the + // QRhiTextures (which happens when we create the Textures or the + // RenderTargets) + { + for (size_t i = 0, m = m_updatedTextureProperties.size(); i < m; ++i) { + auto &updateInfoPair = m_updatedTextureProperties[i]; + RHITexture *rhiTexture = updatedRHITextures[i]; + QRhiTexture *qRhiTexture = rhiTexture->getRhiTexture(); + Texture::TextureUpdateInfo &updateInfo = updateInfoPair.first; + updateInfo.handleType = QAbstractTexture::RHITextureId; + updateInfo.handle = qRhiTexture ? QVariant(qRhiTexture->nativeTexture().object) : QVariant(); + } + } + // Record list of buffer that might need uploading lookForDownloadableBuffers(); } @@ -1971,11 +2013,11 @@ void Renderer::updateTexture(Texture *texture) // Will make the texture requestUpload if (dirtyFlags.testFlag(Texture::DirtyImageGenerators)) { - const QNodeIdVector textureImageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector textureImageIds = texture->textureImageIds(); std::vector<RHITexture::Image> images; images.reserve(textureImageIds.size()); // TODO: Move this into RHITexture directly - for (const QNodeId &textureImageId : textureImageIds) { + for (const Qt3DCore::QNodeId &textureImageId : textureImageIds) { const TextureImage *img = m_nodesManager->textureImageManager()->lookupResource(textureImageId); if (img == nullptr) { @@ -2199,16 +2241,18 @@ void Renderer::jobsDone(Qt3DCore::QAspectManager *manager) // called in main thread once all jobs are done running // sync captured renders to frontend + QMutexLocker lock(&m_pendingRenderCaptureSendRequestsMutex); const std::vector<Qt3DCore::QNodeId> pendingCaptureIds = Qt3DCore::moveAndClear(m_pendingRenderCaptureSendRequests); - for (const Qt3DCore::QNodeId &id : qAsConst(pendingCaptureIds)) { + lock.unlock(); + for (const Qt3DCore::QNodeId &id : std::as_const(pendingCaptureIds)) { auto *backend = static_cast<Qt3DRender::Render::RenderCapture *>( m_nodesManager->frameGraphManager()->lookupNode(id)); backend->syncRenderCapturesToFrontend(manager); } // Do we need to notify any texture about property changes? - if (m_updatedTextureProperties.size() > 0) + if (!m_updatedTextureProperties.empty()) sendTextureChangesToFrontend(manager); sendDisablesToFrontend(manager); @@ -2229,7 +2273,7 @@ bool Renderer::processKeyEvent(QObject *object, QKeyEvent *event) } // Jobs we may have to run even if no rendering will happen -std::vector<QAspectJobPtr> Renderer::preRenderingJobs() +std::vector<Qt3DCore::QAspectJobPtr> Renderer::preRenderingJobs() { if (m_sendBufferCaptureJob->hasRequests()) return { m_sendBufferCaptureJob }; @@ -2243,10 +2287,10 @@ std::vector<QAspectJobPtr> Renderer::preRenderingJobs() // for the rendering of the scene std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() { - std::vector<QAspectJobPtr> renderBinJobs; + std::vector<Qt3DCore::QAspectJobPtr> renderBinJobs; // Remove previous dependencies - m_cleanupJob->removeDependency(QWeakPointer<QAspectJob>()); + m_cleanupJob->removeDependency(QWeakPointer<Qt3DCore::QAspectJob>()); const bool dirtyParametersForCurrentFrame = m_dirtyBits.marked & AbstractRenderer::ParameterDirty; const BackendNodeDirtySet dirtyBitsForFrame = m_dirtyBits.marked | m_dirtyBits.remaining; @@ -2320,7 +2364,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() m_updatedDisableSubtreeEnablers.push_back(node->peerId()); } - int idealThreadCount = QAspectJobManager::idealThreadCount(); + int idealThreadCount = Qt3DCore::QAspectJobManager::idealThreadCount(); const size_t fgBranchCount = m_frameGraphLeaves.size(); if (fgBranchCount > 1) { @@ -2384,7 +2428,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() return renderBinJobs; } -QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const +Qt3DCore::QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const { return static_cast<Qt3DCore::QAbstractFrameAdvanceService *>(m_vsyncFrameAdvanceService.data()); } @@ -2409,12 +2453,12 @@ bool Renderer::performCompute(QRhiCommandBuffer *cb, RenderCommand &command) return true; } -static auto rhiIndexFormat(QAttribute::VertexBaseType type) +static auto rhiIndexFormat(Qt3DCore::QAttribute::VertexBaseType type) { switch (type) { - case QAttribute::VertexBaseType ::UnsignedShort: + case Qt3DCore::QAttribute::VertexBaseType ::UnsignedShort: return QRhiCommandBuffer::IndexUInt16; - case QAttribute::VertexBaseType ::UnsignedInt: + case Qt3DCore::QAttribute::VertexBaseType ::UnsignedInt: return QRhiCommandBuffer::IndexUInt32; default: std::abort(); @@ -2486,7 +2530,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re Buffer *buffer = m_nodesManager->bufferManager()->lookupResource(attrib->bufferId()); RHIBuffer *hbuf = m_RHIResourceManagers->rhiBufferManager()->lookupResource(buffer->peerId()); switch (attrib->attributeType()) { - case QAttribute::VertexAttribute: { + case Qt3DCore::QAttribute::VertexAttribute: { if (!hbuf->bind(&*m_submissionContext, RHIBuffer::Type((int)RHIBuffer::Type::ArrayBuffer | (int)RHIBuffer::Type::ShaderStorageBuffer))) return false; assert(hbuf->rhiBuffer()); @@ -2499,7 +2543,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re command.vertex_input[bindingIndex] = { hbuf->rhiBuffer(), 0 }; break; } - case QAttribute::IndexAttribute: { + case Qt3DCore::QAttribute::IndexAttribute: { if (!hbuf->bind(&*m_submissionContext, RHIBuffer::Type::IndexBuffer)) return false; assert(hbuf->rhiBuffer()); @@ -2508,7 +2552,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re command.indexAttribute = attrib; break; } - case QAttribute::DrawIndirectAttribute: + case Qt3DCore::QAttribute::DrawIndirectAttribute: RHI_UNIMPLEMENTED; break; } @@ -2647,12 +2691,19 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) auto &renderTargetManager = *managers.rhiRenderTargetManager(); auto *renderTarget = renderTargetManager.lookupResource(passInfo.renderTargetId); - if (renderTarget) - rhiRenderTarget = renderTarget->renderTarget; - else if (m_submissionContext->defaultRenderTarget()) + if (renderTarget) { + // Is our RenderTarget targeting offscreen attachments? + if (renderTarget->backBuffer == RHIRenderTarget::BackBuffer::None) + rhiRenderTarget = renderTarget->renderTarget; + else // Or one of the back buffers? + rhiRenderTarget = m_submissionContext->currentSwapChain()->currentFrameRenderTarget(renderTarget->backBuffer == RHIRenderTarget::BackBuffer::Left + ? QRhiSwapChain::LeftBuffer + : QRhiSwapChain::RightBuffer); + } else if (m_submissionContext->defaultRenderTarget()) { rhiRenderTarget = m_submissionContext->defaultRenderTarget(); - else + } else { rhiRenderTarget = m_submissionContext->currentSwapChain()->currentFrameRenderTarget(); + } } auto executeDrawRenderView = [&] (RenderView* rv) { @@ -2712,7 +2763,6 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) // All the RVs in the current passinfo target the same RenderTarget // A single beginPass should take place, unless Computes RVs are intermingled - QRhiResourceUpdateBatch *inPassUpdates = nullptr; static const bool supportsCompute = m_submissionContext->rhi()->isFeatureSupported(QRhi::Compute); // Per Pass Global States @@ -2720,7 +2770,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) if (rv->isCompute()) { // If we were running draw calls we stop the draw pass if (inDraw) { - cb->endPass(); + cb->endPass(m_submissionContext->m_currentUpdates); m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inDraw = false; } @@ -2730,6 +2780,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) if (supportsCompute) { if (!inCompute) { cb->beginComputePass(m_submissionContext->m_currentUpdates); + m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inCompute = true; } executeComputeRenderView(rv); @@ -2739,7 +2790,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) } else { // Same logic than above but reversed if (inCompute) { - cb->endComputePass(); + cb->endComputePass(m_submissionContext->m_currentUpdates); m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inCompute = false; } @@ -2751,6 +2802,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) continue; } cb->beginPass(rhiRenderTarget, clearColor, clearDepthStencil, m_submissionContext->m_currentUpdates); + m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inDraw = true; } @@ -2759,7 +2811,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) const Qt3DCore::QNodeId renderCaptureId = rv->renderCaptureNodeId(); if (!renderCaptureId.isNull()) { const QRenderCaptureRequest request = rv->renderCaptureRequest(); - QRhiRenderTarget *rhiTarget = nullptr; + QRhiRenderTarget *rhiTarget = m_submissionContext->defaultRenderTarget(); RHIRenderTarget *target = nullptr; if (rv->renderTargetId()) { @@ -2774,20 +2826,21 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) QRect rect(QPoint(0, 0), size); if (!request.rect.isEmpty()) rect = rect.intersected(request.rect); - QImage image; if (!rect.isEmpty()) { // Bind fbo as read framebuffer QRhiReadbackResult *readBackResult = new QRhiReadbackResult; readBackResult->completed = [this, readBackResult, renderCaptureId, request] () { const QImage::Format fmt = QImage::Format_RGBA8888_Premultiplied; // fits QRhiTexture::RGBA8 const uchar *p = reinterpret_cast<const uchar *>(readBackResult->data.constData()); - const QImage image(p, readBackResult->pixelSize.width(), readBackResult->pixelSize.height(), fmt); + const QImage image(p, readBackResult->pixelSize.width(), readBackResult->pixelSize.height(), fmt, [] (void *ptr) { + delete static_cast<QRhiReadbackResult *>(ptr); + }, readBackResult); Render::RenderCapture *renderCapture = static_cast<Render::RenderCapture*>(m_nodesManager->frameGraphManager()->lookupNode(renderCaptureId)); renderCapture->addRenderCapture(request.captureId, image); + QMutexLocker lock(&m_pendingRenderCaptureSendRequestsMutex); if (!Qt3DCore::contains(m_pendingRenderCaptureSendRequests, renderCaptureId)) m_pendingRenderCaptureSendRequests.push_back(renderCaptureId); - delete readBackResult; }; QRhiReadbackDescription readbackDesc; @@ -2798,8 +2851,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) const QRhiColorAttachment *color0Att = desc.colorAttachmentAt(0); readbackDesc.setTexture(color0Att->texture()); } - inPassUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); - inPassUpdates->readBackTexture(readbackDesc, readBackResult); + m_submissionContext->m_currentUpdates->readBackTexture(readbackDesc, readBackResult); } else { qCWarning(Backend) << "Requested capture rectangle is outside framebuffer"; } @@ -2811,9 +2863,9 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) } if (Q_LIKELY(inDraw)) - cb->endPass(inPassUpdates); + cb->endPass(m_submissionContext->m_currentUpdates); else if (inCompute) - cb->endComputePass(); + cb->endComputePass(m_submissionContext->m_currentUpdates); m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); diff --git a/src/plugins/renderers/rhi/renderer/renderer.pri b/src/plugins/renderers/rhi/renderer/renderer.pri deleted file mode 100644 index 761a6ce9b..000000000 --- a/src/plugins/renderers/rhi/renderer/renderer.pri +++ /dev/null @@ -1,26 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/rendercommand.cpp \ - $$PWD/renderer.cpp \ - $$PWD/renderview.cpp \ - $$PWD/renderviewbuilder.cpp \ - $$PWD/rhigraphicspipeline.cpp \ - $$PWD/rhishader.cpp \ - $$PWD/shaderparameterpack.cpp \ - $$PWD/logging.cpp \ - $$PWD/commandexecuter.cpp \ - $$PWD/pipelineuboset.cpp - -HEADERS += \ - $$PWD/rendercommand_p.h \ - $$PWD/renderer_p.h \ - $$PWD/renderview_p.h \ - $$PWD/renderviewbuilder_p.h \ - $$PWD/rhigraphicspipeline_p.h \ - $$PWD/rhishader_p.h \ - $$PWD/shaderparameterpack_p.h \ - $$PWD/shadervariables_p.h \ - $$PWD/logging_p.h \ - $$PWD/commandexecuter_p.h \ - $$PWD/pipelineuboset_p.h diff --git a/src/plugins/renderers/rhi/renderer/renderer_p.h b/src/plugins/renderers/rhi/renderer/renderer_p.h index 1c89bd52b..6f4590ef5 100644 --- a/src/plugins/renderers/rhi/renderer/renderer_p.h +++ b/src/plugins/renderers/rhi/renderer/renderer_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RENDERER_H #define QT3DRENDER_RENDER_RHI_RENDERER_H @@ -73,7 +37,7 @@ #include <Qt3DRender/private/renderercache_p.h> #include <Qt3DRender/private/renderviewinitializerjob_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <shaderparameterpack_p.h> #include <logging_p.h> @@ -360,6 +324,7 @@ private: RenderableEntityFilterPtr m_renderableEntityFilterJob; ComputableEntityFilterPtr m_computableEntityFilterJob; + QMutex m_pendingRenderCaptureSendRequestsMutex; std::vector<Qt3DCore::QNodeId> m_pendingRenderCaptureSendRequests; SynchronizerJobPtr m_bufferGathererJob; diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp index cf8d27871..c8ae4e7f1 100644 --- a/src/plugins/renderers/rhi/renderer/renderview.cpp +++ b/src/plugins/renderers/rhi/renderer/renderview.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "renderview_p.h" #include <Qt3DRender/qmaterial.h> @@ -417,8 +381,7 @@ struct AdjacentSubRangeFinder { static bool adjacentSubRange(const RenderCommand &, const RenderCommand &) { - Q_UNREACHABLE(); - return false; + Q_UNREACHABLE_RETURN(false); } }; @@ -605,6 +568,10 @@ struct SubRangeSorter<QSortPolicy::Texture> return identicalTextureCount < smallestVector.size(); }); +#else + Q_UNUSED(view); + Q_UNUSED(begin); + Q_UNUSED(end); #endif } }; @@ -627,8 +594,7 @@ int findSubRange(const EntityRenderCommandDataView *view, case QSortPolicy::Uniform: return end; default: - Q_UNREACHABLE(); - return end; + Q_UNREACHABLE_RETURN(end); } } @@ -641,7 +607,7 @@ void sortByMaterial(EntityRenderCommandDataView *view, int begin, const int end) while (begin != end) { if (begin + 1 < rangeEnd) { std::stable_sort(commandIndices.begin() + begin + 1, commandIndices.begin() + rangeEnd, - [&commands] (const int &iA, const int &iB) { + [&commands] (const size_t &iA, const size_t &iB) { const RenderCommand &a = commands[iA]; const RenderCommand &b = commands[iB]; return a.m_material.handle() < b.m_material.handle(); @@ -1198,6 +1164,13 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi memcpy(&command.m_commandUBO.inverseModelViewProjectionMatrix, &inverseModelViewProjection, sizeof(Matrix4x4)); copyNormalMatrix(command.m_commandUBO.modelViewNormalMatrix, modelViewNormalMatrix.constData()); + + const Armature *armature = entity->renderComponent<Armature>(); + if (armature) { + const UniformValue &skinningPalette = armature->skinningPaletteUniform(); + memcpy(&command.m_commandUBO.skinningPalette, skinningPalette.constData<float>(), + qMin<size_t>(skinningPalette.byteSize(), 100 * 16 * sizeof(float))); + } } }); } @@ -1206,8 +1179,16 @@ void RenderView::updateMatrices() { if (m_renderCameraNode && m_renderCameraLens && m_renderCameraLens->isEnabled()) { - const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); - setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + auto transform = m_renderCameraNode->renderComponent<Transform>(); + if (m_renderCameraNode->isParentLessTransform() && transform && transform->hasViewMatrix()) { + // optimization: if the entity is a QCamera and it doesn't have a parent with a transform component, + // then we use the frontend version of the viewMatrix to avoid extra calculations that may introduce + // rounding errors + setViewMatrix(transform->viewMatrix()); + } else { + const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); + setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + } setViewProjectionMatrix(m_renderCameraLens->projection() * viewMatrix()); // To get the eyePosition of the camera, we need to use the inverse of the @@ -1410,7 +1391,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, ParameterInfoList // only update values of uniforms that have changed // If parameters add been added/removed, the command would have been rebuild // and the parameter pack would be empty - const bool updateUniformsOnly = command->m_parameterPack.submissionUniformIndices().size() > 0; + const bool updateUniformsOnly = !command->m_parameterPack.submissionUniformIndices().empty(); if (!updateUniformsOnly) { // Builds the QUniformPack, sets shader standard uniforms and store attributes name / glname @@ -1465,7 +1446,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, ParameterInfoList break; const Entity *lightEntity = lightSource.entity; const Matrix4x4 lightWorldTransform = *(lightEntity->worldTransform()); - const Vector3D worldPos = lightWorldTransform * Vector3D(0.0f, 0.0f, 0.0f); + const Vector3D worldPos = lightWorldTransform.map(Vector3D(0.0f, 0.0f, 0.0f)); for (Light *light : lightSource.lights) { if (!light->isEnabled()) continue; diff --git a/src/plugins/renderers/rhi/renderer/renderview_p.h b/src/plugins/renderers/rhi/renderer/renderview_p.h index 6c8ea7541..5ef63f4be 100644 --- a/src/plugins/renderers/rhi/renderer/renderview_p.h +++ b/src/plugins/renderers/rhi/renderer/renderview_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RENDERVIEW_H #define QT3DRENDER_RENDER_RHI_RENDERVIEW_H diff --git a/src/plugins/renderers/rhi/renderer/renderviewbuilder.cpp b/src/plugins/renderers/rhi/renderer/renderviewbuilder.cpp index 832f550eb..035848e13 100644 --- a/src/plugins/renderers/rhi/renderer/renderviewbuilder.cpp +++ b/src/plugins/renderers/rhi/renderer/renderviewbuilder.cpp @@ -1,46 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "renderviewbuilder_p.h" #include <Qt3DRender/private/qrenderaspect_p.h> - -#include <QThread> +#include <Qt3DCore/private/qaspectjobmanager_p.h> QT_BEGIN_NAMESPACE @@ -63,7 +26,7 @@ RenderViewBuilder::RenderViewBuilder(Render::FrameGraphNode *leafNode, int rende // In some cases having less jobs is better (especially on fast cpus where // splitting just adds more overhead). Ideally, we should try to set the value // depending on the platform/CPU/nbr of cores - m_optimalParallelJobCount = QThread::idealThreadCount(); + m_optimalParallelJobCount = Qt3DCore::QAspectJobManager::idealThreadCount(); } RenderViewInitializerJobPtr RenderViewBuilder::renderViewJob() const diff --git a/src/plugins/renderers/rhi/renderer/renderviewbuilder_p.h b/src/plugins/renderers/rhi/renderer/renderviewbuilder_p.h index f7c4f606c..eb7484d15 100644 --- a/src/plugins/renderers/rhi/renderer/renderviewbuilder_p.h +++ b/src/plugins/renderers/rhi/renderer/renderviewbuilder_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RENDERVIEWBUILDER_H #define QT3DRENDER_RENDER_RHI_RENDERVIEWBUILDER_H diff --git a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline.cpp b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline.cpp index 824609b7f..feec0aceb 100644 --- a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline.cpp +++ b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "rhigraphicspipeline_p.h" diff --git a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h index ff619c56d..020d4583a 100644 --- a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h +++ b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RHIGRAPHICSPIPELINE_H #define QT3DRENDER_RENDER_RHI_RHIGRAPHICSPIPELINE_H @@ -51,7 +15,7 @@ // We mean it. // -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <rhihandle_types_p.h> #include <pipelineuboset_p.h> #include <Qt3DCore/qnodeid.h> diff --git a/src/plugins/renderers/rhi/renderer/rhirendertarget.cpp b/src/plugins/renderers/rhi/renderer/rhirendertarget.cpp index c7f4d0720..db11f5f88 100644 --- a/src/plugins/renderers/rhi/renderer/rhirendertarget.cpp +++ b/src/plugins/renderers/rhi/renderer/rhirendertarget.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "rhirendertarget_p.h" QT_BEGIN_NAMESPACE diff --git a/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h index 74a85196d..f699db687 100644 --- a/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h +++ b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_RHIRENDERTARGET_H #define QT3DRENDER_RENDER_RHI_RHIRENDERTARGET_H @@ -51,7 +15,7 @@ // We mean it. // -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <rhihandle_types_p.h> #include <private/attachmentpack_p.h> @@ -66,9 +30,16 @@ struct RHIRenderTarget { // Note: only used when rendering to a FBO // as we don't want to remove the default framebuffer's rendertarget // TODO: at some point separate render target and graphics pipeline as the former can be reused - QRhiRenderTarget *renderTarget{}; - QRhiRenderPassDescriptor *renderPassDescriptor{}; - QRhiRenderBuffer *depthStencilBuffer{}; + QRhiRenderTarget *renderTarget{ nullptr }; + QRhiRenderPassDescriptor *renderPassDescriptor{ nullptr }; + QRhiRenderBuffer *depthStencilBuffer{ nullptr }; + + enum class BackBuffer { + None, + Left, + Right, + }; + BackBuffer backBuffer{ BackBuffer::None }; ~RHIRenderTarget(); void cleanup(); diff --git a/src/plugins/renderers/rhi/renderer/rhishader.cpp b/src/plugins/renderers/rhi/renderer/rhishader.cpp index 5684e27ce..5c170346f 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader.cpp +++ b/src/plugins/renderers/rhi/renderer/rhishader.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "rhishader_p.h" #include <QMutexLocker> @@ -332,7 +296,14 @@ void RHIShader::recordAllUniforms(UBO_Member &uboMember, // We iterate through all the [l][n][m] by building [0][0][0] and incrementing forEachArrayAccessor(member.arrayDims, [&](const QString &str) { // "foo.bar[1][2]" - m_unqualifiedUniformNames << (fullMemberName + str); + const QString unqualifiedMemberName = (fullMemberName + str); + m_unqualifiedUniformNames << unqualifiedMemberName; + + // Record as an individual uniform + m_uniformsNames.push_back(unqualifiedMemberName); + const int nameId = StringToInt::lookupId(unqualifiedMemberName); + m_uniformsNamesIds.push_back(nameId); + // Question : does it make sense to also record foo[0], foo[0][0], etc... // if there are e.g. 3 dimensions ? }); @@ -344,20 +315,29 @@ void RHIShader::recordAllUniforms(UBO_Member &uboMember, m_structNamesIds.push_back(StringToInt::lookupId(m_structNames.back())); }); - // Record the struct members - for (const QShaderDescription::BlockVariable& bv : member.structMembers) { - forEachArrayAccessor(member.arrayDims, [&] (const QString& str) { + // Record the array times the struct members => entry[i].struct_member + forEachArrayAccessor(member.arrayDims, [&] (const QString& str) { + UBO_Member arrayMember {StringToInt::lookupId(fullMemberName + str), {}, {}}; + // Record all struct member into the array member[i] + for (const QShaderDescription::BlockVariable& bv : member.structMembers) { //recordAllUniforms("baz", "foo.bar[1][2].") const QString structMemberNamePrefix = fullMemberName + str + QLatin1Char('.'); UBO_Member innerMember {StringToInt::lookupId(structMemberNamePrefix), bv, {}}; recordAllUniforms(innerMember, structMemberNamePrefix); - uboMember.structMembers.push_back(innerMember); - }); - } + arrayMember.structMembers.push_back(innerMember); + } + // When dealing with an array of structs, we treat structMembers as arrayMembers + uboMember.structMembers.push_back(arrayMember); + }); } else { // Final member (not array or struct) // Replace nameId with final nameId name uboMember.nameId = StringToInt::lookupId(fullMemberName); + + // Record as an individual uniform + m_uniformsNames.push_back(fullMemberName); + const int nameId = StringToInt::lookupId(fullMemberName); + m_uniformsNamesIds.push_back(nameId); } } @@ -370,7 +350,7 @@ bool isGeneratedUBOName(const QByteArray& arr) return false; if (!arr.startsWith('_')) return false; - for (int i = 1, N = arr.size(); i < N; i++) { + for (qsizetype i = 1, N = arr.size(); i < N; i++) { if (arr[i] < '0' || arr[i] > '9') return false; } @@ -454,7 +434,7 @@ void RHIShader::introspect() std::vector<UBO_Member> uboMembers; uboMembers.reserve(ubo.members.size()); - for (const QShaderDescription::BlockVariable &member : qAsConst(ubo.members)) { + for (const QShaderDescription::BlockVariable &member : std::as_const(ubo.members)) { m_uniformsNames.push_back(member.name); const int nameId = StringToInt::lookupId(member.name); m_uniformsNamesIds.push_back(nameId); @@ -492,7 +472,7 @@ QHash<QString, ShaderUniform> RHIShader::activeUniformsForUniformBlock(int block ShaderUniformBlock RHIShader::uniformBlockForBlockIndex(int blockIndex) const noexcept { - for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) { + for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) { if (m_uniformBlocks[i].m_index == blockIndex) { return m_uniformBlocks[i]; } @@ -502,7 +482,7 @@ ShaderUniformBlock RHIShader::uniformBlockForBlockIndex(int blockIndex) const no ShaderUniformBlock RHIShader::uniformBlockForBlockNameId(int blockNameId) const noexcept { - for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) { + for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) { if (m_uniformBlocks[i].m_nameId == blockNameId) { return m_uniformBlocks[i]; } @@ -512,7 +492,7 @@ ShaderUniformBlock RHIShader::uniformBlockForBlockNameId(int blockNameId) const ShaderUniformBlock RHIShader::uniformBlockForBlockName(const QString &blockName) const noexcept { - for (int i = 0, m = m_uniformBlocks.size(); i < m; ++i) { + for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) { if (m_uniformBlocks[i].m_name == blockName) { return m_uniformBlocks[i]; } @@ -539,7 +519,7 @@ ShaderUniformBlock RHIShader::uniformBlockForInstanceNameId(int instanceNameId) ShaderStorageBlock RHIShader::storageBlockForBlockIndex(int blockIndex) const noexcept { - for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { + for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { if (m_shaderStorageBlocks[i].m_index == blockIndex) return m_shaderStorageBlocks[i]; } @@ -548,7 +528,7 @@ ShaderStorageBlock RHIShader::storageBlockForBlockIndex(int blockIndex) const no ShaderStorageBlock RHIShader::storageBlockForBlockNameId(int blockNameId) const noexcept { - for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { + for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { if (m_shaderStorageBlocks[i].m_nameId == blockNameId) return m_shaderStorageBlocks[i]; } @@ -557,7 +537,7 @@ ShaderStorageBlock RHIShader::storageBlockForBlockNameId(int blockNameId) const ShaderStorageBlock RHIShader::storageBlockForBlockName(const QString &blockName) const noexcept { - for (int i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { + for (size_t i = 0, m = m_shaderStorageBlockNames.size(); i < m; ++i) { if (m_shaderStorageBlocks[i].m_name == blockName) return m_shaderStorageBlocks[i]; } @@ -586,72 +566,71 @@ bool RHIShader::hasActiveVariables() const noexcept || !m_uniformBlockNamesIds.empty() || !m_shaderStorageBlockNamesIds.empty(); } -void RHIShader::setShaderCode(const std::vector<QByteArray> &shaderCode) +void RHIShader::setShaderCode(std::vector<QByteArray> shaderCode) { - m_shaderCode.clear(); - Qt3DCore::append(m_shaderCode, shaderCode); + m_shaderCode = std::move(shaderCode); } -void RHIShader::setFragOutputs(const QHash<QString, int> &fragOutputs) +void RHIShader::setFragOutputs(QHash<QString, int> fragOutputs) { { QMutexLocker lock(&m_mutex); - m_fragOutputs = fragOutputs; + m_fragOutputs = std::move(fragOutputs); } // updateDNA(); } -const QHash<QString, int> RHIShader::fragOutputs() const +const QHash<QString, int> &RHIShader::fragOutputs() const { QMutexLocker lock(&m_mutex); return m_fragOutputs; } -void RHIShader::initializeAttributes(const std::vector<ShaderAttribute> &attributesDescription) +void RHIShader::initializeAttributes(std::vector<ShaderAttribute> attributesDescription) { - m_attributes = attributesDescription; - m_attributesNames.resize(attributesDescription.size()); - m_attributeNamesIds.resize(attributesDescription.size()); - for (int i = 0, m = attributesDescription.size(); i < m; i++) { - m_attributesNames[i] = attributesDescription[i].m_name; + m_attributes = std::move(attributesDescription); + m_attributesNames.resize(m_attributes.size()); + m_attributeNamesIds.resize(m_attributes.size()); + for (size_t i = 0, m = m_attributes.size(); i < m; i++) { + m_attributesNames[i] = m_attributes[i].m_name; m_attributes[i].m_nameId = StringToInt::lookupId(m_attributesNames[i]); m_attributeNamesIds[i] = m_attributes[i].m_nameId; - qCDebug(Shaders) << "Active Attribute " << attributesDescription[i].m_name; + qCDebug(Shaders) << "Active Attribute " << m_attributes[i].m_name; } } -void RHIShader::initializeSamplers(const std::vector<ShaderAttribute> &samplersDescription) +void RHIShader::initializeSamplers(std::vector<ShaderAttribute> samplersDescription) { - m_samplers = samplersDescription; - m_samplerNames.resize(samplersDescription.size()); - m_samplerIds.resize(samplersDescription.size()); - for (int i = 0, m = samplersDescription.size(); i < m; i++) { - m_samplerNames[i] = samplersDescription[i].m_name; + m_samplers = std::move(samplersDescription); + m_samplerNames.resize(m_samplers.size()); + m_samplerIds.resize(m_samplers.size()); + for (size_t i = 0, m = m_samplers.size(); i < m; i++) { + m_samplerNames[i] = m_samplers[i].m_name; m_samplers[i].m_nameId = StringToInt::lookupId(m_samplerNames[i]); m_samplerIds[i] = m_samplers[i].m_nameId; - qCDebug(Shaders) << "Active sampler " << samplersDescription[i].m_name; + qCDebug(Shaders) << "Active sampler " << m_samplers[i].m_name; } } -void RHIShader::initializeImages(const std::vector<ShaderAttribute> &imagesDescription) +void RHIShader::initializeImages(std::vector<ShaderAttribute> imagesDescription) { - m_images = imagesDescription; - m_imageNames.resize(imagesDescription.size()); - m_imageIds.resize(imagesDescription.size()); - for (int i = 0, m = imagesDescription.size(); i < m; i++) { - m_imageNames[i] = imagesDescription[i].m_name; + m_images = std::move(imagesDescription); + m_imageNames.resize(m_images.size()); + m_imageIds.resize(m_images.size()); + for (size_t i = 0, m = m_images.size(); i < m; i++) { + m_imageNames[i] = m_images[i].m_name; m_images[i].m_nameId = StringToInt::lookupId(m_imageNames[i]); m_imageIds[i] = m_images[i].m_nameId; - qCDebug(Shaders) << "Active image " << imagesDescription[i].m_name; + qCDebug(Shaders) << "Active image " << m_images[i].m_name; } } -void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &uniformBlockDescription) +void RHIShader::initializeUniformBlocks(std::vector<ShaderUniformBlock> uniformBlockDescription) { - m_uniformBlocks = uniformBlockDescription; - m_uniformBlockNames.resize(uniformBlockDescription.size()); - m_uniformBlockNamesIds.resize(uniformBlockDescription.size()); - for (int i = 0, m = uniformBlockDescription.size(); i < m; ++i) { + m_uniformBlocks = std::move(uniformBlockDescription); + m_uniformBlockNames.resize(m_uniformBlocks.size()); + m_uniformBlockNamesIds.resize(m_uniformBlocks.size()); + for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) { m_uniformBlockNames[i] = m_uniformBlocks[i].m_name; m_uniformBlockNamesIds[i] = StringToInt::lookupId(m_uniformBlockNames[i]); m_uniformBlocks[i].m_nameId = m_uniformBlockNamesIds[i]; @@ -667,7 +646,7 @@ void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &u QHash<QString, ShaderUniform> activeUniformsInBlock; while (uniformsIt != uniformsEnd && uniformNamesIt != uniformNamesEnd) { - if (uniformsIt->m_blockIndex == uniformBlockDescription[i].m_index) { + if (uniformsIt->m_blockIndex == m_uniformBlocks[i].m_index) { QString uniformName = *uniformNamesIt; if (!m_uniformBlockNames[i].isEmpty() && !uniformName.startsWith(m_uniformBlockNames[i])) @@ -680,19 +659,19 @@ void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &u ++uniformsIt; ++uniformNamesIt; } - m_uniformBlockIndexToShaderUniforms.insert(uniformBlockDescription[i].m_index, + m_uniformBlockIndexToShaderUniforms.insert(m_uniformBlocks[i].m_index, activeUniformsInBlock); } } void RHIShader::initializeShaderStorageBlocks( - const std::vector<ShaderStorageBlock> &shaderStorageBlockDescription) + std::vector<ShaderStorageBlock> shaderStorageBlockDescription) { - m_shaderStorageBlocks = shaderStorageBlockDescription; - m_shaderStorageBlockNames.resize(shaderStorageBlockDescription.size()); - m_shaderStorageBlockNamesIds.resize(shaderStorageBlockDescription.size()); + m_shaderStorageBlocks = std::move(shaderStorageBlockDescription); + m_shaderStorageBlockNames.resize(m_shaderStorageBlocks.size()); + m_shaderStorageBlockNamesIds.resize(m_shaderStorageBlocks.size()); - for (int i = 0, m = shaderStorageBlockDescription.size(); i < m; ++i) { + for (size_t i = 0, m = m_shaderStorageBlocks.size(); i < m; ++i) { m_shaderStorageBlockNames[i] = m_shaderStorageBlocks[i].m_name; m_shaderStorageBlockNamesIds[i] = StringToInt::lookupId(m_shaderStorageBlockNames[i]); m_shaderStorageBlocks[i].m_nameId = m_shaderStorageBlockNamesIds[i]; diff --git a/src/plugins/renderers/rhi/renderer/rhishader_p.h b/src/plugins/renderers/rhi/renderer/rhishader_p.h index d23c85938..f566f03ae 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader_p.h +++ b/src/plugins/renderers/rhi/renderer/rhishader_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_GLSHADER_P_H #define QT3DRENDER_RENDER_RHI_GLSHADER_P_H @@ -56,7 +20,7 @@ #include <Qt3DRender/qshaderprogram.h> #include <QMutex> #include <QtGui/private/qshader_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> QT_BEGIN_NAMESPACE @@ -88,8 +52,8 @@ public: bool isLoaded() const { return m_isLoaded; } void setLoaded(bool loaded) { m_isLoaded = loaded; } - void setFragOutputs(const QHash<QString, int> &fragOutputs); - const QHash<QString, int> fragOutputs() const; + void setFragOutputs(QHash<QString, int> fragOutputs); + const QHash<QString, int> &fragOutputs() const; inline const std::vector<int> &uniformsNamesIds() const { return m_uniformsNamesIds; } inline const std::vector<int> &standardUniformNameIds() const { return m_standardUniformNamesIds; } @@ -130,7 +94,7 @@ public: bool hasUniform(int nameId) const noexcept; bool hasActiveVariables() const noexcept; - void setShaderCode(const std::vector<QByteArray> &shaderCode); + void setShaderCode(std::vector<QByteArray> shaderCode); const std::vector<QByteArray> &shaderCode() const; const QShader &shaderStage(QShader::Stage stage) const noexcept { return m_stages[stage]; } @@ -182,12 +146,11 @@ private: // Private so that only SubmissionContext can call it friend class SubmissionContext; - void initializeAttributes(const std::vector<ShaderAttribute> &attributesDescription); - void initializeUniformBlocks(const std::vector<ShaderUniformBlock> &uniformBlockDescription); - void - initializeShaderStorageBlocks(const std::vector<ShaderStorageBlock> &shaderStorageBlockDescription); - void initializeSamplers(const std::vector<ShaderAttribute> &samplerDescription); - void initializeImages(const std::vector<ShaderAttribute> &imageDescription); + void initializeAttributes(std::vector<Qt3DRender::Render::Rhi::ShaderAttribute> attributesDescription); + void initializeUniformBlocks(std::vector<ShaderUniformBlock> uniformBlockDescription); + void initializeShaderStorageBlocks(std::vector<ShaderStorageBlock> shaderStorageBlockDescription); + void initializeSamplers(std::vector<ShaderAttribute> samplerDescription); + void initializeImages(std::vector<ShaderAttribute> imageDescription); void recordAllUniforms(UBO_Member &uboMember, QString parentName); std::vector<UBO_Block> m_uboBlocks; diff --git a/src/plugins/renderers/rhi/renderer/shaderparameterpack.cpp b/src/plugins/renderers/rhi/renderer/shaderparameterpack.cpp index 46f6480e4..c07769afc 100644 --- a/src/plugins/renderers/rhi/renderer/shaderparameterpack.cpp +++ b/src/plugins/renderers/rhi/renderer/shaderparameterpack.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "shaderparameterpack_p.h" @@ -86,7 +50,7 @@ void ShaderParameterPack::setTexture(const int glslNameId, int uniformArrayIndex void ShaderParameterPack::setImage(const int glslNameId, int uniformArrayIndex, Qt3DCore::QNodeId id) { - for (int i=0, m = m_images.size(); i < m; ++i) { + for (size_t i=0, m = m_images.size(); i < m; ++i) { if (m_images[i].glslNameId != glslNameId || m_images[i].uniformArrayIndex != uniformArrayIndex) continue; diff --git a/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h b/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h index c69a33f17..be110828f 100644 --- a/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h +++ b/src/plugins/renderers/rhi/renderer/shaderparameterpack_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_SHADERPARAMETERPACK_P_H #define QT3DRENDER_RENDER_RHI_SHADERPARAMETERPACK_P_H diff --git a/src/plugins/renderers/rhi/renderer/shadervariables_p.h b/src/plugins/renderers/rhi/renderer/shadervariables_p.h index bb8d205b5..de4f5207e 100644 --- a/src/plugins/renderers/rhi/renderer/shadervariables_p.h +++ b/src/plugins/renderers/rhi/renderer/shadervariables_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QT3DRENDER_RENDER_RHI_SHADERVARIABLES_P_H #define QT3DRENDER_RENDER_RHI_SHADERVARIABLES_P_H |