Skip to content

Commit

Permalink
✨🚧 Add an example of texture array writing on DX11 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
davidAlgis committed Mar 9, 2023
1 parent f6c5e79 commit 84220a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
30 changes: 6 additions & 24 deletions Plugin/PluginInteropUnityCUDA/src/Texture/texture_D3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,14 @@ Texture_D3D11::~Texture_D3D11()
/// </summary>
void Texture_D3D11::registerTextureInCUDA()
{
// texture2D and texture2D array are ID3D11Texture2D in Unity for DX11
ID3D11Texture2D *texUnityDX11 = (ID3D11Texture2D *)_textureHandle;

// we cast it here, to make it only once.
if(_textureDepth < 1)
{
auto texUnityDX11 = (ID3D11Texture2D *)_textureHandle;
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
CUDA_CHECK(cudaGetLastError());
}
else
{
auto texUnityDX11 = (ID3D11Texture3D *)_textureHandle;
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
CUDA_CHECK(cudaGetLastError());
}
// assert(texUnityDX11);
// D3D11_TEXTURE2D_DESC texDesc;
// texUnityDX11->GetDesc(&texDesc);

// DXGI_FORMAT format = texDesc.Format;
// Log::log().debugLog(std::to_string(format));

// CUDA_CHECK(cudaGetLastError());
// register the texture to cuda : it initialize the _pGraphicsResource

CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));

CUDA_CHECK(cudaGetLastError());
}

void Texture_D3D11::unRegisterTextureInCUDA()
Expand Down
11 changes: 1 addition & 10 deletions Plugin/SampleBasic/src/action_sample_texture_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ActionSampleTextureArray::ActionSampleTextureArray(void *texturePtr, int width,
inline int ActionSampleTextureArray::Start()
{
_texture->registerTextureInCUDA();
_surf = _texture->mapTextureToSurfaceObject();
_surf = _texture->mapTextureToSurfaceObject(1);
return 0;
}

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

//for (int i = 0; i < _texture->getDepth(); i++)
//{
// cudaSurfaceObject_t surf = _texture->mapTextureToSurfaceObject(i);
// kernelCallerWriteTexture(_texture->getDimGrid(),
// _texture->getDimBlock(), surf, GetTime()+2*i, _texture->getWidth(),
// _texture->getHeight());
// _texture->unMapTextureToSurfaceObject(surf);
//}

cudaDeviceSynchronize();
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion Plugin/SampleBasic/src/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void kernelCallerWriteTextureArray(const dim3 dimGrid, const dim3 dimBlock,
const float time, const int width,
const int height, const int depth)
{
writeTexArray<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height,depth, time);
// writeTexArray<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height,depth, time);
writeTex<<<dimGrid, dimBlock>>>(inputSurfaceObj, width, height, time);
}


Expand Down

0 comments on commit 84220a4

Please sign in to comment.