Hi!
As you probably have noticed, from a programmer perspective structured and constant buffers are used quite similar, though there are some major differences between them.
Firstly their memory access work differently.
A constant buffer is extremely fast if all threads in a warp access the same value. But, if all threads read from different spots the reads are serialized – a phenomenon called constant waterfalling, which makes the reading slow (causes headache for people doing bone animations). In all the scenarios you described above, every threads reads from the same address, so I’d go with constant buffers, except maybe for the third scenario (in case you have many, many lights).
Structured buffers on the other hand utilize the unified cache architecture, which means the first read is slow, but all subsequent reads are very fast (if the requested data is already in the cache).
Secondly, their usage is limited.
Constant buffers are so fast, because they are in special registers (constant registers) of which we don’t have much (about 64KB). Structured buffers are not placed in constant registers, which means we generally have more space available. Thus, if the data you want to read gets big, you have to move from constant buffers to structured buffers (e.g. for accessing a huge light list).
Structured buffers can’t be bound to any point in the pipeline, which means not as a vertex buffer etc. They were introduced for DirectCompute on Dx10 hardware, since Dx10 hardware doesn’t allow random-access writes on typed resources (textures, vertex buffers etc). Though, you can read from them in every shader stage.
A structured buffer has some really nice candy. It can have a “hidden counter”, which can be accessed by multiple threads (even from different thread groups) to count things. Curiously this counter is a little bit faster than using an interlockedAdd on a byte address buffer (another untyped resource with much more applications, since it can be bound everywhere, unlike structured buffers.)
Cheers!
Show differencesHistory of post edits
#1Tsus
Posted 06 May 2012 - 09:28 AM
Hi!
As you probably have noticed, from a programmer perspective structured and constant buffers are used quite similar, though there are some major differences between them.
Firstly their caches work differently.
A constant buffer is extremely fast if all threads in a warp access the same value. But, if all threads read from different spots the reads are serialized – a phenomenon called constant waterfalling, which makes the reading slow (causes headache for people doing bone animations). In all the scenarios you described above, every threads reads from the same address, so I’d go with constant buffers, except maybe for the third scenario (in case you have many, many lights).
Structured buffers on the other hand utilize the unified cache architecture, which means the first read is slow, but all subsequent reads are very fast (if the requested data is already in the cache).
Secondly, their usage is limited.
Constant buffers are so fast, because they are in special registers (constant registers) of which we don’t have much (about 64KB). Structured buffers are not placed in constant registers, which means we generally have more space available. Thus, if the data you want to read gets big, you have to move from constant buffers to structured buffers (e.g. for accessing a huge light list).
Structured buffers can’t be bound to any point in the pipeline, which means not as a vertex buffer etc. They were introduced for DirectCompute on Dx10 hardware, since Dx10 hardware doesn’t allow random-access writes on typed resources (textures, vertex buffers etc). Though, you can read from them in every shader stage.
A structured buffer has some really nice candy. It can have a “hidden counter”, which can be accessed by multiple threads (even from different thread groups) to count things. Curiously this counter is a little bit faster than using an interlockedAdd on a byte address buffer (another untyped resource with much more applications, since it can be bound everywhere, unlike structured buffers.)
Cheers!
As you probably have noticed, from a programmer perspective structured and constant buffers are used quite similar, though there are some major differences between them.
Firstly their caches work differently.
A constant buffer is extremely fast if all threads in a warp access the same value. But, if all threads read from different spots the reads are serialized – a phenomenon called constant waterfalling, which makes the reading slow (causes headache for people doing bone animations). In all the scenarios you described above, every threads reads from the same address, so I’d go with constant buffers, except maybe for the third scenario (in case you have many, many lights).
Structured buffers on the other hand utilize the unified cache architecture, which means the first read is slow, but all subsequent reads are very fast (if the requested data is already in the cache).
Secondly, their usage is limited.
Constant buffers are so fast, because they are in special registers (constant registers) of which we don’t have much (about 64KB). Structured buffers are not placed in constant registers, which means we generally have more space available. Thus, if the data you want to read gets big, you have to move from constant buffers to structured buffers (e.g. for accessing a huge light list).
Structured buffers can’t be bound to any point in the pipeline, which means not as a vertex buffer etc. They were introduced for DirectCompute on Dx10 hardware, since Dx10 hardware doesn’t allow random-access writes on typed resources (textures, vertex buffers etc). Though, you can read from them in every shader stage.
A structured buffer has some really nice candy. It can have a “hidden counter”, which can be accessed by multiple threads (even from different thread groups) to count things. Curiously this counter is a little bit faster than using an interlockedAdd on a byte address buffer (another untyped resource with much more applications, since it can be bound everywhere, unlike structured buffers.)
Cheers!