Diligent Engine API Reference: Diligent::DeviceContextD3D12Impl Class Reference

Diligent Engine API Reference

Public Member Functions | List of all members
Diligent::DeviceContextD3D12Impl Class Reference

Implementation of the Diligent::IDeviceContext interface. More...

Inheritance diagram for Diligent::DeviceContextD3D12Impl:

## Public Member Functions
virtual void | QueryInterface (const Diligent::INTERFACE_ID &IID, IObject **ppInterface) override final
| Queries the specific interface, see IObject::QueryInterface() for details.
virtual void | SetPipelineState (IPipelineState *pPipelineState) override final
| Base implementation of IDeviceContext::SetPipelineState(); caches references to the pipeline state object.
virtual void | TransitionShaderResources (IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding) override final
| Transitions shader resources to the require states. More...
virtual void | CommitShaderResources (IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags) override final
| Commits shader resources to the device context. More...
virtual void | SetStencilRef (Uint32 StencilRef) override final
| Sets the stencil reference value. More...
virtual void | SetBlendFactors (const float *pBlendFactors=nullptr) override final
virtual void | SetVertexBuffers (Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags) override final
| Base implementation of IDeviceContext::SetVertexBuffers(); validates parameters and caches references to the buffers.
virtual void | InvalidateState () override final
| Invalidates the cached context state. More...
virtual void | SetIndexBuffer (IBuffer *pIndexBuffer, Uint32 ByteOffset) override final
| Base implementation of IDeviceContext::SetIndexBuffer(); caches the strong reference to the index buffer.
virtual void | SetViewports (Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight) override final
| Sets an array of viewports. More...
virtual void | SetScissorRects (Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight) override final
| Sets active scissor rects. More...
virtual void | SetRenderTargets (Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil) override final
| Binds one or more render targets and the depth-stencil buffer to the pipeline. It also sets the viewport to match the first non-null render target or depth-stencil buffer. More...
virtual void | Draw (DrawAttribs &DrawAttribs) override final
| Executes a draw command. More...
virtual void | DispatchCompute (const DispatchComputeAttribs &DispatchAttrs) override final
| Executes a dispatch compute command. More...
virtual void | ClearDepthStencil (ITextureView *pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil) override final
| Clears a depth-stencil view. More...
virtual void | ClearRenderTarget (ITextureView *pView, const float *RGBA) override final
| Clears a render target view. More...
virtual void | Flush () override final
| Flushes the command buffer.
virtual void | FinishCommandList (class ICommandList **ppCommandList) override final
| Finishes recording commands and generates a command list. More...
virtual void | ExecuteCommandList (class ICommandList *pCommandList) override final
| Executes recorded commands in a command list. More...
virtual void | TransitionTextureState (ITexture *pTexture, D3D12_RESOURCE_STATES State) override final
| Transitions internal D3D12 texture object to a specified state. More...
virtual void | TransitionBufferState (IBuffer *pBuffer, D3D12_RESOURCE_STATES State) override final
| Transitions internal D3D12 buffer object to a specified state. More...
Public Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextD3D12 >
| DeviceContextBase (IReferenceCounters *pRefCounters, IRenderDevice *pRenderDevice, bool bIsDeferred)
bool | CommitShaderResources (IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int)
| Base implementation of IDeviceContext::CommitShaderResources(); validates parameters.
void | SetViewports (Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight)
| Caches the viewports.
void | SetScissorRects (Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight)
| Caches the scissor rects.
bool | SetRenderTargets (Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy=0)
| Caches the render target and depth stencil views. Returns true if any view is different from the cached value and false otherwise.
virtual void | SetSwapChain (ISwapChain *pSwapChain) override final
| Sets the strong pointer to the swap chain.
ISwapChain * | GetSwapChain ()
| Returns the swap chain.
bool | IsDefaultFBBound ()
| Returns true if currently bound frame buffer is the default frame buffer.
void | GetPipelineState (IPipelineState **ppPSO, float *BlendFactors, Uint32 &StencilRef)
| Returns currently bound pipeline state and blend factors.
void | GetRenderTargets (Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV)
| Returns currently bound render targets.
void | GetViewports (Uint32 &NumViewports, Viewport *pViewports)
| Returns currently set viewports.
IRenderDevice * | GetDevice ()
| Returns the render device.

## Additional Inherited Members
Protected Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextD3D12 >
void | GetRenderTargetSize (Uint32 &RTWidth, Uint32 &RTHeight)
| Returns the size of the currently bound render target.
void | ClearStateCache ()
| Clears all cached resources.
Protected Attributes inherited from Diligent::DeviceContextBase< IDeviceContextD3D12 >
RefCntAutoPtr< IRenderDevice > | m_pDevice
| Strong reference to the device.
RefCntAutoPtr< ISwapChain > | m_pSwapChain
| Strong reference to the swap chain. Swap chain holds weak reference to the immediate context.
VertexStreamInfo | m_VertexStreams [MaxBufferSlots]
| Vertex streams. Every stream holds strong reference to the buffer.
Uint32 | m_NumVertexStreams
| Number of bound vertex streams.
RefCntAutoPtr< IPipelineState > | m_pPipelineState
| Strong reference to the bound pipeline state object.
RefCntAutoPtr< IBuffer > | m_pIndexBuffer
| Strong reference to the bound index buffer.
Uint32 | m_IndexDataStartOffset
| Offset from the beginning of the index buffer to the start of the index data, in bytes.
Uint32 | m_StencilRef
| Current stencil reference value.
Float32 | m_BlendFactors [4]
| Curent blend factors.
Viewport | m_Viewports [MaxRenderTargets]
| Current viewports.
Uint32 | m_NumViewports
| Number of current viewports.
Rect | m_ScissorRects [MaxRenderTargets]
| Current scissor rects.
Uint32 | m_NumScissorRects
| Number of current scissor rects.
RefCntAutoPtr< ITextureView > | m_pBoundRenderTargets [MaxRenderTargets]
| Vector of strong references to the bound render targets.
Uint32 | m_NumBoundRenderTargets
| Number of bound render targets.
bool | m_IsDefaultFramebufferBound
| Flag indicating if default render target & depth-stencil buffer are currently bound.
RefCntAutoPtr< ITextureView > | m_pBoundDepthStencil
| Strong references to the bound depth stencil view.

## Detailed Description

Implementation of the Diligent::IDeviceContext interface.

## Member Function Documentation

## ◆ ClearDepthStencil()

void Diligent::DeviceContextD3D12Impl::ClearDepthStencil | ( | ITextureView * | pView,
|  | Uint32 | ClearFlags,
|  | float | fDepth,
|  | Uint8 | Stencil
| ) |  |
| finaloverridevirtual

Clears a depth-stencil view.

Parameters

  [in] | pView | - Pointer to ITextureView interface to clear. The view type must be Diligent::TEXTURE_VIEW_DEPTH_STENCIL.
  [in] | ClearFlags | - Idicates which parts of the buffer to clear, see Diligent::CLEAR_DEPTH_STENCIL_FLAGS.
  [in] | fDepth | - Value to clear depth part of the view with.
  [in] | Stencil | - Value to clear stencil part of the view with.

Remarks
  The full extent of the view is always cleared. Viewport and scissor settings are not applied.

Note
  The depth-stencil view must be bound to the pipeline for clear operation to be performed.

Implements Diligent::IDeviceContext.

## ◆ ClearRenderTarget()

void Diligent::DeviceContextD3D12Impl::ClearRenderTarget | ( | ITextureView * | pView,
|  | const float * | RGBA
| ) |  |
| finaloverridevirtual

Clears a render target view.

Parameters

  [in] | pView | - Pointer to ITextureView interface to clear. The view type must be Diligent::TEXTURE_VIEW_RENDER_TARGET.
  [in] | RGBA | - A 4-component array that represents the color to fill the render target with. If nullptr is provided, the default array {0,0,0,0} will be used.

Remarks
  The full extent of the view is always cleared. Viewport and scissor settings are not applied.

Note
  The render target view must be bound to the pipeline for clear operation to be performed.

Implements Diligent::IDeviceContext.

## ◆ CommitShaderResources()

void Diligent::DeviceContextD3D12Impl::CommitShaderResources | ( | IShaderResourceBinding * | pShaderResourceBinding,
|  | Uint32 | Flags
| ) |  |
| finaloverridevirtual

Commits shader resources to the device context.

Parameters

  [in] | pShaderResourceBinding | - Shader resource binding whose resources will be committed. If pipeline state contains no shader resources, this parameter can be null.
  [in] | Flags | - Additional flags for the operation. See Diligent::COMMIT_SHADER_RESOURCES_FLAG for a list of allowed values.

Remarks
  Pipeline state object that was used to create the shader resource binding must be bound to the pipeline when CommitShaderResources() is called. If no pipeline state object is bound or the pipeline state object does not match shader resource binding, the method will fail.
  If Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES flag is specified, the engine will also transition all shader resources to the correct state. If the flag is not specified, it is assumed that all resources are already in correct states.
  Resources can be explicitly transitioned to the required states by calling IDeviceContext::TransitionShaderResources()

Implements Diligent::IDeviceContext.

## ◆ DispatchCompute()

void Diligent::DeviceContextD3D12Impl::DispatchCompute | ( | const DispatchComputeAttribs & | DispatchAttrs | ) |
| finaloverridevirtual

Executes a dispatch compute command.

Parameters

  [in] | DispatchAttrs | - Structure describing dispatch command attributes, see DispatchComputeAttribs for details.

Implements Diligent::IDeviceContext.

## ◆ Draw()

void Diligent::DeviceContextD3D12Impl::Draw | ( | DrawAttribs & | DrawAttribs | ) |
| finaloverridevirtual

Executes a draw command.

Parameters

  [in] | DrawAttribs | - Structure describing draw command attributes, see DrawAttribs for details.

Implements Diligent::IDeviceContext.

## ◆ ExecuteCommandList()

void Diligent::DeviceContextD3D12Impl::ExecuteCommandList | ( | class ICommandList * | pCommandList | ) |
| finaloverridevirtual

Executes recorded commands in a command list.

Parameters

  [in] | pCommandList | - Pointer to the command list to executre.

Remarks
  After command list is executed, it is no longer valid and should be released.

Implements Diligent::IDeviceContext.

## ◆ FinishCommandList()

void Diligent::DeviceContextD3D12Impl::FinishCommandList | ( | class ICommandList ** | ppCommandList | ) |
| finaloverridevirtual

Finishes recording commands and generates a command list.

Parameters

  [out] | ppCommandList | - Memory location where pointer to the recorded command list will be written.

Implements Diligent::IDeviceContext.

## ◆ InvalidateState()

void Diligent::DeviceContextD3D12Impl::InvalidateState | ( |  | ) |
| finaloverridevirtual

Invalidates the cached context state.

This method should be called by say Unity plugin before (or after) issuing draw commands to invalidate cached states

Implements Diligent::DeviceContextBase< IDeviceContextD3D12 >.

## ◆ SetBlendFactors()

void Diligent::DeviceContextD3D12Impl::SetBlendFactors | ( | const float * | pBlendFactors = `nullptr` | ) |
| finaloverridevirtual

Parameters

  [in] | pBlendFactors | - Array of four blend factors, one for each RGBA component. Theses factors are used if the blend state uses one of the Diligent::BLEND_FACTOR_BLEND_FACTOR or Diligent::BLEND_FACTOR_INV_BLEND_FACTOR blend factors. If nullptr is provided, default blend factors array {1,1,1,1} will be used.

Implements Diligent::IDeviceContext.

## ◆ SetRenderTargets()

void Diligent::DeviceContextD3D12Impl::SetRenderTargets | ( | Uint32 | NumRenderTargets,
|  | ITextureView * | ppRenderTargets[],
|  | ITextureView * | pDepthStencil
| ) |  |
| finaloverridevirtual

Binds one or more render targets and the depth-stencil buffer to the pipeline. It also sets the viewport to match the first non-null render target or depth-stencil buffer.

Parameters

  [in] | NumRenderTargets | - Number of render targets to bind.
  [in] | ppRenderTargets | - Array of pointers to ITextureView that represent the render targets to bind to the device. The type of each view in the array must be Diligent::TEXTURE_VIEW_RENDER_TARGET.
  [in] | pDepthStencil | - Pointer to the ITextureView that represents the depth stencil to bind to the device. The view type must be Diligent::TEXTURE_VIEW_DEPTH_STENCIL.

Remarks
  The device context will keep strong references to all bound render target and depth-stencil views. Thus these views (and consequently referenced textures) cannot be released until they are unbound from the context.
  Any render targets not defined by this call are set to nullptr.
  You can set the default render target and depth stencil using the following call:

      pContext->SetRenderTargets(0, nullptr, nullptr);

Implements Diligent::IDeviceContext.

## ◆ SetScissorRects()

void Diligent::DeviceContextD3D12Impl::SetScissorRects | ( | Uint32 | NumRects,
|  | const Rect * | pRects,
|  | Uint32 | RTWidth,
|  | Uint32 | RTHeight
| ) |  |
| finaloverridevirtual

Sets active scissor rects.

Parameters

  [in] | NumRects | - Number of scissor rectangles to set.
  [in] | pRects | - An array of Rect structures describing the scissor rectangles to bind.
  [in] | RTWidth | - Render target width. If 0 is provided, width of the currently bound render target will be used.
  [in] | RTHeight | - Render target height. If 0 is provided, height of the currently bound render target will be used.

Remarks
  DirectX and OpenGL use different window coordinate systems. In DirectX, the coordinate system origin is in the left top corner of the screen with Y axis pointing down. In OpenGL, the origin is in the left bottom corener of the screen with Y axis pointing up. Render target size is required to convert viewport from DirectX to OpenGL coordinate system if OpenGL device is used.
  All scissor rects must be set atomically as one operation. Any rects not defined by the call are disabled.

Implements Diligent::IDeviceContext.

## ◆ SetStencilRef()

void Diligent::DeviceContextD3D12Impl::SetStencilRef | ( | Uint32 | StencilRef | ) |
| finaloverridevirtual

Sets the stencil reference value.

Parameters

  [in] | StencilRef | - Stencil reference value.

Implements Diligent::IDeviceContext.

## ◆ SetViewports()

void Diligent::DeviceContextD3D12Impl::SetViewports | ( | Uint32 | NumViewports,
|  | const Viewport * | pViewports,
|  | Uint32 | RTWidth,
|  | Uint32 | RTHeight
| ) |  |
| finaloverridevirtual

Sets an array of viewports.

Parameters

  [in] | NumViewports | - Number of viewports to set.
  [in] | pViewports | - An array of Viewport structures describing the viewports to bind.
  [in] | RTWidth | - Render target width. If 0 is provided, width of the currently bound render target will be used.
  [in] | RTHeight- | Render target height. If 0 is provided, height of the currently bound render target will be used.

Remarks
  DirectX and OpenGL use different window coordinate systems. In DirectX, the coordinate system origin is in the left top corner of the screen with Y axis pointing down. In OpenGL, the origin is in the left bottom corener of the screen with Y axis pointing up. Render target size is required to convert viewport from DirectX to OpenGL coordinate system if OpenGL device is used.
  All viewports must be set atomically as one operation. Any viewports not defined by the call are disabled.
  You can set the viewport size to match the currently bound render target using the following call:

      pContext->SetViewports(1, nullptr, 0, 0);

Implements Diligent::IDeviceContext.

## ◆ TransitionBufferState()

void Diligent::DeviceContextD3D12Impl::TransitionBufferState | ( | IBuffer * | pBuffer,
|  | D3D12_RESOURCE_STATES | State
| ) |  |
| finaloverridevirtual

Transitions internal D3D12 buffer object to a specified state.

Parameters

  [in] | pBuffer | - Buffer to transition
  [in] | State | - D3D12 resource state this buffer to transition to

Implements Diligent::IDeviceContextD3D12.

## ◆ TransitionShaderResources()

void Diligent::DeviceContextD3D12Impl::TransitionShaderResources | ( | IPipelineState * | pPipelineState,
|  | IShaderResourceBinding * | pShaderResourceBinding
| ) |  |
| finaloverridevirtual

Transitions shader resources to the require states.

Parameters

  [in] | pPipelineState | - Pipeline state object that was used to create the shader resource binding.
  [in] | pShaderResourceBinding | - Shader resource binding whose resources will be transitioned.

Remarks
  This method explicitly transitiones all resources to the correct states. If this method was called, there is no need to specify Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES when calling IDeviceContext::CommitShaderResources()

Implements Diligent::IDeviceContext.

## ◆ TransitionTextureState()

void Diligent::DeviceContextD3D12Impl::TransitionTextureState | ( | ITexture * | pTexture,
|  | D3D12_RESOURCE_STATES | State
| ) |  |
| finaloverridevirtual

Transitions internal D3D12 texture object to a specified state.

Parameters

  [in] | pTexture | - texture to transition
  [in] | State | - D3D12 resource state this texture to transition to

Implements Diligent::IDeviceContextD3D12.