Jump to content
  • Advertisement
Sign in to follow this  

cgD3D9LoadProgram() returns error: invalid data

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

Share this post

Link to post
Share on other sites
Use CG's error function. It will explain what was wrong in the code, or in the execution.

[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.

Share this post

Link to post
Share on other sites
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] = 1
dcl_2d s1
dcl_2d s0
def c0, 0.000000, 1024.000000, 0.000500, 0.000977
def c1, 1.000000, 0.000000, 0.000000, 0.000000
dcl t0.xy
dcl t1.xyzw
dcl t2.xyz
dcl t3.xyzw
dp3 r1.x, c3, c3
dp3 r0.x, t2, t2
rsq r1.x, r1.x
rsq r0.x, r0.x
mul r1.xyz, r1.x, c3
mul r0.xyz, r0.x, t2
dp3 r0.x, r0, -r1
rcp r1.x, t1.w
mul r7.xy, t1, r1.x
add r4.xy, r7, c0.w
max r0.x, r0, c0
mov r2.y, c0.x
mov r2.x, c0.w
add r5.xy, r7, r2
rcp r2.x, t3.w
mad r3.x, t3.z, r2, -c0.z
texld r8, r4, s1
mov r2.x, r8
texld r8, r5, s1
mov r5.x, r8
mov r4.x, c0
add r2.x, r3, -r2
add r5.x, r3, -r5
cmp r5.x, -r5, c1, r4
cmp r2.x, -r2, c1, r4
texld r8, r7, s1
mov r6.x, r8
mov r1.y, c0.w
mov r1.x, c0
add r1.xy, r7, r1
texld r8, r1, s1
mov r1.x, r8
add r1.x, r3, -r1
add r3.x, r3, -r6
cmp r1.x, -r1, c1, r4
cmp r3.x, -r3, c1, r4
add r2.x, r2, -r1
add r4.x, r5, -r3
mul r6.xy, r7, c0.y
frc r5.xy, r6
mad r1.x, r5, r2, r1
mad r3.x, r5, r4, r3
texld r8, t0, s0
mov r2.xyz, r8
add r1.x, r1, -r3
mul r4.xyz, r2, r0.x
mad r0.x, r5.y, r1, r3
mul r1.xyz, r4, c6
mul r0.xyz, r1, r0.x
mov r0.w, c1.x
mad r0.xyz, r2, c5, r0
mov oC0, r0

cgD3D(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...

Share this post

Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!