How do I load FX files?

Hi guys,

I’ve been working out of 3.6.187 for a while and I once tried upgrading to a newer build, but I had countless problems.

I am using MonoGame for Windows/Desktop (DirectX)

Now, I finally have time for some game development again and I thought it might be a good idea to upgrade to a newer Monogame build. But I quickly remembered my problem: I think loading fx files has changed.

LightingEffect = content.Load<Effect>("FX/LightShader");

this is the way i usually load the file. I processed it in the content pipeline and it compiled without error.

I now get the SharpDX exception

An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll

Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

What am i doing wrong?

(Note: SharpDX exceptions were absolutely standard for me since the start of monogame, for example the one above will also be thrown every time a 3d model is drawn for the first time. A bit annoying, I have no idea why. If I ignore it, the program will run and it won’t show up again, unless I draw a new model. But this one with the fx files cannot be ignored, it won’t let the program run)

What shader profile are you targeting?

VertexShader = compile vs_5_0 DrawWithShadowMapUntextured_VertexShader();
PixelShader = compile ps_5_0 DrawWithShadowMapUntextured_PixelShader();

sm 4 and 5

did something change? Did they stop support for sm4?

I was wondering because I had the same problem with vs_5_0/ps_5_0 and 4_0 a while ago, I had to simplify the shader to stay below the instruction limit, but I lowered it to 4_0_level_9_3 and that did work. I haven’t tried 4_0 or 5_0 since :confused: I created a topic too, but no solution… I didn’t try a younger version of MG then. Maybe I can find the commit that changed this, if this is the same issue I had.

If your shaders are simple enough you can try to target a lower profile, but I guess you’re using SM 5 for a reason?

it’s not a problem with the shaders, the compiler would have told me if it were, after all the limitations and requirements are fixed by the DirectX standard.
As said they compile fine and work fine with an older version, but it would be nice to take advantage of future improvements.

SM5 has stuff like [earlydepthstencil] so yeah, it’s useful.

I’m just saying I had the same issue, but things worked when I targeted a lower shader profile.

well I have finally started building my own MonoGame dlls (based on the old version which ran fine) and i can’t compile any effects either.

So - everything works with the default 3.6.187 monogame dll.
But if i compile my own monogame dll (revision from April 10th, so should conform to 3.6.187) it doesn’t work. That shouldn’t be possible right? Nothing changed.
Except maybe the dependencies…


The problem seems to not lie with the MonoGame changes, but rather with some SharpDX changes.

(again when trying to build a pixel shader it says
Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

in this thing here:

Xna.Framework.Graphics.Shader

  private void CreatePixelShader()
        {
            System.Diagnostics.Debug.Assert(Stage == ShaderStage.Pixel);
            _pixelShader = new PixelShader(GraphicsDevice._d3dDevice, _shaderBytecode);
        }

It seems the problem lies with the SharpDX dependency? Maybe something changed on their part?

Maybe some baseline things changed? No more support for certain semantics? Any idea? (for what it’s worth it doesn’t compile simple pass through shaders either)

I’ve red a lot of threads about this error and it usually revolves around the GPU not supporting some of the features.
That’s rather impossible in my case, I have a fully fledged dx11 card and it worked before. Hmm.

Maybe we should try the latest SharpDX version. There are open issues on upgrading it in the MG repo because of some missing functionality.

SharpDX should be able to throw some more descriptive exceptions, right? Or is that the cost of being so fast?

graphics.GraphicsProfile = GraphicsProfile.HiDef;

was the solution

2 Likes