private void PrepareBuffers(int count) { List <Buffer> toRelease = new List <Buffer>(); for (int i = 0; i < count; i++) { toRelease.Add(allocator.GetTemporaryBuffer(defaultDescription)); } for (int i = 0; i < count; i++) { allocator.ReleaseReference(toRelease[i]); } }
internal BufferPool(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size, CommandList clist = null) { constantBufferAlignment = graphicsDevice.ConstantBufferDataPlacementAlignment; if (size % constantBufferAlignment != 0) { throw new ArgumentException($"size needs to be a multiple of constant buffer alignment ({constantBufferAlignment})", nameof(size)); } this.allocator = allocator; Size = size; if (!UseBufferOffsets) { Data = Marshal.AllocHGlobal(size); } this.commandList = clist; #if XENKO_GRAPHICS_API_VULKAN constantBuffer = new Buffer[BUFFERS_PER_POOL]; for (int i = 0; i < constantBuffer.Length; i++) { constantBuffer[i] = allocator.GetTemporaryBuffer(new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic)); } #else constantBuffer = new Buffer[1]; #endif Reset(); }
internal BufferPool(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size, CommandList clist = null) { constantBufferAlignment = graphicsDevice.ConstantBufferDataPlacementAlignment; if (size % constantBufferAlignment != 0) { throw new ArgumentException($"size needs to be a multiple of constant buffer alignment ({constantBufferAlignment})", nameof(size)); } this.allocator = allocator; Size = size; if (!UseBufferOffsets) { Data = Marshal.AllocHGlobal(size); } this.commandList = clist; #if XENKO_GRAPHICS_API_VULKAN // make buffers now, so we don't have to during gameplay which can cause threading / performance problems // eats some memory up, but memory is cheap compared to CPU / stability if (PreallocatedBuffers == null) { PreallocatedBuffers = new Stack <Buffer>(); for (int i = 0; i < BUFFERS_PER_POOL * POOL_PREALLOCATION; i++) { PreallocatedBuffers.Push(allocator.GetTemporaryBuffer(new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic))); } } // pick our buffers, hopefully from preallocated pool constantBuffer = new Buffer[BUFFERS_PER_POOL]; for (int i = 0; i < constantBuffer.Length; i++) { constantBuffer[i] = PreallocatedBuffers.Count > 0 ? PreallocatedBuffers.Pop() : allocator.GetTemporaryBuffer(new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic)); } #else constantBuffer = new Buffer[1]; #endif Reset(); }
public void Reset() { if (UseBufferOffsets) { // Release previous buffer if (constantBuffer != null) { allocator.ReleaseReference(constantBuffer); } constantBuffer = allocator.GetTemporaryBuffer(new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic)); } bufferAllocationOffset = 0; }
public void Reset() { #if !XENKO_GRAPHICS_API_VULKAN // Release previous buffer if (constantBuffer[bufferIndex] != null) { allocator.ReleaseReference(constantBuffer[bufferIndex]); } constantBuffer[bufferIndex] = allocator.GetTemporaryBuffer(new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic)); #else bufferIndex = (bufferIndex + 1) % constantBuffer.Length; #endif bufferAllocationOffset = 0; }