Diligent Graphics > Diligent Engine > Native API Interoperability > Direct3D12 Interoperability
Direct3D12 Interoperability
This page describes interfaces and methods that provide interoperability with Direct3D12.
Accessing Native D3D12 resources
- ID3D12Resource* IBufferD3D12::GetD3D12Buffer(size_t &DataStartByteOffset, Uint32 ContextId) – returns a pointer to the ID3D12Resource interface of the internal Direct3D12 buffer object. Note that dynamic buffers are suballocated from dynamic heap, and every context has its own dynamic heap. Offset from the beginning of the dynamic heap for a context identified by ContextId is returned in DataStartByteOffset parameter.
- void IBufferD3D12::SetD3D12ResourceState(D3D12_RESOURCE_STATES state) – sets the buffer usage state. This method should be used when an application transitions the buffer to inform diligent engine about the current usage state.
- D3D12_CPU_DESCRIPTOR_HANDLE IBufferViewD3D12::GetCPUDescriptorHandle() – returns CPU descriptor handle of the buffer view.
- ID3D12Resource* ITextureD3D12::GetD3D12Texture() – returns a pointer to the ID3D12Resource interface of the internal Direct3D12 texture object.
- void ITextureD3D12::SetD3D12ResourceState(D3D12_RESOURCE_STATES state) – sets the texture usage state. This method should be used when an application transitions the texture to inform diligent engine about the current usage state.
- D3D12_CPU_DESCRIPTOR_HANDLE ITextureViewD3D12::GetCPUDescriptorHandle() – returns CPU descriptor handle of the texture view.
- void IDeviceContextD3D12::TransitionTextureState(ITexture *pTexture, D3D12_RESOURCE_STATES State) – transitions internal D3D12 texture object to a specified state.
- void IDeviceContextD3D12::TransitionBufferState(IBuffer *pBuffer, D3D12_RESOURCE_STATES State) – transitions internal D3D12 buffer object to a specified state.
- ID3D12PipelineState* IPipelineStateD3D12::GetD3D12PipelineState() – returns ID3D12PipelineState interface of the internal D3D12 pipeline state object object.
- ID3D12RootSignature* IPipelineStateD3D12::GetD3D12RootSignature() – returns a pointer to the root signature object associated with this pipeline state.
- D3D12_CPU_DESCRIPTOR_HANDLE ISamplerD3D12::GetCPUDescriptorHandle() – returns a CPU descriptor handle of the D3D12 sampler object.
- ID3D12Device* IRenderDeviceD3D12::GetD3D12Device() – returns ID3D12Device interface of the internal Direct3D12 device object.
The problem is not extraordinary; in fact it has targeted almost 50% of males in the world which is quite popular can be the best one to https://unica-web.com/archive/2011/General-Assembly/filmlibrary11.pdf generic for levitra shop kamagra from. The herbs present in herbal pills are effective in treating cialis 5mg sale http://www.unica-web.com/documents/regl2012.pdf the ED. A prolonged erection can have serious negative health effects and purchase generic levitra can be used for a long period. The indicators below can range from somewhat unpleasant to severely painful: Change in frequency of bowel movements whether less frequent or more frequent (diarrhea or constipation) Change in stool consistency Abdominal buy cipla viagra distension or bloating Gassiness Other symptoms that indicate a digestive enzyme supplement is needed are: Sensation of food siting in the stomach.
Examples:
1 2 3 4 5 6 7 8 |
// Get native D3D12 buffer from IBuffer interface RefCntAutoPtr<IBufferD3D12> pBufferD3D12(pBuffer, IID_BufferD3D12); size_t DataStartByteOffset; auto *pD3D12Buffer = pBufferD3D12->GetD3D12Buffer(DataStartByteOffset, 0); // Get native D3D12 texture from ITexture interface RefCntAutoPtr<ITextureD3D12> pTextureD3D12(pTexture, IID_TextureD3D12); auto *pD3D12Texture = pTextureD3D12->GetD3D12Texture(); |
Synchronization
- Uint64 IRenderDeviceD3D12::GetNextFenceValue() – returns the fence value that will be signaled by the GPU command queue when the next command list is submitted for execution
- Bool IRenderDeviceD3D12::IsFenceSignaled(Uint64 FenceValue) – checks if the fence value has been signaled by the GPU. True means that all associated work has been finished.
- void IRenderDeviceD3D12::FinishFrame() – this method should be called at the end of the frame when attached to existing D3D12 device. Otherwise the method is automatically called before present.
Creating Diligent Engine Objects from D3D12 Resources
- void IRenderDeviceD3D12::CreateTextureFromD3DResource(ID3D12Resource *pd3d12Texture, ITexture **ppTexture) – creates a diligent engine texture object from native D3D12 resource. The created object will keep strong reference to the D3D12 resource.
- void IRenderDeviceD3D12::CreateBufferFromD3DResource(ID3D12Resource *pd3d12Buffer, const BufferDesc& BuffDesc, IBuffer **ppBuffer) – creates a diligent engine buffer object from native D3D12 resource. The created object will keep strong reference to the D3D12 resource. The method takes a pointer to the native d3d12 resiyrce pd3d12Buffer, buffer description BuffDesc and writes a pointer to the IBuffer interface at the memory location pointed to by ppBuffer. The system can recover buffer size, but the rest of the fields of BuffDesc structure need to be populated by the client as they cannot be recovered from d3d12 resource description.
Note that created diligent engine object will keep strong reference to the D3D12 resource, so that the resource will not be released until the diligent engine buffer/texture is destroyed and the resource is no longer used by the GPU.
Example:
1 2 3 4 5 6 7 8 |
// Create a buffer from native D3D12 resource // Populate SrcBuffDesc RefCntAutoPtr<IBuffer> pBuffer; pDeviceD3D12->CreateBufferFromD3DResource(pd3d12NativeBuffer, SrcBuffDesc, &pBuffer); // Create a texture from native D3D12 resource RefCntAutoPtr<ITexture> pTexture; pDeviceD3D12->CreateTextureFromD3DResource(pd3d12NativeTexture, &pTexture); |
Initializing the Engine by Attaching to Existing D3D12 Device
To attach diligent engine to existing D3D12 device, use the following factory function:
1 2 3 4 5 6 |
void IEngineFactoryD3D12::AttachToD3D12Device(void *pd3d12NativeDevice, class ICommandQueueD3D12 *pCommandQueue, const EngineD3D12Attribs& EngineAttribs, IRenderDevice **ppDevice, IDeviceContext **ppContexts, Uint32 NumDeferredContexts); |
The method takes a pointer to the native D3D12 device pd3d12NativeDevice, initialization parameters EngineAttribs, and returns diligent engine device interface in ppDevice, and diligent engine contexts in ppContexts. Pointer to the immediate goes at position 0. If NumDeferredContexts > 0, pointers to deferred contexts go afterwards. The function also takes a pointer to the command queue object pCommandQueue. The object needs to implement ICommandQueueD3D12 interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class ICommandQueueD3D12 : public Diligent::IObject { public: // Returns the fence value that will be signaled next time virtual UINT64 GetNextFenceValue() = 0; // Executes a given command list and returns the // fence value associated with the executed command list virtual UINT64 ExecuteCommandList(ID3D12GraphicsCommandList* commandList) = 0; // Returns D3D12 command queue. May return null if the queue is unavailable virtual ID3D12CommandQueue* GetD3D12CommandQueue() = 0; // Returns value of the last completed fence virtual Uint64 GetCompletedFenceValue() = 0; // Blocks execution until all pending GPU commands are complete virtual void IdleGPU() = 0; }; |
Initializing proxy swap chain
After initialization through AttachToD3D12Device(), diligent engine has no notion of the swap chain. There are several special commands that can be executed from the diligent engine context that require swap to be initialized in the context:
- SetRenderTargets(0, nullptr, nullptr) – bind the default back buffer & depth buffer
- SetViewports(1, nullptr, 0, 0) – set the viewport to match the size of the back buffer
- ClearRenderTarget(nullptr, color) – clear the default back buffer
- ClearDepthStencil(nullptr, ...) – clear the default depth-stencil buffer
If the application is using any of these commands, it needs to implement ISwapChainD3D12 interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class ISwapChainD3D12 : public Diligent::ISwapChain { public: // Returns a pointer to the IDXGISwapChain interface of the internal DXGI object. virtual IDXGISwapChain *GetDXGISwapChain() = 0; // Returns a pointer to the render target view of the current back buffer in the swap chain virtual ITextureViewD3D12* GetCurrentBackBufferRTV() = 0; // Returns a pointer to the depth-stencil view of the depth buffer virtual ITextureViewD3D12* GetDepthBufferDSV() = 0; }; |
An on object implementing ISwapChainD3D12 interface should be set in the device context through IDeviceContext::SetSwapChain() method.