Skip to content

Commit 95f2f22

Browse files
committed
📝 Update readme.md
1 parent b033417 commit 95f2f22

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

Readme.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository shows a demonstration of interoperability between Unity Engine a
66

77
## Plugins
88

9-
The folder `Plugin` contains a solution that can be generated for visual studio 2019 using [Premake5](https://premake.github.io/download/) with command :
9+
The folder `Plugin` contains a solution that can be generated for visual studio 2019 using [Premake5](https://premake.github.io/download/) with the module [premake5-cuda](https://github.com/theComputeKid/premake5-cuda) :
1010

1111
```
1212
premake5 vs2019
@@ -28,13 +28,14 @@ An `Action` is a base class from which we can inherits to override functions. Th
2828

2929
This library contains two basics examples of actions :
3030
- ActionSampleTexture : it register a Unity __texture__ into CUDA and write some color into it.
31+
- ActionSampleTextureArray : it register a Unity __texture array__ into CUDA and write some color into each texture slice.
3132
- ActionSampleVertexBuffer : it register a Unity __vertex buffer of `float4`__ into CUDA and change their values.
3233

3334
## InteropUnityCUDA the Unity project
3435

3536
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).
3637

37-
The project has only one scene that demonstrate the two simple actions describe above.
38+
The project has only one scene that demonstrate the three simple actions describe above.
3839

3940
# Create your own action
4041

@@ -86,25 +87,24 @@ int Start() override
8687
{
8788
// this has to be done once at start
8889
_texture->registerTextureInCUDA();
90+
// this will map the registered texture in cuda
91+
_texture->mapTextureToSurfaceObject();
8992
return 0;
9093
}
9194
9295
int Update() override
9396
{
94-
// this will map the registered texture in cuda
95-
cudaSurfaceObject_t surf = _texture->mapTextureToSurfaceObject();
96-
// write into it
97-
_texture->writeTexture(surf, GetTime());
98-
// unmap it
99-
_texture->unMapTextureToSurfaceObject(surf);
100-
101-
// call interoperability function here
10297
// call your kernel here
98+
// you can write into a texture using `surf2Dwrite` function
99+
// (see. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html?highlight=surf2dwrite#surf2dwrite)
100+
// to get the cudaSurfaceObject_t you can use getter getSurfaceObjectArray()
103101
return 0;
104102
}
105103
106104
int OnDestroy() override
107105
{
106+
// unmap it
107+
_texture->unmapTextureToSurfaceObject();
108108
_texture->unRegisterTextureInCUDA();
109109
return 0;
110110
}
@@ -130,20 +130,23 @@ public:
130130
int Start() override
131131
{
132132
_texture->registerTextureInCUDA();
133+
_texture->mapTextureToSurfaceObject();
133134
return 0;
134135
}
135136
136137
int Update() override
137138
{
138-
cudaSurfaceObject_t surf = _texture->mapTextureToSurfaceObject();
139-
_texture->writeTexture(surf, GetTime());
140-
_texture->unMapTextureToSurfaceObject(surf);
139+
// this kernel can be found in SampleBasic project and sample_kernels.cu
140+
kernelCallerWriteTexture(_texture->getDimGrid(), _texture->getDimBlock(),
141+
_texture->getSurfaceObject(), GetTime(),
142+
_texture->getWidth(), _texture->getHeight());
141143
return 0;
142144
}
143145
144146
int OnDestroy() override
145147
{
146-
_texture->unRegisterTextureInCUDA();
148+
_texture->unmapTextureToSurfaceObject(surf);
149+
_texture->unregisterTextureInCUDA();
147150
return 0;
148151
}
149152
@@ -233,7 +236,8 @@ protected override void CallOnDestroy()
233236

234237
# Platform availability
235238

236-
It's has been tested only on Unity 2021.1 and CUDA 11.7. At the moment it only work with OpenGL.
239+
It's has been tested only on Unity 2021.1 and CUDA 12.1. At the moment it only work with OpenGL and DirectX11.
240+
For DirectX11 texture only works with `Texture2D` type not with `RenderTexture` (see. https://github.com/davidAlgis/InteropUnityCUDA/issues/2).
237241

238242
# Meta
239243

0 commit comments

Comments
 (0)