Using .fx files on Mac M1?

Hey all,

I’m trying to make a simple pixel shader in Monogame by creating a .fx file and importing it with the Content Pipeline tool. However, I’m using a Mac M1 and when I try to compile I get a build error from the Content.mgcb file. When I remove the .fx import it works fine, so that is definitely the cause.

Here is the relevant snippet of my Content file:

#begin MonoColorize.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:MonoColorize.fx

Is it currently possible to use .fx files on Mac M1 machines? Are there any alternative workflows to using pixel shaders on my machine? Any help would be appreciated!

For reference, I am following this tutorial where a .fx file is simply imported with MGCB: Writing your own 2D Pixel Shader in Monogame for Absolute Beginners

So I’m trying to get around the Content Pipeline by using MGFXC directly as described in official documentation. However when I run this command:

mgfxc Content/MonoColorize.fx Content/MonoColorize.mgfx /Profile:OpenGL

I get the following error:

Application could not be started, or no application associated with the specified file.
ShellExecuteEx failed: Internal error.

Any ideas what I’m missing here? Could it be an issue with Wine or my .net files?

I’m not sure if mgfxc can be used on a Mac, because the documentation says it is for DirectX which will not work on any Mac. Macs use OpenGL.

I had trouble with fx files on a 3-D project I was working on. I could only get them to build correctly on Monogame 3.6 but not Monogame 3.8 The problem occurred for me on both an M-1 Mac and a Windows 11 box. Downgrading to Monogame 3.6 was the only way I could get fx files to work.

If anyone has a better solution, let us know.

It should be possible to run MGFXC using Wine. Did you install Wine like described here: Setting up your development environment for macOS | MonoGame Documentation

2 Likes

Yes I have installed Wine as described in the docs. I tried repeating the steps just now and I still get the same problems.

If it’s helpful, when I just try to compile the project with a .fx file in my Content.mgcb, I get an error when this part of MonoGame.Content.Builder.Tasks.targets is run:

<!-- Execute MGCB from the project directory so we use the correct manifest. -->
    <Exec
      Condition="'%(ContentReference.FullPath)' != ''"
      Command="$(DotnetCommand) $(MGCBCommand) $(MonoGameMGCBAdditionalArguments) /@:&quot;%(ContentReference.FullPath)&quot; /platform:$(MonoGamePlatform) /outputDir:&quot;%(ContentReference.ContentOutputDir)&quot; /intermediateDir:&quot;%(ContentReference.ContentIntermediateOutputDir)&quot; /workingDir:&quot;%(ContentReference.FullDir)&quot;"
      WorkingDirectory="$(MSBuildProjectDirectory)" />

This is the .fx file I am trying to use. It is just a copy/pasted template right now so idk if there are any errors in it that would be interrupting compilation.

#if OPENGL
	#define SV_POSITION POSITION
	#define VS_SHADERMODEL vs_3_0
	#define PS_SHADERMODEL ps_3_0
#else
	#define VS_SHADERMODEL vs_4_0_level_9_1
	#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

Texture2D SpriteTexture;

sampler2D SpriteTextureSampler = sampler_state
{
	Texture = <SpriteTexture>;
};

struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	float4 Color : COLOR0;
	float2 TextureCoordinates : TEXCOORD0;
};

float4 MainPS(VertexShaderOutput input) : COLOR
{
	return tex2D(SpriteTextureSampler,input.TextureCoordinates) * input.Color;
}

technique SpriteDrawing
{
	pass P0
	{
		PixelShader = compile PS_SHADERMODEL MainPS();
	}
};

Once I have installed Wine that way and created the prefix, should shader compilation work automatically or is there a specific way I am supposed to use it to get it to run DirectX?

Hi! Did you find a solution for this problem? I’ve got the same issue trying to build the game content on my M2 Mac.

I installed wine as described in the docs.

I actually solved it just after typing my reply! The solution is quite simple, the wineprefix script in the documentation is wrong and installs a x86 dotnet. Here is how to get it working:

  • delete the .winemonogame folder in your home directory
  • run the script from the documentation again, but replace master with develop
1 Like

Oh wow, thanks for replying to this thread! I had given up solving this and was going to use a separate Windows Machine to handle compilation but that simple typo fix worked.

To summarize for anyone with this problem:

  • The default effect compiler via the content tool doesn’t work on Mac
  • Instead install Wine for use with MonoGame as described in the docs here, but…
  • For the wine install step, replace “master” with “develop” to get the correct script
  • Then, you can use MGFXC to compile effects directly as described in the docs here

If anyone reading this has access to the docs or could inform me how to update them it would be nice to see the MacOS set up page updated to reflect the new file structure.

Cheers!

2 Likes

The documentation is part of the MG repository on GitHub:
Setting up your development environment for macOS

You need to make a pull request for documentation changes, just like you would do for code changes.
You can do that right from that page. Just click the edit icon, make your changes, then click on the propose changes button.

1 Like