コード例 #1
0
    private void Callback(AsyncGPUReadbackRequest request)
    {
        if (request.done)
        {
            if (request.hasError)
            {
                Debug.LogError("Has error!");
            }

            // What the f**k is going on here!??!
            // request.GetData() doesn't match classic buffer.GetData()

            Debug.Log("Layer ct: " + request.layerCount);
            Debug.Log("LayerDataSize: " + request.layerDataSize);
            asyncEdgeVertices = request.GetData <GPUEdgeVertices>(0);

            Debug.Log("Done, length: " + asyncEdgeVertices.Length);
            Debug.Log("First index: " + asyncEdgeVertices[0].index);

            // In bytes check:
            var b = request.GetData <byte>();
            Debug.Log("Byte length: " + b.Length);
            Debug.Log("GPUEdgeVertices vs byte compare: " + (float)b.Length / asyncEdgeVertices.Length);
            Debug.Log("Compare remainder: " + b.Length % asyncEdgeVertices.Length);
            Debug.Log("First byte: " + b[0]);
        }
    }
コード例 #2
0
        public unsafe byte[] GetRawData()
        {
            UnityEngine.Profiling.Profiler.BeginSample("ZOAsyncGPUReadbackPluginRequest::GetRawData");
            if (usePlugin)
            {
                // Get data from cpp plugin
                void *ptr    = null;
                int   length = 0;
                getData_mainThread(this.eventId, ref ptr, ref length);

                // Copy data to a buffer that we own and that will not be deleted
                if (_openglByteBuffer == null || _openglByteBuffer.Length != length)
                {
                    _openglByteBuffer = new byte[length];
                }

                Marshal.Copy(new IntPtr(ptr), _openglByteBuffer, 0, length);

                bufferCreated = true;
                UnityEngine.Profiling.Profiler.EndSample();
                return(_openglByteBuffer);
            }
            else
            {
                UnityEngine.Profiling.Profiler.EndSample();
                return(gpuRequest.GetData <byte>().ToArray());
            }
        }
コード例 #3
0
    private void callAction <T>(T obj)
    {
        if (_request.done && _requesting)
        {
            _requesting = false;

            Unity.Collections.NativeArray <Color32> buffer = _request.GetData <Color32>();
            if (buffer != null && buffer.Length > 0)
            {
                callBack(buffer[0]);
            }
        }
    }
コード例 #4
0
        void EncodeImage(AsyncGPUReadbackRequest req, ulong timeStampNs)
        {
            if (m_Server == null)
            {
                return;
            }
            var       spsNalu   = new NativeList <byte>(Allocator.TempJob);
            var       ppsNalu   = new NativeList <byte>(Allocator.TempJob);
            var       imageNalu = new NativeList <byte>(Allocator.TempJob);
            JobHandle prevJob   = m_JobQueue.Count > 0 ? m_JobQueue.Peek().job : default(JobHandle);
            var       encodeJob = m_Encoder.Encode(prevJob, req.GetData <byte>(), timeStampNs, ref spsNalu, ref ppsNalu, ref imageNalu);

            //Debug.Log("Encode image at t=" + timeStampNs);
            if (encodeJob.Equals(default(JobHandle)))
            {
                spsNalu.Dispose();
                ppsNalu.Dispose();
                imageNalu.Dispose();
                return;
            }

            m_JobQueue.Enqueue(new JobItem {
                job = encodeJob, req = req, spsNalu = spsNalu, ppsNalu = ppsNalu, imageNalu = imageNalu, timeStampNs = timeStampNs
            });
        }
コード例 #5
0
        /// <summary>
        /// Checks if mesh generation on other thread or on the GPU is finished. If so, it is applied to the mesh.
        /// </summary>
        public void Update()
        {
            if (cookie != null && cookie.IsCompleted)
            {
                MeshData result = method.EndInvoke(cookie);
                ApplyToMesh(result);
                UpdateDistances();
                cookie = null;
                method = null;
            }

            if (isComputingOnGPU && gpuReadbackReq.done)
            {
                isComputingOnGPU = false;

                if (gpuReadbackReq.hasError)
                {
                    computeBuffer.Dispose();
                    computeBuffer    = null;
                    configurationOld = bool4.True;
                    GetNeighbors();
                }
                else
                {
                    var      a  = gpuReadbackReq.GetData <Vector3>().ToArray();
                    MeshData md = new MeshData(a, planet.quadMesh.normals, planet.quadMesh.uv);

                    //print(md.vertices.Length + ", [0]: " + md.vertices[0].ToString("F4") + ", [1089]: " + md.vertices[1089].ToString("F4"));
                    method = SpherifyAndDisplace;
                    cookie = method.BeginInvoke(md, null, null);
                    computeBuffer.Dispose();
                    computeBuffer = null;
                }
            }

            //Foliage Stuff:

            if (planet.generateDetails && (planet.generateFoliageInEveryBiome || planet.foliageBiomes.Contains(uniformBiome))) //Generating details if enabled and right biome.
            {
                if (level >= planet.grassLevel && foliageRenderer == null && renderedQuad && collider && distance < planet.dtDisSqr && planet.detailObjectsGenerating < planet.detailObjectsGeneratingSimultaneously)
                {
                    var        down = planet.Vector3Down(renderedQuad.transform.position);
                    Ray        ray  = new Ray(collider.bounds.center - (down * 500), down);
                    RaycastHit hit;

                    if (collider.Raycast(ray, out hit, 5000f)) //Only start foliage generation if the collider is working, it needs a few frames to initialize
                    {
                        foliageRenderer        = renderedQuad.AddComponent <FoliageRenderer>();
                        foliageRenderer.planet = planet;
                        foliageRenderer.quad   = this;
                        planet.detailObjectsGenerating++;
                    }
                }
                if (foliageRenderer != null && distance > planet.dtDisSqr)
                {
                    MonoBehaviour.Destroy(foliageRenderer);
                    foliageRenderer = null;
                }
            }
        }
コード例 #6
0
 public void GetResults()
 {
     if (this.resultData.Length != 0)
     {
         while (this.asyncRequests.Count > 0)
         {
             AsyncGPUReadbackRequest asyncGPUReadbackRequest = this.asyncRequests.Peek();
             if (!asyncGPUReadbackRequest.hasError)
             {
                 if (!asyncGPUReadbackRequest.done)
                 {
                     break;
                 }
                 NativeArray <Color32> data = asyncGPUReadbackRequest.GetData <Color32>(0);
                 for (int i = 0; i < data.Length; i++)
                 {
                     this.resultData[i] = data[i];
                 }
                 this.asyncRequests.Dequeue();
             }
             else
             {
                 this.asyncRequests.Dequeue();
             }
         }
     }
 }
コード例 #7
0
    public void Capture()
    {
        if (useAsync)
        {
            bool done = false;
            while (requests.Count > 0)
            {
                AsyncGPUReadbackRequest req = requests.Peek();
                if (req.hasError)
                {
                    requests.Dequeue();
                }
                else if (req.done)
                {
                    tex.SetPixels32(req.GetData <Color32>().ToArray());
                    requests.Dequeue();
                    done = true;
                }
                else
                {
                    break;
                }
            }

            if (done)
            {
                tex.Apply();
                cam.targetTexture.DiscardContents();
            }
        }
    }
コード例 #8
0
    void OnCompleteReadback(AsyncGPUReadbackRequest request)
    {
        if (request.hasError)
        {
            Debug.LogError("GPU readback error detected");
            return;
        }

        // This happens when the delayed async readback happens as we're exiting play mode
        if (instance == null || visibilityMaskTexture == null)
        {
            return;
        }

        // Read the color of the visibility mask texture to determine which visibility masks are active on cursor
        Texture2D visibilityMaskTex = new Texture2D(
            1,
            1,
            GraphicsFormatUtility.GetTextureFormat(visibilityMaskTexture.graphicsFormat),
            false
            );

        visibilityMaskTex.LoadRawTextureData(request.GetData <Color32>());
        visibilityMaskTex.Apply();

        // Only one pixel so we can sample at 0, 0
        Color sample = visibilityMaskTex.GetPixel(0, 0);

        visibilityMaskValue = DimensionShaderUtils.MaskValueFromSample(sample.linear);
    }
コード例 #9
0
        public unsafe byte[] GetRawData()
        {
            if (_usePlugin)
            {
                // Get data from cpp plugin
                void *ptr    = null;
                int   length = 0;
                getData_mainThread(this._eventId, ref ptr, ref length);

                // Copy data to a buffer that we own and that will not be deleted
                if (_buffer == null || _buffer.Length != length)
                {
                    _buffer = new byte[length];
                }
                UnityEngine.Profiling.Profiler.BeginSample("Marshal.Copy");
                Marshal.Copy(new IntPtr(ptr), _buffer, 0, length);
                UnityEngine.Profiling.Profiler.EndSample();
                _bufferCreated = true;

                return(_buffer);
            }
            else
            {
                return(_gpuRequest.GetData <byte>().ToArray());
            }
        }
コード例 #10
0
        static void batched_OnGPUComplete(AsyncGPUReadbackRequest request)
        {
            if (request.hasError)
            {
                Debug.Log("GPU readback error detected.");
                return;
            }

            var result = request.GetData <Block>();

            for (int i = 0; i < cs_generation_batchsize; i++)
            {
                if (CSGenerationQueue_waitForReadback[i] == null)
                {
                    continue;
                }

                var chkResult = result.GetSubArray(32768 * i, 32768);
                CSGenerationQueue_waitForReadback[i].OnGPUFinish(chkResult);
            }

            blkBufOK = true;
            if (blkBufOK && strBufOK && strlenBufOK)
            {
                HandleStructures();
                csgen_readingBack = false;
            }
        }
コード例 #11
0
        protected void OnCompleteAsyncReadback(AsyncGPUReadbackRequest request)
        {
            if (request.hasError)
            {
                Debug.LogError("Failed to read GPU texture");
                return;
            }
            // Debug.Assert(request.done);

            if (request.done)
            {
                var readbackData = request.GetData <byte>();
                camImageData.SetTextureBufferData(readbackData);
                var image = imageStamped.Image;
                if (image.Data.Length == camImageData.GetImageDataLength())
                {
                    var imageData = camImageData.GetImageData();

                    PostProcessing(ref imageData);

                    // Debug.Log(imageStamped.Image.Height + "," + imageStamped.Image.Width);
                    image.Data = imageData;

                    if (GetParameters().save_enabled)
                    {
                        var saveName = name + "_" + Time.time;
                        camImageData.SaveRawImageData(GetParameters().save_path, saveName);
                        // Debug.LogFormat("{0}|{1} captured", GetParameters().save_path, saveName);
                    }
                }
                readbackData.Dispose();
            }
        }
コード例 #12
0
 public void GetResults()
 {
     if (resultData.Length == 0)
     {
         return;
     }
     while (asyncRequests.Count > 0)
     {
         AsyncGPUReadbackRequest asyncGPUReadbackRequest = asyncRequests.Peek();
         if (asyncGPUReadbackRequest.hasError)
         {
             asyncRequests.Dequeue();
             continue;
         }
         if (asyncGPUReadbackRequest.done)
         {
             NativeArray <Color32> data = asyncGPUReadbackRequest.GetData <Color32>();
             for (int i = 0; i < data.Length; i++)
             {
                 resultData[i] = data[i];
             }
             asyncRequests.Dequeue();
             continue;
         }
         break;
     }
 }
コード例 #13
0
 public virtual void OnRead(AsyncGPUReadbackRequest data)
 {
     if (data.done)
     {
         DecodeData(data.GetData <float>().ToArray());
         newData = true;
     }
 }
コード例 #14
0
 public void ApplyNormalData(AsyncGPUReadbackRequest request)
 {
     //GPU readback might have happened too late and chuck might have been made invisible by that time.
     if (IsVisible)
     {
         var vectorData = request.GetData <Vector3>();
         Filter.sharedMesh.normals = vectorData.ToArray();
     }
 }
コード例 #15
0
        public void UpdateJobsGerstnerCache(AsyncGPUReadbackRequest request)
        {
            NativeArray <ushort> resultData = request.GetData <ushort>();
            NativeArray <ushort> data       = new NativeArray <ushort>(resultData, Allocator.Temp);

            ShapeGerstnerJobs.AddNewOceanDepthCache(this, data);

            data.Dispose();
        }
コード例 #16
0
        void ReadPixel(AsyncGPUReadbackRequest request)
        {
            if (request.hasError)
            {
                Debug.LogError("Can't readback the texture from GPU");
                return;
            }

            output = request.GetData <Color>(0)[0];
        }
コード例 #17
0
 private unsafe void OnReadBack(AsyncGPUReadbackRequest obj)
 {
     if (OK && !obj.hasError && obj.done)
     {
         fixed(byte *data = obj.GetData <byte>().ToArray())
         {
             ROS_Node.Instance.Publish_Image(Topic, name, (uint)Time.frameCount, (uint)obj.width, (uint)obj.height, data);
         }
     }
 }
コード例 #18
0
    void OnCompleteReadback(AsyncGPUReadbackRequest request)
    {
        if (request.hasError)
        {
            Debug.Log("GPU readback error detected.");
            return;
        }

        callback.Invoke(request.GetData <byte>().ToArray());
    }
コード例 #19
0
ファイル: SeaController.cs プロジェクト: Kodhan/Sea
    private void SetPoints(AsyncGPUReadbackRequest obj)
    {
        if (_destroy)
        {
            return;
        }

        _vertices      = obj.GetData <Vector3>().ToArray();
        _mesh.vertices = _vertices;
    }
コード例 #20
0
 /// <summary>
 /// Writes the frame from an asynchronous GPU read request.
 /// </summary>
 /// <param name="r">The asynchronous readback target.</param>
 protected virtual void WriteFrame(AsyncGPUReadbackRequest r, double timestamp)
 {
     if (m_ReadbackTexture == null)
     {
         m_ReadbackTexture = CreateReadbackTexture(r.width, r.height);
     }
     Profiler.BeginSample("BaseTextureRecorder.LoadRawTextureData");
     m_ReadbackTexture.LoadRawTextureData(r.GetData <byte>());
     Profiler.EndSample();
     WriteFrame(m_ReadbackTexture);
 }
コード例 #21
0
 public void StoreData(AsyncGPUReadbackRequest request)
 {
     if (colors.Length > 0)
     {
         colors.Dispose();
     }
     requestLoaded = true;
     colors        = new NativeArray <Color32>(request.GetData <Color32>(), Allocator.Persistent);
     height        = request.height;
     width         = request.width;
 }
コード例 #22
0
        protected void OnTreePositionsRecieved(AsyncGPUReadbackRequest result)
        {
            NativeArray <Matrix4x4> x = result.GetData <Matrix4x4>();
            int length = x.Length;

            for (int i = 0; i < length; i++)
            {
                Matrix4x4 transform = x[i];
                //place collider there
            }
        }
コード例 #23
0
 public void StoreData(AsyncGPUReadbackRequest iRequest)
 {
     iRequestLoaded = true;
     textureBuffer.Clear();
     foreach (Color32 C in iRequest.GetData <Color32>())
     {
         textureBuffer.Add(C);
     }
     height = iRequest.height;
     width  = iRequest.width;
 }
コード例 #24
0
 void OnGpuReadback(AsyncGPUReadbackRequest request, int frameCount)
 {
     if (request.hasError)
     {
         Debug.LogError("Error reading segmentation image from GPU");
     }
     else if (request.done && m_ImageReadCallback != null)
     {
         m_ImageReadCallback(frameCount, request.GetData <T>(), m_Source);
     }
 }
コード例 #25
0
    void OnCompleteReadback(AsyncGPUReadbackRequest request)
    {
        if (request.hasError)
        {
            Debug.Log("GPU readback error detected.");
            return;
        }

        croppedImage   = request.GetData <byte>().ToArray();
        imageRequested = false;
    }
コード例 #26
0
        void CaptureDepthMapAsyncCallback(AsyncGPUReadbackRequest request)
        {
            if (!request.done || request.hasError)
            {
                m_IsCapturingDepthMap = false;
                return;
            }

            m_DepthTextureArray = request.GetData <float>();

            GenerateDepthMaps();
        }
コード例 #27
0
ファイル: ScreenCast.cs プロジェクト: ryogoOkura/OkuraExpr
        void ReadbackDone(AsyncGPUReadbackRequest r, double timestamp)
        {
            if (StreamTexture == null)
            {
                return;
            }

            StreamTexture.LoadRawTextureData(r.GetData <byte>());
            StreamTexture.Apply();

            SendFrame(timestamp);
        }
コード例 #28
0
 void OnGpuReadback(AsyncGPUReadbackRequest request, int frameCount,
                    Action <int, NativeArray <T>, RenderTexture> imageReadCallback)
 {
     if (request.hasError)
     {
         Debug.LogError("Error reading segmentation image from GPU");
     }
     else if (request.done && imageReadCallback != null)
     {
         imageReadCallback(frameCount, request.GetData <T>(), m_Source);
     }
 }
コード例 #29
0
ファイル: WavesGenerator.cs プロジェクト: mikael-rh/Gemini
 void OnCompleteReadback(AsyncGPUReadbackRequest request, Texture2D result)
 {
     if (request.hasError)
     {
         Debug.Log("GPU readback error detected.");
         return;
     }
     if (result != null)
     {
         result.LoadRawTextureData(request.GetData <Color>());
         result.Apply();
     }
 }
コード例 #30
0
 public void ApplyVertexData(AsyncGPUReadbackRequest request)
 {
     //only show renderer and rad data if the chunk is visible.
     //GPU readback might have happened too late and chuck might have been made invisible by that time.
     if (IsVisible)
     {
         var vectorData = request.GetData <Vector3>();
         Filter.sharedMesh.vertices = vectorData.ToArray();
         Filter.sharedMesh.RecalculateBounds();
         Renderer.enabled = true;
         IsCalculating    = false;
     }
 }