From 4bae053c5dd756444c415bd6ddb121f7e3873b83 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 12 Aug 2019 13:00:28 +0200 Subject: RenderView:buildDrawRenderCommands: only set Command members that matter Some values where overridden in Renderer::prepareSubmission so no point in spending time setting them in the first place Change-Id: Iceea0cbe044b883d0797aebd7487f8f6b29ac542 Reviewed-by: Mike Krus --- .../renderers/opengl/renderer/rendercommand_p.h | 4 +- src/render/renderers/opengl/renderer/renderer.cpp | 11 ++--- .../renderers/opengl/renderer/renderview.cpp | 54 ++-------------------- 3 files changed, 10 insertions(+), 59 deletions(-) (limited to 'src/render/renderers') diff --git a/src/render/renderers/opengl/renderer/rendercommand_p.h b/src/render/renderers/opengl/renderer/rendercommand_p.h index 67e02d35b..61cc6d17d 100644 --- a/src/render/renderers/opengl/renderer/rendercommand_p.h +++ b/src/render/renderers/opengl/renderer/rendercommand_p.h @@ -89,7 +89,7 @@ public: // A QAttribute pack might be interesting // This is a temporary fix in the meantime, to remove the hacked methods in Technique - QVector m_attributes; + QVector m_activeAttributes; float m_depth; int m_changeCost; @@ -103,7 +103,7 @@ public: CommandType m_type; int m_workGroups[3]; - // Values filled for draw calls + // Values filled for draw calls by Renderer (in prepare Submission) GLsizei m_primitiveCount; QGeometryRenderer::PrimitiveType m_primitiveType; int m_restartIndexValue; diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp index a05e128a2..af9a6e7e6 100644 --- a/src/render/renderers/opengl/renderer/renderer.cpp +++ b/src/render/renderers/opengl/renderer/renderer.cpp @@ -896,7 +896,7 @@ void Renderer::prepareCommandsSubmission(const QVector &renderView if (rGeometry->isDirty()) m_dirtyGeometry.push_back(rGeometry); - if (!command->m_attributes.isEmpty() && (requiresFullVAOUpdate || requiresPartialVAOUpdate)) { + if (!command->m_activeAttributes.isEmpty() && (requiresFullVAOUpdate || requiresPartialVAOUpdate)) { Profiling::GLTimeRecorder recorder(Profiling::VAOUpload); // Activate shader m_submissionContext->activateShader(shader->dna()); @@ -918,9 +918,8 @@ void Renderer::prepareCommandsSubmission(const QVector &renderView // Prepare the ShaderParameterPack based on the active uniforms of the shader shader->prepareUniforms(command->m_parameterPack); - // TO DO: The step below could be performed by the RenderCommand builder job { // Scoped to show extent - command->m_isValid = !command->m_attributes.empty(); + command->m_isValid = !command->m_activeAttributes.empty(); if (!command->m_isValid) continue; @@ -941,7 +940,7 @@ void Renderer::prepareCommandsSubmission(const QVector &renderView indirectAttribute = attribute; break; case QAttribute::VertexAttribute: { - if (command->m_attributes.contains(attribute->nameId())) + if (command->m_activeAttributes.contains(attribute->nameId())) estimatedCount = qMax(attribute->count(), estimatedCount); break; } @@ -2174,7 +2173,7 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry, if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate) m_submissionContext->specifyIndices(buffer); // Vertex Attribute - } else if (command->m_attributes.contains(attribute->nameId())) { + } else if (command->m_activeAttributes.contains(attribute->nameId())) { if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate) { // Find the location for the attribute const QVector shaderAttributes = shader->attributes(); @@ -2219,7 +2218,7 @@ bool Renderer::requiresVAOAttributeUpdate(Geometry *geometry, continue; if ((attribute->attributeType() == QAttribute::IndexAttribute && attribute->isDirty()) || - (command->m_attributes.contains(attribute->nameId()) && attribute->isDirty())) + (command->m_activeAttributes.contains(attribute->nameId()) && attribute->isDirty())) return true; } return false; diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp index b00f2c473..420b32325 100644 --- a/src/render/renderers/opengl/renderer/renderview.cpp +++ b/src/render/renderers/opengl/renderer/renderview.cpp @@ -632,21 +632,18 @@ QVector RenderView::buildDrawRenderCommands(const QVectorcomponentUuid(); const HMaterial materialHandle = entity->componentHandle(); const QVector renderPassData = m_parameters.value(materialComponentId); - HGeometry geometryHandle = m_manager->lookupHandle(geometryRenderer->geometryId()); - Geometry *geometry = m_manager->data(geometryHandle); // 1 RenderCommand per RenderPass pass on an Entity with a Mesh for (const RenderPassParameterData &passData : renderPassData) { // Add the RenderPass Parameters RenderCommand *command = new RenderCommand(); + command->m_geometryRenderer = geometryRendererHandle; + command->m_geometry = m_manager->geometryManager()->lookupHandle(geometryRenderer->geometryId()); // Project the camera-to-object-center vector onto the camera // view vector. This gives a depth value suitable as the key // for BackToFront sorting. command->m_depth = Vector3D::dotProduct(entity->worldBoundingVolume()->center() - m_data.m_eyePos, m_data.m_eyeViewDir); - - command->m_geometry = geometryHandle; - command->m_geometryRenderer = geometryRendererHandle; command->m_material = materialHandle; // For RenderPass based states we use the globally set RenderState // if no renderstates are defined as part of the pass. That means: @@ -686,51 +683,6 @@ QVector RenderView::buildDrawRenderCommands(const QVectorm_isValid = !command->m_attributes.empty(); - if (command->m_isValid) { - // Update the draw command with what's going to be needed for the drawing - uint primitiveCount = geometryRenderer->vertexCount(); - uint estimatedCount = 0; - Attribute *indexAttribute = nullptr; - - const QVector attributeIds = geometry->attributes(); - for (Qt3DCore::QNodeId attributeId : attributeIds) { - Attribute *attribute = m_manager->attributeManager()->lookupResource(attributeId); - if (attribute->attributeType() == QAttribute::IndexAttribute) - indexAttribute = attribute; - else if (command->m_attributes.contains(attribute->nameId())) - estimatedCount = qMax(attribute->count(), estimatedCount); - } - - // Update the draw command with all the information required for the drawing - command->m_drawIndexed = (indexAttribute != nullptr); - if (command->m_drawIndexed) { - command->m_indexAttributeDataType = GraphicsContext::glDataTypeFromAttributeDataType(indexAttribute->vertexBaseType()); - command->m_indexAttributeByteOffset = indexAttribute->byteOffset(); - } - - // Use the count specified by the GeometryRender - // If not specified use the indexAttribute count if present - // Otherwise tries to use the count from the attribute with the highest count - if (primitiveCount == 0) { - if (indexAttribute) - primitiveCount = indexAttribute->count(); - else - primitiveCount = estimatedCount; - } - - command->m_primitiveCount = primitiveCount; - command->m_primitiveType = geometryRenderer->primitiveType(); - command->m_primitiveRestartEnabled = geometryRenderer->primitiveRestartEnabled(); - command->m_restartIndexValue = geometryRenderer->restartIndexValue(); - command->m_firstInstance = geometryRenderer->firstInstance(); - command->m_instanceCount = geometryRenderer->instanceCount(); - command->m_firstVertex = geometryRenderer->firstVertex(); - command->m_indexOffset = geometryRenderer->indexOffset(); - command->m_verticesPerPatch = geometryRenderer->verticesPerPatch(); - } - commands.append(command); } } @@ -1049,7 +1001,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, // Set default attributes for (const int attributeNameId : attributeNamesIds) - command->m_attributes.push_back(attributeNameId); + command->m_activeAttributes.push_back(attributeNameId); // Parameters remaining could be // -> uniform scalar / vector -- cgit v1.2.3