Jump to content
  • Advertisement
Sign in to follow this  
ClementVidal

Directx9 effect file offline compiling (without fxc.exe)

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

Hello everybody,

For the need of my application, i need to compile an effect file (fx_2_0 profile) offline and then load it afterward.
I do not want to use the fxc.exe tool everything needs to be done using the Directx Api.

I'm using the February 2010 Directx SDK and i'm using the Directx9 API.

Here is the code i'm actually using:

1. Compile the effect from an ascii description:



HRESULT hr;
LPD3DXEFFECTCOMPILER effectCompiler;
LPD3DXBUFFER errorBuffer;
LPD3DXBUFFER effectBuffer;

hr = D3DXCreateEffectCompilerFromFile( myFilePath, NULL, NULL, 0, &effectCompiler, &errorBuffer );
hr = effectCompiler->CompileEffect( 0, &effectBuffer, &errorBuffer );


Until here, eveything is fine, and the bytecode generated is "nearly" the same as the bytecode generated by the fxc.exe tool runned with the follwoing command line;
fxc /T fx_2_0 /Fo s:/test.fxo myFilePath


2. Then i'm trying to create an ID3DXEffect from this bytecode:


//Data are the bytecode stored in theprevious effectBuffer
//byteCount is the size of the previous effectBuffer
ID3DXBuffer* errorBuffer;

hr = D3DXCreateEffect(
device,
data,
byteCount,
NULL,
NULL,
0,
NULL,
&m_ID3DEffect,
&errorBuffer
);




If i use the bytecode generated by the D3dXEffectCompiler::CompileEffect() API,

This function call fail with the following output:

ID3DXEffectCompiler: There were no techniques
ID3DXEffectCompiler: Compilation failed


BUT, if i call the same fonction with the bytecode genereated by FXC.exe this function DOES NOT fail !



Both bytecodes are only slightly differents, here are the first few bytes of each with diferences in bold:

D3dXEffectCompiler::CompileEffect() API bytecode:

[font="Lucida Console"]01 09 ff fe 10 03 00 00 00 00 00 00 05 00 00 00[/font]
[font="Lucida Console"]04 00 00 00 1c 00 00 00 00 00 00 00 00 00 00 00 [/font]
[font="Lucida Console"]01 00 00 00 0d 00 00 00 49 6e 70 75 74 54 65 78 [/font]
[font="Lucida Console"]74 75 72 65 00 f0 ad ba 0c 00 00 00 04 00 00 00[/font]

Fxc.exe bytecode:

[font="Lucida Console"]01 09 ff fe 10 03 00 00 00 00 00 00 05 00 00 00 [/font]
[font="Lucida Console"]04 00 00 00 1c 00 00 00 00 00 00 00 00 00 00 00 [/font]
[font="Lucida Console"]01 00 00 00 0d 00 00 00 49 6e 70 75 74 54 65 78 [/font]
[font="Lucida Console"]74 75 72 65 00 00 00 00 0c 00 00 00 04 00 00 00[/font]




Here is the content of my fx file:



struct VSInput
{
float2 Position : POSITION;
float2 UV0 : TEXCOORD0;
};

struct VSOutput
{
float4 HPosition : POSITION;
float2 UV0 : TEXCOORD0;
};

struct PSInput
{
float2 UV0 : TEXCOORD0;
};

texture InputTexture;
sampler2D InputTextureSampler = sampler_state
{
Texture = <InputTexture>;
MinFilter = Point;
MagFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};

uniform float4
System_DisplayInfo;

uniform float3
Position;

uniform float2
Resolution;

uniform float2
TextureSize;

uniform float
FontSize;

uniform float4
Color;

uniform const bool
UseTexture;

float4 PSMain( PSInput input ) : COLOR0
{
float4
Pixel;

float2 UV = ( input.UV0 / TextureSize );
Pixel = Color;
if (UseTexture) {
Pixel.a = tex2D( InputTextureSampler, UV).a;
}

return Pixel;
}

VSOutput VSMain( VSInput input )
{
VSOutput
output;

// Compute vertex position
float px = Position.x + ( input.Position.x / Resolution.x );
float py = Position.y + ( input.Position.y / Resolution.y );

output.HPosition.x = px * 2.0f - 1.0f;
output.HPosition.y = py * 2.0f - 1.0f;

output.HPosition.x -= 1.0f/Resolution.x/2;
output.HPosition.y -= 1.0f/Resolution.y/2;

output.HPosition.z = 0;
output.HPosition.w = 1;

output.UV0 = input.UV0;

return output;
}

technique MainTechnique
{
pass P0
{
VertexShader = compile vs_3_0 VSMain();
PixelShader = compile ps_3_0 PSMain();
}
}




What the f*** am i doing wrong ?
How can i compile an effect file to byte code and then create the corresponding effect afterward without using fxc.exe?

I have already search the web (and this forum), a lot of people seams to have problems related with thoses functions, but none seams to exactly match my problem...


Thanks a lot for your help !


Clément Vidal

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!