Jump to content
  • Advertisement
Sign in to follow this  
age_of_lion

how to get back a variable value which is changed in a Shader?

This topic is 4816 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

Normally, we set the value of a variable using DirectX SetConstantX()... How can I get back a variable's value which is changed in a Shader, for example , a float variable which is interpolated in the Shader, API need get back this changed value, how to get back it? Help me.

Share this post


Link to post
Share on other sites
Advertisement
I'm curious, what sort of performance hit are we talking about with this method you describe donnie?

Share this post


Link to post
Share on other sites
Reading back from GPU is slow and there is going to be a pipeline stall but in the case of a 1x1 float texture there's no performance problem.

Share this post


Link to post
Share on other sites
Reading data back from the GPU is always a performance hit, no matter how much data is read back. That's becouse it creates a pipeline stall, like DonnieDarko said.

Share this post


Link to post
Share on other sites
Effect effect = ...;

for ( int j = 0; j < effect.Description.Parameters; j++)
{
EffectHandle handleParam = effect.GetParameter(null, j);
ParameterDescription desc = effect.GetParameterDescription(handleParam);

if(desc.Class == ParameterClass.Vector){
Vector4 v4 = effect.GetValueVector4(handleParam);
}

}

I just put Vector4 as an example...

Don't use this for every frame.

Share this post


Link to post
Share on other sites
Rendering to a render target and reading that is barely a performance hit. Almost all multipass effects use the render-target technique.

Share this post


Link to post
Share on other sites
Quote:
Original post by vidalsasoon
Effect effect = ...;

for ( int j = 0; j < effect.Description.Parameters; j++)
{
EffectHandle handleParam = effect.GetParameter(null, j);
ParameterDescription desc = effect.GetParameterDescription(handleParam);

if(desc.Class == ParameterClass.Vector){
Vector4 v4 = effect.GetValueVector4(handleParam);
}

}

I just put Vector4 as an example...

Don't use this for every frame.


This code only sets and reads constant registers. Those do not change during the shader run.

The only way to get a "calculated" value back from a shader is via a render target. At least until Dx10 comes out.

Share this post


Link to post
Share on other sites
Quote:
Original post by rjackets
Rendering to a render target and reading that is barely a performance hit. Almost all multipass effects use the render-target technique.

Carefull with blanket statements like this.

If you mean that rendering to a render target and then setting that render target as a texture in a subsequent pass, then yes, while there is a performance hit, the hit isn't as bad as it was a few years ago.

However, if you mean rendering to a render target and then locking this texture so you can read the information into the CPU, then there will be a sizeable performance hit because this will stall the graphics pipeline and break the graphics chip's parallelism.

neneboricua

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!