From 63790184c79d2765ea726488726cd9f2b43b91d1 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 13 Oct 2020 15:47:27 +0200 Subject: rhi: Fix up vertex inputs with matrices In order to prevent too much voodoo in backends like D3D11, the input layout is expected to specify the slice index for vecX that are part of an unrolled matrix. Also deoptimize the instancing manual test to exercise a matrix too instead of just vectors. Change-Id: If2dcbcbc483645ce2420b2f87dda765b95da6e80 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhid3d11.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/gui/rhi/qrhid3d11.cpp') diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 48e626106c..ce954c9fe0 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -4019,15 +4019,29 @@ bool QD3D11GraphicsPipeline::create() d3dTopology = toD3DTopology(m_topology); if (!vsByteCode.isEmpty()) { + QByteArrayList matrixSliceSemantics; QVarLengthArray inputDescs; for (auto it = m_vertexInputLayout.cbeginAttributes(), itEnd = m_vertexInputLayout.cendAttributes(); it != itEnd; ++it) { D3D11_INPUT_ELEMENT_DESC desc; memset(&desc, 0, sizeof(desc)); - // the output from SPIRV-Cross uses TEXCOORD as the semantic - desc.SemanticName = "TEXCOORD"; - desc.SemanticIndex = UINT(it->location()); + // The output from SPIRV-Cross uses TEXCOORD as the + // semantic, except for matrices that are unrolled into consecutive + // vec2/3/4s attributes and need TEXCOORD_ as + // SemanticName and row/column index as SemanticIndex. + const int matrixSlice = it->matrixSlice(); + if (matrixSlice < 0) { + desc.SemanticName = "TEXCOORD"; + desc.SemanticIndex = UINT(it->location()); + } else { + QByteArray sem; + sem.resize(16); + qsnprintf(sem.data(), sem.size(), "TEXCOORD%d_", it->location() - matrixSlice); + matrixSliceSemantics.append(sem); + desc.SemanticName = matrixSliceSemantics.last().constData(); + desc.SemanticIndex = UINT(matrixSlice); + } desc.Format = toD3DAttributeFormat(it->format()); desc.InputSlot = UINT(it->binding()); desc.AlignedByteOffset = it->offset(); -- cgit v1.2.3