Ejemplo n.º 1
0
        public unsafe ThreadedSparseUploader Begin(int maxDataSizeInBytes, int biggestDataUpload, int maxOperationCount)
        {
#if !DISABLE_HYBRID_RENDERER_V2_FRAME_LIMIT
            if (SystemInfo.supportsAsyncGPUReadback)
            {
                m_LimitingRequests[m_CurrFrame].WaitForCompletion();
                m_LimitingRequests[m_CurrFrame] = AsyncGPUReadback.Request(m_LimitingBuffers[m_CurrFrame]);
            }
#endif

            // First: recover all buffers from the previous frames (if any)
            // TODO: handle change in QualitySettings.maxQueuedFrames
            var currStack = m_FrameReuseBuffers[m_CurrFrame];
            while (currStack.Count != 0)
            {
                var buffer = currStack.Pop();
                m_FreeBuffers.Push(buffer);
            }

            // Second: calculate total size needed this frame, allocate buffers and map what is needed
            var operationSize           = UnsafeUtility.SizeOf <Operation>();
            var maxOperationSizeInBytes = maxOperationCount * operationSize;
            var sizeNeeded = maxOperationSizeInBytes + maxDataSizeInBytes;
            var bufferSizeWithMaxPaddingRemoved = m_BufferChunkSize - operationSize - biggestDataUpload;
            var numBuffersNeeded = (sizeNeeded + bufferSizeWithMaxPaddingRemoved - 1) / bufferSizeWithMaxPaddingRemoved;
            EnsurePreallocatedComputeBuffers(numBuffersNeeded);

            if (numBuffersNeeded < 0)
            {
                numBuffersNeeded = 0;
            }

            m_MappedBuffers = new NativeArray <MappedBuffer>(numBuffersNeeded, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < numBuffersNeeded; ++i)
            {
                var id     = m_FreeBuffers.Pop();
                var cb     = m_UploadBuffers[id];
                var data   = cb.BeginWrite <byte>(0, m_BufferChunkSize);
                var marker = MappedBuffer.PackMarker(0, m_BufferChunkSize);
                m_MappedBuffers[i] = new MappedBuffer
                {
                    m_Data     = (byte *)data.GetUnsafePtr(),
                    m_Marker   = marker,
                    m_BufferID = id,
                };
            }

            m_ThreadData->m_Buffers    = (MappedBuffer *)m_MappedBuffers.GetUnsafePtr();
            m_ThreadData->m_NumBuffers = numBuffersNeeded;

            // TODO: set safety handle on thread data
            return(new ThreadedSparseUploader
            {
                m_Data = m_ThreadData
            });
        }
        public ThreadedSparseUploader Begin(int maxDataSizeInBytes, int biggestDataUpload, int maxOperationCount)
        {
            // First: recover all buffers from the previous frames (if any)
            RecoverBuffers();

            // Second: calculate total size needed this frame, allocate buffers and map what is needed
            var operationSize           = UnsafeUtility.SizeOf <Operation>();
            var maxOperationSizeInBytes = maxOperationCount * operationSize;
            var sizeNeeded = maxOperationSizeInBytes + maxDataSizeInBytes;
            var bufferSizeWithMaxPaddingRemoved = m_BufferChunkSize - operationSize - biggestDataUpload;
            var numBuffersNeeded = (sizeNeeded + bufferSizeWithMaxPaddingRemoved - 1) / bufferSizeWithMaxPaddingRemoved;

            if (numBuffersNeeded < 0)
            {
                numBuffersNeeded = 0;
            }

            m_MappedBuffers = new NativeArray <MappedBuffer>(numBuffersNeeded, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < numBuffersNeeded; ++i)
            {
                var id     = m_UploadBufferPool.GetBufferId();
                var cb     = m_UploadBufferPool.GetBufferFromId(id);
                var data   = cb.BeginWrite <byte>(0, m_BufferChunkSize);
                var marker = MappedBuffer.PackMarker(0, m_BufferChunkSize);
                m_MappedBuffers[i] = new MappedBuffer
                {
                    m_Data     = (byte *)data.GetUnsafePtr(),
                    m_Marker   = marker,
                    m_BufferID = id,
                };
            }

            m_ThreadData->m_Buffers    = (MappedBuffer *)m_MappedBuffers.GetUnsafePtr();
            m_ThreadData->m_NumBuffers = numBuffersNeeded;

            // TODO: set safety handle on thread data
            return(new ThreadedSparseUploader
            {
                m_Data = m_ThreadData
            });
        }