From a6f23f40534d796ca549ca179a02bd4906d60f44 Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Fri, 15 Mar 2024 10:47:44 +0100 Subject: Skinning: check the type of the joint indices Joint indices are normally used as integer, Qt just defined it as float only if the rhi backend could not support integer attributes. However now it will be followed by the model definition. Instead, if the rhi backend could not support it, a warning will be generated. Fixes: QTBUG-123316 Pick-to: 6.5 Change-Id: I6dc8b6ef863e8601d2874feaa05c21cb7b9e4a86 Reviewed-by: Jonas Karlsson (cherry picked from commit 1c981cd280189d099f01973900cec27f77921100) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit a694e036cc15a938e6782933cde65d0eedb4db98) Reviewed-by: Inho Lee --- .../rendererimpl/qssglayerrenderdata.cpp | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/runtimerender/rendererimpl/qssglayerrenderdata.cpp b/src/runtimerender/rendererimpl/qssglayerrenderdata.cpp index 5f972a6e..5ae54457 100644 --- a/src/runtimerender/rendererimpl/qssglayerrenderdata.cpp +++ b/src/runtimerender/rendererimpl/qssglayerrenderdata.cpp @@ -1243,6 +1243,18 @@ bool QSSGLayerRenderData::prepareModelsForRender(const RenderableNodeEntries &re if (maybeDebugDraw && debugDrawSystem->isEnabled(QSSGDebugDrawSystem::Mode::MeshLodNormal)) debugDrawSystem->debugNormals(*bufferManager, theModelContext, theSubset, subsetLevelOfDetail, (theModelCenter - camera->getGlobalPos()).length() * 0.01); + static auto checkF32TypeIndex = [&rhiCtx](QRhiVertexInputAttribute::Format f) { + if ((f == QRhiVertexInputAttribute::Format::Float4) + || (f == QRhiVertexInputAttribute::Format::Float3) + || (f == QRhiVertexInputAttribute::Format::Float2) + || (f == QRhiVertexInputAttribute::Format::Float)) { + return true; + } + if (!rhiCtx->rhi()->isFeatureSupported(QRhi::IntAttributes)) + qWarning() << "WARN: Model has non-integer type indices for skinning but current RHI backend doesn't support it!"; + return false; + }; + if (theMaterialObject->type == QSSGRenderGraphObject::Type::DefaultMaterial || theMaterialObject->type == QSSGRenderGraphObject::Type::PrincipledMaterial || theMaterialObject->type == QSSGRenderGraphObject::Type::SpecularGlossyMaterial) { @@ -1261,8 +1273,11 @@ bool QSSGLayerRenderData::prepareModelsForRender(const RenderableNodeEntries &re const auto boneCount = model.skin ? model.skin->boneCount : model.skeleton ? model.skeleton->boneCount : 0; renderer->defaultMaterialShaderKeyProperties().m_boneCount.setValue(theGeneratedKey, boneCount); - renderer->defaultMaterialShaderKeyProperties().m_usesFloatJointIndices.setValue( - theGeneratedKey, !rhiCtx->rhi()->isFeatureSupported(QRhi::IntAttributes)); + if (auto idJoint = theSubset.rhi.ia.inputs.indexOf(QSSGRhiInputAssemblerState::JointSemantic); idJoint != -1) { + const auto attr = theSubset.rhi.ia.inputLayout.attributeAt(idJoint); + renderer->defaultMaterialShaderKeyProperties().m_usesFloatJointIndices.setValue(theGeneratedKey, checkF32TypeIndex(attr->format())); + } + // Instancing renderer->defaultMaterialShaderKeyProperties().m_usesInstancing.setValue(theGeneratedKey, usesInstancing); // Morphing @@ -1319,8 +1334,10 @@ bool QSSGLayerRenderData::prepareModelsForRender(const RenderableNodeEntries &re const auto boneCount = model.skin ? model.skin->boneCount : model.skeleton ? model.skeleton->boneCount : 0; renderer->defaultMaterialShaderKeyProperties().m_boneCount.setValue(theGeneratedKey, boneCount); - renderer->defaultMaterialShaderKeyProperties().m_usesFloatJointIndices.setValue( - theGeneratedKey, !rhiCtx->rhi()->isFeatureSupported(QRhi::IntAttributes)); + if (auto idJoint = theSubset.rhi.ia.inputs.indexOf(QSSGRhiInputAssemblerState::JointSemantic); idJoint != -1) { + const auto attr = theSubset.rhi.ia.inputLayout.attributeAt(idJoint); + renderer->defaultMaterialShaderKeyProperties().m_usesFloatJointIndices.setValue(theGeneratedKey, checkF32TypeIndex(attr->format())); + } // Instancing bool usesInstancing = theModelContext.model.instancing() -- cgit v1.2.3