コード例 #1
0
        protected IEnumerator Profile()
        {
            yield return(0);

            while (true)
            {
                if (this.dataList.Count > 0)
                {
                    int  count           = this.dataList.Count;
                    long totalCompress   = 0;
                    long totalDecompress = 0;
                    foreach (var file in this.dataList)
                    {
                        var timer = Stopwatch.StartNew();
                        var data  = CompressTool.Decompress(file.data);
                        timer.Stop();
                        UnityEngine.Debug.LogFormat("Decompress costs {0}", timer.ElapsedMilliseconds);
                        totalDecompress += timer.ElapsedMilliseconds;

                        timer = Stopwatch.StartNew();
                        data  = CompressTool.Compress(data);
                        timer.Stop();
                        UnityEngine.Debug.LogFormat("Compress costs {0}", timer.ElapsedMilliseconds);
                        totalCompress += timer.ElapsedMilliseconds;
                        yield return(0);
                    }

                    UnityEngine.Debug.LogFormat("Total {2} costs {0}, {1}", totalCompress, totalDecompress, count);
                    UnityEngine.Debug.LogFormat("30 frame time costs {0}, {1}", totalCompress / 30.0f / count, totalDecompress / 30.0f / count);
                }
            }
        }
コード例 #2
0
        protected override void OnSuccessed(FrameData frame)
        {
            if (this.data.Count > this.maxDataCount)
            {
                this.data.Dequeue();
            }

            var readback = frame.readback;

            var data = readback.GetData <byte>().ToArray();

            if (this.useCompress)
            {
                data = CompressTool.Compress(data);
            }
            var para = new Parameter()
            {
                x = readback.width, y = readback.height, compressed = this.useCompress
            };

            this.data.Enqueue(new FileData()
            {
                parameter = para, data = data
            });
        }
コード例 #3
0
        protected override void OnSuccessed(FrameData frame)
        {
            var readback = frame.readback;

            var data  = readback.GetData <byte>().ToArray();
            var timer = System.Diagnostics.Stopwatch.StartNew();

            data   = CompressTool.Compress(data, CompressTool.CompressAlgorithm.Zstd); timer.Stop();
            total += timer.ElapsedMilliseconds;
            count++;
            var para = new AsyncGPUDataSerializer.Parameter()
            {
                x = readback.width, y = readback.height, compressed = true
            };
            var fileData = new AsyncGPUDataSerializer.FileData()
            {
                parameter = para, data = data
            };

            Debug.Log("Data size " + data.Length);
            this.socket.Send(socketData, fileData);
        }
コード例 #4
0
        protected void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            this.fileQueueCount = this.socket.fileQueue.Count;

            if (this.currentTexture == null && this.socket.fileQueue.Count > 0)
            {
                AsyncGPUDataSerializer.FileData d;
                this.socket.fileQueue.TryPeek(out d);
                this.currentTexture = TextureManager.Create(d.parameter.x, d.parameter.y, TextureFormat.RGBA32, false);
            }

            if (this.currentTexture != null)
            {
                AsyncGPUDataSerializer.FileData d;
                if (this.socket.fileQueue.TryDequeue(out d))
                {
                    var timer = System.Diagnostics.Stopwatch.StartNew();
                    var data  = CompressTool.Decompress(d.data, CompressTool.CompressAlgorithm.Zstd);
                    timer.Stop();
                    total += timer.ElapsedMilliseconds;
                    count++;
                    this.currentTexture.LoadRawTextureData(data);
                    this.currentTexture.Apply();

                    Debug.Log("res is " + d.parameter.x + " " + d.parameter.y);
                }
            }

            Graphics.Blit(this.currentTexture, destination);

            if (count > 0)
            {
                var avgTime = total * 1.0d / count / 1000;
                Debug.LogFormat("Average decompress time {0}, fps is {1}", avgTime, 1 / avgTime);
            }
        }
コード例 #5
0
        protected IEnumerator ReadData()
        {
            yield return(null);

            foreach (var t in this.dataList)
            {
                t.DestoryObj();
            }

            this.dataList.Clear();

            var filePath = System.IO.Path.Combine(Application.streamingAssetsPath, this.fileNmae);
            var fileData = FileTool.Read <Queue <AsyncGPUDataSerializer.FileData> >(filePath, FileTool.SerializerType.Binary);

            foreach (var d in fileData)
            {
                var newTex = TextureManager.Create(d.parameter.x, d.parameter.y, TextureFormat.RGBA32, false);
                var data   = d.parameter.compressed?CompressTool.Decompress(d.data):d.data;
                newTex.LoadRawTextureData(data);
                newTex.Apply();
                this.dataList.Add(newTex);
                yield return(null);
            }
        }