Example #1
0
        public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
        {
            var dst = (TextureView)destination;

            if (_gd.CommandBufferPool.OwnedByCurrentThread)
            {
                _gd.PipelineInternal.EndRenderPass();

                var cbs = _gd.PipelineInternal.CurrentCommandBuffer;

                CopyToImpl(cbs, dst, srcRegion, dstRegion, linearFilter);
            }
            else if (_gd.BackgroundQueue.Handle != 0)
            {
                lock (_gd.BackgroundQueueLock)
                {
                    using var cbp = new CommandBufferPool(
                              _gd.Api,
                              _device,
                              _gd.BackgroundQueue,
                              _gd.QueueFamilyIndex,
                              isLight: true);

                    using var cbs = cbp.Rent();

                    CopyToImpl(cbs, dst, srcRegion, dstRegion, linearFilter);
                }
            }
            else
            {
                // TODO...
            }
        }
Example #2
0
        public unsafe void PushData(CommandBufferPool cbp, CommandBufferScoped?cbs, Action endRenderPass, BufferHolder dst, int dstOffset, ReadOnlySpan <byte> data)
        {
            bool isRender = cbs != null;
            CommandBufferScoped scoped = cbs ?? cbp.Rent();

            // Must push all data to the buffer. If it can't fit, split it up.

            endRenderPass?.Invoke();

            while (data.Length > 0)
            {
                if (_freeSize < data.Length)
                {
                    FreeCompleted();
                }

                while (_freeSize == 0)
                {
                    if (!WaitFreeCompleted(cbp))
                    {
                        if (isRender)
                        {
                            _gd.FlushAllCommands();
                            scoped   = cbp.Rent();
                            isRender = false;
                        }
                        else
                        {
                            scoped = cbp.ReturnAndRent(scoped);
                        }
                    }
                }

                int chunkSize = Math.Min(_freeSize, data.Length);

                PushDataImpl(scoped, dst, dstOffset, data.Slice(0, chunkSize));

                dstOffset += chunkSize;
                data       = data.Slice(chunkSize);
            }

            if (!isRender)
            {
                scoped.Dispose();
            }
        }
Example #3
0
        public Span <byte> GetTextureData(CommandBufferPool cbp, TextureView view, int size, int layer, int level)
        {
            var flushStorage = ResizeIfNeeded(size);

            using (var cbs = cbp.Rent())
            {
                var buffer = flushStorage.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
                var image  = view.GetImage().Get(cbs).Value;

                view.CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, size, true, layer, level, 1, 1, singleSlice: true);
            }

            flushStorage.WaitForFences();
            return(flushStorage.GetDataStorage(0, size));
        }
Example #4
0
        public Span <byte> GetBufferData(CommandBufferPool cbp, BufferHolder buffer, int offset, int size)
        {
            var flushStorage = ResizeIfNeeded(size);

            using (var cbs = cbp.Rent())
            {
                var srcBuffer = buffer.GetBuffer(cbs.CommandBuffer);
                var dstBuffer = flushStorage.GetBuffer(cbs.CommandBuffer);

                BufferHolder.Copy(_gd, cbs, srcBuffer, dstBuffer, offset, 0, size);
            }

            flushStorage.WaitForFences();
            return(flushStorage.GetDataStorage(0, size));
        }
Example #5
0
        public Span <byte> GetTextureData(CommandBufferPool cbp, TextureView view, int size)
        {
            GAL.TextureCreateInfo info = view.Info;

            var flushStorage = ResizeIfNeeded(size);

            using (var cbs = cbp.Rent())
            {
                var buffer = flushStorage.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
                var image  = view.GetImage().Get(cbs).Value;

                view.CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, size, true, 0, 0, info.GetLayers(), info.Levels, singleSlice: false);
            }

            flushStorage.WaitForFences();
            return(flushStorage.GetDataStorage(0, size));
        }
Example #6
0
        private ReadOnlySpan <byte> GetData(CommandBufferPool cbp)
        {
            int size;
            var bufferHolder = _flushStorage;

            if (bufferHolder == null)
            {
                size = 0;

                for (int level = 0; level < Info.Levels; level++)
                {
                    size += Info.GetMipSize(level);
                }

                size = GetBufferDataLength(size);

                bufferHolder = _gd.BufferManager.Create(_gd, size);

                var existingStorage = Interlocked.CompareExchange(ref _flushStorage, bufferHolder, null);
                if (existingStorage != null)
                {
                    bufferHolder.Dispose();
                    bufferHolder = existingStorage;
                }
            }
            else
            {
                size = bufferHolder.Size;
            }

            using (var cbs = cbp.Rent())
            {
                var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
                var image  = GetImage().Get(cbs).Value;

                CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, size, true, 0, 0, Info.GetLayers(), Info.Levels, singleSlice: false);
            }

            bufferHolder.WaitForFences();
            return(GetDataFromBuffer(bufferHolder.GetDataStorage(0, size)));
        }