cgD3D9LoadProgram() returns error: invalid data

Started by
4 comments, last by Pipo DeClown 18 years, 11 months ago
hi everybody, i experience a very strange problem. I've already searched for similar posts, but I didn't find a suitable answer. so my problem is the following: I have a fragment program, which compile fine with both runtime cg compiler and command line compiler, with the ps_2_0 profile. But when I try to load it, I get the following error -2005529767 (invalid data in the directx error look up tool). I have no idea where the problem comes from, but I know where it comes from:

FragmentOutput mainfrag(
  VertexOutput IN,
  const uniform float3 lightmodeldir0 : C3,      // position of light0 in view coordinates
  const uniform float3 eyepositionmodel : C4,      // camera position in view coordinates

  const uniform float3 AmbientColor : C5,
  const uniform float3 DiffuseColor : C6,
  const uniform float3 SpecularColor : C7,
  const uniform float specExp : C8,
  const uniform float4x4 matworld : C9,
  const uniform float4x4 mattsm : C10,
  uniform sampler2D basetexture0,         // normal tex
  uniform sampler2D basetexture1         // shadow map texture
)
{
  FragmentOutput finalColor;
 
  float fEpsilon = 0.001f;
 
  float texelSize = 1.0f / 1024f;
 
  float fZToCompare = IN.PositionZ.z/IN.PositionZ.w - fEpsilon;
  //float shadow = 0;//1.0f * (( fZToCompare > shadowTex) ? 0.0 : 1.0);
 
  float2 ShadowTexC = IN.projCoords.xy / IN.projCoords.w;
 
  // transform to texel space
  float2 texelpos = 1024 * ShadowTexC;

  // Determine the lerp amounts          
  float2 lerps = frac( texelpos );
 
  //read in bilerp stamp, doing the shadow checks
  float sourcevals[4];
  sourcevals[0] = (fZToCompare > tex2D( basetexture1, ShadowTexC ).r) ? 0.0f : 1.0f;        
  sourcevals[1] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(texelSize, 0) ).r) ? 0.0f : 1.0f;        
  sourcevals[2] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(0, texelSize) ).r) ? 0.0f : 1.0f;        
  sourcevals[3] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(texelSize, texelSize) ).r) ? 0.0f : 1.0f;        
 
  // lerp between the shadow values to calculate our light amount
  float shadow = lerp( lerp( sourcevals[0], sourcevals[1], lerps.x ),
                  lerp( sourcevals[2], sourcevals[3], lerps.x ),
                 lerps.y );
  //float shadow = sourcevals[0];
 
  float4 Kd         = tex2D( basetexture0,  IN.TexCoord0.xy );   // normal texture
     
  float3 N         = normalize(IN.Normal);
  float3 L         = -normalize(lightmodeldir0);
  float diffuse      = max( dot(N, L), 0 );      
       
  float3 finalShadow   = float3(shadow, shadow, shadow);
  finalColor.Color   = float4( ( Kd.xyz * AmbientColor ) + ( Kd.xyz * diffuse * DiffuseColor/* + Ks.xyz * SpecularColor */) * finalShadow, 1 );
 
 
  return finalColor;
   
}

when I comment the lerp function and uncommend the "float shadow = sourcevals[0];" line (meaning only one sample is used), then it loads successfully. I've already had similar with other shaders. I use the 9.0c april revision of directx, and the latest drivers for my ATI 9600 card. I've tried both Cg 1.3 and 1.4b2, the same problem occures. Could someone help me please ? I'm really stuck... I've find others post about the same subject, but didn't find any answer. Is it possible that the pseudo assembler code generated by Cg is source of the problem ? Why does some shaders work and some other don't ? I've check the instruction count, and that don't seem to be an issue. Greg
Gregory Jaegy[Homepage]
Advertisement
*push*
Gregory Jaegy[Homepage]
Use CG's error function. It will explain what was wrong in the code, or in the execution.
(cgGetError())

[edit] If I remember correctly, there's a function that really returns the CG compiler output (it might be the previous), or you could try to compile it with the CG compiler MANUALLY, and see what is wrong with the code.
Could you show the entire shader? I'm suspecting that the problem lies in the FragmentOutput and VertexOutput structures.
I also guess the compiler might produce wrong code, but I should admit, I'm not really an asm professional ;) So if anyone could try to check it...

So here are the structure definitions:

struct VertexInput{	float4 Position 	: POSITION;	float3 Normal 		: NORMAL;	float2 TexCoord0 	: TEXCOORD;};struct VertexOutput{      float4 Position   : POSITION;      float2 TexCoord0  : TEXCOORD0;      float4 projCoords : TEXCOORD1;      float3 Normal     : TEXCOORD2;      float4 PositionZ : TEXCOORD3;     };struct FragmentOutput{	float4 Color : COLOR;};


The generated asm code, as well as the output of the cg log :

// cgc version 1.3.0001, build date Jan  7 2005 14:01:35// command line args: -q -profile ps_2_0 -entry mainfrag//vendor NVIDIA Corporation//version 1.0.02//profile ps_2_0//program mainfrag//semantic mainfrag.lightworlddir0 : C3//semantic mainfrag.eyepositionmodel : C4//semantic mainfrag.AmbientColor : C5//semantic mainfrag.DiffuseColor : C6//semantic mainfrag.SpecularColor : C7//semantic mainfrag.specExp : C8//semantic mainfrag.matworld : C9//semantic mainfrag.mattsm : C10//semantic mainfrag.basetexture0//semantic mainfrag.basetexture1//var float2 IN.TexCoord0 : $vin.TEX0 : TEX0 : 0 : 1//var float4 IN.projCoords : $vin.TEX1 : TEX1 : 0 : 1//var float3 IN.Normal : $vin.TEX2 : TEX2 : 0 : 1//var float4 IN.PositionZ : $vin.TEX3 : TEX3 : 0 : 1//var float3 lightworlddir0 : C3 : c[3] : 1 : 1//var float3 eyepositionmodel : C4 : c[4] : 2 : 0//var float3 AmbientColor : C5 : c[5] : 3 : 1//var float3 DiffuseColor : C6 : c[6] : 4 : 1//var float3 SpecularColor : C7 : c[7] : 5 : 0//var float specExp : C8 : c[8] : 6 : 0//var float4x4 matworld : C9 : c[9], 4 : 7 : 0//var float4x4 mattsm : C10 : c[10], 4 : 8 : 0//var sampler2D basetexture0 :  : texunit 0 : 9 : 1//var sampler2D basetexture1 :  : texunit 1 : 10 : 1//var float4 mainfrag.Color : $vout.COL : COL : -1 : 1//const c[0] = 0 1024 0.0005 0.0009765625//const c[1] = 1dcl_2d s1dcl_2d s0def c0, 0.000000, 1024.000000, 0.000500, 0.000977def c1, 1.000000, 0.000000, 0.000000, 0.000000dcl t0.xydcl t1.xyzwdcl t2.xyzdcl t3.xyzwdp3 r1.x, c3, c3dp3 r0.x, t2, t2rsq r1.x, r1.xrsq r0.x, r0.xmul r1.xyz, r1.x, c3mul r0.xyz, r0.x, t2dp3 r0.x, r0, -r1rcp r1.x, t1.wmul r7.xy, t1, r1.xadd r4.xy, r7, c0.wmax r0.x, r0, c0mov r2.y, c0.xmov r2.x, c0.wadd r5.xy, r7, r2rcp r2.x, t3.wmad r3.x, t3.z, r2, -c0.ztexld r8, r4, s1mov r2.x, r8texld r8, r5, s1mov r5.x, r8mov r4.x, c0add r2.x, r3, -r2add r5.x, r3, -r5cmp r5.x, -r5, c1, r4cmp r2.x, -r2, c1, r4texld r8, r7, s1mov r6.x, r8mov r1.y, c0.wmov r1.x, c0add r1.xy, r7, r1texld r8, r1, s1mov r1.x, r8add r1.x, r3, -r1add r3.x, r3, -r6cmp r1.x, -r1, c1, r4cmp r3.x, -r3, c1, r4add r2.x, r2, -r1add r4.x, r5, -r3mul r6.xy, r7, c0.yfrc r5.xy, r6mad r1.x, r5, r2, r1mad r3.x, r5, r4, r3texld r8, t0, s0mov r2.xyz, r8add r1.x, r1, -r3mul r4.xyz, r2, r0.xmad r0.x, r5.y, r1, r3mul r1.xyz, r4, c6mul r0.xyz, r1, r0.xmov r0.w, c1.xmad r0.xyz, r2, c5, r0mov oC0, r0cgD3D(EXT): "A D3D failure occured during shader creation." (hr=Invalid data (0x88760b59))A D3D failure has occured


Hope someone could point me to the right direction...
Gregory Jaegy[Homepage]
I don't think people other than professionals are able to solve this matter for you. So I advice you to visit newsgroups and contact nVidia through e-mail.

This topic is closed to new replies.

Advertisement