Categories
Software

Home Builder for Blender on Linux with CUDA

Not long ago I was recommended a video on YouTube from Andrew Peel. He has built an addon for Blender that allows a user to drag and drop pre-built home assets into a 3D model to help with home design and visualization.

To use the addon you need to use a custom version of Blender that allows for parametric libraries to be added. Andrew provides a pre-built version of his “Pyclone” Blender version for Windows but one does not exist for macOS or Linux.

After completing the build on macOS, I used the instructions from DiggnDeeper to successfully build the Pyclone version on Linux.

One issue with the build is that he did not work with CUDA yet. So below are the full instructions for building Pyclone on Linux with CUDA (based on the original Blender instructions and DiggnDeeper’s instructions).

Install Packages

Install the essential packages with the package manager.

sudo apt-get update
sudo apt-get install build-essential git subversion cmake libx11-dev libxxf86vm-dev libxcursor-dev libxi-dev libxrandr-dev libxinerama-dev libglew-dev

Install CUDA Toolbox

Next we need to install the CUDA toolbox that is used to compile for nVidia graphics cards. The version below is for Ubuntu 20.04. If you need another version visit NVIDIA’s website and select your version.

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda

Install NVIDIA OptiX

Now not everyone will need Optix support so you can feel free to skip this step if you can’t take advantage of hardware acceleration in RTX cards. But if you need that support then this section is for you.

First you’ll need to sign up for the NVIDIA Developer Program. Don’t worry, it isn’t hard. You just need to create an account and you’ll be approved. So head over there and join.

Next you need to download the OptiX SDK from here. You’ll want to save it in a location where you want it to stay as it will extract files in the location of the script file.

At the time of writing, OptiX version 7.2.0 does not work with Blender 2.91, which is what Pyclone is built on. So you’ll have to scroll all the way to the bottom of the OptiX page and download version 7.1.0.

After downloading you’ll need to run the script. If you downloaded the file to your downloads folder it will look like this.

chmod +x ~/Downloads/NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64.sh
cd ~/Downloads
./NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64.sh

Now you’ll have the OptiX SDK in a place where your Blender build can access it. You’ll need the location of the folder later in the build.

Download Source Code

Now we need to download the source code from CreativeDesigner3D on Github.

mkdir ~/blender-git
cd ~/blender-git
git clone https://github.com/CreativeDesigner3D/BlenderSource.git

Download Required Libraries

I used Blender’s recommendation and used precompiled libraries. There was really no reason for me to recompile them. The ones used are for CentOS 7 but were recommended for an Ubuntu installation.

mkdir ~/blender-git/lib
cd ~/blender-git/lib
svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/linux_centos7_x86_64

Prepare Build

We need to set some custom parameters in order for this build to work with CUDA support on Linux.

mkdir ~/blender-git/build_linux_release
cd ~/blender-git/build_linux_release
cmake ~/blender-git/BlenderSource

CMake will create the needed files we need to customize.

cd ~/blender-git/build_linux_release

Inside the directory you’ll find a file called CMakeCache.txt. That file needs to be opened and the following two settings need to be changed to “ON”.

WITH_CYCLES_CUDA_BINARIES:BOOL=ON
WITH_CYCLES_CUDA_BUILD_SERIAL:BOOL=ON

The setting “WITH_CYCLES_CUDA_BUILD_SERIAL” is not absolutely necessary depending on your computer hardware. On my VM the CUDA compiler was crashing and I had to make sure the processes were running in serial and not in parallel. It makes the build take a little longer, but prevented the crashing. Save the CMakeCache.txt file when you are done editing it.

If you are building with OptiX there are a few more settings you will need to update.

WITH_CYCLES_DEVICE_OPTIX=ON
OPTIX_INCLUDE_DIR=/path/to/NVIDIA-OptiX-SDK-7.x.x-xxx/include

Just change the “/path/to…” to the folder location where you extracted the OptiX SDK. Remember to add the “/include” at the end.

Now there is one file that we need to change permissions on for the build to complete:

chmod +x ~/blender-git/BlenderSource/doc/manpage/blender.1.py

Build the Custom Blender

Now that we have all of the configuration correct it is time to build the custom Blender.

cd ~/blender-git/BlenderSource
make update
make release

That’s it. Sit back and wait while the build happens. It will likely take a while, depending on your computer’s hardware.

If you need some help or have questions, join in the discussion on Discord https://discord.gg/yxZSbtJFkw