diff options
Diffstat (limited to 'src/plugins/renderers/rhi')
22 files changed, 280 insertions, 313 deletions
diff --git a/src/plugins/renderers/rhi/CMakeLists.txt b/src/plugins/renderers/rhi/CMakeLists.txt index 4e7febe57..9e0699a8d 100644 --- a/src/plugins/renderers/rhi/CMakeLists.txt +++ b/src/plugins/renderers/rhi/CMakeLists.txt @@ -56,7 +56,6 @@ if(QT_FEATURE_private_tests) target_compile_definitions(RhiRendererLib PRIVATE BUILD_QT3D_MODULE QT_BUILDING_QT - QT_NO_FOREACH ) endif() @@ -95,6 +94,9 @@ qt_internal_add_plugin(RhiRendererPlugin Qt::ShaderToolsPrivate ) +# QTransform conflicts +set_target_properties(RhiRendererPlugin PROPERTIES UNITY_BUILD OFF) + #### Keys ignored in scope 1:.:.:rhi.pro:<TRUE>: # DISTFILES = "rhirenderer.json" diff --git a/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri b/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri deleted file mode 100644 index e156d3ce5..000000000 --- a/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri +++ /dev/null @@ -1,9 +0,0 @@ -#DEFINES += QT3D_RENDER_ASPECT_OPENGL_DEBUG - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/submissioncontext_p.h - -SOURCES += \ - $$PWD/submissioncontext.cpp diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp index 32fd7fcf2..f0dcb044f 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -41,46 +41,17 @@ #include <private/qdebug_p.h> #include <QSurface> #include <QWindow> -#include <QtShaderTools/private/qshaderbaker_p.h> +#include <rhi/qrhi.h> +#include <rhi/qshaderbaker.h> -#ifdef Q_OS_WIN -#include <QtGui/private/qrhid3d11_p.h> -#endif - -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) -#include <QtGui/private/qrhimetal_p.h> -#endif - -#ifndef QT_NO_OPENGL -#include <QtGui/private/qrhigles2_p.h> -#endif - -#if QT_CONFIG(vulkan) -#include <QtGui/private/qrhivulkan_p.h> -#endif #include <bitset> QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { -static QHash<unsigned int, SubmissionContext *> static_contexts; - -unsigned int nextFreeContextId() noexcept -{ - for (unsigned int i = 0; i < 0xffff; ++i) { - if (!static_contexts.contains(i)) - return i; - } - - qFatal("Couldn't find free context ID"); - return 0; -} - namespace { //RHIBuffer::Type attributeTypeToGLBufferType(QAttribute::AttributeType type) noexcept @@ -442,6 +413,13 @@ void applyStateHelper(const StencilMask *state, QRhiGraphicsPipeline *gp) noexce gp->setStencilReadMask(std::get<1>(values)); } +void applyStateHelper(const LineWidth *state, QRhiGraphicsPipeline *gp) noexcept +{ + const auto values = state->values(); + gp->setLineWidth(std::get<0>(values)); + // no GL_LINE_SMOOTH equivalent on RHI +} + static QShader::Stage rhiShaderStage(QShaderProgram::ShaderType type) noexcept { switch (type) { @@ -468,7 +446,6 @@ SubmissionContext::SubmissionContext() : m_initialized(false), m_ownsRhiCtx(false), m_drivenExternally(false), - m_id(nextFreeContextId()), m_material(nullptr), m_renderer(nullptr), m_rhi(nullptr), @@ -481,7 +458,6 @@ SubmissionContext::SubmissionContext() m_fallbackSurface(nullptr) #endif { - static_contexts[m_id] = this; m_contextInfo.m_api = QGraphicsApiFilter::RHI; // We set those version numbers because QShaderGenerator wants major > 0 @@ -492,9 +468,6 @@ SubmissionContext::SubmissionContext() SubmissionContext::~SubmissionContext() { releaseResources(); - - Q_ASSERT(static_contexts[m_id] == this); - static_contexts.remove(m_id); } void SubmissionContext::initialize() @@ -1420,26 +1393,45 @@ void preprocessRHIShader(std::vector<QByteArray> &shaderCodes) } } -int glslVersionForFormat(const QSurfaceFormat &format) noexcept +QShaderVersion glslVersionForFormat(const QSurfaceFormat &format) noexcept { const int major = format.majorVersion(); const int minor = format.minorVersion(); - - static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { - { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, - { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, - { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, - }; - - const auto it = glVersionToGLSLVersion.find({ major, minor }); - if (it == glVersionToGLSLVersion.end()) { - if (major < 3) { - return 120; + const auto type = format.renderableType(); + + if (type != QSurfaceFormat::OpenGLES) { + static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { + { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, + { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, + { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return 120; + } else { + return major * 100 + minor * 10; + } } else { - return major * 100 + minor * 10; + return *it; + } + } + else { + static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { + { { 3, 2 }, 320 }, { { 3, 1 }, 310 }, { { 3, 0 }, 300 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return {100, QShaderVersion::GlslEs}; + } else { + return {major * 100 + minor * 10, QShaderVersion::GlslEs}; + } + } else { + return {*it, QShaderVersion::GlslEs}; } - } else { - return *it; } } } @@ -1525,12 +1517,14 @@ void SubmissionContext::loadShader(Shader *shaderNode, ShaderManager *shaderMana const std::vector<Qt3DCore::QNodeId> &sharedShaderIds = rhiShaderManager->shaderIdsForProgram(rhiShader); if (sharedShaderIds.size() == 1) { - // Shader in the cache hasn't been loaded yet - // We want a copy of the QByteArray as preprocessRHIShader will - // modify them - std::vector<QByteArray> shaderCodes = shaderNode->shaderCode(); - preprocessRHIShader(shaderCodes); - rhiShader->setShaderCode(shaderCodes); + { + // Shader in the cache hasn't been loaded yet + // We want a copy of the QByteArray as preprocessRHIShader will + // modify them + std::vector<QByteArray> shaderCodes = shaderNode->shaderCode(); + preprocessRHIShader(shaderCodes); + rhiShader->setShaderCode(std::move(shaderCodes)); + } const ShaderCreationInfo loadResult = createShaderProgram(rhiShader); shaderNode->setStatus(loadResult.linkSucceeded ? QShaderProgram::Ready diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h index 350ed00b6..bb639ccfc 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h @@ -27,8 +27,8 @@ #include <shadervariables_p.h> #include <rhihandle_types_p.h> #include <QSurface> -#include <QtGui/private/qrhi_p.h> #include <QOffscreenSurface> +#include <rhi/qrhi.h> QT_BEGIN_NAMESPACE @@ -174,7 +174,6 @@ private: bool m_initialized; bool m_ownsRhiCtx; bool m_drivenExternally; - const unsigned int m_id; QHash<Qt3DCore::QNodeId, HRHIBuffer> m_renderBufferHash; diff --git a/src/plugins/renderers/rhi/io/io.pri b/src/plugins/renderers/rhi/io/io.pri deleted file mode 100644 index bac06ba95..000000000 --- a/src/plugins/renderers/rhi/io/io.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/rhibuffer.cpp - -HEADERS += \ - $$PWD/rhibuffer_p.h - diff --git a/src/plugins/renderers/rhi/io/rhibuffer.cpp b/src/plugins/renderers/rhi/io/rhibuffer.cpp index 868c49cfe..9607e8c32 100644 --- a/src/plugins/renderers/rhi/io/rhibuffer.cpp +++ b/src/plugins/renderers/rhi/io/rhibuffer.cpp @@ -3,7 +3,8 @@ #include "rhibuffer_p.h" #include <submissioncontext_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> + QT_BEGIN_NAMESPACE namespace Qt3DRender { diff --git a/src/plugins/renderers/rhi/managers/managers.pri b/src/plugins/renderers/rhi/managers/managers.pri deleted file mode 100644 index de3f29b30..000000000 --- a/src/plugins/renderers/rhi/managers/managers.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/rhihandle_types_p.h \ - $$PWD/rhiresourcemanagers_p.h - -SOURCES += \ - $$PWD/rhiresourcemanagers.cpp diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp index 598c32ef9..8cffaac4f 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp @@ -10,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> @@ -243,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()), }; @@ -323,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())); } } @@ -597,7 +598,7 @@ void PipelineUBOSet::uploadUBOsForCommand(const RenderCommand &command, uploadUniform(uniforms, ubo, arrayStructMember, distanceToCommand, - i * blockVariable.size / arr0); + int(i * blockVariable.size / arr0)); } } } else { // Array of scalars diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h index aa4ed00d2..55c3bbb60 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h @@ -16,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_p.h b/src/plugins/renderers/rhi/renderer/rendercommand_p.h index dc5d97f93..392650385 100644 --- a/src/plugins/renderers/rhi/renderer/rendercommand_p.h +++ b/src/plugins/renderers/rhi/renderer/rendercommand_p.h @@ -26,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> @@ -57,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 diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index 45485a6c7..4a25bb464 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -93,8 +93,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { @@ -336,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; @@ -613,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; @@ -759,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) @@ -769,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) @@ -780,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) @@ -1143,9 +1163,17 @@ 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(); @@ -1185,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; @@ -1234,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 @@ -1241,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();; @@ -1256,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; } } @@ -1442,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; @@ -1475,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 = @@ -1536,7 +1585,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) 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(); @@ -1552,7 +1601,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) 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(); @@ -1588,7 +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); @@ -1626,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, @@ -1648,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 @@ -1662,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; @@ -1842,7 +1891,7 @@ void Renderer::updateResources() // 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(rhiTexture) }; + const Qt3DCore::QNodeIdVector referenceTextureIds = { rhiTextureManager->texNodeIdForRHITexture.value(rhiTexture) }; // Store properties and referenceTextureIds Texture::TextureUpdateInfo updateInfo; updateInfo.properties = info.properties; @@ -1964,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) { @@ -2203,7 +2252,7 @@ void Renderer::jobsDone(Qt3DCore::QAspectManager *manager) } // Do we need to notify any texture about property changes? - if (m_updatedTextureProperties.size() > 0) + if (!m_updatedTextureProperties.empty()) sendTextureChangesToFrontend(manager); sendDisablesToFrontend(manager); @@ -2224,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 }; @@ -2238,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; @@ -2315,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) { @@ -2379,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()); } @@ -2404,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(); @@ -2481,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()); @@ -2494,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()); @@ -2503,7 +2552,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re command.indexAttribute = attrib; break; } - case QAttribute::DrawIndirectAttribute: + case Qt3DCore::QAttribute::DrawIndirectAttribute: RHI_UNIMPLEMENTED; break; } @@ -2642,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) { @@ -2707,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 @@ -2725,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); @@ -2746,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; } @@ -2794,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"; } @@ -2807,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 5ff7d9d44..000000000 --- a/src/plugins/renderers/rhi/renderer/renderer.pri +++ /dev/null @@ -1,28 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/rendercommand.cpp \ - $$PWD/renderer.cpp \ - $$PWD/renderview.cpp \ - $$PWD/renderviewbuilder.cpp \ - $$PWD/rhigraphicspipeline.cpp \ - $$PWD/rhirendertarget.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/rhirendertarget_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 463aec7d3..6f4590ef5 100644 --- a/src/plugins/renderers/rhi/renderer/renderer_p.h +++ b/src/plugins/renderers/rhi/renderer/renderer_p.h @@ -37,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> diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp index 60a447ae6..c8ae4e7f1 100644 --- a/src/plugins/renderers/rhi/renderer/renderview.cpp +++ b/src/plugins/renderers/rhi/renderer/renderview.cpp @@ -1164,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))); + } } }); } @@ -1172,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 @@ -1376,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 diff --git a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h index 3f6c0c672..020d4583a 100644 --- a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h +++ b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h @@ -15,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_p.h b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h index bfb57568d..f699db687 100644 --- a/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h +++ b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h @@ -15,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> @@ -30,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 5a308fa37..5c170346f 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader.cpp +++ b/src/plugins/renderers/rhi/renderer/rhishader.cpp @@ -566,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 (size_t 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 (size_t 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 (size_t 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 (size_t 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]; @@ -647,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])) @@ -660,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 (size_t 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 ec46a39f8..f566f03ae 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader_p.h +++ b/src/plugins/renderers/rhi/renderer/rhishader_p.h @@ -20,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 @@ -52,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; } @@ -94,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]; } @@ -146,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/rhi.pri b/src/plugins/renderers/rhi/rhi.pri deleted file mode 100644 index 5fdb77c00..000000000 --- a/src/plugins/renderers/rhi/rhi.pri +++ /dev/null @@ -1,16 +0,0 @@ - -include (renderer/renderer.pri) -include (io/io.pri) -include (textures/textures.pri) -include (graphicshelpers/graphicshelpers.pri) -include (managers/managers.pri) - -INCLUDEPATH += $$PWD - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH - -gcov { - QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage - QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage -} diff --git a/src/plugins/renderers/rhi/rhi.pro b/src/plugins/renderers/rhi/rhi.pro deleted file mode 100644 index a767223f4..000000000 --- a/src/plugins/renderers/rhi/rhi.pro +++ /dev/null @@ -1,36 +0,0 @@ -TARGET = rhirenderer - -PLUGIN_TYPE = renderers -PLUGIN_CLASS_NAME = RhiRendererPlugin -load(qt_plugin) - -QT += core-private gui-private 3dcore 3dcore-private 3drender 3drender-private - -greaterThan(QT_MAJOR_VERSION, 5) { - QT += shadertools shadertools-private -} - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH - -# We use QT_AUTOTEST_EXPORT to test the plug-ins, which needs QT_BUILDING_QT -DEFINES += QT_BUILDING_QT - -SOURCES += \ - main.cpp - -DISTFILES += \ - rhirenderer.json - -include(rhi.pri) - -qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_AVX2 -} - -qtConfig(qt3d-simd-sse2):!qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE2 -} - diff --git a/src/plugins/renderers/rhi/textures/texture.cpp b/src/plugins/renderers/rhi/textures/texture.cpp index 6bbfb1d13..4561aa936 100644 --- a/src/plugins/renderers/rhi/textures/texture.cpp +++ b/src/plugins/renderers/rhi/textures/texture.cpp @@ -5,7 +5,7 @@ #include "texture_p.h" #include <private/qdebug_p.h> -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <QDebug> #include <Qt3DCore/private/vector_helper_p.h> #include <Qt3DRender/qtexture.h> @@ -19,8 +19,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { @@ -193,15 +191,12 @@ void filterLayersAndFaces(const QTextureImageData &data, F f) f(createUploadEntry(level, 0, data.data(0, 0, level))); } } else if (layers > 1 && faces == 1) { - qWarning() << Q_FUNC_INFO << "Unsupported case, see QTBUG-83343"; - /* for (int layer = 0; layer < data.layers(); layer++) { - for (int level = 0; level < mipLevels; level++) { + for (int level = 0; level < miplevels; level++) { f(createUploadEntry(level, layer, data.data(layer, 0, level))); } } - */ - } else if (faces > 1 && layers == 1) { + } else if (faces > 1 && layers == 1) { // Mip levels do not seem to be supported by cubemaps... for (int face = 0; face < data.faces(); face++) { f(createUploadEntry(0, face, data.data(0, face, 0))); @@ -218,8 +213,7 @@ void filterLayerAndFace(int layer, int face, F f) if (layer == 0 && face == 0) { f(0); } else if (layer > 0 && face == 0) { - qWarning() << Q_FUNC_INFO << "Unsupported case, see QTBUG-83343"; - // f(layer); + f(layer); } else if (layer == 0 && face > 0) { f(face); } else { @@ -632,7 +626,20 @@ QRhiTexture *RHITexture::buildRhiTexture(SubmissionContext *ctx) } } - QRhiTexture *rhiTexture = ctx->rhi()->newTexture(rhiFormat, pixelSize, sampleCount, rhiFlags); + if(actualTarget == QAbstractTexture::Target3D) + rhiFlags |= QRhiTexture::ThreeDimensional; + + QRhiTexture *rhiTexture = nullptr; + switch (m_properties.target) { + case QAbstractTexture::Target1DArray: + case QAbstractTexture::Target2DArray: + //This will setup the array flags correctly + rhiTexture = ctx->rhi()->newTextureArray(rhiFormat, m_properties.layers, pixelSize, sampleCount, rhiFlags); + break; + default: + rhiTexture = ctx->rhi()->newTexture(rhiFormat, pixelSize, sampleCount, rhiFlags); + break; + } if (!rhiTexture->create()) { qWarning() << Q_FUNC_INFO << "creating QRhiTexture failed"; @@ -721,7 +728,7 @@ void RHITexture::uploadRhiTextureData(SubmissionContext *ctx) }); } - if (uploadEntries.size() > 0) { + if (!uploadEntries.empty()) { QRhiTextureUploadDescription uploadDescription; uploadDescription.setEntries(uploadEntries.begin(), uploadEntries.end()); ctx->m_currentUpdates->uploadTexture(m_rhi, uploadDescription); diff --git a/src/plugins/renderers/rhi/textures/textures.pri b/src/plugins/renderers/rhi/textures/textures.pri deleted file mode 100644 index dd9e6404f..000000000 --- a/src/plugins/renderers/rhi/textures/textures.pri +++ /dev/null @@ -1,9 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/renderbuffer.cpp \ - $$PWD/texture.cpp - -HEADERS += \ - $$PWD/renderbuffer_p.h \ - $$PWD/texture_p.h |