コード例 #1
0
ファイル: BufferPool.cs プロジェクト: vol16bit/xenko
        public void Allocate(GraphicsDevice graphicsDevice, int size, BufferPoolAllocationType type, ref BufferPoolAllocationResult bufferPoolAllocationResult)
        {
            var result = bufferAllocationOffset;

            bufferAllocationOffset += size;

            // Align next allocation
            // Note: total Size should be a multiple of alignment, so that CanAllocate() and Allocate() Size check matches
            bufferAllocationOffset = (bufferAllocationOffset + constantBufferAlignment - 1) / constantBufferAlignment * constantBufferAlignment;

            if (bufferAllocationOffset > Size)
            {
                throw new InvalidOperationException();
            }

            // Map (if needed)
            if (useBufferOffsets && mappedConstantBuffer.Resource == null)
            {
                Map(commandList);
            }

            bufferPoolAllocationResult.Data = Data + result;
            bufferPoolAllocationResult.Size = size;

            if (useBufferOffsets)
            {
                bufferPoolAllocationResult.Uploaded = true;
                bufferPoolAllocationResult.Offset   = result;
                bufferPoolAllocationResult.Buffer   = constantBuffer;
            }
            else
            {
                bufferPoolAllocationResult.Uploaded = false;

                if (type == BufferPoolAllocationType.UsedMultipleTime)
                {
                    if (bufferPoolAllocationResult.Buffer == null || bufferPoolAllocationResult.Buffer.SizeInBytes != size)
                    {
                        // Release old buffer in case size changed
                        if (bufferPoolAllocationResult.Buffer != null)
                        {
                            bufferPoolAllocationResult.Buffer.Dispose();
                        }

                        bufferPoolAllocationResult.Buffer = Buffer.Constant.New(graphicsDevice, size, graphicsDevice.Features.HasResourceRenaming ? GraphicsResourceUsage.Dynamic : GraphicsResourceUsage.Default);
                        //bufferPoolAllocationResult.Buffer = Buffer.New(graphicsDevice, size, BufferFlags.ConstantBuffer);
                    }
                }
            }
        }
コード例 #2
0
        public void Allocate(GraphicsDevice graphicsDevice, int size, BufferPoolAllocationType type, ref BufferPoolAllocationResult bufferPoolAllocationResult)
        {
            var result = bufferAllocationOffset;

            bufferAllocationOffset += size;

            if (bufferAllocationOffset > Size)
            {
                throw new InvalidOperationException();
            }

            // TODO: We only implemented the D3D11/ES 2.0 compatibility mode
            // Need to write code to take advantage of cbuffer offsets later
            bufferPoolAllocationResult.Data     = Data + result;
            bufferPoolAllocationResult.Size     = size;
            bufferPoolAllocationResult.Uploaded = false;
            if (type == BufferPoolAllocationType.UsedMultipleTime)
            {
                if (bufferPoolAllocationResult.Buffer == null || bufferPoolAllocationResult.Buffer.SizeInBytes != size)
                {
                    // Release old buffer in case size changed
                    if (bufferPoolAllocationResult.Buffer != null)
                    {
                        bufferPoolAllocationResult.Buffer.Dispose();
                    }

                    bufferPoolAllocationResult.Buffer = Buffer.Constant.New(graphicsDevice, size);
                }
            }
        }