Diligent Engine API Reference
DeviceContext.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
28 
29 #include "Object.h"
30 #include "DeviceCaps.h"
31 #include "Constants.h"
32 #include "Buffer.h"
33 #include "InputLayout.h"
34 #include "Shader.h"
35 #include "Texture.h"
36 #include "Sampler.h"
37 #include "ResourceMapping.h"
38 #include "TextureView.h"
39 #include "BufferView.h"
40 #include "DepthStencilState.h"
41 #include "BlendState.h"
42 #include "PipelineState.h"
43 #include "CommandList.h"
44 #include "SwapChain.h"
45 
46 namespace Diligent
47 {
48 
49 // {DC92711B-A1BE-4319-B2BD-C662D1CC19E4}
50 static constexpr INTERFACE_ID IID_DeviceContext =
51 { 0xdc92711b, 0xa1be, 0x4319, { 0xb2, 0xbd, 0xc6, 0x62, 0xd1, 0xcc, 0x19, 0xe4 } };
52 
54 
56 enum PRIMITIVE_TOPOLOGY : Int32
57 {
60 
64 
68 
72 
76 
80 
84 
88 
92 
96 
100 
104 
108 
112 
116 
120 
124 
128 
132 
136 
140 
144 
148 
152 
156 
160 
164 
168 
172 
176 
180 
184 
188 
192 
196 
200 
204 
207 };
208 
210 
213 {
216  union
217  {
219  Uint32 NumVertices;
220 
222  Uint32 NumIndices;
223  };
227 
229  Bool IsIndexed;
230 
233  Uint32 NumInstances;
234 
239 
242  Uint32 BaseVertex;
243 
247 
248  union
249  {
253 
257  };
261 
265 
266 
268 
285  NumVertices(0),
287  IsIndexed(False),
288  NumInstances(1),
289  IsIndirect(False),
290  BaseVertex(0),
294  pIndirectDrawAttribs(nullptr)
295  {}
296 };
297 
299 
302 {
305 };
306 
308 
313 {
317 
322 
326 
328 
332  DispatchComputeAttribs( Uint32 GroupsX = 1, Uint32 GroupsY = 1, Uint32 GroupsZ = 1 ) :
333  ThreadGroupCountX( GroupsX ),
334  ThreadGroupCountY( GroupsY ),
335  ThreadGroupCountZ( GroupsZ ),
336  pIndirectDispatchAttribs(nullptr),
338  {}
339 
341 
345  DispatchComputeAttribs( IBuffer *pDispatchAttribs, Uint32 Offset = 0 ) :
346  ThreadGroupCountX( 0 ),
347  ThreadGroupCountY( 0 ),
348  ThreadGroupCountZ( 0 ),
349  pIndirectDispatchAttribs( pDispatchAttribs ),
350  DispatchArgsByteOffset( Offset )
351  {}
352 };
353 
356 {
360 };
361 
364 {
366 
370 };
371 
372 
374 
376 struct Viewport
377 {
379  Float32 TopLeftX;
380 
385  Float32 TopLeftY;
386 
388  Float32 Width;
389 
391  Float32 Height;
392 
394  Float32 MinDepth;
395 
397  Float32 MaxDepth;
398 
400  Viewport(Float32 _TopLeftX = 0, Float32 _TopLeftY = 0,
401  Float32 _Width = 0, Float32 _Height = 0,
402  Float32 _MinDepth = 0, Float32 _MaxDepth = 1 )
403  :
404  TopLeftX( _TopLeftX ),
405  TopLeftY( _TopLeftY ),
406  Width ( _Width ),
407  Height ( _Height ),
408  MinDepth( _MinDepth ),
409  MaxDepth( _MaxDepth )
410  {}
411 };
412 
414 
420 struct Rect
421 {
422  Int32 left;
423  Int32 top;
424  Int32 right;
425  Int32 bottom;
426 
428  Rect( Int32 _left = 0, Int32 _top = 0, Int32 _right = 0, Int32 _bottom = 0 ) :
429  left ( _left ),
430  top ( _top ),
431  right ( _right ),
432  bottom( _bottom )
433  {}
434 };
435 
436 
438 
443 class IDeviceContext : public IObject
444 {
445 public:
447  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
448 
450 
452  virtual void SetPipelineState(IPipelineState *pPipelineState) = 0;
453 
454 
461  virtual void TransitionShaderResources(IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding) = 0;
462 
464 
479  virtual void CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags) = 0;
480 
482 
484  virtual void SetStencilRef(Uint32 StencilRef) = 0;
485 
486 
493  virtual void SetBlendFactors(const float* pBlendFactors = nullptr) = 0;
494 
495 
497 
503  // The vertex buffers must have been created with the Diligent::BIND_VERTEX_BUFFER flag.
520  virtual void SetVertexBuffers(Uint32 StartSlot,
521  Uint32 NumBuffersSet,
522  IBuffer **ppBuffers,
523  Uint32 *pStrides,
524  Uint32 *pOffsets,
525  Uint32 Flags) = 0;
526 
528 
531  virtual void InvalidateState() = 0;
532 
533 
535 
543  virtual void SetIndexBuffer(IBuffer *pIndexBuffer, Uint32 ByteOffset) = 0;
544 
545 
547 
563  virtual void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight ) = 0;
564 
566 
578  virtual void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight ) = 0;
579 
582 
599  virtual void SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil ) = 0;
600 
602 
604  virtual void Draw(DrawAttribs &DrawAttribs) = 0;
605 
607 
610  virtual void DispatchCompute( const DispatchComputeAttribs &DispatchAttrs ) = 0;
611 
613 
621  virtual void ClearDepthStencil( ITextureView *pView, Uint32 ClearFlags = CLEAR_DEPTH_FLAG, float fDepth = 1.f, Uint8 Stencil = 0 ) = 0;
622 
624 
631  virtual void ClearRenderTarget( ITextureView *pView, const float *RGBA = nullptr ) = 0;
632 
634 
636  virtual void FinishCommandList( ICommandList **ppCommandList) = 0;
637 
639 
642  virtual void ExecuteCommandList( ICommandList *pCommandList) = 0;
643 
645  virtual void Flush() = 0;
646 
648 
662  virtual void SetSwapChain( ISwapChain *pSwapChain) = 0;
663 };
664 
665 }
Interpret the vertex data as a list of points. D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_POINTLIST. OpenGL counterpart: GL_POINTS.
Definition: DeviceContext.h:71
virtual void SetIndexBuffer(IBuffer *pIndexBuffer, Uint32 ByteOffset)=0
Binds an index buffer to the pipeline.
virtual void SetScissorRects(Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight)=0
Sets active scissor rects.
virtual void SetStencilRef(Uint32 StencilRef)=0
Sets the stencil reference value.
Interpret the vertex data as a list of 20 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:155
virtual void Draw(DrawAttribs &DrawAttribs)=0
Executes a draw command.
Uint32 FirstInstanceLocation
For instanced rendering, LOCATION (or INDEX, but NOT the byte offset) in the vertex buffer to start r...
Definition: DeviceContext.h:260
Rect(Int32 _left=0, Int32 _top=0, Int32 _right=0, Int32 _bottom=0)
Initializes the structure.
Definition: DeviceContext.h:428
PRIMITIVE_TOPOLOGY
Input primitive topology.
Definition: DeviceContext.h:56
Interpret the vertex data as a list of 11 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:119
Uint32 BaseVertex
For indexed rendering, a constant which is added to each index before accessing the vertex buffer...
Definition: DeviceContext.h:242
Undefined type.
Definition: GraphicsTypes.h:41
CLEAR_DEPTH_STENCIL_FLAGS
Defines which parts of the depth-stencil buffer to clear.
Definition: DeviceContext.h:301
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Float32 TopLeftX
X coordinate of the left boundary of the viewport.
Definition: DeviceContext.h:379
virtual void SetRenderTargets(Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil)=0
Binds one or more render targets and the depth-stencil buffer to the pipeline. It also sets the viewp...
Interpret the vertex data as a list of 16 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:139
virtual void DispatchCompute(const DispatchComputeAttribs &DispatchAttrs)=0
Executes a dispatch compute command.
virtual void SetPipelineState(IPipelineState *pPipelineState)=0
Sets the pipeline state.
Interpret the vertex data as a list of five control point patches. D3D counterpart: D3D_PRIMITIVE_TO...
Definition: DeviceContext.h:95
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
Interpret the vertex data as a list of 15 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:135
Interpret the vertex data as a list of nine control point patches. D3D counterpart: D3D_PRIMITIVE_TO...
Definition: DeviceContext.h:111
Interpret the vertex data as a list of 32 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:203
IBuffer * pIndirectDrawAttribs
For indirect rendering, pointer to the buffer, from which draw attributes will be read...
Definition: DeviceContext.h:264
virtual void Flush()=0
Flushes the command buffer.
Describes the viewport.
Definition: DeviceContext.h:376
Int32 bottom
Y coordinate of the bottom boundary of the viewport.
Definition: DeviceContext.h:425
SET_VERTEX_BUFFERS_FLAGS
Defines allowed flags for IDeviceContext::SetVertexBuffers() function.
Definition: DeviceContext.h:355
Float32 MinDepth
Minimum depth of the viewport. Ranges between 0 and 1.
Definition: DeviceContext.h:394
DrawAttribs()
Initializes the structure members with default values.
Definition: DeviceContext.h:283
Viewport(Float32 _TopLeftX=0, Float32 _TopLeftY=0, Float32 _Width=0, Float32 _Height=0, Float32 _MinDepth=0, Float32 _MaxDepth=1)
Initializes the structure.
Definition: DeviceContext.h:400
Interpret the vertex data as a list of four control point patches. D3D counterpart: D3D_PRIMITIVE_TO...
Definition: DeviceContext.h:91
Interpret the vertex data as a list of 30 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:195
Shader resource binding interface.
Definition: ShaderResourceBinding.h:40
Interpret the vertex data as a list of 22 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:163
Float32 Width
Viewport width.
Definition: DeviceContext.h:388
Undefined topology.
Definition: DeviceContext.h:59
Bool IsIndirect
Indicates if indirect draw call will be performed. If set to True, pIndirectDrawAttribs must contain ...
Definition: DeviceContext.h:238
Int32 right
X coordinate of the right boundary of the viewport.
Definition: DeviceContext.h:424
Interpret the vertex data as a list of 24 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:171
Describes dispatch command arguments.
Definition: DeviceContext.h:312
DispatchComputeAttribs(Uint32 GroupsX=1, Uint32 GroupsY=1, Uint32 GroupsZ=1)
Initializes the structure to perform non-indirect dispatch command.
Definition: DeviceContext.h:332
Interpret the vertex data as a list of lines. D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_LINELIST. OpenGL counterpart: GL_LINES.
Definition: DeviceContext.h:75
Interpret the vertex data as a list of 19 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:151
virtual void TransitionShaderResources(IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding)=0
Transitions shader resources to the require states.
Interpret the vertex data as a list of eight control point patches. D3D counterpart: D3D_PRIMITIVE_T...
Definition: DeviceContext.h:107
Interpret the vertex data as a list of ten control point patches. D3D counterpart: D3D_PRIMITIVE_TOP...
Definition: DeviceContext.h:115
DispatchComputeAttribs(IBuffer *pDispatchAttribs, Uint32 Offset=0)
Initializes the structure to perform indirect dispatch command.
Definition: DeviceContext.h:345
Interpret the vertex data as a list of 28 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:187
Buffer interface.
Definition: Buffer.h:200
virtual void FinishCommandList(ICommandList **ppCommandList)=0
Finishes recording commands and generates a command list.
VALUE_TYPE IndexType
For an indexed draw call, type of elements in the index buffer. Allowed values: VT_UINT16 and VT_UINT...
Definition: DeviceContext.h:226
virtual void SetBlendFactors(const float *pBlendFactors=nullptr)=0
Uint32 DispatchArgsByteOffset
If pIndirectDispatchAttribs is not nullptr, indicates offset from the beginning of the buffer to the ...
Definition: DeviceContext.h:325
Device context interface.
Definition: DeviceContext.h:443
Int32 left
X coordinate of the left boundary of the viewport.
Definition: DeviceContext.h:422
Swap chain interface.
Definition: SwapChain.h:41
Int32 top
Y coordinate of the top boundary of the viewport.
Definition: DeviceContext.h:423
Interpret the vertex data as a list of 21 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:159
Uint32 NumIndices
For an indexed draw call, number of indices to draw.
Definition: DeviceContext.h:222
virtual void InvalidateState()=0
Invalidates the cached context state.
Interpret the vertex data as a list of six control point patches. D3D counterpart: D3D_PRIMITIVE_TOP...
Definition: DeviceContext.h:99
Texture view interface.
Definition: TextureView.h:163
Uint32 NumVertices
For a non-indexed draw call, number of vertices to draw.
Definition: DeviceContext.h:219
Interpret the vertex data as a list of 17 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:143
VALUE_TYPE
Value type.
Definition: GraphicsTypes.h:39
Command list interface.
Definition: CommandList.h:42
Interpret the vertex data as a list of 25 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:175
Interpret the vertex data as a list of 12 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:123
Interpret the vertex data as a list of 13 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:127
Definition: PipelineState.h:209
virtual void ExecuteCommandList(ICommandList *pCommandList)=0
Executes recorded commands in a command list.
Uint32 NumInstances
Number of instances to draw. If more than one instance is specified, instanced draw call will be perf...
Definition: DeviceContext.h:233
Interpret the vertex data as a list of 26 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:179
Uint32 ThreadGroupCountY
Number of groups dispatched in Y direction.
Definition: DeviceContext.h:315
Interpret the vertex data as a list of 23 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:167
Defines the draw command attributes.
Definition: DeviceContext.h:212
virtual void CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags)=0
Commits shader resources to the device context.
Transition resources being committed.
Definition: DeviceContext.h:369
Clear stencil part of the buffer.
Definition: DeviceContext.h:304
virtual void SetViewports(Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight)=0
Sets an array of viewports.
virtual void SetVertexBuffers(Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags)=0
Binds vertex buffers to the pipeline.
Describes the rectangle.
Definition: DeviceContext.h:420
Float32 Height
Viewport Height.
Definition: DeviceContext.h:391
virtual void ClearDepthStencil(ITextureView *pView, Uint32 ClearFlags=CLEAR_DEPTH_FLAG, float fDepth=1.f, Uint8 Stencil=0)=0
Clears a depth-stencil view.
Interpret the vertex data as a list of 31 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:199
Clear depth part of the buffer.
Definition: DeviceContext.h:303
Interpret the vertex data as a list of three control point patches. D3D counterpart: D3D_PRIMITIVE_T...
Definition: DeviceContext.h:87
Interpret the vertex data as a triangle strip. D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP...
Definition: DeviceContext.h:67
virtual void SetSwapChain(ISwapChain *pSwapChain)=0
Sets the swap chain in the device context.
Uint32 ThreadGroupCountX
Number of groups dispatched in X direction.
Definition: DeviceContext.h:314
Helper value that stores the total number of topologies in the enumeration.
Definition: DeviceContext.h:206
Float32 TopLeftY
Y coordinate of the top boundary of the viewport. When defining a viewport, DirectX convention is use...
Definition: DeviceContext.h:385
Reset the vertex buffers to only the buffers specified in this call. All buffers previously bound to ...
Definition: DeviceContext.h:359
Interpret the vertex data as a list of one control point patches. D3D counterpart: D3D_PRIMITIVE_TOP...
Definition: DeviceContext.h:79
COMMIT_SHADER_RESOURCES_FLAG
Defines allowed flags for IDeviceContext::CommitShaderResources() function.
Definition: DeviceContext.h:363
Interpret the vertex data as a list of triangles. D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_TRIANGLELI...
Definition: DeviceContext.h:63
Interpret the vertex data as a list of 29 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:191
Interpret the vertex data as a list of two control point patches. D3D counterpart: D3D_PRIMITIVE_TOP...
Definition: DeviceContext.h:83
Interpret the vertex data as a list of 14 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:131
Interpret the vertex data as a list of seven control point patches. D3D counterpart: D3D_PRIMITIVE_T...
Definition: DeviceContext.h:103
Uint32 IndirectDrawArgsOffset
For indirect rendering, offset from the beginning of the buffer to the location of draw command attri...
Definition: DeviceContext.h:246
IBuffer * pIndirectDispatchAttribs
Pointer to the buffer containing dispatch arguments. If not nullptr, then indirect dispatch command i...
Definition: DeviceContext.h:321
Interpret the vertex data as a list of 18 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:147
Bool IsIndexed
Indicates if index buffer will be used to index input vertices.
Definition: DeviceContext.h:229
Uint32 StartVertexLocation
For non-indexed rendering, LOCATION (or INDEX, but NOT the byte offset) of the first vertex in the ve...
Definition: DeviceContext.h:252
Uint32 ThreadGroupCountZ
Number of groups dispatched in Z direction.
Definition: DeviceContext.h:316
Interpret the vertex data as a list of 27 control point patches. D3D counterpart: D3D_PRIMITIVE_TOPO...
Definition: DeviceContext.h:183
virtual void ClearRenderTarget(ITextureView *pView, const float *RGBA=nullptr)=0
Clears a render target view.
Float32 MaxDepth
Maximum depth of the viewport. Ranges between 0 and 1.
Definition: DeviceContext.h:397
PRIMITIVE_TOPOLOGY Topology
Input primitive topology, see Diligent::PRIMITIVE_TOPOLOGY.
Definition: DeviceContext.h:215
Uint32 FirstIndexLocation
For indexed rendering, LOCATION (NOT the byte offset) of the first index in the index buffer to start...
Definition: DeviceContext.h:256