Cg program behaving weird.

Started by
2 comments, last by GameDev.net 18 years, 7 months ago
Hi, I have written a very simple fragment program for a general-purpose application. Here is the snippet of the Cg source code: ############################################### uniform samplerRECT MATexture : TEXUNIT0; uniform samplerRECT RPTexture : TEXUNIT1; float2 DecodeIndex (float Index, float2 TexSize) { float CONV_CONST; float normAddr1D; CONV_CONST = 1.0 / TexSize.x; normAddr1D = Index * CONV_CONST; return float2(frac (normAddr1D) * TexSize.x, normAddr1D); } // DecodeIndex float4 Traverse ( uniform samplerRECT TextureA : TEXUNIT2, float2 Index : TEXCOORD2, float2 GridIndex : TEXCOORD0, uniform float4 ParameterList ) : COLOR { // DECLARE VARIABLES float4 A; float4 MA; float4 RP; float2 R; float M; // FOR TESTING ONLY float4 d = float4(0, 0, 0, 0); float d2 = float(0); float d2sqrt = float(0); A = texRECT (TextureA, Index); R = float2 (0, 0); MA = texRECT (MATexture, R); GridIndex = DecodeIndex (MA.z, ParameterList.xy); MA = texRECT (MATexture, GridIndex); while (1 != MA.x) { if (M != MA.x) { } else { RP = texRECT (RPTexture, GridIndex); if (0 != (distance (A.yzw, RP.yzw))) { // FOR TESTING ONLY d = RP - A; d2 = pow (d.y, 2) + pow (d.z, 2) + pow (d.w, 2); d2 = d2 + 0.000625; d2sqrt = sqrt (d2); break; // FOR TESTING } } } return float4 (d2sqrt, d2, 0, 0); // return float4 (d2, d.y, d.z, d.w); } ############################################### Also here is the "first" fragment values for all the textures (in case you need it). MATexture = float4(0.142857, 0, 0, 2) RPTexture = float4(0, -0.172046, -0.483953, 0.097067) TextureA = float4(0, 0.021291, 0.053253, 0.077247) When I return the data as: "return float4 (d2, d.x, d.y, d.z);", the program returns proper values. However, when I try to return the data as : "return float4 (d2sqrt, d2, 0, 0);", the program returns garbage values. Both the values of d2sqrt and d2 are not correct. The values returned are junk if I try returning in any other format like "return float4 d2sqrt" or else. I am totally confused as to what is happening and why it it returning junk values when I try to output in a different way. Here is some information regarding my development environment. Platform and OS : IA32(AMD) and Linux RedHat 9.0 Cg Driver : Release from June 15, 2005 Cg Profile : fp40 Graphics Hardware and driver : Nvidia 6600GT and driver version - 1.0-7667 released on June 22, 2005. Please help. Thanks
Advertisement
Cg has had many codegen bugs (and still has AFAIK).
You'd better get used to looking at the generated asm code :(
(the game I worked on was full Cg)

compare both generated code; they shouldn't be too different, so the error is likely to stand out.

Good Luck,
Janos
Act of War - EugenSystems/Atari
Perhaps the problem is that if and while are not supported on your hardware.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Hi,

Quote:Original post by JohnBolton
Perhaps the problem is that if and while are not supported on your hardware.


"if" and "while" statements are supported on the hardware.

- FMS

This topic is closed to new replies.

Advertisement