Jump to content

  • Log In with Google      Sign In   
  • Create Account

what is register in HLSL?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 sobeit   Members   -  Reputation: 433

Like
0Likes
Like

Posted 09 October 2013 - 02:06 PM

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

 



Sponsor:

#2 Migi0027   Crossbones+   -  Reputation: 1728

Like
1Likes
Like

Posted 09 October 2013 - 02:09 PM

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, 09 October 2013 - 02:11 PM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#3 MJP   Moderators   -  Reputation: 11385

Like
2Likes
Like

Posted 09 October 2013 - 02:22 PM

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.



#4 sobeit   Members   -  Reputation: 433

Like
0Likes
Like

Posted 09 October 2013 - 02:35 PM

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, 09 October 2013 - 02:43 PM.


#5 Migi0027   Crossbones+   -  Reputation: 1728

Like
0Likes
Like

Posted 09 October 2013 - 02:40 PM

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).


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#6 MJP   Moderators   -  Reputation: 11385

Like
2Likes
Like

Posted 09 October 2013 - 02:41 PM

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.



#7 sobeit   Members   -  Reputation: 433

Like
0Likes
Like

Posted 09 October 2013 - 03:01 PM

thanks a lot, I think i've got the idea of it.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS