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

register keyword in HLSL?

Started by 215648 Jun 27, 2015 at 10:42 AM 3 replies 7.8k views
Original Post
215648
215648

What does register keyword in HLSL mean? I've seen people using it while defining constant buffers like this:

cbuffer cbPerFrame : register(c0.... some weird things here)

{

};

Also, what do these numbers mean in register keyword? like register(b0), register(cb0), etc. I used to use effects11 before and at that time, I didn't had to bother with these things.

Juliean
Juliean

Also, what do these numbers mean in register keyword? like register(b0), register(cb0), etc. I used to use effects11 before and at that time, I didn't had to bother with these things.

Every shader-resource in DirectX11 is bound to a certain slot, with calls like PSSetShaderResource, etc... . Ususally in the shader, resources are assigned to slots in the order they are declared, like first cbuffer would be 0, second would be 1. With register() you can make sure that a certain resource always has a fixed slot. This can be mandatory if e.g. your application defines a global camera c-buffer which is always bound to slot 3. If a shader uses only this cbuffer, without register it would be assumed at slot 0.

215648
215648


Also, what do these numbers mean in register keyword? like register(b0), register(cb0), etc. I used to use effects11 before and at that time, I didn't had to bother with these things.


Every shader-resource in DirectX11 is bound to a certain slot, with calls like PSSetShaderResource, etc... . Ususally in the shader, resources are assigned to slots in the order they are declared, like first cbuffer would be 0, second would be 1. With register() you can make sure that a certain resource always has a fixed slot. This can be mandatory if e.g. your application defines a global camera c-buffer which is always bound to slot 3. If a shader uses only this cbuffer, without register it would be assumed at slot 0.
What is cb0 or c0 or something like that? What does c/cb mean?
Juliean
Juliean

What is cb0 or c0 or something like that? What does c/cb mean?

You can read on their exact definition on the MSDN, which should be your go-to-instantly for any such questions about shaders:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd607359%28v=vs.85%29.aspx

In short, the letter marks the type of register/resource you are specifying, and the number the slot. so c0 is first constant-buffer, t3 is fourth texture, s7 is eight sampler unit... For usage, consider my first reply.

215648
215648


What is cb0 or c0 or something like that? What does c/cb mean?


You can read on their exact definition on the MSDN, which should be your go-to-instantly for any such questions about shaders:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd607359(v=vs.85).aspx

In short, the letter marks the type of register/resource you are specifying, and the number the slot. so c0 is first constant-buffer, t3 is fourth texture, s7 is eight sampler unit... For usage, consider my first reply.
Okay, thanks!

Topic Locked

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

Sign in to reply to this topic.