• 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
mrheisenberg

What is the point of using D3DReflect instead of just setting a struct?

4 posts in this topic

Hello,I was looking around articles where people discuss working with shader reflections and I wonder why is it even needed.I mean you can just do like in DirectX Toolkit: make the constant buffer class to be a template(the template being the struct with the constants) and put a Update(T& newData) where it maps the resource and updates it with data from newData.Isn't that 100 times simpler to use?Or am I missing something about the proper use of shader reflections.

0

Share this post


Link to post
Share on other sites

The biggest down side to that approach is that you require knowledge of the exact shader files at design time so that you can create a struct of the appropriate type.  If you are trying to rapid prototype some algorithms, this means you have to recompile something anytime your constant buffer layouts change.  It also means that you have a struct type that is dependent on another file that isn't directly enforced or monitored by your build chain, which can lead to mismatches and difficult to debug issues.

 

In Hieroglyph 3, the reflection information is used at startup to determine what data needs to be packed into the constant buffers.  This allows you to reconfigure the data as long as your renderer has access to the needed information.  I use the type and name of the variables as the unique identifiers for the information, but you could use whatever methodology that you want.  So if my engine already supports the setting of 'ViewPosition', then I can add that as a parameter to a shader file and automatically get the value without having to recompile the engine / application.

 

Both methods have their merits (as you pointed out, the loading process is significantly easier if you know ahead of time what the layout will be) but for my engine I value the ability to rapidly iterate on shader based algorithms!

2

Share this post


Link to post
Share on other sites

What worries me is the string comparisons each frame,I think I'll have to make some hashing algorithm

EDIT: but wait,don't you also need to know the names of the shader when you set them by string,I mean you still have to know what's in the constants of the shader,otherwise you don't know what you should be setting

Edited by mrheisenberg
0

Share this post


Link to post
Share on other sites

What worries me is the string comparisons each frame,I think I'll have to make some hashing algorithm

EDIT: but wait,don't you also need to know the names of the shader when you set them by string,I mean you still have to know what's in the constants of the shader,otherwise you don't know what you should be setting

 

That is precisely what the reflection information tells you.  And the string comparisons are only performed when the shader is loaded at runtime - after that, direct references to the relevant data are acquired and reused from that point onward.  There is no negative performance aspect to working with the data in this way.  The only real difference is that you are copying data into a buffer via memcpy rather than setting the value of a struct member.

0

Share this post


Link to post
Share on other sites

Like Jason mentioned it enables you to keep your application code somewhat generic, without having to strongly tie your C++ code to your shader code. Personally I haven't ever really seen the need for a fully generic shader constant system, since in most cases the engine needs knowledge of what values it's setting and so you're not going to avoid the code dependency. Plus for real games that need to scale to hundreds of draw calls you need to tightly control exactly how you update your constant buffers in order to avoid performance deficiencies. In our engine at work we try to compromise by using matching C++ structs and constant buffer layouts for all values that are set by the engine. Then for special materials that have runtime-animated properties, we put those properties in their own constant buffer and we build a hash table of the offsets of each property so that a certain value can quickly be looked up and set by hash.

The one case where we make heavy use of reflection is for textures. Our material shaders can potentially use many textures, but any individual permutation will only use a subset since most will get optimized away. So to handle this, our build pipeline reflects the shaders and builds a list of only the textures actually needed by a particular shader so that we can set them efficiently at runtime.

1

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