Skip to content

Commit 0aae79e

Browse files
committed
✨🚧 Add an example of texture array writing on DX11 #3
1 parent e34e5df commit 0aae79e

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

Plugin/PluginInteropUnityCUDA/src/Texture/texture_D3D11.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,14 @@ Texture_D3D11::~Texture_D3D11()
2727
/// </summary>
2828
void Texture_D3D11::registerTextureInCUDA()
2929
{
30+
// texture2D and texture2D array are ID3D11Texture2D in Unity for DX11
31+
ID3D11Texture2D *texUnityDX11 = (ID3D11Texture2D *)_textureHandle;
3032

31-
// we cast it here, to make it only once.
32-
if(_textureDepth < 1)
33-
{
34-
auto texUnityDX11 = (ID3D11Texture2D *)_textureHandle;
35-
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
36-
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
37-
CUDA_CHECK(cudaGetLastError());
38-
}
39-
else
40-
{
41-
auto texUnityDX11 = (ID3D11Texture3D *)_textureHandle;
42-
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
43-
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
44-
CUDA_CHECK(cudaGetLastError());
45-
}
46-
// assert(texUnityDX11);
47-
// D3D11_TEXTURE2D_DESC texDesc;
48-
// texUnityDX11->GetDesc(&texDesc);
49-
50-
// DXGI_FORMAT format = texDesc.Format;
51-
// Log::log().debugLog(std::to_string(format));
52-
53-
// CUDA_CHECK(cudaGetLastError());
5433
// register the texture to cuda : it initialize the _pGraphicsResource
55-
34+
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
35+
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
36+
37+
CUDA_CHECK(cudaGetLastError());
5638
}
5739

5840
void Texture_D3D11::unRegisterTextureInCUDA()

Plugin/SampleBasic/src/action_sample_texture_array.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ActionSampleTextureArray::ActionSampleTextureArray(void *texturePtr, int width,
2525
inline int ActionSampleTextureArray::Start()
2626
{
2727
_texture->registerTextureInCUDA();
28-
_surf = _texture->mapTextureToSurfaceObject();
28+
_surf = _texture->mapTextureToSurfaceObject(1);
2929
return 0;
3030
}
3131

@@ -36,15 +36,6 @@ int ActionSampleTextureArray::Update()
3636
_surf, GetTime(), _texture->getWidth(),
3737
_texture->getHeight(), _texture->getDepth());
3838

39-
//for (int i = 0; i < _texture->getDepth(); i++)
40-
//{
41-
// cudaSurfaceObject_t surf = _texture->mapTextureToSurfaceObject(i);
42-
// kernelCallerWriteTexture(_texture->getDimGrid(),
43-
// _texture->getDimBlock(), surf, GetTime()+2*i, _texture->getWidth(),
44-
// _texture->getHeight());
45-
// _texture->unMapTextureToSurfaceObject(surf);
46-
//}
47-
4839
cudaDeviceSynchronize();
4940
return 0;
5041
}

Plugin/SampleBasic/src/main.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void kernelCallerWriteTextureArray(const dim3 dimGrid, const dim3 dimBlock,
6161
const float time, const int width,
6262
const int height, const int depth)
6363
{
64-
writeTexArray<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height,depth, time);
64+
// writeTexArray<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height,depth, time);
65+
writeTex<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height, time);
6566
}
6667

6768

0 commit comments

Comments
 (0)