0
\$\begingroup\$

I'm studying HLSL cookbook. In that sample code, author used a lot of register sementic.

like this

cbuffer cbPointLightDomain : register( b0 )
{
    float4x4 LightProjection : packoffset( c0 );
}

cbuffer cbPointLightPixel : register( b1 )
{
    float3 PointLightPos : packoffset( c0 );
    float PointLightRangeRcp : packoffset( c0.w );
    float3 PointColor : packoffset( c1 );
    float2 LightPerspectiveValues : packoffset( c2 );
}

what is benefit of this?

actually I erased every register keywords and ran program.

the result is completely fine.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

register exists to let you manually explicitly specify which register to use for a particular shader variable, in the event that you need to for some particular purpose or because you like to be explicit and not rely on how the compiler will pick registers (which may change over time).

It is optional, which is why you can remove it and everything still works.

\$\endgroup\$
1
  • \$\begingroup\$ The main use for it is to make sure different shaders bind the same data to the same register. This lets you more efficiently share Constant Buffers between different shaders, and only update/bind them with 'frequency of update' instead of rebinding/updating them every Draw \$\endgroup\$ Oct 11, 2017 at 19:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .