Diligent Engine API Reference
Public Member Functions | Static Public Attributes | List of all members
Diligent::DeviceContextD3D11Impl Class Reference

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

Inheritance diagram for Diligent::DeviceContextD3D11Impl:
Diligent::DeviceContextBase< IDeviceContextD3D11 > Diligent::ObjectBase< IDeviceContextD3D11, IMemoryAllocator > Diligent::RefCountedObject< IDeviceContextD3D11, IMemoryAllocator > Diligent::IDeviceContextD3D11 Diligent::IDeviceContext Diligent::IObject

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 ClearState () override final
 Clears the context state.
 
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.
 
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...
 
ID3D11DeviceContext * GetD3D11DeviceContext ()
 Returns a pointer to the ID3D11DeviceContext interface of the internal Direct3D11 object. More...
 
void ClearShaderStateCache ()
 Clears the state caches. This function is called once per frame (before present) to release all outstanding objects that are only kept alive by references in the cache.
 
- Public Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextD3D11 >
 DeviceContextBase (IMemoryAllocator &RawMemAllocator, 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.
 
void SetSwapChain (ISwapChain *pSwapChain)
 Sets the strong pointer to the swap chain.
 
ISwapChainGetSwapChain ()
 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.
 
IRenderDeviceGetDevice ()
 Returns the render device.
 
- Public Member Functions inherited from Diligent::RefCountedObject< IDeviceContextD3D11, IMemoryAllocator >
virtual IReferenceCountersGetReferenceCounters () const override final
 
virtual Atomics::Long AddRef () override
 
virtual Atomics::Long Release () override
 

Static Public Attributes

static const int NumShaderTypes = 6
 Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute)
 

Additional Inherited Members

- Protected Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextD3D11 >
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< IDeviceContextD3D11 >
RefCntAutoPtr< IRenderDevicem_pDevice
 Strong reference to the device.
 
RefCntAutoPtr< ISwapChainm_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< IPipelineStatem_pPipelineState
 Strong reference to the bound pipeline state object.
 
RefCntAutoPtr< IBufferm_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< ITextureViewm_pBoundRenderTargets [MaxRenderTargets]
 Vector of strong references to the bound render targets.
 
Uint32 m_NumBoundRenderTargets
 Number of bound render targets.
 
RefCntAutoPtr< ITextureViewm_pBoundDepthStencil
 Strong references to the bound depth stencil view.
 

Detailed Description

Implementation of the Diligent::IDeviceContextD3D11 interface.

Member Function Documentation

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::Draw ( DrawAttribs DrawAttribs)
finaloverridevirtual

Executes a draw command.

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

Implements Diligent::IDeviceContext.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

ID3D11DeviceContext* Diligent::DeviceContextD3D11Impl::GetD3D11DeviceContext ( )
inlinevirtual

Returns a pointer to the ID3D11DeviceContext interface of the internal Direct3D11 object.

The method does NOT call AddRef() on the returned interface, so Release() must not be called.

Implements Diligent::IDeviceContextD3D11.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::SetStencilRef ( Uint32  StencilRef)
finaloverridevirtual

Sets the stencil reference value.

Parameters
[in]StencilRef- Stencil reference value.

Implements Diligent::IDeviceContext.

void Diligent::DeviceContextD3D11Impl::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.

void Diligent::DeviceContextD3D11Impl::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.