• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Paul__

Append buffer: buffer byte stride vs resource view byte stride

6 posts in this topic

Hello all,

I'm getting this error from dx:

"ID3D11DeviceContext::DrawIndexed: The Shader Resource View in slot 0 of the Vertex Shader unit has structure stride 128 while the shader expects a structure stride of 32. This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching)."

The app works as expected, but I want to avoid the error filling the log. Have done lots of searching on net and experimenting with code and can't get rid of it.

What I've got is an append buffer that the compute shader writes to through a UAV. It's then unbound from compute shader, and bound to the vertex shader as a resource view.

The append buffer is made with a StructureByteStride of 128 bytes. This one struct contains 4 vertices. Need to have 4 vertices in one chunk, so that when vertices are written to the append buffer they are written in one append() as two primitives and aren't mixed up in the append process.

But the vertex shader reads single 32 byte vertices. Here's how the buffer is declared in the vert shader:
StructuredBuffer<cVertIn> vertsIn

So I guess the mismatch is between the 128 byte stride specified when the buffer was created, and the 32 byte stride of the struct declared in the vert shader hlsl.

Is there a way of having different byte strides for a resource view and its associated buffer? Any other way to avoid the error? I have to use an append buffer, because the amount of data the compute shader generates is variable.

Paul
0

Share this post


Link to post
Share on other sites
If you use a StructuredBuffer then the stride declared in the shader needs to exactly match the stride that you used when you created the actual Buffer resource, you can't create an SRV with a different stride. The only alternatives I know of would be to use a ByteAddressBuffer instead of a StructuredBuffer and manage the append/ingatomic increment yourself, or to copy the buffer contents from one structured buffer to another structured buffer with a different stride.
1

Share this post


Link to post
Share on other sites
Hi MJP, thanks for your reply. Dash it! I was hoping that there was some way around. I tried copying the buffer to another some weeks ago, but that was just too slow (the buffer is very large). I might give the raw buffer + atomic increment thing a go. Or change the vertex buffer to accept a 128 byte struct, and read from within that struct the one vert it needs. Thanks for the advice.
0

Share this post


Link to post
Share on other sites
If you only read from a portion of your structure, then the generated assembly will only have enough memory loads to cover that portion of the structure. So in your case if your vertex shader only uses 32 bytes, the assembly will only load 32 bytes.
1

Share this post


Link to post
Share on other sites
Meaning that then the vertex shader will still report to dx a 32 byte stride? I assumed that the hlsl compiler looked at which struct was used with the StructuredBuffer. Oh well. Perhaps I'll live with the warning, or work out how to use a raw buffer with a counter. Thanks again!
0

Share this post


Link to post
Share on other sites
No what I mean is that the shader won't fetch all 128 bytes of the structure if your shader doesn't use all of it, even if the stride in HLSL is 128 bytes. You'd still need to calculate the buffer index based on the stride of 128 bytes, but you can do something like this:

[code]
struct Vertex
{
float3 Position;
float3 Normal;
...
};


struct VertexGroup
{
Vertex Vertices[4];
};

StructuredBuffer Vertices<VertexGroup>;

void VSMain(in uint VertexID : SV_VertexID)
{
Vertex vtx = Vertices[VertexID / 4].Vertices[VertexID % 4];
...
}
[/code]

Then it that case the vertex shader will only access 1 vertex worth of data. Edited by MJP
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0