Jump to content
  • Advertisement
Sign in to follow this  
KaiserJohan

DX11 Bound but unused vertex buffers affecting the input layout?

This topic is 696 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

 

  1. Will each vertex still load those (unused) buffers, negatively impacting performance?
  2. 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.

Share this post


Link to post
Share on other sites
Advertisement

1. Nope, the Input Layout says which attributes to load, and which 'slots' to load them from. If a buffer happens to be bound to an unused slot, no big deal.

Note that this isn't true in other API's. In certain other API's, it's a big performance pitfall to accidentally have extra attributes bound to the pipeline like this :)

2. There's no need to unbind buffers, no. I unbind buffers in debug builds, but not shipping builds as a debugging tool.

However... When you bind a resource to the device, the device holds a reference to that resource until it is unbound. If you release a buffer but it happens to still be bound to the infrequently used slot #15, then the memory won't actually be release until you do unbind it. I generally call ID3D11DeviceContext::ClearState at the beginning of every frame to avoid long-term bindings like this.

Edited by Hodgman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!