Jump to content
  • Advertisement
Sign in to follow this  
Halsafar

HLSL -- Cache parameters handles

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to SetValue() many parameters each frame for a fx shader. I have read that it is faster to get a handle to the variable so you don't have to do a name look-up each frame. How do I go about this?

Share this post


Link to post
Share on other sites
Advertisement
When you call D3DXCompileShaderFromFile() the last argument of that function, if used, will return a pointer to a ID3DXConstantTable interface which can be used to access shader constants.
After you get that interface you can call ID3DXConstantTable::GetConstantByName() to get an handle to the constant like this:

D3DXHANDLE hConstant = m_pConstantTable->GetConstantByName( NULL, "myConstant" );


After that, to use the constant handle you call ID3DXConstantTable::Set* methods and pass the handle to those methods.

p.s. I don't know if that's how you do it with d3dx effects.

Share this post


Link to post
Share on other sites
With the effects framework, it's even easier. You have the following functions at your disposal:

GetParameter()
GetParameterByName()
GetParameterBySemantic()


GetParameter() is useful for retrieving individual elements of an array. There are also maching functions for retrieving technique handles, like:

GetTechnique()
GetTechniqueByName()



Now, you can just do:

D3DXHANDLE param = effect->GetParameterByName( NULL, "diffuseColor" )
effect->SetVector( param, &color );

Share this post


Link to post
Share on other sites
Nice site. Decent FX Article there.

Curious, why use GetParameterBySemantic when it seems identical to GetParameterByName, at least in the article you have on your site the use between the 2 is indistinguishable, in both case's your getting the handle via the parameter name...

Aren't semantics the way you connect stuff to the pipeline?
float4 texCoordDiffuse0 : TEXCOORD0

So wouldn't the use of GetBySemantic be used to get texCoordDiffuse0 via TEXCOORD0...

Share this post


Link to post
Share on other sites
Quote:
Original post by Halsafar
Curious, why use GetParameterBySemantic when it seems identical to GetParameterByName, at least in the article you have on your site the use between the 2 is indistinguishable, in both case's your getting the handle via the parameter name...

Aren't semantics the way you connect stuff to the pipeline?
float4 texCoordDiffuse0 : TEXCOORD0

So wouldn't the use of GetBySemantic be used to get texCoordDiffuse0 via TEXCOORD0...

Exactly, that is correct. I find that polling parameters by semantic is much better than polling by their name, because it is a pain to have to write shaders with the exact same variable names every time. If you produce a standard set of semantics for your project (much like DXSAS), then writing shaders and integrating them with your engine will be much easier.

Share this post


Link to post
Share on other sites
Quote:
Original post by circlesoft
Quote:
Original post by Halsafar
Curious, why use GetParameterBySemantic when it seems identical to GetParameterByName, at least in the article you have on your site the use between the 2 is indistinguishable, in both case's your getting the handle via the parameter name...

Aren't semantics the way you connect stuff to the pipeline?
float4 texCoordDiffuse0 : TEXCOORD0

So wouldn't the use of GetBySemantic be used to get texCoordDiffuse0 via TEXCOORD0...

Exactly, that is correct. I find that polling parameters by semantic is much better than polling by their name, because it is a pain to have to write shaders with the exact same variable names every time. If you produce a standard set of semantics for your project (much like DXSAS), then writing shaders and integrating them with your engine will be much easier.

Just to add something... my understanding of the standard semantics stuff is that it also helps with the overall production pipeline (esp. the bits you might buy/licence and not actually create yourself). If your content creation tools, debugging tools and runtime engine all use the same names you get a lot of interoperability for free [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Just to add something... my understanding of the standard semantics stuff is that it also helps with the overall production pipeline (esp. the bits you might buy/licence and not actually create yourself). If your content creation tools, debugging tools and runtime engine all use the same names you get a lot of interoperability for free [smile]

Ah, right. The last time I heard, both ATI's RenderMonkey and Nvidia's FX Composer supported DXSAS (and are probably adding more). SAS does take into account many different types of data binds (ie Sas.EnvironmentMap and Sas.Time.Now), but many engines may require their own specialized symantics. However, I think you will see *a lot* more of this with the emergence of XNA and hence, a completely unified pipeline.

Share this post


Link to post
Share on other sites
Quote:
Original post by Halsafar
Whoa, DXSAS... A standard use of semantics, I'd like to read up on this.


[DirectX SDK Documentation]
DirectX Graphics ->
Reference ->
Effect Reference ->
DirectX Standard Annotation and Semantics Reference


[DXSAS == DirectX Standard Annotation and Semantics]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!