[SlimDX/C#] Effect.FromMemory fails with FXO files

Started by
4 comments, last by STufaro 14 years, 8 months ago
Hello all, I am working in C# and DirectX 9 via SlimDX. I have the following:

            string[] effectPath = EffectPaths;
            for (int i = 0; i < effectPath.Length; i++)
            {
                if (System.IO.File.Exists(effectPath))
                {
                    byte[] effectdata = File.ReadAllBytes(effectPath);
                    string errorList;
                    MyEffects = Effect.FromMemory(D3DDev, effectdata, null, null, null, ShaderFlags.None, MyEffectPool, out errorList);
                    numEffects++;
                }
            }
My effects are .FXO files compiled with fxc.exe under VS and PS 2.0. Effect.FromMemory fails with D3DXERR_INVALIDDATA: Invalid data (-2005529767) ...this has been puzzling me and I haven't been able to find anything on it. Is it obvious what I'm doing wrong? Much obliged, Steve.
Advertisement
Are you compiling SlimDX from source, or using the March release? Also, what compile options are you using for fxc?
Mike Popoloski | Journal | SlimDX
Thank you, Michael, for your prompt and polite reply.

I am using a SlimDX DLL you built me. Remember? In Pierce at lunch, sometime in mid/late-April (I think it was the day before our second differential equations test). So I'm newer than March 2009. I feel superior to all other SlimDX users because of this, but my enlarged ego does not help Effect.FromMemory work as I require it to.

As for fxc, here are the lines I use to compile each half of my effect (vertex and pixel shader):

fxc /E vs_main /T vs_2_0 /Fo fixedfunc_vs.fxo fixedfunc.fxfxc /E ps_main /T ps_2_0 /Fo fixedfunc_ps.fxo fixedfunc.fx


Thanks again for any help.
Apologies for the double-post, but I found something from a while ago that might be interesting to us:

http://www.gamedev.net/community/forums/topic.asp?topic_id=519022

While my first error is (I believe) related to Effect.FromMemory, that topic's first post describes another SlimDX issue I am having.

Here's a complete list of errors I'm getting:

1. FromMemory/no effect pool/.FXO compiled shader:
- D3DXERR_INVALIDDATA

2. FromFile/no effect pool/.FXO compiled shader:
- D3DXERR_INVALIDDATA

3. Either of the two cases above, WITH effect pool:
- D3DXERR_INVALIDDATA

4. FromFile/effect pool/.FX text (uncompiled)
- E_FAIL (the problem described in the link above)

5. FromFile/no effect pool/.FX text (uncompiled)
- works. But it's slow (takes ~5 seconds for the effect to compile on my 2.66GHz Core 2 Duo...that's annoying).

So the findings would indicate:

1. There's a problem with my .FXO files, maybe? What should my compile options be if those are no good?

2. There's a problem with the effect pool, possibly a problem in SlimDX, as I'm having the exact problem the first poster is having in the link I gave above. I use
EffectPool myEffectPool = new EffectPool()
before I call the function. There's not really much else I could be doing wrong, I think.
Just a word on my "progress":

I fixed the EffectPool errors I was getting: I was declaring EffectPool like so:
EffectPool myEffectPool = new EffectPool();

when actually you shouldn't do that--i.e., it needs to be left as:
EffectPool myEffectPool;

Of course then you get an annoying warning that it will always have its default value of null, so what I do is
 EffectPool myEffectPool = new EffectPool(); ...myEffectPool.Dispose();myEffectPool = null;myEffect = Effect.FromFile(D3DDev, Path, null, null, null, ShaderFlags.None, myEffectPool);

So it has to be null going into .FromFile() (contrary to what I saw on another thread)--I actually stumbled on fact that by mistake. But I don't like the warning so I mess with it. At least I know it's not a problem with SlimDX.

With respect to the other half of this effects bonanza, I still think I must be .FXO'ing my stuff wrong. I still get D3DXERR_INVALIDDATA when I try to create an effect from a precompiled FXO file.

Since I'm doubting myself all over now, what exactly is the way one compiles a shader offline as an FXO using fxc? More specifically:

-- Can I put the vertex and pixel shaders in one file with a .FXO using fxc.exe? How?
-- What switches am I supposed to be setting in fxc to get a created effect identical to the one that I get from the JIT effect compiler I use when I give .FromFile a .fx file (I'm using vertex and pixel shader 2.0)?
Well, figured it out thanks to help from big Mike.Popoloski.

I should be using fx_2_0 and not compiling the vertex/pixel shaders separately. Hope this helps someone in the future.

-- Steve.

This topic is closed to new replies.

Advertisement