I have a questions regarding vertex buffers and input layouts.
My mesh drawing code is essentially like this:
void DX11Mesh::Draw() { mContext->IASetVertexBuffers(VertexBufferSlot::VERTEX_BUFFER_SLOT_POSITIONS, 1, &mVertexBuffer.p, &gPositionStride, &gStaticOffset); if (mNormalBuffer) mContext->IASetVertexBuffers(VertexBufferSlot::VERTEX_BUFFER_SLOT_NORMALS, 1, &mNormalBuffer.p, &gNormalStride, &gStaticOffset); if (mTexcoordBuffer) mContext->IASetVertexBuffers(VertexBufferSlot::VERTEX_BUFFER_SLOT_TEXCOORDS, 1, &mTexcoordBuffer.p, &gTexcoordStride, &gStaticOffset); if (mTangentBuffer) mContext->IASetVertexBuffers(VertexBufferSlot::VERTEX_BUFFER_SLOT_TANGENTS, 1, &mTangentBuffer.p, &gTangentStride, &gStaticOffset); if (mHasBones) mContext->IASetVertexBuffers(VertexBufferSlot::VERTEX_BUFFER_SLOT_BONE_WEIGHTS, 1, &mBoneWeightBuffer.p, &gBoneWeightStride, &gStaticOffset); mContext->IASetIndexBuffer(mIndexBuffer, DXGI_FORMAT_R16_UINT, 0); mContext->DrawIndexed(mNumIndices, 0, 0); }
Say the mesh has all the components (POSITIONS, NORMALS, TEXCOORDS, TANGENTS, BONE_WEIGHTS) but in some pass (like a shadowmap pass where the input layout only specifies the POSITIONS and BONE_WEIGHTS) the other vertex buffers (NORMALS, TEXCOORDS, TANGENTS) are still bound.
- Will each vertex still load those (unused) buffers, negatively impacting performance?
- Also does it make sense to "unbind" the vertex buffers after use? for example Mesh1 uses bones but Mesh2 dosn't, yet BONE_WEIGHTS will still be bound during Mesh2 pass.