Jump to content
  • Advertisement
Sign in to follow this  

[HLSL] How to share data between technique in HLSL?

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

How to share data between technique? I use a static global variable and set a value in one technique. Then in another technique, get the static global variable's value. The value is not correct. I get 0.0f from "share_data". The code is like:
static float share_data=0.0f;

VS_OUT techA_Vertex(VS_IN in)
{
	share_data=1.0;		// set the global variable to 1.0f
}

VS_OUT techB_Vertex(VS_IN in)
{
	// get the global variable
	// but the value is 0.0f
	float test=share_data;
	
}

technique techA
{
	pass p0
	{
		VertexShader = compile vs_3_0 techA_Vertex();
		PixelShader  = NULL;
	}
}

technique techB
{
	pass p0
	{
		VertexShader = compile vs_3_0 techB_Vertex();
		PixelShader  = NULL;
	}
}

What's the "static" mean? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Read the documentation:

static - Mark a local variable so that it is initialized one time and persists between function calls. If the declaration does not include an initializer, the value is set to zero. A global variable marked static is not visible to an application.

If you want to be able to set the value of a variable in your shader, you don't need to specify any modifiers. Just declare it globally, and it will get the default "uniform", "extern", and "const" modifers.

Share this post


Link to post
Share on other sites
If I just declare the variable globally, I will get error message from "fxc" compiler.

error x3025: global variables are implicitly constant, enable compatibility mode to allow modification

If I specify the compile option "/Gec", I can modify the global variable in shader.

But I still get the wrong value between technique.

I means that I modify the global variable in one technique, and then read the variable in another technique. But I get the wrong value.

How to exchange data in shader?

Thanks!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!