Class GPUContext
Interface for GPU device context that can record and send graphics commands to the GPU in a sequence.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Graphics/GPUContext.h
Syntax
public class GPUContext : public ScriptingObject
Constructors
GPUContext(GPUDevice* device)
Fields
_lastRenderTime
Declaration
protected double _lastRenderTime = -1
Field Value
double
|
Methods
BindCB(int32 slot, GPUConstantBuffer* cb)
Binds the constant buffer to the slot.
Declaration
public virtual void BindCB(int32 slot, GPUConstantBuffer* cb) = 0
Parameters
int32
slot
The slot index. |
GPUConstantBuffer
cb
The constant buffer. |
BindIB(GPUBuffer* indexBuffer)
Binds the index buffer to the pipeline.
Declaration
public virtual void BindIB(GPUBuffer* indexBuffer) = 0
Parameters
GPUBuffer
indexBuffer
The index buffer. |
BindSampler(int32 slot, GPUSampler* sampler)
Binds the texture sampler to the pipeline.
Declaration
public virtual void BindSampler(int32 slot, GPUSampler* sampler) = 0
Parameters
int32
slot
The slot index. |
GPUSampler
sampler
The sampler. |
BindSR(int32 slot, GPUResourceView* view)
Binds the resource view to the shader resource slot (texture view or buffer view).
Declaration
public virtual void BindSR(int32 slot, GPUResourceView* view) = 0
Parameters
int32
slot
The slot index. |
GPUResourceView
view
The resource view. |
BindSR(int32 slot, GPUTexture* t)
Binds the texture to the shader resource slot.
Declaration
public void BindSR(int32 slot, GPUTexture* t)
Parameters
int32
slot
The slot index. |
GPUTexture
t
The GPU texture. |
BindUA(int32 slot, GPUResourceView* view)
Binds the resource view to the unordered access slot (texture view or buffer view).
Declaration
public virtual void BindUA(int32 slot, GPUResourceView* view) = 0
Parameters
int32
slot
The slot index. |
GPUResourceView
view
The resource view. |
BindVB(const Span<GPUBuffer* >& vertexBuffers, const uint32* vertexBuffersOffsets=nullptr, GPUVertexLayout* vertexLayout=nullptr)
Binds the vertex buffers to the pipeline.
Declaration
public virtual void BindVB(const Span<GPUBuffer* >& vertexBuffers, const uint32* vertexBuffersOffsets=nullptr, GPUVertexLayout* vertexLayout=nullptr) = 0
Parameters
Span<GPUBuffer >
vertexBuffers
The array of vertex buffers to use. |
uint32
vertexBuffersOffsets
The optional array of byte offsets from the vertex buffers begins. Can be used to offset the vertex data when reusing the same buffer allocation for multiple geometry objects. |
GPUVertexLayout
vertexLayout
The optional vertex layout to use when passing data from vertex buffers to the vertex shader. If null, layout will be automatically extracted from vertex buffers combined. |
Clear(GPUTextureView* rt, const Color& color)
Clears texture surface with a color. Supports volumetric textures and texture arrays (including cube textures).
Declaration
public virtual void Clear(GPUTextureView* rt, const Color& color) = 0
Parameters
GPUTextureView
rt
The target surface. |
Color
color
The clear color. |
ClearDepth(GPUTextureView* depthBuffer, float depthValue=1.0f, uint8 stencilValue = 0)
Clears depth buffer.
Declaration
public virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue=1.0f, uint8 stencilValue = 0) = 0
Parameters
GPUTextureView
depthBuffer
The depth buffer to clear. |
float
depthValue
The clear depth value. |
uint8
stencilValue
The clear stencil value. |
ClearState()
Clears the context state.
Declaration
public virtual void ClearState() = 0
ClearUA(GPUBuffer* buf, const Float4& value)
Clears an unordered access buffer with a float value.
Declaration
public virtual void ClearUA(GPUBuffer* buf, const Float4& value) = 0
Parameters
GPUBuffer
buf
The buffer to clear. |
Float4
value
The clear value. |
ClearUA(GPUBuffer* buf, const uint32 value[4])
Clears an unordered access buffer with an unsigned value.
Declaration
public virtual void ClearUA(GPUBuffer* buf, const uint32 value[4]) = 0
Parameters
GPUBuffer
buf
The buffer to clear. |
uint32
value
The clear value. |
ClearUA(GPUTexture* texture, const Float4& value)
Clears an unordered access texture with a float value.
Declaration
public virtual void ClearUA(GPUTexture* texture, const Float4& value) = 0
Parameters
GPUTexture
texture
The texture to clear. |
Float4
value
The clear value. |
ClearUA(GPUTexture* texture, const uint32 value[4])
Clears an unordered access texture with an unsigned value.
Declaration
public virtual void ClearUA(GPUTexture* texture, const uint32 value[4]) = 0
Parameters
GPUTexture
texture
The texture to clear. |
uint32
value
The clear value. |
CopyBuffer(GPUBuffer* dstBuffer, GPUBuffer* srcBuffer, uint32 size, uint32 dstOffset = 0, uint32 srcOffset = 0)
Copies the buffer data.
Declaration
public virtual void CopyBuffer(GPUBuffer* dstBuffer, GPUBuffer* srcBuffer, uint32 size, uint32 dstOffset = 0, uint32 srcOffset = 0) = 0
Parameters
GPUBuffer
dstBuffer
The destination buffer to write to. |
GPUBuffer
srcBuffer
The source buffer to read from. |
uint32
size
The size of data to copy (in bytes). |
uint32
dstOffset
The offset (in bytes) from the destination buffer start to copy data to. |
uint32
srcOffset
The offset (in bytes) from the source buffer start to copy data from. |
CopyCounter(GPUBuffer* dstBuffer, uint32 dstOffset, GPUBuffer* srcBuffer)
Copies the counter buffer value.
Declaration
public virtual void CopyCounter(GPUBuffer* dstBuffer, uint32 dstOffset, GPUBuffer* srcBuffer) = 0
Parameters
GPUBuffer
dstBuffer
The destination buffer. |
uint32
dstOffset
The destination aligned byte offset. |
GPUBuffer
srcBuffer
The source buffer. |
CopyResource(GPUResource* dstResource, GPUResource* srcResource)
Copies the resource data (whole resource).
Declaration
public virtual void CopyResource(GPUResource* dstResource, GPUResource* srcResource) = 0
Parameters
GPUResource
dstResource
The destination resource. |
GPUResource
srcResource
The source resource. |
CopySubresource(GPUResource* dstResource, uint32 dstSubresource, GPUResource* srcResource, uint32 srcSubresource)
Copies the subresource data.
Declaration
public virtual void CopySubresource(GPUResource* dstResource, uint32 dstSubresource, GPUResource* srcResource, uint32 srcSubresource) = 0
Parameters
GPUResource
dstResource
The destination resource. |
uint32
dstSubresource
The destination subresource index. |
GPUResource
srcResource
The source resource. |
uint32
srcSubresource
The source subresource index. |
CopyTexture(GPUTexture* dstResource, uint32 dstSubresource, uint32 dstX, uint32 dstY, uint32 dstZ, GPUTexture* srcResource, uint32 srcSubresource)
Copies region of the texture.
Declaration
public virtual void CopyTexture(GPUTexture* dstResource, uint32 dstSubresource, uint32 dstX, uint32 dstY, uint32 dstZ, GPUTexture* srcResource, uint32 srcSubresource) = 0
Parameters
GPUTexture
dstResource
The destination resource. |
uint32
dstSubresource
The destination subresource index. |
uint32
dstX
The x-coordinate of the upper left corner of the destination region. |
uint32
dstY
The y-coordinate of the upper left corner of the destination region. |
uint32
dstZ
The z-coordinate of the upper left corner of the destination region. |
GPUTexture
srcResource
The source resource. |
uint32
srcSubresource
The source subresource index. |
Dispatch(GPUShaderProgramCS* shader, uint32 threadGroupCountX, uint32 threadGroupCountY, uint32 threadGroupCountZ)
Executes a command list from a thread group.
Declaration
public virtual void Dispatch(GPUShaderProgramCS* shader, uint32 threadGroupCountX, uint32 threadGroupCountY, uint32 threadGroupCountZ) = 0
Parameters
GPUShaderProgramCS
shader
The compute shader program to execute. |
uint32
threadGroupCountX
The number of groups dispatched in the x direction. |
uint32
threadGroupCountY
The number of groups dispatched in the y direction. |
uint32
threadGroupCountZ
The number of groups dispatched in the z direction. |
DispatchIndirect(GPUShaderProgramCS* shader, GPUBuffer* bufferForArgs, uint32 offsetForArgs)
Executes a command list from a thread group. Buffer must contain GPUDispatchIndirectArgs.
Declaration
public virtual void DispatchIndirect(GPUShaderProgramCS* shader, GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0
Parameters
GPUShaderProgramCS
shader
The compute shader program to execute. |
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
uint32
offsetForArgs
The aligned byte offset for arguments. |
Draw(GPUTexture* dst, GPUTexture* src)
Draws the specified source texture to destination render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
Declaration
public void Draw(GPUTexture* dst, GPUTexture* src)
Parameters
GPUTexture
dst
The destination texture. |
GPUTexture
src
The source texture. |
Draw(GPUTexture* rt)
Draws the specified texture to render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
Declaration
public void Draw(GPUTexture* rt)
Parameters
GPUTexture
rt
The texture. |
Draw(GPUTextureView* rt)
Draws the specified texture to render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
Declaration
public void Draw(GPUTextureView* rt)
Parameters
GPUTextureView
rt
The texture view. |
Draw(int32 startVertex, uint32 verticesCount)
Draws non-indexed, non-instanced primitives.
Declaration
public void Draw(int32 startVertex, uint32 verticesCount)
Parameters
int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
uint32
verticesCount
The vertices count. |
Returns
void
|
DrawFullscreenTriangle(int32 instanceCount=1)
Draws the fullscreen triangle (using single triangle). Use instance count parameter to render more than one instance of the triangle.
Declaration
public void DrawFullscreenTriangle(int32 instanceCount=1)
Parameters
int32
instanceCount
The instance count. Use SV_InstanceID in vertex shader to detect volume slice plane index. |
DrawIndexed(uint32 indicesCount, int32 startVertex = 0, int32 startIndex = 0)
Draws the indexed primitives.
Declaration
public void DrawIndexed(uint32 indicesCount, int32 startVertex = 0, int32 startIndex = 0)
Parameters
uint32
indicesCount
The indices count. |
int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
int32
startIndex
The location of the first index read by the GPU from the index buffer. |
Returns
void
|
DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance = 0, int32 startVertex = 0, int32 startIndex = 0)
Draws the indexed, instanced primitives.
Declaration
public virtual void DrawIndexedInstanced(uint32 indicesCount, uint32 instanceCount, int32 startInstance = 0, int32 startVertex = 0, int32 startIndex = 0) = 0
Parameters
uint32
indicesCount
The indices count. |
uint32
instanceCount
Number of instances to draw. |
int32
startInstance
A value added to each index before reading per-instance data from a vertex buffer. |
int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
int32
startIndex
The location of the first index read by the GPU from the index buffer. |
DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs)
Draws the instanced GPU-generated indexed primitives. Buffer must contain GPUDrawIndexedIndirectArgs.
Declaration
public virtual void DrawIndexedInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0
Parameters
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
uint32
offsetForArgs
The aligned byte offset for arguments. |
DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance = 0, int32 startVertex = 0)
Draws the instanced primitives.
Declaration
public virtual void DrawInstanced(uint32 verticesCount, uint32 instanceCount, int32 startInstance = 0, int32 startVertex = 0) = 0
Parameters
uint32
verticesCount
The vertices count. |
uint32
instanceCount
Number of instances to draw. |
int32
startInstance
A value added to each index before reading per-instance data from a vertex buffer. |
int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs)
Draws the instanced GPU-generated primitives. Buffer must contain GPUDrawIndirectArgs.
Declaration
public virtual void DrawInstancedIndirect(GPUBuffer* bufferForArgs, uint32 offsetForArgs) = 0
Parameters
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
uint32
offsetForArgs
The aligned byte offset for arguments. |
EventBegin(const Char* name)
Begins the profile event.
Declaration
public virtual void EventBegin(const Char* name)
Parameters
Char
name
The name. |
EventEnd()
Ends the last profile event.
Declaration
public virtual void EventEnd()
Flush()
Flushes the command buffer (calls GPU execution).
Declaration
public virtual void Flush() = 0
FlushState()
Flushes the internal cached context state with a command buffer.
Declaration
public virtual void FlushState() = 0
ForceRebindDescriptors()
Forces graphics backend to rebind descriptors after command list was used by external graphics library.
Declaration
public virtual void ForceRebindDescriptors()
FrameBegin()
Begins new frame and enters commands collecting mode.
Declaration
public virtual void FrameBegin()
FrameEnd()
Ends the current frame rendering.
Declaration
public virtual void FrameEnd()
GetDevice()
GetNativePtr()
Gets the native pointer to the underlying graphics device context. It's a low-level platform-specific handle.
Declaration
public virtual void* GetNativePtr() const = 0
Returns
void
|
GetState()
Gets the current pipeline state binded to the graphics pipeline.
Declaration
public virtual GPUPipelineState* GetState() const = 0
Returns
GPUPipelineState
The current state. |
IsDepthBufferBinded()
Determines whether depth buffer is binded to the pipeline. [Deprecated in v1.10]
Declaration
public virtual bool IsDepthBufferBinded() = 0
Returns
bool
|
LogInvalidResourceUsage(int32 slot, const GPUResourceView* view, InvalidBindPoint bindPoint)
Declaration
protected static void LogInvalidResourceUsage(int32 slot, const GPUResourceView* view, InvalidBindPoint bindPoint)
Parameters
int32
slot
|
GPUResourceView
view
|
InvalidBindPoint
bindPoint
|
ResetCB()
Unbinds all constant buffer slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
Declaration
public virtual void ResetCB() = 0
ResetCounter(GPUBuffer* buffer)
Resets the counter buffer to zero (hidden by the driver).
Declaration
public virtual void ResetCounter(GPUBuffer* buffer) = 0
Parameters
GPUBuffer
buffer
The buffer. |
ResetRenderTarget()
Unbinds all the render targets and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
Declaration
public virtual void ResetRenderTarget() = 0
ResetSR()
Unbinds all shader resource slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
Declaration
public virtual void ResetSR() = 0
ResetUA()
Unbinds all unordered access resource slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
Declaration
public virtual void ResetUA() = 0
ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource = 0, int32 destSubResource = 0, PixelFormat format=PixelFormat::Unknown)
Resolves the multisampled texture by performing a copy of the resource into a non-multisampled resource.
Declaration
public virtual void ResolveMultisample(GPUTexture* sourceMultisampleTexture, GPUTexture* destTexture, int32 sourceSubResource = 0, int32 destSubResource = 0, PixelFormat format=PixelFormat::Unknown) = 0
Parameters
GPUTexture
sourceMultisampleTexture
The source multisampled texture. Must be multisampled. |
GPUTexture
destTexture
The destination texture. Must be single-sampled. |
int32
sourceSubResource
The source sub-resource index. |
int32
destSubResource
The destination sub-resource index. |
PixelFormat
format
The format. Indicates how the multisampled resource will be resolved to a single-sampled resource. |
SetBlendFactor(const Float4& value)
Sets the blend factor that modulate values for a pixel shader, render target, or both.
Declaration
public virtual void SetBlendFactor(const Float4& value) = 0
Parameters
Float4
value
Blend factors, one for each RGBA component. |
SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView* >& rts)
Sets the render targets and the depth buffer to the output.
Declaration
public virtual void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView* >& rts) = 0
Parameters
GPUTextureView
depthBuffer
The depth buffer (can be null). |
Span<GPUTextureView >
rts
The array with render targets to bind. |
SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt)
Sets the render target and the depth buffer to the output.
Declaration
public virtual void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) = 0
Parameters
GPUTextureView
depthBuffer
The depth buffer. |
GPUTextureView
rt
The render target. |
SetRenderTarget(GPUTextureView* rt)
Sets the render target to the output.
Declaration
public virtual void SetRenderTarget(GPUTextureView* rt) = 0
Parameters
GPUTextureView
rt
The render target. |
SetResourceState(GPUResource* resource, uint64 state, int32 subresource=-1)
Sets the state of the resource (or subresource).
Declaration
public virtual void SetResourceState(GPUResource* resource, uint64 state, int32 subresource=-1)
Parameters
GPUResource
resource
|
uint64
state
|
int32
subresource
|
SetScissor(const Rectangle& scissorRect)
Sets the scissor rectangle.
Declaration
public virtual void SetScissor(const Rectangle& scissorRect) = 0
Parameters
Rectangle
scissorRect
The scissor rectangle (in pixels). |
SetState(GPUPipelineState* state)
Sets the graphics pipeline state.
Declaration
public virtual void SetState(GPUPipelineState* state) = 0
Parameters
GPUPipelineState
state
The state to bind. |
SetStencilRef(uint32 value)
Sets the reference value for depth stencil tests.
Declaration
public virtual void SetStencilRef(uint32 value) = 0
Parameters
uint32
value
Reference value to perform against when doing a depth-stencil test. |
SetViewport(const Viewport& viewport)
Sets the rendering viewport.
Declaration
public virtual void SetViewport(const Viewport& viewport) = 0
Parameters
Viewport
viewport
The viewport (in pixels). |
SetViewport(float width, float height)
Sets the rendering viewport.
Declaration
public void SetViewport(float width, float height)
Parameters
float
width
The width (in pixels). |
float
height
The height (in pixels). |
Returns
void
|
SetViewportAndScissors(const Viewport& viewport)
Sets the rendering viewport and scissor rectangle.
Declaration
public void SetViewportAndScissors(const Viewport& viewport)
Parameters
Viewport
viewport
The viewport (in pixels). |
Returns
void
|
SetViewportAndScissors(float width, float height)
Sets the rendering viewport and scissor rectangle.
Declaration
public void SetViewportAndScissors(float width, float height)
Parameters
float
width
The width (in pixels). |
float
height
The height (in pixels). |
Returns
void
|
UnBindCB(int32 slot)
Unbinds constant buffer slot.
Declaration
public void UnBindCB(int32 slot)
Parameters
int32
slot
The slot index. |
Returns
void
|
UnBindSR(int32 slot)
Unbinds shader resource slot.
Declaration
public void UnBindSR(int32 slot)
Parameters
int32
slot
The slot index. |
Returns
void
|
UnBindUA(int32 slot)
Unbinds unordered access resource slot.
Declaration
public void UnBindUA(int32 slot)
Parameters
int32
slot
The slot index. |
Returns
void
|
UpdateBuffer(GPUBuffer* buffer, const void* data, uint32 size, uint32 offset = 0)
Updates the buffer data.
Declaration
public virtual void UpdateBuffer(GPUBuffer* buffer, const void* data, uint32 size, uint32 offset = 0) = 0
Parameters
GPUBuffer
buffer
The destination buffer to write to. |
void
data
The pointer to the data. |
uint32
size
The data size (in bytes) to write. |
uint32
offset
The offset (in bytes) from the buffer start to copy data to. |
UpdateCB(GPUConstantBuffer* cb, const void* data)
Updates the constant buffer data.
Declaration
public virtual void UpdateCB(GPUConstantBuffer* cb, const void* data) = 0
Parameters
GPUConstantBuffer
cb
The constant buffer. |
void
data
The pointer to the data. |
UpdateTexture(GPUTexture* texture, int32 arrayIndex, int32 mipIndex, const void* data, uint32 rowPitch, uint32 slicePitch)
Updates the texture data.
Declaration
public virtual void UpdateTexture(GPUTexture* texture, int32 arrayIndex, int32 mipIndex, const void* data, uint32 rowPitch, uint32 slicePitch) = 0
Parameters
GPUTexture
texture
The destination texture. |
int32
arrayIndex
The destination surface index in the texture array. |
int32
mipIndex
The absolute index of the mip map to update. |
void
data
The pointer to the data. |
uint32
rowPitch
The row pitch (in bytes) of the input data. |
uint32
slicePitch
The slice pitch (in bytes) of the input data. |