Class Buffer
All-in-One Buffer class linked SharpDX.Direct3D11.Buffer.
[DataSerializer(typeof(BufferSerializer))]
[DataSerializerGlobal(typeof(ReferenceSerializer<Buffer>), null, DataSerializerGenericMode.None, false, false, Profile = "Content")]
[ContentSerializer(typeof(DataContentSerializer<Buffer>))]
public class Buffer : GraphicsResource, IDisposable, IComponent, IReferencable, ICollectorHolder
- Inheritance
-
Buffer
- Implements
- Derived
-
Buffer<T>
- Inherited Members
- Extension Methods
Remarks
This class is able to create constant buffers, indexelementCountrtex buffers, structured buffer, raw buffers, argument buffers.
Constructors
Buffer()
public Buffer()
Buffer(GraphicsDevice)
Initializes a new instance of the Buffer class.
protected Buffer(GraphicsDevice device)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
Fields
elementCount
protected int elementCount
Field Value
Properties
Description
Gets the description of this buffer.
public BufferDescription Description { get; }
Property Value
ElementCount
Gets the number of elements.
public int ElementCount { get; protected set; }
Property Value
Remarks
This value is valid for structured buffers, raw buffers and index buffers that are used as a SharedResourceView.
Flags
Buffer flags describing the type of buffer.
public BufferFlags Flags { get; }
Property Value
InitialCounterOffset
The initial Append/Consume buffer counter offset. A value of -1 indicates the current offset should be kept. Any other values set the hidden counter for that Appendable/Consumable Buffer. This value is only relevant for Buffers which have the 'Append' or 'Counter' flag, otherwise it is ignored. The value get's initialized to -1.
public int InitialCounterOffset { get; set; }
Property Value
SizeInBytes
Gets the size of the buffer in bytes.
public int SizeInBytes { get; }
Property Value
- int
The size of the buffer in bytes.
StructureByteStride
The size of the structure (in bytes) when it represents a structured/typed buffer.
public int StructureByteStride { get; }
Property Value
Usage
Value that identifies how the buffer is to be read from and written to.
public GraphicsResourceUsage Usage { get; }
Property Value
ViewFlags
Gets the type of this buffer view.
public BufferFlags ViewFlags { get; }
Property Value
ViewFormat
Gets the format of this buffer view.
public PixelFormat ViewFormat { get; }
Property Value
Methods
Clone()
Clones this instance.
public Buffer Clone()
Returns
- Buffer
A clone of this instance
Remarks
This method will not copy the content of the buffer to the clone
GetData(CommandList, Buffer, DataPointer)
Copies the content of this buffer from GPU memory to a CPU memory using a specific staging resource.
public void GetData(CommandList commandList, Buffer stagingTexture, DataPointer toData)
Parameters
commandList
CommandListstagingTexture
BufferThe staging buffer used to transfer the buffer.
toData
DataPointerTo data pointer.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetData<TData>(CommandList)
Gets the content of this buffer to an array of data.
public TData[] GetData<TData>(CommandList commandList) where TData : unmanaged
Parameters
commandList
CommandList
Returns
- TData[]
Type Parameters
TData
The type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice. This method creates internally a stagging resource if this texture is not already a stagging resouce, copies to it and map it to memory. Use method with explicit staging resource for optimal performances.
GetData<TData>(CommandList, Buffer, ref TData)
Copies the content of this buffer from GPU memory to an array of data on CPU memory using a specific staging resource.
public void GetData<TData>(CommandList commandList, Buffer stagingTexture, ref TData toData) where TData : unmanaged
Parameters
commandList
CommandListstagingTexture
BufferThe staging buffer used to transfer the buffer.
toData
TDataTo data.
Type Parameters
TData
The type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetData<TData>(CommandList, Buffer, TData[])
Copies the content of this buffer from GPU memory to an array of data on CPU memory using a specific staging resource.
public void GetData<TData>(CommandList commandList, Buffer stagingTexture, TData[] toData) where TData : unmanaged
Parameters
commandList
CommandListstagingTexture
BufferThe staging buffer used to transfer the buffer.
toData
TData[]To data.
Type Parameters
TData
The type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice.
Exceptions
- ArgumentException
When strides is different from optimal strides, and TData is not the same size as the pixel format, or Width * Height != toData.Length
GetData<TData>(CommandList, ref TData)
Copies the content of this buffer to an array of data.
public void GetData<TData>(CommandList commandList, ref TData toData) where TData : unmanaged
Parameters
commandList
CommandListtoData
TDataThe destination buffer to receive a copy of the texture datas.
Type Parameters
TData
The type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice. This method creates internally a stagging resource if this texture is not already a stagging resouce, copies to it and map it to memory. Use method with explicit staging resource for optimal performances.
GetData<TData>(CommandList, TData[])
Copies the content of this buffer to an array of data.
public void GetData<TData>(CommandList commandList, TData[] toData) where TData : unmanaged
Parameters
commandList
CommandListtoData
TData[]The destination buffer to receive a copy of the texture datas.
Type Parameters
TData
The type of the T data.
Remarks
This method is only working when called from the main thread that is accessing the main GraphicsDevice. This method creates internally a stagging resource if this texture is not already a stagging resouce, copies to it and map it to memory. Use method with explicit staging resource for optimal performances.
InitializeFromImpl(BufferDescription, BufferFlags, PixelFormat, nint)
Initializes a new instance of the Buffer class.
protected Buffer InitializeFromImpl(BufferDescription description, BufferFlags viewFlags, PixelFormat viewFormat, nint dataPointer)
Parameters
description
BufferDescriptionThe description.
viewFlags
BufferFlagsType of the buffer.
viewFormat
PixelFormatThe view format.
dataPointer
nintThe data pointer.
Returns
New(GraphicsDevice, BufferDescription, PixelFormat)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, BufferDescription description, PixelFormat viewFormat = PixelFormat.None)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
description
BufferDescriptionThe description of the buffer.
viewFormat
PixelFormatView format used if the buffer is used as a shared resource view.
Returns
New(GraphicsDevice, DataPointer, int, BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, DataPointer dataPointer, int elementSize, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
dataPointer
DataPointerThe data pointer.
elementSize
intSize of the element.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, DataPointer, int, BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, DataPointer dataPointer, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
dataPointer
DataPointerThe data pointer.
elementSize
intSize of the element.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, byte[], int, BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance from a byte array.
public static Buffer New(GraphicsDevice device, byte[] initialValue, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat = PixelFormat.None, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
initialValue
byte[]The initial value of this buffer.
elementSize
intSize of an element. Must be equal to 2 or 4 for an index buffer, or to the size of a struct for a structured/typed buffer. Can be set to 0 for other buffers.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, int, BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, int bufferSize, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
bufferSize
intSize of the buffer in bytes.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, int, BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, int bufferSize, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
bufferSize
intSize of the buffer in bytes.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, int, int, BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, int bufferSize, int elementSize, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
bufferSize
intSize of the buffer in bytes.
elementSize
intSize of an element in the buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
New(GraphicsDevice, int, int, BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer New(GraphicsDevice device, int bufferSize, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
Parameters
device
GraphicsDeviceThe GraphicsDevice.
bufferSize
intSize of the buffer in bytes.
elementSize
intSize of an element in the buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
New<T>(GraphicsDevice, int, BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer<T> New<T>(GraphicsDevice device, int elementCount, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
Parameters
device
GraphicsDeviceThe GraphicsDevice.
elementCount
intNumber of T elment in this buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
New<T>(GraphicsDevice, ref T, BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer<T> New<T>(GraphicsDevice device, ref T value, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
Parameters
device
GraphicsDeviceThe GraphicsDevice.
value
TThe initial value of this buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type of the buffer, to get the sizeof from.
New<T>(GraphicsDevice, ref T, BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer<T> New<T>(GraphicsDevice device, ref T value, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
Parameters
device
GraphicsDeviceThe GraphicsDevice.
value
TThe initial value of this buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type of the buffer, to get the sizeof from.
New<T>(GraphicsDevice, T[], BufferFlags, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer<T> New<T>(GraphicsDevice device, T[] initialValue, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
Parameters
device
GraphicsDeviceThe GraphicsDevice.
initialValue
T[]The initial value of this buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type of the buffer, to get the sizeof from.
New<T>(GraphicsDevice, T[], BufferFlags, PixelFormat, GraphicsResourceUsage)
Creates a new Buffer instance.
public static Buffer<T> New<T>(GraphicsDevice device, T[] initialValue, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
Parameters
device
GraphicsDeviceThe GraphicsDevice.
initialValue
T[]The initial value of this buffer.
bufferFlags
BufferFlagsThe buffer flags to specify the type of buffer.
viewFormat
PixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usage
GraphicsResourceUsageThe usage.
Returns
Type Parameters
T
Type of the buffer, to get the sizeof from.
OnDestroyed()
Called when graphics device has been detected to be internally destroyed.
protected override void OnDestroyed()
OnNameChanged()
Called when Name property was changed.
protected override void OnNameChanged()
OnRecreate()
Called when graphics device has been recreated.
protected override bool OnRecreate()
Returns
Recreate(nint)
Explicitly recreate buffer with given data. Usually called after a GraphicsDevice reset.
public void Recreate(nint dataPointer)
Parameters
dataPointer
nint
RecreateWith(nint)
Reload Buffer from given data if GraphicsDevice has been reset.
public Buffer RecreateWith(nint dataPointer)
Parameters
dataPointer
nintThe data pointer.
Returns
- Buffer
This instance.
RecreateWith<T>(T[])
Reload Buffer from given data if GraphicsDevice has been reset.
public Buffer RecreateWith<T>(T[] dataPointer) where T : unmanaged
Parameters
dataPointer
T[]The data pointer.
Returns
- Buffer
This instance.
Type Parameters
T
Recreate<T>(T[])
Explicitly recreate buffer with given data. Usually called after a GraphicsDevice reset.
public void Recreate<T>(T[] dataPointer) where T : unmanaged
Parameters
dataPointer
T[]
Type Parameters
T
SetData(CommandList, DataPointer, int)
Copies the content an array of data on CPU memory to this buffer into GPU memory.
public void SetData(CommandList commandList, DataPointer fromData, int offsetInBytes = 0)
Parameters
commandList
CommandListfromData
DataPointerA data pointer.
offsetInBytes
intThe offset in bytes to write to.
Remarks
See the unmanaged documentation about Map/UnMap for usage and restrictions.
Exceptions
SetData<TData>(CommandList, ref TData, int)
Copies the content an array of data on CPU memory to this buffer into GPU memory.
public void SetData<TData>(CommandList commandList, ref TData fromData, int offsetInBytes = 0) where TData : unmanaged
Parameters
commandList
CommandListfromData
TDataThe data to copy from.
offsetInBytes
intThe offset in bytes to write to.
Type Parameters
TData
The type of the T data.
Remarks
See the unmanaged documentation about Map/UnMap for usage and restrictions.
Exceptions
SetData<TData>(CommandList, TData[], int)
Copies the content an array of data on CPU memory to this buffer into GPU memory.
public void SetData<TData>(CommandList commandList, TData[] fromData, int offsetInBytes = 0) where TData : unmanaged
Parameters
commandList
CommandListfromData
TData[]The data to copy from.
offsetInBytes
intThe offset in bytes to write to.
Type Parameters
TData
The type of the T data.
Remarks
See the unmanaged documentation about Map/UnMap for usage and restrictions.
Exceptions
ToStaging()
Return an equivalent staging texture CPU read-writable from this instance.
public Buffer ToStaging()
Returns
- Buffer
A new instance of this buffer as a staging resource