[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

The script is not working for me. When I put {

wget -qO- https://raw.githubusercontent.com/MonoGame/MonoGame/develop/Tools/MonoGame.Effect.Compiler/mgfxc_wine_setup.sh | bash

}

into my terminal, I get the following errors:

/tmp/winemg2 ~
~
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0Warning: Failed to create the file /tmp/winemg2/dotnet-sdk.zip: No such file
Warning: or directory
0 184M 0 15946 0 0 31892 0 1:41:14 --:–:-- 1:41:14 32214
curl: (23) Failure writing output to destination

7-Zip [64] 16.02 : Copyright © 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs Intel® Core™ i7-6567U CPU @ 3.30GHz (406E3),ASM,AES-NI)

Scanning the drive for archives:

ERROR: No more files
/tmp/winemg2/dotnet-sdk.zip

System ERROR:
Unknown error -2147024872
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0Warning: Failed to create the file /tmp/winemg2/firefox.exe: No such file or
Warning: directory
0 38.3M 0 15852 0 0 91630 0 0:07:18 --:–:-- 0:07:18 91630
curl: (23) Failure writing output to destination

7-Zip [64] 16.02 : Copyright © 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs Intel® Core™ i7-6567U CPU @ 3.30GHz (406E3),ASM,AES-NI)

Scanning the drive for archives:

ERROR: No more files
/tmp/winemg2/firefox.exe

System ERROR:
Unknown error -2147024872
cp: cannot stat ‘/tmp/winemg2/firefox_data/core/d3dcompiler_47.dll’: No such file or directory

I have never used Wine before and I have never used bash commands before. I don’t know what I’m doing, but I know that this script needs to be updated in order to work. Can anyone assist?

UPDATE:

I’d just like to mention that I have all of the environment variables in place and yes I have the wine prefix in my home folder and yes I installed d3dcompiler_47 onto it. I could not install .NET Core 3 onto the wine prefix because it complains that I am supposed to use a 32 version of a wine prefix in order to install dotnotcore 30 onto it… even though everyone else is using the 64 version… but I have dotnet3 on my machine so not sure if that matters or not.

Mine wasn’t working before so I did a complete redo of:

sudo apt install wine64 p7zip-full

and then did a redo of:

wget -qO- https://raw.githubusercontent.com/MonoGame/MonoGame/master/Tools/MonoGame.Effect.Compiler/mgfxc_wine_setup.sh | bash

But… then I noticed it was quitting the commands after the 7z for the:

# get dotnet
...
7z x ........................

(and I don’t know much about Linux yet either)
So I pasted into the CLI from Kwyrky’s script above for the next few lines:

# 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"

And then pasted this after it finished:

# 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"

Then to be extra sure, I went into terminal in VSCode and did:

MGFXC_WINE_PATH=/home/jei/.winemonogame

(where jei is my username)
so… then I did a save and rebuild of the fx and voila… it works.
I don’t know if this helps in your situation or not, but I post this reply here in case it helps anyone.

(Previously I was copying xnb’s from Windows but maybe those don’t always work from what I’ve heard… question mark?)

Anyway thanks to Monogame community… I got it working. :slight_smile:

1 Like