Skip to content

Commit eda2bd9

Browse files
committed
✨🚧 Support DX11 on textures without copy (see #2 (comment))
1 parent ffc24df commit eda2bd9

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

Plugin/PluginInteropUnityCUDA/src/Buffer/vertex_buffer_D3D11.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
VertexBuffer_D3D11::VertexBuffer_D3D11(void* bufferHandle, int size)
99
: VertexBuffer(bufferHandle, size)
10-
{}
10+
{
11+
Log::log().debugLogError("Vertex buffer interoperability on DX11 is not yet supported");
12+
}
1113

1214
VertexBuffer_D3D11::~VertexBuffer_D3D11()
1315
{
@@ -20,14 +22,16 @@ VertexBuffer_D3D11::~VertexBuffer_D3D11()
2022
/// </summary>
2123
void VertexBuffer_D3D11::registerBufferInCUDA()
2224
{
23-
Log::log().debugLog("try register");
25+
26+
Log::log().debugLogError("Register buffer on DX11 is not yet supported");
2427
// register the texture to cuda : it initialize the _pGraphicsResource
25-
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(&_pGraphicsResource, (ID3D11Resource*)_bufferHandle, cudaGraphicsRegisterFlagsWriteDiscard));
26-
Log::log().debugLog("register");}
28+
// CUDA_CHECK(cudaGraphicsD3D11RegisterResource(&_pGraphicsResource, (ID3D11Resource*)_bufferHandle, cudaGraphicsRegisterFlagsWriteDiscard));
29+
}
2730

2831
void VertexBuffer_D3D11::unRegisterBufferInCUDA()
2932
{
30-
CUDA_CHECK(cudaGraphicsUnregisterResource(_pGraphicsResource));
33+
Log::log().debugLogError("Unregister buffer on DX11 is not yet supported");
34+
// CUDA_CHECK(cudaGraphicsUnregisterResource(_pGraphicsResource));
3135
}
3236

3337

Plugin/PluginInteropUnityCUDA/src/Texture/texture_D3D11.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Texture_D3D11::Texture_D3D11(void *textureHandle, int textureWidth,
1616

1717
Texture_D3D11::~Texture_D3D11()
1818
{
19-
_texBufferInterop->Release();
19+
// _texBufferInterop->Release();
2020
CUDA_CHECK(cudaGetLastError());
2121
};
2222

@@ -28,33 +28,31 @@ Texture_D3D11::~Texture_D3D11()
2828
void Texture_D3D11::registerTextureInCUDA()
2929
{
3030

31-
// This method initialize the buffer textures that will be registered in
32-
// CUDA This method will use m_device attributes in RenderAPI_D3D11, make
33-
// sure it has been well initialized.
34-
int retCodeCreate = _renderAPI->createTexture2D(
35-
_textureWidth, _textureHeight, _textureDepth, &_texBufferInterop);
36-
// we initialize
37-
if (retCodeCreate < 0)
31+
// we cast it here, to make it only once.
32+
if(_textureDepth < 1)
3833
{
39-
Log::log().debugLogError("Could not initialize texture on DX11 for "
40-
"copy. Interoperability has failed.");
34+
auto texUnityDX11 = (ID3D11Texture2D *)_textureHandle;
35+
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
36+
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
37+
CUDA_CHECK(cudaGetLastError());
4138
}
42-
43-
44-
// we cast it here, to make it only once.
45-
_texUnityDX11 = (ID3D11Texture2D *)_textureHandle;
46-
// assert(_texBufferInterop);
39+
else
40+
{
41+
auto texUnityDX11 = (ID3D11Texture3D *)_textureHandle;
42+
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
43+
&_pGraphicsResource, texUnityDX11, cudaGraphicsRegisterFlagsNone));
44+
CUDA_CHECK(cudaGetLastError());
45+
}
46+
// assert(texUnityDX11);
4747
// D3D11_TEXTURE2D_DESC texDesc;
48-
// _texBufferInterop->GetDesc(&texDesc);
48+
// texUnityDX11->GetDesc(&texDesc);
4949

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

5353
// CUDA_CHECK(cudaGetLastError());
5454
// register the texture to cuda : it initialize the _pGraphicsResource
55-
CUDA_CHECK(cudaGraphicsD3D11RegisterResource(
56-
&_pGraphicsResource, _texBufferInterop, cudaGraphicsRegisterFlagsNone));
57-
CUDA_CHECK(cudaGetLastError());
55+
5856
}
5957

6058
void Texture_D3D11::unRegisterTextureInCUDA()

Plugin/SampleBasic/src/action_sample_texture.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ int ActionSampleTexture::Update()
3131
kernelCallerWriteTexture(_texture->getDimGrid(), _texture->getDimBlock(),
3232
_surf, GetTime(), _texture->getWidth(),
3333
_texture->getHeight());
34-
cudaDeviceSynchronize();
35-
// Log::log().debugLog("copy from API to Unity");
36-
_texture->copyAPITextureToUnityTexture();
34+
// cudaDeviceSynchronize();
3735
return 0;
3836
}
3937

0 commit comments

Comments
 (0)