   (D3D10) Using vertex buffers as a shader resource view, and VB access in shaders
  Hi, I've been perusing the documentation in the Dec DXSDK, specifically the Direct3D 10 stuff. As I understand it, since I could have a buffer bound to be vertex or index buffer and as a shader resource, as well as the buffer support in HLSL (both the 'buffer' type, as well as the 'load' instrinsic func), it seems that there is no restriction to using a VB or IB as a shader resource. However, I am curious as to a few things regarding the Load function:1) The syntax (copied below) implies that there is no variable returned. What good is a Load function that doesn't return data? Is this a problem with the documentation, or is the data supposed to be accessed some other way?2) How would vertex buffers with this, i.e. if I wanted to get the data for the nth vertex in a buffer, what would be the usage (especially considering the doc doesn't explicitly mention anything about 'return' or 'out' values)?2a) Assuming the load function behaves like an array lookup, how can we avoid trying to look up data outside the vertex buffer? The GetDimensions function only works with textures, not buffers.3) Anyone got any ideas on what a possible use for VB/IB access in a shader could be? I was discussing this with circlesoft, and the only thing we could come up with is possibly generating adjacency information on the GPU or something.   
Quote:Original post by Cypher19Hi, I've been perusing the documentation in the Dec DXSDK, specifically the Direct3D 10 stuff. As I understand it, since I could have a buffer bound to be vertex or index buffer and as a shader resource, as well as the buffer support in HLSL (both the 'buffer' type, as well as the 'load' instrinsic func), it seems that there is no restriction to using a VB or IB as a shader resource. However, I am curious as to a few things regarding the Load function:1) The syntax (copied below) implies that there is no variable returned. What good is a Load function that doesn't return data? Is this a problem with the documentation, or is the data supposed to be accessed some other way?2) How would vertex buffers with this, i.e. if I wanted to get the data for the nth vertex in a buffer, what would be the usage (especially considering the doc doesn't explicitly mention anything about 'return' or 'out' values)?2a) Assuming the load function behaves like an array lookup, how can we avoid trying to look up data outside the vertex buffer? The GetDimensions function only works with textures, not buffers.3) Anyone got any ideas on what a possible use for VB/IB access in a shader could be? I was discussing this with circlesoft, and the only thing we could come up with is possibly generating adjacency information on the GPU or something.I don't have the Dec05 SDK on this machine so this is from memory...Load obviously returns data, the docs must be crazy.  One obvious thing for using this for is to implement "multiple index buffers" for multiple streams.  i.e. Separate IB/VB pairs for Points, Normals, UVs, etc...  Random access to per-instance (or per-binding) data on a mesh is another option...  the options are endless... IIRC the SparseMorphTargets sample uses loads from the VS but like I said I can't see that code right now.Paul;Also, you're correct, GetDimensions doesn't work on buffers.  If you need the dimensions then you have to pass them along.  For the most part though you can usually "guarantee" that shaders access only valid ranges of the buffers.  Out-of-bounds access is also well defined in D3D10 so if you happen to go awry, you'll get consistent return values.Paul;Quote:IIRC the SparseMorphTargets sample uses loads from the VS but like I said I can't see that code right now.Enh, just checked and neither of the fx files in that project have shader resources of type 'buffer', nor use the Load command.Quote:If you need the dimensions then you have to pass them along.Eesh, that'll be a bit interesting to do, especially with geometry shader stream out.   ;  Not sure about the other questions, but I was reading the specs on SO last night, so here's something... [smile]Quote:Original post by Cypher19Quote:If you need the dimensions then you have to pass them along.Eesh, that'll be a bit interesting to do, especially with geometry shader stream out.You can use a query to find out how much data the SO generated. I haven't personally tried it, but from what I've read:Create a D3D10_QUERY_DESC structure, where D3D10_QUERY_DESC::Query is D3D10_QUERY_SO_STATISTICS and D3D10_QUERY_DESC::MiscFlags is 0.Quote:D3D10_QUERY_SO_STATISTICS:Gets streaming output statistics, such as the number of primitives streamed out in between Begin and End. GetData will return a D3D10_QUERY_DATA_SO_STATISTICSUse ID3D10Device::CreateQuery() to create an ID3D10Query object. Calling Begin() and End() as appropriate. Then use ID3D10Query::GetData() to get a D3D10_QUERY_DATA_SO_STATISTICS object - which contains values for how many primitives were written and how much space is required.hthJack   ;Quote:3) Anyone got any ideas on what a possible use for VB/IB access in a shader could be? I was discussing this with circlesoft, and the only thing we could come up with is possibly generating adjacency information on the GPU or something.Tons of things. You can splice together your vertex shader from multiple streams however you see fit. You can get around interpolation limits by passing the indices into the pixel shader along with the barycentric coordinates and do this yourself (getting as many interpolaters as you want). You can store data at a triangle frequency and have your GS load it... The list is endless really.