This repository shows a demonstration of interoperability between Unity Engine and CUDA. More specifically it proposes to create and render graphics objects (eg. texture) in Unity and editing them directly through CUDA kernel. This permit to bypass compute shader and to benefits of the full capacity of CUDA.
The Plugin
folder contains the c++ library used for interoperability. They can be regenerated with CMake. Assuming you are at the root of interopUnityCUDA, here are the commands to execute:
cd .\Plugin
mkdir build
cmake -B build
Then to compile it :
cmake --build build --config Release
cmake --build build --config Debug
Moreover, to use the library in you unity project, you need to copy the content of the folder Debug
and Release
to your unity project.
The C++ projet consists of three library :
This library include a singleton logger to simplify debugging between Unity and Native Plugin. Moreover it contains Unity native plugin API used by the other library.
This library contains the class that handle interoperability between Unity, Graphics API and CUDA. Moreover, it has function to register and call new Action
.
An Action
is a base class from which we can inherits to override functions. These functions will be called on render thread which is a necessary condition to make interoperability works.
This library contains two basics examples of actions :
- ActionSampleTexture : it register a Unity texture into CUDA and write some color into it.
- ActionSampleTextureArray : it register a Unity texture array into CUDA and write some color into each texture slice.
- ActionSampleVertexBuffer : it register a Unity vertex buffer of
float4
into CUDA and change their values.
The folder InteropUnityCUDA
contains the Unity project with the script to handle actions and call them in render thread. Furthermore, there is a script to display in Unity the log informations of the different plugin that use logger of Utilities (see. above).
The project has only one scene that demonstrate the three simple actions describe above.
See the dedicated documentation here.
See the dedicated documentation here.
It has been tested only on Unity 2021.1 and CUDA 12.2. At the moment it only work with OpenGL and DirectX11 graphics API. The plugin has been made for windows, but it can be compile with Linux too.
For DirectX11 texture only works with Texture2D
type not with RenderTexture
(see. #2).
This repository has been developed within the scopes of the thesis of David Algis in collaboration with XLIM and Studio Nyx.