how to fix error

Started by
3 comments, last by lomateron 10 years, 10 months ago

in my geometry shader I have something like this:


float r[10]={0,0,0,0,0,0,0,0,0,0};
float4 g;

uint max=Tex2Da.Load(uint3(0,0,0));

for(uint i=0;i<max;i++)  //max is never greater than 10
{
     g  = Tex2Db.Load(uint3(0,0,0));

     uint mod=i%4;
     r   = g[mod];
}

now I use the array "r" to output some vertices SV_Position.
when i compile that code I get the error:
-emitting a system-interpreted value which is not written in every execution path of the shader-
and the error points to were I give a value to the SV_Position variable using the "r" array
Does that means that code can't be compiled?
if I take away the line
r = g[mod];
the code will work
Advertisement

g is a vector but you access it as an array of vectors.

yeah that can be done in HLSL, there is nothing wrong about that, even if i change

r[i] = g[mod];

for this:

r[i] = g.x;

it will return the same error

When you use the array index operator on a vector, you are indexing into the scalar elements of the vector. That means you are index from 0-3 for the xyzw coordinates in g, which appears to be ok in the way you are using it (although it does seem confusing to read...).

Can you post the rest of the shader? That might help someone spot what is causing the error.

The rest of the shader is ugly but ok here is it complete


struct VS_PPLL
{
    float4 Pos : PITION;
	uint Id : anceID;
};

struct PS_Ff
{
    float4 Pos : SV_POSITION;
	float4 Frc : FFOO;
};


[maxvertexcount(17)] 
void GSInstJoFo( point VS_PPLL input[1] , inout PointStream<PS_Ff> duo )
{
	PS_Ff output;

	uint cC=uint(C.y);

	uint3 u=uint3(input[0].Id%cC,input[0].Id/cC,0);

	output.Pos.x=(float(u.x)/C.y)*2.0f-1.0f+1.0f/C.y;
	output.Pos.y=1.0f-(float(u.y)/C.y)*2.0f-1.0f/C.y;
	output.Pos.zw=float2(0.0f,1.0f);

	output.Frc=Tex2Db.Load(u);

	uint nJo=uint(Tex2Dg.Load(u));
	     if(!(any(output.Frc.xyz))){
	duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();
	duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();}
	else if(nJo==0 && any(output.Frc.xyz)){ duo.Append( output );
	duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();
	duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();}
	else
	{
		uint i=0;
		float3 p1=Tex2Da.Load(u).xyz;
		uint3 e=u;
		float4 jntsClss;
		float3 dSum=float3(0.0f,0.0f,0.0f); float mCntr=0.0f;
		float doit,l;
		float3 arrD[16];
		uint4 arrJP[4];
		uint fl,fl2;
		for(i=0;i<nJo;i++)
		{
			fl=i%4;
			if(fl==0)
			{
				fl2=i/4;
				e.x = (u.x*4) + fl2;
				arrJP[fl2]     = uint4(Tex2Dc.Load(e));
				jntsClss = Tex2Df.Load(e);
			}

			e.x=arrJP[fl2][fl]%cC;
			e.y=arrJP[fl2][fl]/cC;

			arrD=Tex2Da.Load(e).xyz;

			arrD=arrD-p1;
			if(any(arrD))
			{
				l=length(arrD);
				if(l<ballCLe(jntsClss[fl]))
				{
					arrD=normalize(arrD);
					doit=dot(arrD,output.Frc.xyz);
					if(doit!=0.0f)
					{
						dSum+=doit*arrD;
						mCntr++;
					}
					else
					{
						arrD=float3(0.0f,0.0f,0.0f);
					}
				}
			}
		}
		if(mCntr==0.0f){duo.Append( output );
		duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();
		duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();duo.RestartStrip();}
		else
		{
			dSum=normalize(dSum);
			dSum=dSum*dot(dSum,output.Frc.xyz);
			float3 dPer=normalize(output.Frc.xyz-dSum);
			dPer=dPer*dot(dPer,output.Frc.xyz);

			dSum=dSum/mCntr;

			output.Frc.xyz=dSum+dPer;
			duo.Append( output );duo.RestartStrip();

			for(i=0;i<nJo;i++)
			{
				if(any(arrD))
				{
					output.Frc.xyz=arrD*dot(arrD,dSum);

					fl=i%4;fl2=i/4;

					u.xy=uint2(arrJP[fl2][fl]%cC,arrJP[fl2][fl]/cC);
					output.Pos.x=(float(u.x)/C.y)*2.0f-1.0f+1.0f/C.y;
					output.Pos.y=1.0f-(float(u.y)/C.y)*2.0f-1.0f/C.y;

					duo.Append( output );duo.RestartStrip();
				}
				else{duo.RestartStrip();}
			}
			for(i=0;i<16-nJo;i++)
			{
				duo.RestartStrip();
			}
		}	
	}
}

The error points to this, the one that is more down in the code


output.Pos.x=(float(u.x)/C.y)*2.0f-1.0f+1.0f/C.y;
output.Pos.y=1.0f-(float(u.y)/C.y)*2.0f-1.0f/C.y;

which depends on "u"

"u" depends on the array "arrJP"

"arrJP" depends on "Tex2Dc.Load(e)"

"Tex2Dc.Load(e)" depends on "e"

"e" depends on the loop number "i"

"i" depends on the loop wich has max value "nJo"

"nJo" depends on "Tex2Dg.Load(u)"

"Tex2Dg.Load(u)" depends on "u"

finally "u" depends on VS_PPLL--> Id

C.y is a constant

----------------------------------------------------------------------------------------------------------------

ERROR IS FIXED BY INITIALIZING


float3 arrD[16];
uint4 arrJP[4];

This topic is closed to new replies.

Advertisement