Exemple #1
0
        public void EndAndCommit(ThreadedSparseUploader tsu)
        {
            // TODO: release safety handle of thread data
            m_ThreadData->m_DataPtr       = null;
            m_ThreadData->m_OperationsPtr = null;
            int writtenData = math.min(m_ThreadData->m_CurrDataOffset, m_ThreadData->m_MaxDataOffset);
            int writtenOps  = math.min(m_ThreadData->m_CurrOperation, m_ThreadData->m_MaxOperations);

#if UNITY_2020_1_OR_NEWER
            m_DataBuffer[m_CurrFrame].EndWrite <byte>(writtenData);
            m_OperationsBuffer[m_CurrFrame].EndWrite <Operation>(writtenOps);
#endif

            // Uncomment this to display how much data the uploader will copy.
            //Debug.Log($"SPARSE UPLOADER: uploaded {m_ThreadData->m_CurrDataOffset / (1024.0 * 1024.0)} MiB in {m_ThreadData->m_CurrOperation} operations");

            if (m_ThreadData->m_CurrOperation > 0)
            {
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "operations", m_OperationsBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "src", m_DataBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "dst", m_DestinationBuffer);
                m_SparseUploaderShader.Dispatch(m_KernelIndex, m_ThreadData->m_CurrOperation, 1, 1);
            }

            m_CurrFrame += 1;
            if (m_CurrFrame >= k_NumBufferedFrames)
            {
                m_CurrFrame = 0;
            }
            m_ThreadData->m_CurrDataOffset = 0;
            m_ThreadData->m_CurrOperation  = 0;
            m_ThreadData->m_MaxDataOffset  = 0;
            m_ThreadData->m_MaxOperations  = 0;
        }
        public void EndAndCommit(ThreadedSparseUploader tsu)
        {
            // TODO: release safety handle of thread data
            m_ThreadData->m_DataPtr           = null;
            m_ThreadData->m_CopyOperationsPtr = null;
            int writtenData = math.min(m_ThreadData->m_CurrDataOffset, m_ThreadData->m_MaxDataOffset);
            int writtenOps  = math.min(m_ThreadData->m_CurrOperation, m_ThreadData->m_MaxOperation);

            m_DataBuffer[m_CurrFrame].EndWrite <byte>(writtenData);
            m_UploadOperationBuffer[m_CurrFrame].EndWrite <UploadOperation>(writtenOps);

            if (m_ThreadData->m_CurrOperation > 0)
            {
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "operations", m_UploadOperationBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "src", m_DataBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, "dstAddr", m_DestinationBuffer);
                m_SparseUploaderShader.Dispatch(m_KernelIndex, m_ThreadData->m_CurrOperation, 1, 1);
            }

            m_CurrFrame += 1;
            if (m_CurrFrame >= k_NumBufferedFrames)
            {
                m_CurrFrame = 0;
            }
            m_ThreadData->m_CurrDataOffset = 0;
            m_ThreadData->m_CurrOperation  = 0;
            m_ThreadData->m_MaxDataOffset  = 0;
            m_ThreadData->m_MaxOperation   = 0;
        }
        public void EndAndCommit(ThreadedSparseUploader tsu)
        {
            var numBuffers = m_ThreadData->m_NumBuffers;
            var frameData  = m_FreeFrameData.Count > 0 ? m_FreeFrameData.Pop() : new FrameData();

            for (int iBuf = 0; iBuf < numBuffers; ++iBuf)
            {
                var mappedBuffer = m_MappedBuffers[iBuf];
                MappedBuffer.UnpackMarker(mappedBuffer.m_Marker, out var operationOffset, out var dataOffset);
                var numOps          = (int)(operationOffset / UnsafeUtility.SizeOf <Operation>());
                var computeBufferID = mappedBuffer.m_BufferID;
                var computeBuffer   = m_UploadBufferPool.GetBufferFromId(computeBufferID);

                if (numOps > 0)
                {
                    computeBuffer.EndWrite <byte>(m_BufferChunkSize);

                    DispatchUploads(numOps, computeBuffer);

                    frameData.m_Buffers.Push(computeBufferID);
                }
                else
                {
                    computeBuffer.EndWrite <byte>(0);
                    m_UploadBufferPool.PutBufferId(computeBufferID);
                }
            }

            if (SystemInfo.supportsAsyncGPUReadback)
            {
                var fenceBufferId = m_FenceBufferPool.GetBufferId();
                frameData.m_FenceBuffer = fenceBufferId;
                frameData.m_Fence       = AsyncGPUReadback.Request(m_FenceBufferPool.GetBufferFromId(fenceBufferId));
            }

            m_FrameData.Add(frameData);

            m_MappedBuffers.Dispose();

            StepFrame();
        }
        public void EndAndCommit(ThreadedSparseUploader tsu)
        {
            // TODO: release safety handle of thread data
            m_ThreadData->m_DataPtr       = null;
            m_ThreadData->m_OperationsPtr = null;
            int writtenData = math.min(m_ThreadData->m_CurrDataOffset, m_ThreadData->m_MaxDataOffset);
            int writtenOps  = math.min(m_ThreadData->m_CurrOperation, m_ThreadData->m_MaxOperations);

#if UNITY_2020_1_OR_NEWER
            m_DataBuffer[m_CurrFrame].EndWrite <byte>(writtenData);
            m_OperationsBuffer[m_CurrFrame].EndWrite <Operation>(writtenOps);
#endif

            // Uncomment this to display how much data the uploader will copy.
            //Debug.Log($"SPARSE UPLOADER: uploaded {m_ThreadData->m_CurrDataOffset / (1024.0 * 1024.0)} MiB in {m_ThreadData->m_CurrOperation} operations");

            int numOps = m_ThreadData->m_CurrOperation;
            for (int i = 0; i < numOps; i += k_MaxThreadGroupsPerDispatch)
            {
                int opsBegin        = i;
                int opsEnd          = math.min(opsBegin + k_MaxThreadGroupsPerDispatch, numOps);
                int numThreadGroups = opsEnd - opsBegin;

                m_SparseUploaderShader.SetBuffer(m_KernelIndex, m_OperationsID, m_OperationsBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, m_SrcBufferID, m_DataBuffer[m_CurrFrame]);
                m_SparseUploaderShader.SetBuffer(m_KernelIndex, m_DstBufferID, m_DestinationBuffer);
                m_SparseUploaderShader.SetInt(m_OperationsBaseID, opsBegin);

                m_SparseUploaderShader.Dispatch(m_KernelIndex, numThreadGroups, 1, 1);
            }

            m_CurrFrame += 1;
            if (m_CurrFrame >= k_NumBufferedFrames)
            {
                m_CurrFrame = 0;
            }
            m_ThreadData->m_CurrDataOffset = 0;
            m_ThreadData->m_CurrOperation  = 0;
            m_ThreadData->m_MaxDataOffset  = 0;
            m_ThreadData->m_MaxOperations  = 0;
        }
Exemple #5
0
        public void EndAndCommit(ThreadedSparseUploader tsu)
        {
            var numBuffers = m_ThreadData->m_NumBuffers;

            for (int iBuf = 0; iBuf < numBuffers; ++iBuf)
            {
                var mappedBuffer = m_MappedBuffers[iBuf];
                MappedBuffer.UnpackMarker(mappedBuffer.m_Marker, out var operationOffset, out var dataOffset);
                var numOps          = (int)(operationOffset / UnsafeUtility.SizeOf <Operation>());
                var computeBufferID = mappedBuffer.m_BufferID;
                var computeBuffer   = m_UploadBuffers[computeBufferID];

                if (numOps > 0)
                {
                    computeBuffer.EndWrite <byte>(m_BufferChunkSize);

                    DispatchUploads(numOps, computeBuffer);

                    m_FrameReuseBuffers[m_CurrFrame].Push(computeBufferID);
                }
                else
                {
                    computeBuffer.EndWrite <byte>(0);
                    m_FreeBuffers.Push(computeBufferID);
                }
            }

            m_MappedBuffers.Dispose();

            m_CurrFrame += 1;
            if (m_CurrFrame >= m_NumBufferedFrames)
            {
                m_CurrFrame = 0;
            }
            // TODO: release safety handle of thread data
            m_ThreadData->m_Buffers    = null;
            m_ThreadData->m_NumBuffers = 0;
            m_ThreadData->m_CurrBuffer = 0;
        }