Jump to content
  • Advertisement
Sign in to follow this  

Question about hardware instancing and HLSL semantics

This topic is 472 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

When you are doing instancing your input layout might look something like this (from Frank Luna's DX11 book):

const D3D11_INPUT_ELEMENT_DESC InputLayoutDesc::InstancedBasic32[8] = 
    {"NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    { "WORLD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "WORLD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "WORLD", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 48, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 64,  D3D11_INPUT_PER_INSTANCE_DATA, 1 }

My question is, what semantic names can I give to the instanced data? Here Frank Luna is using "WORLD" but I don't see that mentioned on any HLSL semantic reference pages. Also, what if I want to pass a view-projection matrix as part of the instanced data? Can I use "VIEWPROJ"? Does it matter? Does the runtime use the semantics at all?


Share this post

Link to post
Share on other sites
51 minutes ago, belfegor said:

Can you elaborate why is it better to use Structured buffer for instance data?


Because :)

The per instance vertex stream is the historic solution at an age GPU where not able to read memory randomly and Westeros was still the land of the children of the forest ! When you use that, you quickly reach the limit of streams and definitely increase the API calls to bind vertex buffers, plus they are only received by the vertex shader, any property for the pixel shader have to be sent by interpolators, it is costly. I could add more reasons but you get the idea.


With a structured buffer, you can store as many information as you want, you can read them at any stage, the only requirement is to forward the instance id. The only quirk is to provide manually the offset to the first instance, usually in a constant buffer as sv_instanceid start at 0.



Share this post

Link to post
Share on other sites
Just now, Infinisearch said:

Is this really that much of a concern?

It can :) , depends of your data set load, if you draw pong, go for it, if you draw starcraft 2, forget about it ! You can also be concerned with under the hood shader recompilation as there is no input assembly hardware anymore and all is memory fetch inline in the shader code anyway. The only benefit to use vertex stream is to make use of typed load from exotic formats. Really, it is not a big loss in practice.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!