Exemplo n.º 1
0
        //Dynamic size entries are split into chunks that are spread around the file. We need to read per chunk
        unsafe ReadHandle ScheduleDynamicSizeElementArrayReads(Entry entry, uint elementOffset, uint elementCount, long readSize, void *buffer)
        {
            var   block = m_Blocks[(int)entry.Header.BlockIndex];
            byte *dst   = (byte *)buffer;

            var chunkReads = new NativeBlockList <ReadCommand>(64, 64);

            for (int i = 0; i < elementCount; ++i)
            {
                var e = new ElementRead();
                e.start   = entry.GetAdditionalStoragePtr()[i + elementOffset];
                e.end     = i + elementOffset + 1 == entry.Count ? (long)entry.Header.HeaderMeta : entry.GetAdditionalStoragePtr()[i + elementOffset + 1];
                e.readDst = dst;
                var readOffset = ProcessDynamicSizeElement(ref chunkReads, ref block, e);
                dst      += readOffset;
                readSize -= readOffset;
            }

            Checks.CheckEquals(0, readSize);

            //TODO: find a way to use the block array chunks directly for scheduling, probably add readcommandbuffer
            using (NativeArray <ReadCommand> readCommands = new NativeArray <ReadCommand>((int)chunkReads.Count, Allocator.Temp))
            {
                var cmdsPtr = (ReadCommand *)readCommands.GetUnsafePtr();

                for (int i = 0; i < readCommands.Length; ++i)
                {
                    *(cmdsPtr + i) = chunkReads[i];
                }
                chunkReads.Dispose();
                return(m_FileReader.Read(cmdsPtr, (uint)readCommands.Length, ReadMode.Async));
            }
        }
Exemplo n.º 2
0
        public NativeBlockList(int blockSize, int initialCapacity)
        {
            Checks.CheckEquals(true, UnsafeUtility.IsBlittable <T>());
            m_BlockSize = blockSize;
            uint preAllocatedBlockCount = ComputeBlockCount((uint)initialCapacity, m_BlockSize);

            m_Capacity         = preAllocatedBlockCount * (uint)m_BlockSize;
            Count              = 0;
            m_BlockSlots       = preAllocatedBlockCount;
            m_UnusedBlockSlots = 0;
            m_BlockList        = (MemBlock *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <MemBlock>() * preAllocatedBlockCount, UnsafeUtility.AlignOf <MemBlock>(), Allocator.Persistent);

            while (preAllocatedBlockCount > 0)
            {
                --preAllocatedBlockCount;
                var block = new MemBlock();
                block.mem = UnsafeUtility.Malloc(UnsafeUtility.SizeOf <T>() * m_BlockSize, UnsafeUtility.AlignOf <T>(), Allocator.Persistent);
                *(m_BlockList + preAllocatedBlockCount) = block;
            }
        }