Jump to content

How to access native D3D12/D3D11 handles in Unigine 2.20?


photo

Recommended Posts

Posted

Dear members of Unigine.

I am trying to create plugin for an external graphics library and I need to get access to the native DX handles. 

The external graphics library creates its GPU context on the application’s real device/queue. Its APIs require these pointers:

  • int dpCreateContextD3D12(dpContext** out, void* d3d12_device, void* d3d12_command_queue, unsigned int plugin_id);
  • int dpCreateContextD3D11(dpContext** out, void* d3d11_device, unsigned int plugin_id);

 

This is part of the api that show cases what I need (i think)

/// This function creates a new context, which is needed for using the correction library
/// @param ppContext The address of a pointer variable that receives the pointer to a newly created dpContext
/// @param pDevice   A pointer to an ID3D12Device which is used for creating global resources during 
///                  context creation.
/// @param pQueue    A pointer to an ID3D12CommandQueue to create the commandlist and allocators with.
/// @param pluginId  The ID given 
/// @return The function return dpNoError when the context was created successful. If ppContext, pDevice or pQueue is NULL
///         this method return dpInvalidPointer. If dpD3DError is returned the internal used resources creation
///         has failed.
/// @remark NOTE: At this moment, we do not deal with multiple devices or command queues in the same context.
/// A plugin, which needs to run on multi-GPU or uses multiple command queues, must initialize multiple context instances.
DPLIB_API dpResult dpCreateContextD3D12( dpContext** ppContext, ID3D12Device* pDevice, ID3D12CommandQueue* pQueue, unsigned int pluginId );

Could you please advice the supported way for a C++ plugin to get these native handles at runtime. For example, anything similar to these speculative functions examples)

A public RenderContext interface, e.g.:   (Note: Not sure if render context is relevant for DX12)
auto rc   = Unigine::Render::getContext();
auto rc12 = Unigine::RenderContextD3D12::cast(rc);
ID3D12Device dev = rc12 ? rc12->getD3DDevice() : nullptr;
ID3D12CommandQueue q = rc12 ? rc12->getGraphicsCommandQueue() : nullptr;

Or direct render accessors: ( More speculative examples) 
ID3D12Device dev = (ID3D12Device)Unigine::Render::getD3D12Device();
ID3D12CommandQueue q = (ID3D12CommandQueue)Unigine::Render::getD3D12CommandQueue();
ID3D11Device dev11 = (ID3D11Device*)Unigine::Render::getD3D11Device();

In addition, is it possible to find the equivalent requests also for vulkan?

I apologize in advance if any of this is off base; I am new to both Unigine and graphics programming.

All the best. 
Mario

Posted

Hi Mario,

Unfortunately, there is currently no native D3D12/D3D11 native interfaces that will allow you to do this easily. They may appear in API in the future SDK versions. Now you can try to create your own D3D11/D3D12 device and use ResourceExternalMemory / ResourceFence to obtain needed textures and syncronize them with the engine side.

There is also CUDA sample in Sim edition that shows how to use these classes properly to communicate with CUDA device and it's memory, however, no such samples available for Community SDK yet.

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...