Push Constant Buffer with Float Array in HLSL

Recently, I’ve encountered an issue that DX12 couldn’t update push constant buffer correctly as I expected. And Following is the structure defined in HLSL:

Then, application would call SetGraphicsRoot32BitConstants of Dx12DebugGraphicsCommandList to uploading push constant buffer. Unfortunately, the data would not upload to push constants correctly. So, I noticed MSDN which said following specification:

“A constant buffer is a specialized buffer resource that is accessed like a buffer. Each constant buffer can hold up to 4096 vectors; each vector contains up to four 32-bit values. You can bind up to 14 constant buffers per pipeline stage (2 additional slots are reserved for internal use).” Please refer to MSDN related shader constants for detail.

So, I changed the structure which used float4 instead of float to define constant buffer due to packing rule:

As the result, process the index as below:

Eventually, push constant buffer could be uploaded correctly.

赞 (3)


电子邮件地址不会被公开。 必填项已用*标注