Skip to main content
GameDev.net gamedev.net
🔒 Locked

Structured Buffer size in hlsl 5.1

Started by twomags Oct 31, 2020 at 11:12 AM 3 replies 13.1k views
Original Post
twomags
twomags

Hi all.

I have a Skinned Mesh class working nicely in DirectX 12 but I'm finding it's limited to 29 bones. I am using an instance buffer with a few variables (World matrix, material, alpha etc…) and the bone transforms for each instance.

Declared in the shader as:

struct SkinnedInstanceData

{

float4x4 World;

float4x4 TexTransform;

uint MaterialIndex;

float Alpha;

uint ShaderSwitches;

uint Pad;

float4x4 BoneTransforms[29];

};

StructuredBuffer gSkinnedInstanceData : register(t1, space1);

If I change the 29 bones to 30 or more I get a run-time shader compile error as follows:

error X4599: structured buffer elements cannot be larger than 2048 bytes in vs_5_1 (actual size 2064 bytes)

This appears to be a hardware limit on size (the same for constant buffers possibly?)

Obviously 29 bones is quite a small count! How is anyone else managing to get more bone data to the GPU?

Thanks for your help!

Ian

turanszkij
turanszkij

What you want to do in this case is instead have two buffers:

  • ConstantBuffer should be storing WorldMatrix, MaterialIndex, and other per mesh data
  • StructuredBuffer should be storing a matrix for every bone. You don't have to declare in the shader how many bones it will be able to hold.

An other thing, is that you probably don't need float4x4 for bone transforms (because you don't have perspective matrices in there probably). So a float4x3 or float3x4 should be enough.

twomags
twomags

@turanszkij

Thank you very much!

Does that mean I create a StructuredBuffer big enough to fit (Mesh1→ numer of bones * Mesh1→max number of instances) + (Mesh2→number of bones * Mesh2→max number of instances) + (Mesh3→… etc)

Then keep a record of the starting point within that StructuredBuffer of the first bone of each instance of each mesh I need to draw?

I could use the spare uint (Pad) to store this while I'm filling the SkinnedInstanceData buffer and the bone data StructuredBuffer on the CPU side.

This sounds like a possible plan. I'll have a go and post the result.

Thanks again for your help.

Ian

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.