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

Does the HLSL compiler in Visual Studio 2012 remove unreferenced constant buffers and shader resources for sure?

5 posts in this topic

I've been planning to refactor my shader library and put all possible constant buffers and textures in one .hlsli file and then include that file to every shader that uses a constant buffer or a texture or whatever.My question is - for instance if I have 20 constant buffers in the .hlsli file, but I onclude it in one pixel shader and that pixel shader references values from only one cbuffer and only one of the textures and one of the samplers, all the other ones will not get compiled, right?And I won't be uploading to them from the application, so it would be if they don't exist, right?

0

Share this post


Link to post
Share on other sites

As far as I know, any unreferenced resource (texture, sampler, buffet etc) won't have any effect on the final shader. You may use some shader tools to verify this in the compiled shader code. 

 

The cbuffers and resources defined inside the shader files are more like declarations that "this kind of data with this name may exist and it is formatted this way", so the shader file alone and the compiler don't create any of those resources for you. 

 

Otherwise, the shader compiler will go through all the file and all the included files, so longer shader files you create, more time it will take to compile them. I think that the compiler parses all the functions (for syntax errors and such) even if the functions aren't used. 

 

 

Cheers!

0

Share this post


Link to post
Share on other sites
It's a touchy subject. There's a lot the HLSL compiler doesn't know that you would assume it should.

I know for sure that if you use only a part of the cbuffer (i.e. the first 12 bytes out of 32), the compiler will still compile as if it were 32 (the full size).

However, I don't know about fully unused cbuffers. Granted, it will take more time to compile, which in bigger projects this can be a major problem, particularly for fast game iteration (as in development); which is very important. I wouldn't do it if I were you.
0

Share this post


Link to post
Share on other sites

The compile will absolutely strip unused resources from the compiled shader. You can verify this very easily by checking the resulting assembly dumped from fxc.exe.

Constant buffers are either stripped entirely, or left intact. The compiler won't selectively strip out parts of the constant buffer that aren't used, because this would change the layout the buffer.

2

Share this post


Link to post
Share on other sites

The compiler will remove unused objects from the shader file.  However, you should consider that each object will be located at a different register if there are different numbers of textures and constant buffers being bound (this assumes you don't explicitly set the register by hand).  That really isn't too big of a deal, but you have to consider it anyways.

 

If you set your build chain up properly, then you should build your shader as soon as you save it to disk, and then just use the compiled shader at runtime.  This is the strategy imposed on you by the Windows Store style apps, and it actually makes sense to follow this path.  So in this case, it probably won't make to much of a difference if the compilation takes a bit longer to remove the unnecessary objects.

1

Share this post


Link to post
Share on other sites

you should consider that each object will be located at a different register if there are different numbers of textures and constant buffers being bound

 

True, the compiler will optimize unused resources away, and re-index the used slots. If you manually bind a resource to a slot (e.g.: <float> texture : register(t[4])), the shader is guaranteed to use that specific slot/register index.

Edited by eppo
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