Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Put these 3D graphics terms into relation for me

4: Adsense

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
3 replies to this topic

#1 Cygon   Members   


Posted 17 July 2012 - 04:28 AM

I have last seriously worked with 3D graphics using Direct3D 9 and I'm now in the process of refreshing my knowledge for Direct3D 11. In D3D9 I already used shaders extensively and I understand the purpose and advantages of constant buffers in D3D11, but my mental map currently consists of some disconnected islands of which I'm not sure how they are properly arranged.

This is how I believe it fits together. Can someone rearrange the terms in this tree to how things actually are?

Graphics Pipeline




S0 ... S127


ConstantBuffer 1

ConstantBuffer 2


Sampler 1

Sampler 2


Texture 1

Texture 2


<same here as in vertex shaders>

So in words, shaders distinguish between constant buffers and resources (i.e. constant buffers are not resources). I base that assumption on the fact that HLSL lets you explicitly declare which register a constant buffer is in but not a sampler. Also on the fact that ID3D11DeviceContext::PSSetConstantBuffers() and ID3D11DeviceContext::PSSetShaderResources() are separate methods and I've seen examples assigning a constant buffer to constant buffer slot 0 and a texture to resource slot 0.

And I assume shader registers (S0 ... S127) are the same thing ID3D11DeviceContext::PSSetConstantBuffers() assigns. What happens when I load a pre-SM4.0 shader? Is a constant buffer implicitly created for the parameters it declares? Or can registers hold either a constant buffer or a variable (though I can't find any way to access registers or variables directly in the D3D11 API).

Edited by Cygon, 17 July 2012 - 05:11 AM.

Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.

#2 clb   Members   


Posted 17 July 2012 - 05:58 AM

There are no separate 'constant registers' and 'constant buffers'. All constant variables are assigned into some constant buffer, either explicitly my the shader author, or automatically by the shader compiler. All constant variables outside any constant buffers go into a global $Global constant buffer. From http://msdn.microsoft.com/en-us/library/windows/desktop/bb509581(v=vs.85).aspx : "There are two default constant buffers available, $Global and $Param. Variables that are placed in the global scope are added implicitly to the $Global cbuffer, using the same packing method that is used for cbuffers."

The layout inside a Constant Buffer consists of a list of Constant Registers, each of which are 4xfloat vectors, and the variables in each Constant Buffer are laid out to these Constant Registers.

Textures and Texture Samplers are separate from Constant Buffer Slots, and these three are all assigned separately.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

#3 Hodgman   Moderators   


Posted 17 July 2012 - 06:16 AM

In D3D9, each shader stage (pixel/vertex) has ~16 s registers, which hold both a texture pointer and a sampler state, and 256+ c registers, which hold a 16-byte constant value (e.g. a float4, one row of a matrix, one float with padding).
Also, on early D3D9 cards (or on D3D11's "DX9 feature level"), the s registers can't be used in vertex shaders.

in D3D11, each shader stage has: s registers for sampler states, t registers for texture pointers, b registers for constant buffers, and u registers for UAV pointers.
The c registers are basically gone, and instead it's as if the b registers store (hidden) offsets into a huge amount of (hidden) c registers.

In HLSL, all of your variables (of all data types) can use the register keyword to specify the mapping yourself, or you can reflect on the results of the shader compiler to discover the mapping, e.g. s3 for the 4th sampler

When setting a value via the D3D API, the register index used will be used to look up the corresponding register file, so the b file if setting a cbuffer or the t file if setting a texture.

Edited by Hodgman, 17 July 2012 - 06:19 AM.

#4 MJP   Moderators   


Posted 17 July 2012 - 12:41 PM

Constant buffers are resources. They're just one type of resource, and there are several others. The two broad groups of resources are "Buffers" and "Textures", and there are various sub-types within those groups:

  • Constant buffers - used for providing heterogeneous constant values to shaders, directly accessible by variable names. These are read-only in shaders, and cannot be access through a shader resource view.
  • Buffers - provides an array of typed, homogeneous data to a shader, where the type comes from a DXGI_FORMAT.
  • Structured buffers - provides an array of typed, homogeneous data to a shader, where the type is a user-defined structure.
  • Byte-address buffers - also called raw buffers. Provides provides an array of raw data to a shader, where the data is accessed directly by byte offset and returned as a uint.
  • Texture1D - one-dimensional texture, typed on a DXGI_FORMAT
  • Texture1DArray - array of one dimensional textures
  • Texture2D - two-dimensional texture, typed on a DXGI_FORMAT
  • Texture2DArray - array of two-dimensional textures
  • Texture3D - three-dimensional texture, typed on a DXGI_FORMAT

Constant buffers are special in that they can't be accessed through a shader resource view or an unordered access view, unlike the other buffer and texture types. Instead you bind them with *SSetConstantBuffers, and they're accessed by variable name in the shader. But otherwise they are the same as other buffer resources: you create them with CreateBuffer, you access their data with Map, and you can pass them to functions like CopyResource.

As for registers, there really aren't "registers" anymore you had with constant registers in D3D9 where they held numeric values. Instead the registers are really just "slots" that use as binding points for resources. This way the shader can say "hey I expect a Texture2D at slot 3", and the CPU can bind a shader resource view at slot with with *SSetShaderResources.

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.