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

HLSL Dynamic Linking

8 posts in this topic

I noticed that they have added dynamic linking to shader model 5, which can be used through classes and interfaces. I did a quick search but didn't find much on the subject. Is it just not catching on?

Any way my real question is this. Lets say I want to implement a deferred shading renderer that stores a material ID in the gbuffer and applies different BDRFs based on that ID. What kind of performance difference, if any, would I likely see implementing it in these ways:

[code]
switch(matID)
{
case 0:
return BlinnPhongBRDF(NdotL, NdotE);
break;
case 1:
return AnisotropicBRDF(NdotL, NdotE);
break
...
}
[/code]

vs.

[code]
interface BRDF
{
float4 CalculateLighting(float NdotL, float NdotE);
};

...

return BRDFArray[matID].CalculateLighting(NdotL, NdotE);
[/code]
0

Share this post


Link to post
Share on other sites
According to my experience you won't see any real performance difference. In the switch example, the compiler will probably either branch or flatten, in the dynamic linking example it will look-up in some kind of function table and a jump to a correct subroutine. Given that probably rather large blocks of fragments will have the same material anyway, the performance will be very similar (not much divergence). Nevertheless I guess dynamic linking might be a tiny bit faster here - just my guess :)
0

Share this post


Link to post
Share on other sites
I'd wager the HLSL compiler would reduce it basically to example #1. It's primarily a maintenance/code brevity thing, not performance.
1

Share this post


Link to post
Share on other sites
When I first saw the DX11 dynamic linking mentioned a couple years ago, I immediately started fantasising about being able to "plug" pieces of shaders (functions, methods?) into existing shaders on-the-fly, while just complying with an implied "function header". How terribly sad I was to find out how foolish I was and that it actually is just a "clearer" way of dynamic branching [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] All the shader with all the possible classes still has to compile at once [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
0

Share this post


Link to post
Share on other sites
The best part is that the Cg compiler did this ages ago in software and doesn't require SM5, while the D3D implementation does [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

EDIT: It really is something of a non-feature.
0

Share this post


Link to post
Share on other sites
Dynamic linkage isn't a replacement for dynamic branching. Binding of class implementations to interfaces happens in your application code, before you issue a draw call. So it doesn't make sense for a deferred light shader, where the implementation of a light might change for each pixel based on the BRDF. It would make more sense in a forward renderer, where you would pick the BRDF based on the material bound for the draw call.
0

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1333733227' post='4928835']The best part is that the Cg compiler did this ages ago in software and doesn't require SM5, while the D3D implementation does [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img][/quote]You might be interested in this HLSL SM3 approach: [url="http://code4k.blogspot.com.au/2011/11/advanced-hlsl-using-closures-and.html"]http://code4k.blogsp...osures-and.html[/url][quote]EDIT: It really is something of a non-feature.[/quote]As MJP points out above, it lets you dictate the branch value on the CPU before issuing a draw-call, eliminating branches from shaders, while still being able to write them in a branchy way.

The earlier equivalent to this was branching on boolean registers, which some GPU drivers use to eliminate the branch in software ([i]and other drivers don't, but do still branch faster than a regular branch-on-ALU-results[/i]).
0

Share this post


Link to post
Share on other sites
Dynamically linked methods' performance matches that of static function calls; also, the linking overhead is just that of setting one constant buffer.

The feature is designed to reduce the combinatory explosion of number of shader types for different techniques, without sacrificing performance. For example, you can have a single abstract shader for all your material types but just switch the BRDF implementation and light implementations on the fly.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1333775822' post='4928970']
You might be interested in this HLSL SM3 approach: http://code4k.blogsp...osures-and.html
[/quote]

Not even. It [url="http://http.developer.nvidia.com/GPUGems/gpugems_ch32.html"]literally works the same way that dynamic linkage does[/url] (at least from an API standpoint) except it doesn't require any form of hardware or driver support. If the D3D implementation worked like this it'd be *awesome,* but as it stands you need to target SM5 for it to even work which is basically a deal-killer.
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