D3D11 ShaderResourceView for Buffers
category: code [glöplog]
Howdy fellow D3D11 coders, I wonder how to correctly create a shader resource view for buffers. Thats is, like OpenGL texture buffer objects.
I'm currently reading some old AMD presentation (see pages 15 to 17):
https://de.slideshare.net/DevCentralAMD/vertex-shader-tricks-bill-bilodeau
Page 15 - Create an SRV point buffer and bind to VS
Page 17 - The shader itself
The simple question is, how to create this SRV? This smells more like an UAV to me. I'm unsure what values to set within the Buffer structure of the D3D11_SHADER_RESOURCE_VIEW_DESC. I don't get how to set the values for FirstElement/ElementOffset and NumElements/ElementWidth. Good old MSDN is a bit light on the documentation side there. Is it bytes, is it element count, element size, strides, whatever!?
And from what I see in the shader on Page 17 an SRV can acutally be a structure? Meh... So far my needs were only vertex textures which were more D3D9-ish to use (that is, dead simple).
Thanks in advance for any enlightenmt, E1.
I'm currently reading some old AMD presentation (see pages 15 to 17):
https://de.slideshare.net/DevCentralAMD/vertex-shader-tricks-bill-bilodeau
Page 15 - Create an SRV point buffer and bind to VS
Page 17 - The shader itself
The simple question is, how to create this SRV? This smells more like an UAV to me. I'm unsure what values to set within the Buffer structure of the D3D11_SHADER_RESOURCE_VIEW_DESC. I don't get how to set the values for FirstElement/ElementOffset and NumElements/ElementWidth. Good old MSDN is a bit light on the documentation side there. Is it bytes, is it element count, element size, strides, whatever!?
And from what I see in the shader on Page 17 an SRV can acutally be a structure? Meh... So far my needs were only vertex textures which were more D3D9-ish to use (that is, dead simple).
Thanks in advance for any enlightenmt, E1.
Quote:
I don't get how to set the values for FirstElement/ElementOffset and NumElements/ElementWidth. Good old MSDN is a bit light on the documentation side there. Is it bytes, is it element count, element size, strides, whatever!?
for the SRV you only need ElementOffset=0 and ElementWidth=count (NOT bytes/stride).
FirstElement / NumElements is for UAVs (and are also counts, NOT bytes/stride)
Just to verify... it seems like there are two things stuffed into one. First you can create a buffer with D3D11_RESOURCE_MISC_BUFFER_STRUCTURED and the correct stride, the other thing would be to create the buffer without the flag, but create the view with a correct DXGI format - the "GL-TBO" version?
well, I only used D3D11_RESOURCE_MISC_BUFFER_STRUCTURED buffers with SRV and UAV so far (with each having DXGI_FORMAT_UNKNOWN), for accessing structured buffers in compute shaders. Can't help much regarding the non-structured non-UAV scheme, sorry.
I'm winging this one since it's been 2 years since I touched D3D11.
The structure has an Offset/Count and Offset/Stride union in it. If you feed the format member a deterministic value you use the primary, if not you use the latter (as the documentation in it's very MS-way says "we'll take it from format if it's available").
So, if you feed a structure of your own as an 'element', you define the format as unknown and set the stride to the structure size. Then, in the shader, define a cbuffer that corresponds with the members in each element (or tuple really in this case). Bind to the right constant slot and voila. The shader on page 17 indexes the struct, CPU and shader agree on what's in there. Keep an eye on alignment.
The structure has an Offset/Count and Offset/Stride union in it. If you feed the format member a deterministic value you use the primary, if not you use the latter (as the documentation in it's very MS-way says "we'll take it from format if it's available").
So, if you feed a structure of your own as an 'element', you define the format as unknown and set the stride to the structure size. Then, in the shader, define a cbuffer that corresponds with the members in each element (or tuple really in this case). Bind to the right constant slot and voila. The shader on page 17 indexes the struct, CPU and shader agree on what's in there. Keep an eye on alignment.
Thanks for the help guys. This makes things clear. And now I will hopefully get something done for next Revision...