Jump to content

  • Log In with Google      Sign In   
  • Create Account


HLSL Dynamic Linking


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Chris_F   Members   -  Reputation: 1938

Like
0Likes
Like

Posted 06 April 2012 - 02:08 AM

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:

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

vs.

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

...

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


Sponsor:

#2 pcmaster   Members   -  Reputation: 647

Like
0Likes
Like

Posted 06 April 2012 - 05:48 AM

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 :)

#3 InvalidPointer   Members   -  Reputation: 1366

Like
1Likes
Like

Posted 06 April 2012 - 06:30 AM

I'd wager the HLSL compiler would reduce it basically to example #1. It's primarily a maintenance/code brevity thing, not performance.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#4 pcmaster   Members   -  Reputation: 647

Like
0Likes
Like

Posted 06 April 2012 - 06:38 AM

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 Posted Image All the shader with all the possible classes still has to compile at once Posted Image

#5 InvalidPointer   Members   -  Reputation: 1366

Like
0Likes
Like

Posted 06 April 2012 - 11:27 AM

The best part is that the Cg compiler did this ages ago in software and doesn't require SM5, while the D3D implementation does Posted Image

EDIT: It really is something of a non-feature.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#6 MJP   Moderators   -  Reputation: 10226

Like
0Likes
Like

Posted 06 April 2012 - 10:53 PM

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.

#7 Hodgman   Moderators   -  Reputation: 27590

Like
0Likes
Like

Posted 06 April 2012 - 11:17 PM

The best part is that the Cg compiler did this ages ago in software and doesn't require SM5, while the D3D implementation does Posted Image

You might be interested in this HLSL SM3 approach: http://code4k.blogsp...osures-and.html

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

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 (and other drivers don't, but do still branch faster than a regular branch-on-ALU-results).

#8 Nik02   Crossbones+   -  Reputation: 2643

Like
0Likes
Like

Posted 06 April 2012 - 11:23 PM

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.

Niko Suni


#9 InvalidPointer   Members   -  Reputation: 1366

Like
1Likes
Like

Posted 07 April 2012 - 07:43 AM

You might be interested in this HLSL SM3 approach: http://code4k.blogsp...osures-and.html


Not even. It literally works the same way that dynamic linkage does (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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS