[SOLVED] Effect compilation on Linux

What are the high level steps to do effect compilation on Linux?

So far I did these steps:

install-mgcb-editor
https://docs.monogame.net/articles/getting_started/1_setting_up_your_development_environment_ubuntu.html#install-mgcb-editor

and the last optional step
optional-set-up-wine-for-effect-compilation
https://docs.monogame.net/articles/getting_started/1_setting_up_your_development_environment_ubuntu.html#optional-set-up-wine-for-effect-compilation

So from reading the script used in optional-set-up-wine-for-effect-compilation I think there is now a wineprefix which has the dependencies for effect compilation installed?

What now? I guess I need to install the mgcb editor in Wine so that when I start the editor it has access to the dependencies?

Here is the script which is used in the documentation

#!/bin/bash
# This script is used to setup the needed Wine environment
# so that mgfxc can be run on Linux / macOS systems.

# check dependencies
if ! type "wine64" > /dev/null 2>&1
then
    echo "wine64 not found"
    exit 1
fi

if ! type "7z" > /dev/null 2>&1
then
    echo "7z not found"
    exit 1
fi

# init wine stuff
export WINEARCH=win64
export WINEPREFIX=$HOME/.winemonogame
wine64 wineboot

TEMP_DIR="${TMPDIR:-/tmp}"
SCRIPT_DIR="$TEMP_DIR/winemg2"
mkdir -p "$SCRIPT_DIR"

# get dotnet
DOTNET_URL="https://download.visualstudio.microsoft.com/download/pr/adeab8b1-1c44-41b2-b12a-156442f307e9/65ebf805366410c63edeb06e53959383/dotnet-sdk-3.1.201-win-x64.zip"
curl $DOTNET_URL --output "$SCRIPT_DIR/dotnet-sdk.zip"
7z x "$SCRIPT_DIR/dotnet-sdk.zip" -o"$WINEPREFIX/drive_c/windows/system32/"

# get d3dcompiler_47
FIREFOX_URL="https://download-installer.cdn.mozilla.net/pub/firefox/releases/62.0.3/win64/ach/Firefox%20Setup%2062.0.3.exe"
curl $FIREFOX_URL --output "$SCRIPT_DIR/firefox.exe"
7z x "$SCRIPT_DIR/firefox.exe" -o"$SCRIPT_DIR/firefox_data/"
cp -f "$SCRIPT_DIR/firefox_data/core/d3dcompiler_47.dll" "$WINEPREFIX/drive_c/windows/system32/d3dcompiler_47.dll"

# append MGFXC_WINE_PATH env variable
echo "export MGFXC_WINE_PATH=$HOME/.winemonogame" >> ~/.profile
echo "export MGFXC_WINE_PATH=$HOME/.winemonogame" >> ~/.zprofile

# cleanup
rm -rf "$SCRIPT_DIR"

Got it working :sweat_smile:

The steps above are everything you need to do. Just make sure that you have set up an environment variable MGFXC_WINE_PATH=/home/<user>/.winemonogame (replace with your username!) pointing to the right wineprefix. You can then just use the mgcb-editor and it should be able to do the effect compilation.

I did the same thing on Linux Mint 20 and am still getting this error when building:

MGFXC effect compiler requires a valid Wine installation to be able to compile shaders.
Setup instructions:
- Create 64 bit wine prefix
- Install d3dcompiler_47 using winetricks
- Install .NET Core 3
- Setup MGFXC_WINE_PATH environment variable to point to a valid wine prefix

I installed the mgcb-editor and ran the bash script, then set the variable with export MGFXC_WINE_PATH=/home/myuser/.winemonogame. I’ve also closed and reopened the mgcb editor to make sure.

I have a pending pull request to make sure there are linebreaks before the new exports in the files ~/.profile and ~/.zprofile. https://github.com/Kwyrky/MonoGame/pull/1

Check these if they are OK. If they are make sure the variable is set, e.g. open a new terminal and just print it with echo $MGFXC_WINE_PATH. If it is, it should be possible to run the tool from the same terminal with mgcb-editor. Does this work for you?

Thanks! After a restart and adding the line breaks, it actually starts building, but now it fails with no error message, even in debug mode. All the paths look correct to me.

OK, just as a side note for others maybe I should have put it more clearly that the linebreaks where necessary in my case because it appended the lines with the export statements right at the end and I had a ~/.profile which had text in the last line. So the pull request is only to make sure that the commands end up as a valid command in their own lines. They don’t need an extra line in between or something.

So what I tested so far is only to add a new content project and add a new effect to it and hit build which worked. All inside the mgcb-tool. I did not try to build a game with content so far which I guess is what you tried?

The new lines you added should not be needed as the command itself will always add the env variable in a new line.

Also just a logout and login is needed to refresh the env variables, I think I forgot to mention it in the docs.

PS. You made a PR against your own repo XD

lol I thought GitHub would select the base repository automatically. Lets try again: https://github.com/MonoGame/MonoGame/pull/7327

This scenario is possible only if there is no linebreak / empty line before running the script. This can be seen with this example script:

#! /bin/bash

echo -n "TEST" > no-empty-line-at-the-end
echo "export would end up in the last line right after the command which was there" >> no-empty-line-at-the-end

echo "TEST" > empty-line-at-the-end
echo "export would end up in the last line right but it was empty so it is ok" >> empty-line-at-the-end

echo -n "TEST" > no-empty-line-at-the-end-updated-script
echo "" >> no-empty-line-at-the-end-updated-script # FIX
echo "export would end up in the last line right after the command which was there but we made sure there will be a new line" >> no-empty-line-at-the-end-updated-script
# empty-line-at-the-end
TEST
export would end up in the last line right but it was empty so it is ok

# no-empty-line-at-the-end
TESTexport would end up in the last line right after the command which was there

# no-empty-line-at-the-end-updated-script
TEST
export would end up in the last line right after the command which was there but we made sure there will be a new line

I think this time the pull request ended up in the right repository :smile: :partying_face: :tada:

Yes, I tried building just an effect in a new project. It fails for both brand new and existing effects.

Yes but are you working inside the mgcb-tool or did you run dotnet from the command line to build and run the project? I only tested it shortly with the mgcb-tool so far. I will try to do a quick test as soon as I find time for that.

Oh sorry, I missed that part of your previous message. I’m building through the mgcb-editor.

I just did a quick test. It works fine in both cases. So using the mgcb-editor as well as getting the content build by running the dotnet run command.

Is there an error message when you build the content?

Unfortunately not, whether I run it in Debug mode or even in the Terminal.

Here’s what I see for the output:

Immediately before you start mgcb-tool in the command line I would print the environment variable(s). I think printenv | grep MGFXC_WINE_PATH to be sure that it is available / defined for the mgcb-tool. If it is I don’t know what else could be the reason that it is not building effect files.

Does other content apart from effects get build with the tool?

I did all that and the environment variable path is correct. Other content, such as textures, build just fine. Maybe @harry-cpp might know the issue?

1 Like