Jump to content
  • Advertisement
Sign in to follow this  

Put these 3D graphics terms into relation for me

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

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



[indent=4]S0 ... S127


[indent=3]ConstantBuffer 1

[indent=3]ConstantBuffer 2


[indent=3]Sampler 1

[indent=3]Sampler 2
[indent=3]Texture 1
[indent=3]Texture 2
[indent=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 [font=courier new,courier,monospace]ID3D11DeviceContext::PSSetConstantBuffers()[/font] and [font=courier new,courier,monospace]ID3D11DeviceContext::PSSetShaderResources()[/font] 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 [font=courier new,courier,monospace]ID3D11DeviceContext::PSSetConstantBuffers()[/font] 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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
In D3D9, each shader stage (pixel/vertex) has ~16 [font=courier new,courier,monospace]s[/font] registers, which hold both a texture pointer and a sampler state, and 256+ [font=courier new,courier,monospace]c[/font] 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 [font=courier new,courier,monospace]s[/font] registers can't be used in vertex shaders.

in D3D11, each shader stage has: [font=courier new,courier,monospace]s[/font] registers for sampler states, [font=courier new,courier,monospace]t[/font] registers for texture pointers, [font=comic sans ms,cursive]b[/font] registers for constant buffers, and [font=courier new,courier,monospace]u[/font] registers for UAV pointers.
The [font=courier new,courier,monospace]c[/font] registers are basically gone, and instead it's as if the [font=courier new,courier,monospace]b[/font] registers store (hidden) offsets into a huge amount of (hidden) [font=courier new,courier,monospace]c[/font] 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. [font=courier new,courier,monospace]s3[/font] 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 [font=courier new,courier,monospace]b[/font] file if setting a [font=courier new,courier,monospace]cbuffer[/font] or the [font=courier new,courier,monospace]t[/font] file if setting a [font=courier new,courier,monospace]texture[/font]. Edited by Hodgman

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  


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!