HLSL -- Cache parameters handles
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?
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:
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.
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.
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 );
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 );
Try to take a look at my website: [articles section]
http://www.gents.it/ggd/
I hope that helps!!!
Byez,
http://www.gents.it/ggd/
I hope that helps!!!
Byez,
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...
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...
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.
Quote:Original post by circlesoftQuote: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
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.
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement