Jump to content
  • Advertisement
Sign in to follow this  
yk_cadcg

[hlsl] error of "Use of potentially uninitialized variable"

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

Hi, below hlsl 10 gets below error and exit, thanks for suggestions!
struct PS_OUTPUT
{
	uint4 col :	SV_Target;
	float depth :			SV_Depth;
};

PS_OUTPUT psHashJoin(..)
{
PS_OUTPUT output;
	if(..)
	{
		output.col = ..
		output.depth = 1.f;
		return output;
	}
warning X4000: Use of potentially uninitialized variable (output)

Share this post


Link to post
Share on other sites
Advertisement
If that is your whole script then its because if that "if" statement evaluates to false you wont be setting output.col or output.depth, or returning any output.

Share this post


Link to post
Share on other sites
The error message is quite clear in my opinion, you haven't initialized the variable output.

PS_OUTPUT output;

// What value does output have here?

if(..)

{

output.col = ..

output.depth = 1.f;

return output;

}


Share this post


Link to post
Share on other sites
Thank you!
in the ps code, actually sometimes I just don't want to update the depthbuffer.
Then I choose to "uninitialize" ouput.depth, and it proves that it's ok when I wrote API like this:

D3D10_DEPTH_STENCIL_DESC dsDesc;
dsDesc.DepthEnable = true; //note: if false,then won't discard automatically! since I'll use occlusion query, i want it discard depth==1.0
dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO; //note: this only means that dx won't write z AUTOMATICALLY, but I can still write SV_Depth is ps!!!
dsDesc.DepthFunc = D3D10_COMPARISON_LESS;
dsDesc.StencilEnable = false;
ID3D10DepthStencilState * pDSState;
g_pd3dDevice->CreateDepthStencilState(&dsDesc, &pDSState);
g_pd3dDevice->OMSetDepthStencilState(pDSState, 1);


Quote:
Original post by Omid Ghavami
The error message is quite clear in my opinion, you haven't initialized the variable output.
*** Source Snippet Removed ***


Share this post


Link to post
Share on other sites
Perhaps you could use HLSL's clip intrinsic to abort rendering when the depth-test fails. If that's no good, you could achieve the same effect by writing an invisible pixel, provided you can find an appropriate depth value to write with (or simply disable depth-writes, if that's viable).

Admiral

Share this post


Link to post
Share on other sites
Thank you!
actually I *am using "disable depth writes", by
dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
and I dismissed the depth component from PS_OUTPUT.
This way, I use "discard" to dynamic flow control (DFC), but I can't benefit the potential big profit from early-z, since I can't write z, so can't update z to be 1.0 dynamically, so can't do early z in the next pass.


Quote:
Original post by TheAdmiral
Perhaps you could use HLSL's clip intrinsic to abort rendering when the depth-test fails. If that's no good, you could achieve the same effect by writing an invisible pixel, provided you can find an appropriate depth value to write with (or simply disable depth-writes, if that's viable).

Admiral


Share this post


Link to post
Share on other sites
I don't find that to be good practice. It seems that if I ever fail to write meaningful data to the output (i.e. I screwed up), I would want the compiler to let me know.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!