public ParameterConstantBuffer(GraphicsDevice device, string constantBufferName, ShaderConstantBufferDescription constantBufferDesc)
        {
            ConstantBufferDesc = constantBufferDesc;
            constantBufferDatas = new ConstantBufferData[GraphicsDevice.ThreadCount];
            dataStreams = new DataPointer[GraphicsDevice.ThreadCount];

            for (uint i = 0; i < GraphicsDevice.ThreadCount; ++i)
            {
                constantBufferDatas[i] = new ConstantBufferData(constantBufferDesc);
                dataStreams[i] = new DataPointer(constantBufferDatas[i].Data, constantBufferDesc.Size);
            }

            Buffer = SiliconStudio.Xenko.Graphics.Buffer.New(device, constantBufferDatas[0].Desc.Size, BufferFlags.ConstantBuffer, UsingMap ? GraphicsResourceUsage.Dynamic : GraphicsResourceUsage.Default);
            
            // We want to clear flags
            // TODO: Should be later replaced with either an internal field on GraphicsResourceBase, or a reset counter somewhere?
            Buffer.Reload = Reload;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new <see cref="Buffer" /> instance.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="dataPointer">The data pointer.</param>
 /// <param name="elementSize">Size of the element.</param>
 /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>An instance of a new <see cref="Buffer" /></returns>
 public static Buffer New(GraphicsDevice device, DataPointer dataPointer, int elementSize, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New(device, dataPointer, elementSize, bufferFlags, PixelFormat.None, usage));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new Raw buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Raw buffer.</param>
 /// <param name="additionalBindings">The additional bindings (for example, to create a combined raw/index buffer, pass <see cref="BufferFlags.IndexBuffer" />)</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Raw buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, BufferFlags additionalBindings = BufferFlags.None, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(Buffer.New(device, value, 0, BufferFlags.RawBuffer | additionalBindings, usage));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Loads an image from an unmanaged memory pointer.
 /// </summary>
 /// <param name="dataBuffer">Pointer to an unmanaged memory. If <see cref="makeACopy"/> is false, this buffer must be allocated with <see cref="Utilities.AllocateMemory"/>.</param>
 /// <param name="makeACopy">True to copy the content of the buffer to a new allocated buffer, false otherwise.</param>
 /// <param name="loadAsSRGB">Indicate if the image should be loaded as an sRGB texture</param>
 /// <returns>An new image.</returns>
 /// <remarks>If <see cref="makeACopy"/> is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose. </remarks>
 public static Image Load(DataPointer dataBuffer, bool makeACopy = false, bool loadAsSRGB = false)
 {
     return Load(dataBuffer.Pointer, dataBuffer.Size, makeACopy, loadAsSRGB);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new Typed buffer <see cref="GraphicsResourceUsage.Default" /> uasge.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Typed buffer.</param>
 /// <param name="viewFormat">The view format of the buffer.</param>
 /// <param name="isUnorderedAccess">if set to <c>true</c> this buffer supports unordered access (RW in HLSL).</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Typed buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, PixelFormat viewFormat, bool isUnorderedAccess = false, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(Buffer.New(device, value, 0, BufferFlags.ShaderResource | (isUnorderedAccess?BufferFlags.UnorderedAccess : BufferFlags.None), viewFormat, usage));
 }
Exemplo n.º 6
0
            /// <summary>
            /// Creates a new StructuredCounter buffer <see cref="GraphicsResourceUsage.Default" /> uasge.
            /// </summary>
            /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
            /// <param name="value">The value to initialize the StructuredCounter buffer.</param>
            /// <param name="elementSize">Size of the element.</param>
            /// <returns>A StructuredCounter buffer</returns>
            public static Buffer New(GraphicsDevice device, DataPointer value, int elementSize)
            {
                const BufferFlags BufferFlags = BufferFlags.StructuredCounterBuffer | BufferFlags.ShaderResource | BufferFlags.UnorderedAccess;

                return(Buffer.New(device, value, elementSize, BufferFlags));
            }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new constant buffer with <see cref="GraphicsResourceUsage.Dynamic"/> usage.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the constant buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A constant buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, GraphicsResourceUsage usage = GraphicsResourceUsage.Dynamic)
 {
     return(Buffer.New(device, value, 0, BufferFlags.ConstantBuffer, usage));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Copies the content an array of data on CPU memory to this buffer into GPU memory.
 /// </summary>
 /// <param name="fromData">A data pointer.</param>
 /// <param name="offsetInBytes">The offset in bytes to write to.</param>
 /// <exception cref="System.ArgumentException"></exception>
 /// <remarks>
 /// This method is only working when called from the main thread that is accessing the main <see cref="GraphicsDevice"/>. See the unmanaged documentation about Map/UnMap for usage and restrictions.
 /// </remarks>
 public void SetData(DataPointer fromData, int offsetInBytes = 0)
 {
     SetData(GraphicsDevice, fromData, offsetInBytes);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new index buffer with <see cref="GraphicsResourceUsage.Immutable"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the index buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A index buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return(Buffer.New(device, value, 0, BufferFlags.IndexBuffer, usage));
 }