Quantcast
Channel: Questions in topic: "native plugin"
Viewing all articles
Browse latest Browse all 376

Update DX11 texture asynchronously in native plugin?

$
0
0
Sorry for the long question :D **tl;dr version :)** Is it possible to update DirectX 11 textures asynchronously in native plugin (C++)? I've written a plugin that retrieves data from Kinect. Currently, color stream data is written to a texture created by Unity in a separate thread in the plugin using DirectX 9 as shown in the example below. D3DLOCKED_RECT lockedRectangle; colorFrameTextureDX9->LockRect(0, &lockedRectangle, NULL, 0); memcpy(lockedRectangle.pBits, colorFrameMat.data, colorFrameMat.total() * colorFrameMat.channels()); colorFrameTextureDX9->UnlockRect(0); With DX9 this works beautifully. As far as I know calling *LockRect* on a DX9 texture locks the texture data and *memcpy* after that is thread safe. ---------- Using [this][1] code sample from unity I've added support for DX11 textures. ID3D11DeviceContext *ctx = NULL; device->GetImmediateContext(&ctx); // Device is sent from Unity D3D11_TEXTURE2D_DESC desc; colorFrameTextureDX11->GetDesc(&desc); ctx->UpdateSubresource(colorFrameTextureDX11, 0, NULL, colorFrameMat.data, colorFrameMat.cols * colorFrameMat.channels(), 0); ctx->Release(); When Unity is run in DX11 mode, this runs perfectly for a few second after which it crashes without error report. I believe the problem is in using [UpdateSubresource][2] method which doesn't lock the texture causing simultaneous access from Unity's rendering pipeline and plugin thread. In DX11 documentation I came across the [Map][3]/[Unmap][4] methods for updating textures which work similarly to [LockRect][5]/[UnlockRect][6] methods from DX9. However these methods can only be used with DX11 textures created as [D3D11_USAGE_DYNAMIC][7] and the texture from Unity is created as [D3D11_USAGE_DEFAULT][8]. Is it possible to change or recreate the texture created in Unity with different usage flags? Thanks in advance to anyone who even read it all :D [1]: http://docs.unity3d.com/uploads/Examples/RenderingPluginExample45.zip [2]: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx [3]: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx [4]: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476485(v=vs.85).aspx [5]: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205913(v=vs.85).aspx [6]: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205914(v=vs.85).aspx [7]: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476259(v=vs.85).aspx [8]: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476259(v=vs.85).aspx

Viewing all articles
Browse latest Browse all 376

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>