6
6
class Texture
7
7
{
8
8
public:
9
- // / <summary>
10
- // / Constructor of texture
11
- // / </summary>
12
- // / <param name="textureHandle">A pointer of texture with float4 that has
13
- // / been generated with Unity (see function GetNativeTexturePtr
14
- // / https://docs.unity3d.com/ScriptReference/Texture.GetNativeTexturePtr.html)
15
- // / </param> < param name="textureWidth"> the width of the texture</param>
16
- // / < param name="textureHeight"> the height of the texture</param>
17
- // / <param name="textureDepth">the depth of the texture</param>
9
+ /* *
10
+ * Constructor of texture
11
+ * @param textureHandle A pointer of texture with float4 that has
12
+ * been generated with Unity (see function GetNativeTexturePtr
13
+ * https://docs.unity3d.com/ScriptReference/Texture. GetNativeTexturePtr.html)
14
+ * @param textureWidth the width of the texture
15
+ * @ param textureHeight the height of the texture
16
+ * @ param textureDepth the depth of the texture (should be greater than 0)
17
+ */
18
18
UNITY_INTERFACE_EXPORT Texture (void *textureHandle, int textureWidth,
19
- int textureHeight,
20
- int textureDepth);
19
+ int textureHeight, int textureDepth);
21
20
22
- // / <summary>
23
- // / Register the texture in CUDA, this has to be override because it depends
24
- // / on the graphics api
25
- // / </summary>
21
+ /* *
22
+ * Destructor of texture, will free _surfObjArray
23
+ */
24
+ UNITY_INTERFACE_EXPORT ~Texture ();
25
+
26
+ /* *
27
+ * Register the texture in CUDA, this has to be override because it depends
28
+ * on the graphics api
29
+ */
26
30
UNITY_INTERFACE_EXPORT virtual void registerTextureInCUDA () = 0;
27
31
28
- // / <summary>
29
- // / Unregister the texture in CUDA, this has to be override because it
30
- // / depends on the graphics api
31
- // / </summary>
32
- UNITY_INTERFACE_EXPORT virtual void unRegisterTextureInCUDA () = 0;
33
-
34
-
35
- // / <summary>
36
- // / For some API (DX11) CUDA cannot edit the texture created by Unity
37
- // / therefore, we have to create a new texture that will used as a buffer
38
- // / between the unity texture and the surface object that is modify by CUDA
39
- // / For these API, this function will copy the content of the unity texture
40
- // / to this buffer, for the other API. It'll do nothing.
41
- // / If Unity texture has been modify in Unity, you have to do the copy before
42
- // / reading it in CUDA. It's not necessary if you only write into the texture
43
- // / in CUDA, or if the texture has not been modify in Unity.
44
- // / Tips : not necessary for write only in CUDA or read only in Unity
45
- // / </summary>
32
+ /* *
33
+ * Unregistered the texture in CUDA, this has to be override because it
34
+ * depends on the graphics api
35
+ */
36
+ UNITY_INTERFACE_EXPORT virtual void unregisterTextureInCUDA () = 0;
37
+
38
+ /* *
39
+ * For some API (DX11) CUDA cannot edit the texture created by Unity
40
+ * therefore, we have to create a new texture that will used as a buffer
41
+ * between the unity texture and the surface object that is modify by CUDA
42
+ * For these API, this function will copy the content of the unity texture
43
+ * to this buffer, for the other API. It'll do nothing. If Unity texture has
44
+ * been modify in Unity, you have to do the copy before reading it in CUDA.
45
+ * It's not necessary if you only write into the texture in CUDA, or if the
46
+ * texture has not been modify in Unity. Tips : not necessary for write only
47
+ * in CUDA or read only in Unity
48
+ */
46
49
UNITY_INTERFACE_EXPORT virtual void copyUnityTextureToAPITexture () = 0;
47
50
48
-
49
- // / <summary>
50
- // / For some API (DX11) CUDA cannot edit the texture created by Unity
51
- // / therefore, we have to create a new texture that will used as a buffer
52
- // / between the unity texture and the surface object that is modify by CUDA
53
- // / For these API, this function will copy the content of the buffer texture
54
- // / to the unity texture, for the other API. It'll do nothing.
55
- // / If API texture has been modify by, you have to do the copy before
56
- // / reading it in Unity. It's not necessary if you only read into the texture
57
- // / in CUDA, or if the texture is only write only in Unity.
58
- // / Tips : not necessary for read only in CUDA or write only in Unity
59
- // / </summary>
51
+ /* *
52
+ * For some API (DX11) CUDA cannot edit the texture created by Unity
53
+ * therefore, we have to create a new texture that will used as a buffer
54
+ * between the unity texture and the surface object that is modify by CUDA
55
+ * For these API, this function will copy the content of the buffer texture
56
+ * to the unity texture, for the other API. It'll do nothing.
57
+ * If API texture has been modify by, you have to do the copy before
58
+ * reading it in Unity. It's not necessary if you only read into the
59
+ * texture in CUDA, or if the texture is only write only in Unity. Tips :
60
+ * not necessary for read only in CUDA or write only in Unity
61
+ */
60
62
UNITY_INTERFACE_EXPORT virtual void copyAPITextureToUnityTexture () = 0;
61
63
62
- // / <summary>
63
- // / Map a cuda array to the graphics resources and wrap it into a surface
64
- // / object of cuda
65
- // / </summary>
66
- // / <param name="indexInArray"> Array index for array textures or cubemap
67
- // / face index as defined by cudaGraphicsCubeFace for cubemap textures for
68
- // / the subresource to access </param> <returns>a cuda surface object on
69
- // / device memory and which can be edited in cuda</returns>
70
- UNITY_INTERFACE_EXPORT cudaSurfaceObject_t mapTextureToSurfaceObject (
71
- int indexInArray = 0 );
72
-
73
-
74
- // / <summary>
75
- // / Unmap the cuda array from graphics resources and destroy surface object
76
- // / This function will wait for all previous GPU activity to complete
77
- // / </summary>
78
- // / <param name="inputSurfObj">the surface object that has been created with
79
- // / <c>mapTextureToSurfaceObject</c> function</param>
80
- UNITY_INTERFACE_EXPORT void unMapTextureToSurfaceObject (
81
- cudaSurfaceObject_t &inputSurfObj);
82
-
83
- UNITY_INTERFACE_EXPORT cudaSurfaceObject_t* mapTextureArrayToSurfaceObject ();
84
-
85
- UNITY_INTERFACE_EXPORT cudaTextureObject_t mapTextureToTextureObject (
86
- int indexInArray = 0 );
87
-
88
- UNITY_INTERFACE_EXPORT void unMapTextureToTextureObject (
89
- cudaTextureObject_t &texObj);
90
-
91
- // / <summary>
92
- // / Get the default dimension block (8,8,1)
93
- // / </summary>
64
+ /* *
65
+ * Map the cuda array from the graphics resources and create a surface
66
+ * object from it. To write into the surface object use the getter of
67
+ * _surfObjArray.
68
+ */
69
+ UNITY_INTERFACE_EXPORT void mapTextureToSurfaceObject ();
70
+
71
+ /* *
72
+ * Unmap the cuda array from graphics resources and destroy surface object
73
+ * This function will wait for all previous GPU activity to complete
74
+ */
75
+ UNITY_INTERFACE_EXPORT void unmapTextureToSurfaceObject ();
76
+
77
+ /* *
78
+ * Get the default dimension block (8,8,1)
79
+ */
94
80
UNITY_INTERFACE_EXPORT dim3 getDimBlock () const ;
95
81
96
- // / <summary>
97
- // / Get the default dimension grid ((sizeBuffer + 7)/8,((sizeBuffer +
98
- // / 7)/8,1)
99
- // / </summary>
82
+ /* *
83
+ * Get the default dimension grid ((sizeBuffer + 7)/8,((sizeBuffer +
84
+ * 7)/8,1)
85
+ */
100
86
UNITY_INTERFACE_EXPORT dim3 getDimGrid () const ;
101
87
102
- // / <summary>
103
- // / Get the width of the texture
104
- // / </summary>
88
+ /* *
89
+ * Get the width of the texture
90
+ */
105
91
UNITY_INTERFACE_EXPORT int getWidth () const ;
106
92
107
- // / <summary>
108
- // / Get the height of the texture
109
- // / </summary>
93
+ /* *
94
+ * Get the height of the texture
95
+ */
110
96
UNITY_INTERFACE_EXPORT int getHeight () const ;
111
97
112
- // / <summary>
113
- // / Get the depth of the texture
114
- // / </summary>
98
+ /* *
99
+ * Get the depth of the texture
100
+ */
115
101
UNITY_INTERFACE_EXPORT int getDepth () const ;
116
102
117
- // / <summary>
118
- // / Get the native texture pointer
119
- // / </summary>
103
+ /* *
104
+ * Get the native texture pointer
105
+ */
120
106
UNITY_INTERFACE_EXPORT void *getNativeTexturePtr () const ;
121
107
108
+ /* *
109
+ * Get the pointer of _surfObjArray
110
+ * This array of surface object is necessary
111
+ * to write or read into a texture
112
+ */
113
+ UNITY_INTERFACE_EXPORT cudaSurfaceObject_t *getSurfaceObjectArray () const ;
114
+
115
+ /* *
116
+ * Get the surface object associated to the given indexInArray
117
+ * This array of surface object is necessary
118
+ * to write or read into a texture
119
+ * @param indexInArray index of the texture to get the surface object (must
120
+ * be between 0 and textureDepth)
121
+ * @return the surface object associated to it
122
+ */
123
+ UNITY_INTERFACE_EXPORT cudaSurfaceObject_t
124
+ getSurfaceObject (int indexInArray = 0 ) const ;
125
+
122
126
protected:
123
127
// Pointer to the texture created in Unity
124
128
void *_textureHandle;
@@ -129,9 +133,14 @@ class Texture
129
133
// depth of the texture <2 <=> to Texture2D; >1 <=> Texture2DArray
130
134
int _textureDepth;
131
135
// Resource that can be used to retrieve the surface object for CUDA
132
- cudaGraphicsResource *_pGraphicsResource ;
136
+ cudaGraphicsResource *_graphicsResource ;
133
137
134
138
private:
139
+ // An array of surface object that will be of the size of texture depth
140
+ // the surface object is the object that you can used to write into texture
141
+ // from cuda api (eg. with surf2DWrite)
142
+ cudaSurfaceObject_t *_surfObjArray;
143
+
135
144
dim3 _dimBlock;
136
145
dim3 _dimGrid;
137
146
};
0 commit comments