what is register in HLSL?

Started by
5 comments, last by sobeit 10 years, 6 months ago

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

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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.


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?

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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.

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

This topic is closed to new replies.

Advertisement