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(); }
public GraphicsContext(GraphicsDevice graphicsDevice, GraphicsResourceAllocator allocator = null, CommandList commandList = null) { CommandList = commandList ?? graphicsDevice.InternalMainCommandList ?? CommandList.New(graphicsDevice).DisposeBy(graphicsDevice); Allocator = allocator ?? new GraphicsResourceAllocator(graphicsDevice).DisposeBy(graphicsDevice); // prepare some resources now, so we don't need to do it during runtime (which can cause lag spikes or worse) // DirectX doesn't seem to like this very much, though if (GraphicsDevice.Platform == GraphicsPlatform.Vulkan && AvailableAllocators == null && PrepareVulkanAllocatorCount > 0) { AvailableAllocators = new Queue <ResourceGroupAllocator>(); while (AvailableAllocators.Count < PrepareVulkanAllocatorCount) { AvailableAllocators.Enqueue(new ResourceGroupAllocator(Allocator, CommandList, 2).DisposeBy(graphicsDevice)); } } if (AvailableAllocators?.Count > 0) { ResourceGroupAllocator = AvailableAllocators.Dequeue(); } else { ResourceGroupAllocator = new ResourceGroupAllocator(Allocator, CommandList, 2).DisposeBy(graphicsDevice); } }
public ResourceGroupAllocator(GraphicsResourceAllocator allocator, CommandList commandList) { this.allocator = allocator; this.commandList = commandList; this.graphicsDevice = commandList.GraphicsDevice; SetupNextDescriptorPool(); }
public ResourceGroupAllocator(GraphicsResourceAllocator allocator, CommandList commandList) { this.allocator = allocator; this.commandList = commandList; this.graphicsDevice = commandList.GraphicsDevice; SetupNextDescriptorPool(); bufferPools.Add(currentBufferPool = BufferPool.New(allocator, graphicsDevice, 1024 * 1024, commandList)); }
public ResourceGroupAllocator(GraphicsResourceAllocator allocator, CommandList commandList) { this.allocator = allocator; this.commandList = commandList; this.graphicsDevice = commandList.GraphicsDevice; SetupNextDescriptorPool(); // prepare some buffers now, so we don't need to worry about threading issues later PreallocateBuffers(PREALLOCATE_RESOURCE_COUNT); }
public ResourceGroupAllocator(GraphicsResourceAllocator allocator, CommandList commandList, int initialCount) { this.allocator = allocator; this.commandList = commandList; this.graphicsDevice = commandList.GraphicsDevice; SetupNextDescriptorPool(); for (int i = 0; i < initialCount; i++) { bufferPools.Add(currentBufferPool = BufferPool.New(allocator, graphicsDevice, 1024 * 1024, 4, commandList)); } }
internal BufferPool(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size) { 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); } 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(); }
internal BufferPool(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size, int initialCount, 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; defaultDescription = new BufferDescription(Size, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Dynamic); PrepareBuffers(initialCount); Reset(); }
public static BufferPool New(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size) { return(new BufferPool(allocator, graphicsDevice, size)); }
public static BufferPool New(GraphicsResourceAllocator allocator, GraphicsDevice graphicsDevice, int size, int initialCount, CommandList clist = null) { return(new BufferPool(allocator, graphicsDevice, size, initialCount, clist)); }
public GraphicsContext(GraphicsDevice graphicsDevice, GraphicsResourceAllocator allocator = null, CommandList commandList = null) { CommandList = commandList ?? graphicsDevice.InternalMainCommandList ?? CommandList.New(graphicsDevice).DisposeBy(graphicsDevice); Allocator = allocator ?? new GraphicsResourceAllocator(graphicsDevice).DisposeBy(graphicsDevice); ResourceGroupAllocator = new ResourceGroupAllocator(Allocator, CommandList).DisposeBy(graphicsDevice); }