Jump to content
  • Advertisement
Sign in to follow this  
sobeit

OpenGL what is register in HLSL?

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

Hi all,

 

I'm having trouble understanding the register concept in HLSL. 

my understanding is that it's not real register like cpu register, but rather just a buffer binding point like in OpenGL, right?

and I saw some code snippet using :register(b0), others using :register(s[8]) and register(s), what's the difference of using square brackets?

 

thanks

 

Share this post


Link to post
Share on other sites
Advertisement

This should help you: http://msdn.microsoft.com/en-us/library/windows/desktop/dd607359(v=vs.85).aspx

 

A register is basically as you described it, a binding point, though it doesn't need to be a buffer, although you can also describe it as an package offset.

:register(s[8])

That will basically say that a sampler is located at the sampler port 8. But in other cases/examples, like binding textures, you'd normally use e.g. t0, t3, t9, etc...

 

Hope this helps.

-MIGI0027

Edited by Migi0027

Share this post


Link to post
Share on other sites

The "register" keyword is referring to actual registers in D3D shader assembly. Just like any other ISA there are multiple register types that are used for different purposes. Some are for storing the results of instructions or passing values to instructions, some are used for passing values between vertex shaders and pixel shaders, and a bunch are used for binding resources to slots as you've suspected. Normally the compiler auto-assigns resources to registers, but if you use the register keyword you can do this manually.

Share this post


Link to post
Share on other sites
cbuffer cbPerObjectGroup : register(b1)
{
	matrix gViewProj;
	matrix gPreviousViewProjMatrix;
	matrix gViewProjInverseMatrix;
	matrix gView;
	
	matrix gLightWVP;
	float4 xyzgEyePosW_wDoMotionBlur;
	
	Light gLight0;
	Light gLight1;
	Light gLight2;
	Light gLight3;
	Light gLight4;
	Light gLight5;
	Light gLight6;
	Light gLight7;
};
cbuffer cbPerObject: register(b2)
{
	matrix gWVP : packoffset(c0);
	matrix gW : packoffset(c4);
	matrix gUnused : packoffset(c8);
};

so, if I declare something like above, means that all variables in the structure are going to be stored in "register b1"? what does the register mean in this case?

Edited by sobeit

Share this post


Link to post
Share on other sites

All of those variables mentioned above are all going to be stored in the package you call cbPerObjectGroup, but somehow your program needs to find this package, so you assign in to the "register" buffer 1.

 

Then using the integer 1 on the CPU side you can access its data (One way, CPU -> GPU).

Share this post


Link to post
Share on other sites

It means that constant buffer will be assigned to register b1. This means that when you bind a constant buffer to your shader (let's assume it's a pixel shader) using PSSetConstantBuffers, you'll want to specify a StartSlot of 1 so that your buffer gets bound to slot 1, which corresponds to register b1.

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!