PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Merkwürdiges Verhalten des Cg Compilers


Asmodeus
2005-03-09, 10:34:24
Ich wollte die Möglichkeit des Texturzugriffs innerhalb eines Vertexprogrammes testen. Zuerst habe ich in GLSL etwas geschrieben und der im Treiber integrierte cgc (Version 1.3) hat die Sache ohne Fehler übersetzt und es lief ohne Probleme. Dann hat ein Kollege von mir die Sache in Cg versucht und zum kompilieren die cgc.exe verwendet (Version 1.3). Dabei trat der Compiler Fehler 9999 auf, sobald man versuchte im Vertexprogramm auf eine Textur zuzugreifen. Merkwürdig ist jedoch, wenn man mit der cgc.exe und den ensprechenden Parametern das GLSL-Programm kompiliert, dann gibt es keinen Fehler.

Hat jemand ein ähnliches Verhalten bei sich bemerkt oder könnte das bitte nochmal jemand bei sich testen.

Gruss, Carsten.

ScottManDeath
2005-03-09, 16:11:36
Kannst Du vielleicht mal das test file posten, dann sinkt meine Faulheitshemmschwelle ganz schnell nach unten ;)

Asmodeus
2005-03-09, 16:53:09
Kannst Du vielleicht mal das test file posten, dann sinkt meine Faulheitshemmschwelle ganz schnell nach unten ;)

Ok, wenn es denn sein muß ;)

Also, zuerst der Simple-Code in GLSL:


uniform sampler2D Texture0;

varying vec4 Color;

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;

Color = texture2D(Texture0,gl_TexCoord[0].xy);

gl_Position = ftransform();
}


Dabei erzeugt der Compiler folgendes (Profil ist vp40):


...
PARAM c[4] = { program.local[0..3] };
TEMP R0;
TEMP CC;
BB1:
DP4 result.position.w, vertex.attrib[0], c[3];
DP4 result.position.z, vertex.attrib[0], c[2];
DP4 result.position.y, vertex.attrib[0], c[1];
DP4 result.position.x, vertex.attrib[0], c[0];
MOV result.texcoord[0], vertex.attrib[8];
TEX R0, vertex.attrib[8], texture[0], 2D;
MOV result.texcoord[1], R0;
END
...


Gut zu sehen der TEX-Befehl, hat also alles so funktioniert wie es soll.

Und jetzt der Cg-Simple-Code:


struct vertex
{
float3 position : POSITION;
float4 color0 : COLOR0;
uniform sampler2D dmap;
};

struct output
{
float4 position : POSITION;
float4 color0 : COLOR0;
};

output main( vertex IN, uniform float4x4 modelViewProj )
{
output OUT;

OUT.color0 = tex2D( IN.dmap, float2(IN.position.x,IN.position.y) );

float4 v = float4( IN.position.x, IN.position.y, 0.0, 1.0f );

OUT.position = mul( modelViewProj, v );

return OUT;
}


Bei der Verwendung des vp30 Profiles kommt die erwartete Fehlermeldung:

error C1115: unable to find compatible overloaded function "tex2D"


Bei der Verwendung des vp40 Profiles kommt nur noch die Fehlermeldung:

fatal error C9999: *** exception during compilation ***


Gruss, Carsten.

ScottManDeath
2005-03-09, 17:26:57
struct vertex
{
float3 position : POSITION;
float4 color0 : COLOR0;

};
struct output
{
float4 position : POSITION;
float4 color0 : COLOR0;
};

output main( vertex IN, uniform float4x4 modelViewProj , uniform sampler2D dmap)
{
output OUT;

OUT.color0 = tex2D( dmap, float2(IN.position.x,IN.position.y) );

float4 v = float4( IN.position.x, IN.position.y, 0.0, 1.0f );

OUT.position = mul( modelViewProj, v );

return OUT;
}

Ich hab den sampler aus dem struct rausgenommen und direkt in die Parameterliste der main Funktion gesetzt. Dann kommt das raus. Das gleiche kommt raus wenn der sampler direkt (wie bei der GLSL Version) im globalen Scope sitzt.


24 lines, 0 errors.
!!ARBvp1.0
OPTION NV_vertex_program3;
# cgc version 1.3.0001, build date Jan 7 2005 14:01:35
# command line args: -profile vp40
# source file: c.cg
#vendor NVIDIA Corporation
#version 1.0.02
#profile vp40
#program main
#semantic main.modelViewProj
#semantic main.dmap
#var float3 IN.position : $vin.ATTR0 : ATTR0 : 0 : 1
#var float4 IN.color0 : $vin.ATTR3 : ATTR3 : 0 : 0
#var float4x4 modelViewProj : : c[0], 4 : 1 : 1
#var sampler2D dmap : : texunit 0 : 2 : 1
#var float4 main.position : $vout.HPOS : HPOS : -1 : 1
#var float4 main.color0 : $vout.COL0 : COL0 : -1 : 1
#const c[4] = 0 1
PARAM c[5] = { program.local[0..3],
{ 0, 1 } };
TEMP R0;
TEMP CC;
BB1:
TEX R0, vertex.attrib[0], texture[0], 2D;
MOV result.color, R0;
MOV R0.xy, vertex.attrib[0];
MOV R0.zw, c[4].xyxy;
DP4 result.position.w, R0, c[3];
DP4 result.position.z, R0, c[2];
DP4 result.position.y, R0, c[1];
DP4 result.position.x, R0, c[0];
END
# 8 instructions, 1 R-regs


IMHO ist das semantisch nicht ok wenn der uniform sampler in einem interpolierten Parameter struct drinne sitzt. Allerdings sollte man das mit einer Fehlermeldung quitieren und nicht einfach so abkacken ;) Du kannst ja mal testen ob das in GLSL genauso ist mit dem sampler im struct, falls es die GLSL Grammatik zulässt.

Asmodeus
2005-03-09, 17:45:10
Besten Dank für die schnelle Problemlösung. :wink:

Gruss, Carsten.