summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-07-13 14:40:44 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-07-16 10:55:10 +0200
commit3b290d1c820f272268836057bcb489dff7531e75 (patch)
tree546544170368e5f91afc898f12945e2c83feb2d2 /src
parenta0ae0a9912efef181d1f7c25ba0ec48878978f26 (diff)
Add AttributeInfo to allow comparing RenderCommand geometry layouts
Also start adding tests Change-Id: Ia9d7fb9beaf8623c47bfafd6f5f0751c6571f82f Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/renderers/rhi/CMakeLists.txt79
-rw-r--r--src/plugins/renderers/rhi/managers/rhiresourcemanagers.cpp13
-rw-r--r--src/plugins/renderers/rhi/managers/rhiresourcemanagers_p.h7
-rw-r--r--src/plugins/renderers/rhi/renderer/rendercommand.cpp16
-rw-r--r--src/plugins/renderers/rhi/renderer/rendercommand_p.h13
-rw-r--r--src/plugins/renderers/rhi/renderer/renderview.cpp15
-rw-r--r--src/plugins/renderers/rhi/rhi.cmake9
7 files changed, 132 insertions, 20 deletions
diff --git a/src/plugins/renderers/rhi/CMakeLists.txt b/src/plugins/renderers/rhi/CMakeLists.txt
index cf1e1e496..4ee31a20f 100644
--- a/src/plugins/renderers/rhi/CMakeLists.txt
+++ b/src/plugins/renderers/rhi/CMakeLists.txt
@@ -1,5 +1,63 @@
# Generated from rhi.pro.
+set(rhiRendererSources graphicshelpers/submissioncontext.cpp graphicshelpers/submissioncontext_p.h
+ io/rhibuffer.cpp io/rhibuffer_p.h
+ managers/rhihandle_types_p.h
+ managers/rhiresourcemanagers.cpp managers/rhiresourcemanagers_p.h
+ renderer/commandexecuter.cpp renderer/commandexecuter_p.h
+ renderer/logging.cpp renderer/logging_p.h
+ renderer/rendercommand.cpp renderer/rendercommand_p.h
+ renderer/renderer.cpp renderer/renderer_p.h
+ renderer/renderview.cpp renderer/renderview_p.h
+ renderer/renderviewbuilder.cpp renderer/renderviewbuilder_p.h
+ renderer/rhigraphicspipeline.cpp renderer/rhigraphicspipeline_p.h
+ renderer/rhirendertarget.cpp renderer/rhirendertarget_p.h
+ renderer/rhishader.cpp renderer/rhishader_p.h
+ renderer/shaderparameterpack.cpp renderer/shaderparameterpack_p.h
+ renderer/shadervariables_p.h
+ renderer/pipelineuboset.cpp renderer/pipelineuboset_p.h
+ textures/renderbuffer.cpp textures/renderbuffer_p.h
+ textures/texture.cpp textures/texture_p.h
+)
+
+#####################################################################
+## Static library used for Unit Tests:
+#####################################################################
+
+if(QT_FEATURE_private_tests)
+
+ add_library(RhiRendererLib STATIC ${rhiRendererSources})
+
+ target_include_directories(RhiRendererLib PUBLIC
+ managers
+ io
+ graphicshelpers
+ renderer
+ textures
+ )
+
+ target_link_libraries(RhiRendererLib
+ PUBLIC
+ Qt::3DCore
+ Qt::3DCorePrivate
+ Qt::3DRender
+ Qt::3DRenderPrivate
+ Qt::Core
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ Qt::ShaderTools
+ Qt::ShaderToolsPrivate
+ )
+
+ target_compile_definitions(RhiRendererLib PRIVATE
+ BUILD_QT3D_MODULE
+ QT_BUILDING_QT
+ QT_NO_FOREACH
+ )
+
+endif()
+
#####################################################################
## RhiRendererPlugin Plugin:
#####################################################################
@@ -8,33 +66,16 @@ qt_internal_add_plugin(RhiRendererPlugin
OUTPUT_NAME rhirenderer
TYPE renderers
SOURCES
- graphicshelpers/submissioncontext.cpp graphicshelpers/submissioncontext_p.h
- io/rhibuffer.cpp io/rhibuffer_p.h
main.cpp
- managers/rhihandle_types_p.h
- managers/rhiresourcemanagers.cpp managers/rhiresourcemanagers_p.h
- renderer/commandexecuter.cpp renderer/commandexecuter_p.h
- renderer/logging.cpp renderer/logging_p.h
- renderer/rendercommand.cpp renderer/rendercommand_p.h
- renderer/renderer.cpp renderer/renderer_p.h
- renderer/renderview.cpp renderer/renderview_p.h
- renderer/renderviewbuilder.cpp renderer/renderviewbuilder_p.h
- renderer/rhigraphicspipeline.cpp renderer/rhigraphicspipeline_p.h
- renderer/rhirendertarget.cpp renderer/rhirendertarget_p.h
- renderer/rhishader.cpp renderer/rhishader_p.h
- renderer/shaderparameterpack.cpp renderer/shaderparameterpack_p.h
- renderer/shadervariables_p.h
- renderer/pipelineuboset.cpp renderer/pipelineuboset_p.h
- textures/renderbuffer.cpp textures/renderbuffer_p.h
- textures/texture.cpp textures/texture_p.h
+ ${rhiRendererSources}
DEFINES
+ BUILD_QT3D_MODULE
QT_BUILDING_QT
QT_NO_FOREACH QT_NO_FOREACH
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}
graphicshelpers
io
- jobs
managers
renderer
textures
diff --git a/src/plugins/renderers/rhi/managers/rhiresourcemanagers.cpp b/src/plugins/renderers/rhi/managers/rhiresourcemanagers.cpp
index c8718bb4d..385fa24b4 100644
--- a/src/plugins/renderers/rhi/managers/rhiresourcemanagers.cpp
+++ b/src/plugins/renderers/rhi/managers/rhiresourcemanagers.cpp
@@ -81,6 +81,19 @@ void RHIResourceManagers::releaseAllResources()
releaseAll(m_rhiGraphicsPipelineManager);
}
+int RHIGraphicsPipelineManager::getIdForAttributeVec(const std::vector<AttributeInfo> &attributesInfo)
+{
+ auto it = std::find(m_attributesInfo.begin(),
+ m_attributesInfo.end(),
+ attributesInfo);
+ if (it == m_attributesInfo.end()) {
+ m_attributesInfo.emplace_back(attributesInfo);
+ return m_attributesInfo.size() - 1;
+ }
+ return std::distance(m_attributesInfo.begin(), it);
+}
+
+
} // Rhi
} // Render
diff --git a/src/plugins/renderers/rhi/managers/rhiresourcemanagers_p.h b/src/plugins/renderers/rhi/managers/rhiresourcemanagers_p.h
index 3bc90ff0c..c6caa75d1 100644
--- a/src/plugins/renderers/rhi/managers/rhiresourcemanagers_p.h
+++ b/src/plugins/renderers/rhi/managers/rhiresourcemanagers_p.h
@@ -58,6 +58,7 @@
#include <rhishader_p.h>
#include <rhigraphicspipeline_p.h>
#include <rhirendertarget_p.h>
+#include <rendercommand_p.h>
#include <Qt3DRender/private/apishadermanager_p.h>
#include <Qt3DRender/private/renderstateset_p.h>
@@ -100,6 +101,12 @@ class Q_AUTOTEST_EXPORT RHIGraphicsPipelineManager
{
public:
RHIGraphicsPipelineManager() { }
+
+ int getIdForAttributeVec(const std::vector<AttributeInfo> &attributesInfo);
+
+private:
+ using AttributeInfoVec= std::vector<AttributeInfo>;
+ std::vector<AttributeInfoVec> m_attributesInfo;
};
class Q_AUTOTEST_EXPORT RHIResourceManagers
diff --git a/src/plugins/renderers/rhi/renderer/rendercommand.cpp b/src/plugins/renderers/rhi/renderer/rendercommand.cpp
index 7b9bd0c35..9e82192f5 100644
--- a/src/plugins/renderers/rhi/renderer/rendercommand.cpp
+++ b/src/plugins/renderers/rhi/renderer/rendercommand.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "rendercommand_p.h"
-#include "renderer/rhigraphicspipeline_p.h"
+#include "rhigraphicspipeline_p.h"
QT_BEGIN_NAMESPACE
@@ -105,6 +105,20 @@ bool operator==(const RenderCommand &a, const RenderCommand &b) noexcept
&& a.m_isValid == b.m_isValid && a.m_computeCommand == b.m_computeCommand);
}
+bool operator==(const AttributeInfo &a, const AttributeInfo &b)
+{
+ return a.nameId == b.nameId &&
+ a.classification == b.classification &&
+ a.stride == b.stride &&
+ a.offset == b.offset &&
+ a.divisor == b.divisor;
+}
+
+bool operator!=(const AttributeInfo &a, const AttributeInfo &b)
+{
+ return !(a == b);
+}
+
} // namespace Rhi
} // namespace Render
} // namespace Qt3DRender
diff --git a/src/plugins/renderers/rhi/renderer/rendercommand_p.h b/src/plugins/renderers/rhi/renderer/rendercommand_p.h
index 07a13e583..42a305122 100644
--- a/src/plugins/renderers/rhi/renderer/rendercommand_p.h
+++ b/src/plugins/renderers/rhi/renderer/rendercommand_p.h
@@ -104,6 +104,18 @@ struct CommandUBO
static_assert(sizeof(CommandUBO) == 6 * (16 * sizeof(float)) + 2 * (12 * sizeof(float)),
"UBO doesn't match std140");
+struct Q_AUTOTEST_EXPORT AttributeInfo
+{
+ int nameId = -1;
+ QRhiVertexInputBinding::Classification classification = QRhiVertexInputBinding::PerVertex;
+ size_t stride = 0;
+ size_t offset = 0;
+ size_t divisor = 0;
+};
+
+Q_AUTOTEST_EXPORT bool operator==(const AttributeInfo &a, const AttributeInfo &b);
+Q_AUTOTEST_EXPORT bool operator!=(const AttributeInfo &a, const AttributeInfo &b);
+
class Q_AUTOTEST_EXPORT RenderCommand
{
public:
@@ -155,6 +167,7 @@ public:
bool m_primitiveRestartEnabled;
bool m_isValid;
+ std::vector<AttributeInfo> m_attributeInfo;
QVarLengthArray<QRhiCommandBuffer::VertexInput, 8> vertex_input;
const Attribute *indexAttribute {};
diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp
index 7798611a3..931f50a97 100644
--- a/src/plugins/renderers/rhi/renderer/renderview.cpp
+++ b/src/plugins/renderers/rhi/renderer/renderview.cpp
@@ -875,6 +875,11 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit
{ // Scoped to show extent
+ // Build of list of Attribute Layout information which
+ // allows use to compare the layout of geometries against
+ // one another.
+ // { name, classification, stride, offset, divisor }
+
// Update the draw command with what's going to be needed for the drawing
int primitiveCount = geometryRenderer->vertexCount();
int estimatedCount = 0;
@@ -882,6 +887,8 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit
Attribute *indirectAttribute = nullptr;
const QList<Qt3DCore::QNodeId> attributeIds = geometry->attributes();
+ command.m_attributeInfo.clear();
+ command.m_attributeInfo.reserve(attributeIds.size());
for (Qt3DCore::QNodeId attributeId : attributeIds) {
using namespace Qt3DCore;
@@ -901,6 +908,14 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit
Q_UNREACHABLE();
break;
}
+
+ if (attribute->attributeType() == QAttribute::VertexAttribute) {
+ command.m_attributeInfo.push_back({ attribute->nameId(),
+ attribute->divisor() == 0 ? QRhiVertexInputBinding::PerVertex : QRhiVertexInputBinding::PerInstance,
+ size_t(attribute->byteStride()),
+ size_t(attribute->byteOffset()),
+ size_t(attribute->divisor()) });
+ }
}
command.m_drawIndexed = (indexAttribute != nullptr);
diff --git a/src/plugins/renderers/rhi/rhi.cmake b/src/plugins/renderers/rhi/rhi.cmake
new file mode 100644
index 000000000..292cb0103
--- /dev/null
+++ b/src/plugins/renderers/rhi/rhi.cmake
@@ -0,0 +1,9 @@
+function(qt3d_setup_rhi_renderer_target target)
+
+ set(rhiplugindir ${PROJECT_SOURCE_DIR}/src/plugins/renderers/rhi)
+ target_link_libraries(${target}
+ PRIVATE
+ RhiRendererLib
+ )
+
+endfunction()