Class GPUContext
Interface for GPU device context that can record and send graphics commands to the GPU in a sequence.
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class GPUContext : Object
Constructors
GPUContext()
Properties
NativePtr
Gets the native pointer to the underlying graphics device context. It's a low-level platform-specific handle.
Declaration
[Unmanaged]
public IntPtr NativePtr { get; }
Property Value
System.IntPtr
|
Methods
BindCB(Int32, IntPtr)
Binds the constant buffer to the slot.
Declaration
[Unmanaged]
public void BindCB(int slot, IntPtr cb)
Parameters
System.Int32
slot
The slot index. |
System.IntPtr
cb
The constant buffer. |
BindIB(GPUBuffer)
Binds the index buffer to the pipeline.
Declaration
[Unmanaged]
public void BindIB(GPUBuffer indexBuffer)
Parameters
GPUBuffer
indexBuffer
The index buffer. |
BindSampler(Int32, GPUSampler)
Binds the texture sampler to the pipeline.
Declaration
[Unmanaged]
public void BindSampler(int slot, GPUSampler sampler)
Parameters
System.Int32
slot
The slot index. |
GPUSampler
sampler
The sampler. |
BindSR(Int32, GPUResourceView)
Binds the resource view to the shader resource slot (texture view or buffer view).
Declaration
[Unmanaged]
public void BindSR(int slot, GPUResourceView view)
Parameters
System.Int32
slot
The slot index. |
FlaxEngine.GPUResourceView
view
The resource view. |
BindSR(Int32, GPUTexture)
Binds the texture to the shader resource slot.
Declaration
[Unmanaged]
public void BindSR(int slot, GPUTexture t)
Parameters
System.Int32
slot
The slot index. |
GPUTexture
t
The GPU texture. |
BindUA(Int32, GPUResourceView)
Binds the resource view to the unordered access slot (texture view or buffer view).
Declaration
[Unmanaged]
public void BindUA(int slot, GPUResourceView view)
Parameters
System.Int32
slot
The slot index. |
FlaxEngine.GPUResourceView
view
The resource view. |
BindVB(GPUBuffer[], UInt32*)
Binds the vertex buffers to the pipeline.
Declaration
[Unmanaged]
public void BindVB(GPUBuffer[] vertexBuffers, uint *vertexBuffersOffsets = default(uint *))
Parameters
GPUBuffer[]
vertexBuffers
The array of vertex buffers to use. |
System.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. |
Clear(GPUTextureView, Color)
Clears texture surface with a color. Supports volumetric textures and texture arrays (including cube textures).
Declaration
[Unmanaged]
public void Clear(GPUTextureView rt, Color color)
Parameters
GPUTextureView
rt
The target surface. |
Color
color
The clear color. |
ClearDepth(GPUTextureView, Single)
Clears depth buffer.
Declaration
[Unmanaged]
public void ClearDepth(GPUTextureView depthBuffer, float depthValue = 1F)
Parameters
GPUTextureView
depthBuffer
The depth buffer to clear. |
System.Single
depthValue
The clear depth value. |
ClearState()
Clears the context state.
Declaration
[Unmanaged]
public void ClearState()
ClearUA(GPUBuffer, Float4)
Clears an unordered access buffer with a float value.
Declaration
[Unmanaged]
public void ClearUA(GPUBuffer buf, Float4 value)
Parameters
GPUBuffer
buf
The buffer to clear. |
Float4
value
The clear value. |
CopyBuffer(GPUBuffer, GPUBuffer, UInt32, UInt32, UInt32)
Copies the buffer data.
Declaration
[Unmanaged]
public void CopyBuffer(GPUBuffer dstBuffer, GPUBuffer srcBuffer, uint size, uint dstOffset = 0U, uint srcOffset = 0U)
Parameters
GPUBuffer
dstBuffer
The destination buffer to write to. |
GPUBuffer
srcBuffer
The source buffer to read from. |
System.UInt32
size
The size of data to copy (in bytes). |
System.UInt32
dstOffset
The offset (in bytes) from the destination buffer start to copy data to. |
System.UInt32
srcOffset
The offset (in bytes) from the source buffer start to copy data from. |
CopyCounter(GPUBuffer, UInt32, GPUBuffer)
Copies the counter buffer value.
Declaration
[Unmanaged]
public void CopyCounter(GPUBuffer dstBuffer, uint dstOffset, GPUBuffer srcBuffer)
Parameters
GPUBuffer
dstBuffer
The destination buffer. |
System.UInt32
dstOffset
The destination aligned byte offset. |
GPUBuffer
srcBuffer
The source buffer. |
CopyResource(GPUResource, GPUResource)
Copies the resource data (whole resource).
Declaration
[Unmanaged]
public void CopyResource(GPUResource dstResource, GPUResource srcResource)
Parameters
GPUResource
dstResource
The destination resource. |
GPUResource
srcResource
The source resource. |
CopySubresource(GPUResource, UInt32, GPUResource, UInt32)
Copies the subresource data.
Declaration
[Unmanaged]
public void CopySubresource(GPUResource dstResource, uint dstSubresource, GPUResource srcResource, uint srcSubresource)
Parameters
GPUResource
dstResource
The destination resource. |
System.UInt32
dstSubresource
The destination subresource index. |
GPUResource
srcResource
The source resource. |
System.UInt32
srcSubresource
The source subresource index. |
CopyTexture(GPUTexture, UInt32, UInt32, UInt32, UInt32, GPUTexture, UInt32)
Copies region of the texture.
Declaration
[Unmanaged]
public void CopyTexture(GPUTexture dstResource, uint dstSubresource, uint dstX, uint dstY, uint dstZ, GPUTexture srcResource, uint srcSubresource)
Parameters
GPUTexture
dstResource
The destination resource. |
System.UInt32
dstSubresource
The destination subresource index. |
System.UInt32
dstX
The x-coordinate of the upper left corner of the destination region. |
System.UInt32
dstY
The y-coordinate of the upper left corner of the destination region. |
System.UInt32
dstZ
The z-coordinate of the upper left corner of the destination region. |
GPUTexture
srcResource
The source resource. |
System.UInt32
srcSubresource
The source subresource index. |
Dispatch(IntPtr, UInt32, UInt32, UInt32)
Executes a command list from a thread group.
Declaration
[Unmanaged]
public void Dispatch(IntPtr shader, uint threadGroupCountX, uint threadGroupCountY, uint threadGroupCountZ)
Parameters
System.IntPtr
shader
The compute shader program to execute. |
System.UInt32
threadGroupCountX
The number of groups dispatched in the x direction. |
System.UInt32
threadGroupCountY
The number of groups dispatched in the y direction. |
System.UInt32
threadGroupCountZ
The number of groups dispatched in the z direction. |
DispatchIndirect(IntPtr, GPUBuffer, UInt32)
Executes a command list from a thread group. Buffer must contain GPUDispatchIndirectArgs.
Declaration
[Unmanaged]
public void DispatchIndirect(IntPtr shader, GPUBuffer bufferForArgs, uint offsetForArgs)
Parameters
System.IntPtr
shader
The compute shader program to execute. |
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
System.UInt32
offsetForArgs
The aligned byte offset for arguments. |
Draw(GPUTexture)
Draws the specified texture to render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
Declaration
[Unmanaged]
public void Draw(GPUTexture rt)
Parameters
GPUTexture
rt
The texture. |
Draw(GPUTexture, GPUTexture)
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
[Unmanaged]
public void Draw(GPUTexture dst, GPUTexture src)
Parameters
GPUTexture
dst
The destination texture. |
GPUTexture
src
The source texture. |
Draw(GPUTextureView)
Draws the specified texture to render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
Declaration
[Unmanaged]
public void Draw(GPUTextureView rt)
Parameters
GPUTextureView
rt
The texture view. |
Draw(UInt32, UInt32)
Draws non-indexed, non-instanced primitives.
Declaration
[Unmanaged]
public void Draw(uint startVertex, uint verticesCount)
Parameters
System.UInt32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
System.UInt32
verticesCount
The vertices count. |
DrawFullscreenTriangle(Int32)
Draws the fullscreen triangle (using single triangle). Use instance count parameter to render more than one instance of the triangle.
Declaration
[Unmanaged]
public void DrawFullscreenTriangle(int instanceCount = 1)
Parameters
System.Int32
instanceCount
The instance count. Use SV_InstanceID in vertex shader to detect volume slice plane index. |
DrawIndexed(UInt32, Int32, Int32)
Draws the indexed primitives.
Declaration
[Unmanaged]
public void DrawIndexed(uint indicesCount, int startVertex = 0, int startIndex = 0)
Parameters
System.UInt32
indicesCount
The indices count. |
System.Int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
System.Int32
startIndex
The location of the first index read by the GPU from the index buffer. |
DrawIndexedInstanced(UInt32, UInt32, Int32, Int32, Int32)
Draws the indexed, instanced primitives.
Declaration
[Unmanaged]
public void DrawIndexedInstanced(uint indicesCount, uint instanceCount, int startInstance = 0, int startVertex = 0, int startIndex = 0)
Parameters
System.UInt32
indicesCount
The indices count. |
System.UInt32
instanceCount
Number of instances to draw. |
System.Int32
startInstance
A value added to each index before reading per-instance data from a vertex buffer. |
System.Int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
System.Int32
startIndex
The location of the first index read by the GPU from the index buffer. |
DrawIndexedInstancedIndirect(GPUBuffer, UInt32)
Draws the instanced GPU-generated indexed primitives. Buffer must contain GPUDrawIndexedIndirectArgs.
Declaration
[Unmanaged]
public void DrawIndexedInstancedIndirect(GPUBuffer bufferForArgs, uint offsetForArgs)
Parameters
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
System.UInt32
offsetForArgs
The aligned byte offset for arguments. |
DrawInstanced(UInt32, UInt32, Int32, Int32)
Draws the instanced primitives.
Declaration
[Unmanaged]
public void DrawInstanced(uint verticesCount, uint instanceCount, int startInstance = 0, int startVertex = 0)
Parameters
System.UInt32
verticesCount
The vertices count. |
System.UInt32
instanceCount
Number of instances to draw. |
System.Int32
startInstance
A value added to each index before reading per-instance data from a vertex buffer. |
System.Int32
startVertex
A value added to each index before reading a vertex from the vertex buffer. |
DrawInstancedIndirect(GPUBuffer, UInt32)
Draws the instanced GPU-generated primitives. Buffer must contain GPUDrawIndirectArgs.
Declaration
[Unmanaged]
public void DrawInstancedIndirect(GPUBuffer bufferForArgs, uint offsetForArgs)
Parameters
GPUBuffer
bufferForArgs
The buffer with drawing arguments. |
System.UInt32
offsetForArgs
The aligned byte offset for arguments. |
Flush()
Flushes the command buffer (calls GPU execution).
Declaration
[Unmanaged]
public void Flush()
FlushState()
Flushes the internal cached context state with a command buffer.
Declaration
[Unmanaged]
public void FlushState()
GetState()
Gets the current pipeline state binded to the graphics pipeline.
Declaration
[Unmanaged]
public GPUPipelineState GetState()
Returns
GPUPipelineState
The current state. |
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
[Unmanaged]
public void ResetCB()
ResetCounter(GPUBuffer)
Resets the counter buffer to zero (hidden by the driver).
Declaration
[Unmanaged]
public void ResetCounter(GPUBuffer buffer)
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
[Unmanaged]
public void ResetRenderTarget()
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
[Unmanaged]
public void ResetSR()
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
[Unmanaged]
public void ResetUA()
ResolveMultisample(GPUTexture, GPUTexture, Int32, Int32, PixelFormat)
Resolves the multisampled texture by performing a copy of the resource into a non-multisampled resource.
Declaration
[Unmanaged]
public void ResolveMultisample(GPUTexture sourceMultisampleTexture, GPUTexture destTexture, int sourceSubResource = 0, int destSubResource = 0, PixelFormat format)
Parameters
GPUTexture
sourceMultisampleTexture
The source multisampled texture. Must be multisampled. |
GPUTexture
destTexture
The destination texture. Must be single-sampled. |
System.Int32
sourceSubResource
The source sub-resource index. |
System.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(Float4)
Sets the blend factor that modulate values for a pixel shader, render target, or both.
Declaration
[Unmanaged]
public void SetBlendFactor(Float4 value)
Parameters
Float4
value
Blend factors, one for each RGBA component. |
SetRenderTarget(GPUTextureView)
Sets the render target to the output.
Declaration
[Unmanaged]
public void SetRenderTarget(GPUTextureView rt)
Parameters
GPUTextureView
rt
The render target. |
SetRenderTarget(GPUTextureView, GPUTextureView)
Sets the render target and the depth buffer to the output.
Declaration
[Unmanaged]
public void SetRenderTarget(GPUTextureView depthBuffer, GPUTextureView rt)
Parameters
GPUTextureView
depthBuffer
The depth buffer. |
GPUTextureView
rt
The render target. |
SetRenderTarget(GPUTextureView, GPUTextureView[])
Sets the render targets and the depth buffer to the output.
Declaration
[Unmanaged]
public void SetRenderTarget(GPUTextureView depthBuffer, GPUTextureView[] rts)
Parameters
GPUTextureView
depthBuffer
The depth buffer (can be null). |
GPUTextureView[]
rts
The array with render targets to bind. |
SetScissor(ref Rectangle)
Sets the scissor rectangle.
Declaration
[Unmanaged]
public void SetScissor(ref Rectangle scissorRect)
Parameters
Rectangle
scissorRect
The scissor rectangle (in pixels). |
SetState(GPUPipelineState)
Sets the graphics pipeline state.
Declaration
[Unmanaged]
public void SetState(GPUPipelineState state)
Parameters
GPUPipelineState
state
The state to bind. |
SetStencilRef(UInt32)
Sets the reference value for depth stencil tests.
Declaration
[Unmanaged]
public void SetStencilRef(uint value)
Parameters
System.UInt32
value
Reference value to perform against when doing a depth-stencil test. |
SetViewport(ref Viewport)
Sets the rendering viewport.
Declaration
[Unmanaged]
public void SetViewport(ref Viewport viewport)
Parameters
Viewport
viewport
The viewport (in pixels). |
SetViewport(Single, Single)
Sets the rendering viewport.
Declaration
[Unmanaged]
public void SetViewport(float width, float height)
Parameters
System.Single
width
The width (in pixels). |
System.Single
height
The height (in pixels). |
SetViewportAndScissors(Viewport)
Sets the rendering viewport and scissor rectangle.
Declaration
[Unmanaged]
public void SetViewportAndScissors(Viewport viewport)
Parameters
Viewport
viewport
The viewport (in pixels). |
SetViewportAndScissors(Single, Single)
Sets the rendering viewport and scissor rectangle.
Declaration
[Unmanaged]
public void SetViewportAndScissors(float width, float height)
Parameters
System.Single
width
The width (in pixels). |
System.Single
height
The height (in pixels). |
UpdateBuffer(GPUBuffer, IntPtr, UInt32, UInt32)
Updates the buffer data.
Declaration
[Unmanaged]
public void UpdateBuffer(GPUBuffer buffer, IntPtr data, uint size, uint offset = 0U)
Parameters
GPUBuffer
buffer
The destination buffer to write to. |
System.IntPtr
data
The pointer to the data. |
System.UInt32
size
The data size (in bytes) to write. |
System.UInt32
offset
The offset (in bytes) from the buffer start to copy data to. |
UpdateCB(IntPtr, IntPtr)
Updates the constant buffer data.
Declaration
[Unmanaged]
public void UpdateCB(IntPtr cb, IntPtr data)
Parameters
System.IntPtr
cb
The constant buffer. |
System.IntPtr
data
The pointer to the data. |
UpdateTexture(GPUTexture, Int32, Int32, IntPtr, UInt32, UInt32)
Updates the texture data.
Declaration
[Unmanaged]
public void UpdateTexture(GPUTexture texture, int arrayIndex, int mipIndex, IntPtr data, uint rowPitch, uint slicePitch)
Parameters
GPUTexture
texture
The destination texture. |
System.Int32
arrayIndex
The destination surface index in the texture array. |
System.Int32
mipIndex
The absolute index of the mip map to update. |
System.IntPtr
data
The pointer to the data. |
System.UInt32
rowPitch
The row pitch (in bytes) of the input data. |
System.UInt32
slicePitch
The slice pitch (in bytes) of the input data. |