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
deviceGraphicsDeviceThe 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
commandListCommandListstagingTextureBufferThe staging buffer used to transfer the buffer.
toDataDataPointerTo 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
commandListCommandList
Returns
- TData[]
Type Parameters
TDataThe 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
commandListCommandListstagingTextureBufferThe staging buffer used to transfer the buffer.
toDataTDataTo data.
Type Parameters
TDataThe 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
commandListCommandListstagingTextureBufferThe staging buffer used to transfer the buffer.
toDataTData[]To data.
Type Parameters
TDataThe 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
commandListCommandListtoDataTDataThe destination buffer to receive a copy of the texture datas.
Type Parameters
TDataThe 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
commandListCommandListtoDataTData[]The destination buffer to receive a copy of the texture datas.
Type Parameters
TDataThe 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, IntPtr)
Initializes a new instance of the Buffer class.
protected Buffer InitializeFromImpl(BufferDescription description, BufferFlags viewFlags, PixelFormat viewFormat, IntPtr dataPointer)
Parameters
descriptionBufferDescriptionThe description.
viewFlagsBufferFlagsType of the buffer.
viewFormatPixelFormatThe view format.
dataPointerIntPtrThe 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
deviceGraphicsDeviceThe GraphicsDevice.
descriptionBufferDescriptionThe description of the buffer.
viewFormatPixelFormatView 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
deviceGraphicsDeviceThe GraphicsDevice.
dataPointerDataPointerThe data pointer.
elementSizeintSize of the element.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
dataPointerDataPointerThe data pointer.
elementSizeintSize of the element.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
initialValuebyte[]The initial value of this buffer.
elementSizeintSize 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.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
bufferSizeintSize of the buffer in bytes.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
bufferSizeintSize of the buffer in bytes.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
bufferSizeintSize of the buffer in bytes.
elementSizeintSize of an element in the buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
bufferSizeintSize of the buffer in bytes.
elementSizeintSize of an element in the buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
elementCountintNumber of T elment in this buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe 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
deviceGraphicsDeviceThe GraphicsDevice.
valueTThe initial value of this buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType 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
deviceGraphicsDeviceThe GraphicsDevice.
valueTThe initial value of this buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType 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
deviceGraphicsDeviceThe GraphicsDevice.
initialValueT[]The initial value of this buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType 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
deviceGraphicsDeviceThe GraphicsDevice.
initialValueT[]The initial value of this buffer.
bufferFlagsBufferFlagsThe buffer flags to specify the type of buffer.
viewFormatPixelFormatThe view format must be specified if the buffer is declared as a shared resource view.
usageGraphicsResourceUsageThe usage.
Returns
Type Parameters
TType 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(IntPtr)
Explicitly recreate buffer with given data. Usually called after a GraphicsDevice reset.
public void Recreate(IntPtr dataPointer)
Parameters
dataPointerIntPtr
RecreateWith(IntPtr)
Reload Buffer from given data if GraphicsDevice has been reset.
public Buffer RecreateWith(IntPtr dataPointer)
Parameters
dataPointerIntPtrThe 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
dataPointerT[]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
dataPointerT[]
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
commandListCommandListfromDataDataPointerA data pointer.
offsetInBytesintThe 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
commandListCommandListfromDataTDataThe data to copy from.
offsetInBytesintThe offset in bytes to write to.
Type Parameters
TDataThe 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
commandListCommandListfromDataTData[]The data to copy from.
offsetInBytesintThe offset in bytes to write to.
Type Parameters
TDataThe 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