Ejemplo n.º 1
0
 public override void Awake()
 {
     base.Awake();
     processPipeDelegator  = ProcessPipe;
     atmosThread           = gameObject.AddComponent <AtmosThread>();
     atmosThread.tickDelay = 40;
     simulation            = new AtmosSimulation();
     sampler = CustomSampler.Create("AtmosphericsStep");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of Awake()
        /// </summary>
        public void Awake()
        {
            m_InitSampler   = CustomSampler.Create("UIElements." + gameObject.name + ".Initialize");
            m_UpdateSampler = CustomSampler.Create("UIElements." + gameObject.name + ".Update");

            m_InitSampler.Begin();
            Initialize(gameObject.name);
            m_InitSampler.End();
        }
Ejemplo n.º 3
0
 void CreateSamplers(int count)
 {
     idleSamplers = new CustomSampler[count];
     jobSamplers  = new CustomSampler[count];
     for (int i = 0; i < count; i++)
     {
         idleSamplers[i] = CustomSampler.Create("MyThreadPool.Idle");
         jobSamplers[i]  = CustomSampler.Create("MyThreadPool.Job");
     }
 }
Ejemplo n.º 4
0
 public WorldLoadingThread()
 {
     objectRunningList              = new TreeDictionary <long, NifLoadJob>();
     terrainRunningList             = new TreeDictionary <long, NifLoadJob>();
     objectPositions                = new SCG.List <ObjectPosition>();
     MAX_RUNNING_THREADS            = ProgramSettings.get("MAX_RUNNING_THREADS", 2);
     this.loadingQueueSampler       = CustomSampler.Create("LoadingQueuesampler");
     this.objectRunningListSampler  = CustomSampler.Create("LoadingQueuesampler");
     this.terrainRunningListSampler = CustomSampler.Create("LoadingQueuesampler");
 }
Ejemplo n.º 5
0
        public static bool GetVisiblePointUnderCursor(
            Vector3[] vertices,
            Transform meshTransform,
            UnityEngine.Camera camera,
            Vector3 mousePos,
            float accuracy,
            out Vector2 screenVertex,
            out Vector3 worldVertex)
        {
            CustomSampler s  = CustomSampler.Create("point-search");
            CustomSampler s2 = CustomSampler.Create("point-raycast");

            s.Begin();
            float   minDist           = float.MaxValue;
            Vector3 closetsPoint      = Vector3.zero;
            var     worldMatrix       = meshTransform.localToWorldMatrix;
            var     screenMatrix      = camera.projectionMatrix * camera.worldToCameraMatrix;
            var     mousePosViewSpace = camera.ScreenToViewportPoint(mousePos);
            var     accuracyViewSpace = camera.ScreenToViewportPoint(new Vector3(accuracy, 0, 0)).x;

            for (int n = 0; n < vertices.Length; n++)
            {
                var worldPoint  = worldMatrix.MultiplyPoint(vertices[n]);
                var screenPoint = camera.WorldToScreenPoint(worldPoint);
                //var screenPoint = screenMatrix.MultiplyPoint(worldPoint);
                //var distVect = screenPoint - mousePos;
                var distVect = screenPoint - mousePos;
                distVect.z = 0;
                if (distVect.magnitude <= accuracy)
                {
                    var dist = (worldPoint - camera.transform.position).magnitude;
                    if (dist < minDist)
                    {
                        minDist      = dist;
                        closetsPoint = worldPoint;
                    }
                }
            }
            s.End();
            s2.Begin();
            if (CheckVertexVisibility(closetsPoint, camera, mousePos))
            {
                var screenPoint = camera.WorldToScreenPoint(closetsPoint);
                screenVertex = new Vector2(screenPoint.x, screenPoint.y);
                worldVertex  = closetsPoint;
                return(true);
            }
            s2.End();

            screenVertex = Vector2.zero;
            worldVertex  = Vector3.zero;
            return(false);
        }
Ejemplo n.º 6
0
 public static CustomSampler GetSampler(this CustomSamplerID samplerID)
 {
     if (s_Samplers == null)
     {
         s_Samplers = new CustomSampler[(int)CustomSamplerID.Max];
         for (int i = 0; i < (int)CustomSamplerID.Max; i++)
         {
             var id = (CustomSamplerID)i;
             s_Samplers[i] = CustomSampler.Create("C#_" + id);
         }
     }
     return(s_Samplers[(int)samplerID]);
 }
Ejemplo n.º 7
0
    private CustomSampler AttachCustomRecorder(string label, int slot)
    {
        CustomSampler newSampler = CustomSampler.Create(label);

        recorders[slot] = newSampler.GetRecorder();
        isCustom[slot]  = true;
        profilerData.recorderData[slot].label = label;
        if (!newSampler.isValid)
        {
            Debug.LogWarningFormat("ProfilerHUD: recorder \"{0}\" is either invalid or temporarily unavailable", label);
        }
        return(newSampler);
    }
Ejemplo n.º 8
0
        internal PathProcessor(AstarPath astar, PathReturnQueue returnQueue, int processors, bool multithreaded)
        {
            this.astar       = astar;
            this.returnQueue = returnQueue;

            if (processors < 0)
            {
                throw new System.ArgumentOutOfRangeException("processors");
            }

            if (!multithreaded && processors != 1)
            {
                throw new System.Exception("Only a single non-multithreaded processor is allowed");
            }

            // Set up path queue with the specified number of receivers
            queue        = new ThreadControlQueue(processors);
            pathHandlers = new PathHandler[processors];

            for (int i = 0; i < processors; i++)
            {
                pathHandlers[i] = new PathHandler(i, processors);
            }

            if (multithreaded)
            {
#if UNITY_2017_3_OR_NEWER
                profilingSampler = CustomSampler.Create("Calculating Path");
#endif

                threads = new Thread[processors];

                // Start lots of threads
                for (int i = 0; i < processors; i++)
                {
                    var pathHandler = pathHandlers[i];
                    threads[i] = new Thread(() => CalculatePathsThreaded(pathHandler));
#if !UNITY_SWITCH || UNITY_EDITOR
                    // Note: Setting the thread name seems to crash when deploying for Switch: https://forum.arongranberg.com/t/path-processor-crashing-nintendo-switch-build/6584
                    threads[i].Name = "Pathfinding Thread " + i;
#endif
                    threads[i].IsBackground = true;
                    threads[i].Start();
                }
            }
            else
            {
                // Start coroutine if not using multithreading
                threadCoroutine = CalculatePaths(pathHandlers[0]);
            }
        }
Ejemplo n.º 9
0
        static void Add <T>(T obj, Event eventTypes, System.Action <T[], int, Event> action1, System.Action <T[], int> action2, int archetypeVariant = 0) where T : class, IEntityIndex
        {
            if (obj.EntityIndex != 0)
            {
                throw new System.ArgumentException("This object is already registered. Call Remove before adding the object again.");
            }
            if (isIterating)
            {
                throw new System.Exception("Cannot add or remove entities during an event (Update/LateUpdate/...) that this helper initiated");
            }

            if (instance == null)
            {
                CreateInstance();
            }

            // Add in a hash of the event types
            archetypeVariant = (int)eventTypes * 12582917;


            var type = obj.GetType();

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i].type == type && data[i].variant == archetypeVariant)
                {
                    data[i].Add(obj);
                    return;
                }
            }

            {
                Memory.Realloc(ref data, data.Length + 1);
                // A copy is made here so that these variables are captured by the lambdas below instead of the original action1/action2 parameters.
                // If this is not done then the C# JIT will allocate a lambda capture object every time this function is executed
                // instead of only when we need to create a new archetype. Doing that would create a lot more unnecessary garbage.
                var ac1 = action1;
                var ac2 = action2;
                System.Action <object[], int, Event> a1 = (objs, count, ev) => ac1((T[])objs, count, ev);
                System.Action <object[], int, Event> a2 = (objs, count, ev) => ac2((T[])objs, count);
                data[data.Length - 1] = new Archetype {
                    type           = type,
                    events         = eventTypes,
                    variant        = archetypeVariant,
                    archetypeIndex = (data.Length - 1) + 1,                     // Note: offset by +1 to ensure that entity index = 0 is an invalid index
                    action         = ac1 != null ? a1 : a2,
                    sampler        = CustomSampler.Create(type.Name),
                };
                data[data.Length - 1].Add(obj);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TouchHandler" /> class.
        /// </summary>
        /// <param name="addPointer">A function called when a new pointer is detected.</param>
        /// <param name="updatePointer">A function called when a pointer is moved or its parameter is updated.</param>
        /// <param name="pressPointer">A function called when a pointer touches the surface.</param>
        /// <param name="releasePointer">A function called when a pointer is lifted off.</param>
        /// <param name="removePointer">A function called when a pointer is removed.</param>
        /// <param name="cancelPointer">A function called when a pointer is cancelled.</param>
        public TouchHandler(PointerDelegate addPointer, PointerDelegate updatePointer, PointerDelegate pressPointer, PointerDelegate releasePointer, PointerDelegate removePointer, PointerDelegate cancelPointer)
        {
            this.addPointer     = addPointer;
            this.updatePointer  = updatePointer;
            this.pressPointer   = pressPointer;
            this.releasePointer = releasePointer;
            this.removePointer  = removePointer;
            this.cancelPointer  = cancelPointer;

            touchPool      = new ObjectPool <TouchPointer>(10, () => new TouchPointer(this), null, resetPointer);
            touchPool.Name = "Touch";

            updateSampler = CustomSampler.Create("[TouchScript] Update touch");
        }
Ejemplo n.º 11
0
    public void AddTask(Task task, long activeStates)
    {
        TaskData td = new TaskData();

        td.Task          = task;
        task.TaskManager = this;
        td.ActiveStates  = activeStates;

        m_tasks.Add(td);
#if UNITY_EDITOR
        m_taskSamplers.Add(CustomSampler.Create(task.GetType().Name));
#endif
        m_taskCount = m_tasks.Count;
    }
Ejemplo n.º 12
0
        private void InitializeLogic(int width, int height)
        {
#if DEBUG
            renderTextureBuffer = new ScreenShotLogic(width, height);
            var behaviourGmo = new GameObject();
            behaviourGmo.hideFlags = HideFlags.HideAndDontSave;
            GameObject.DontDestroyOnLoad(behaviourGmo);
            var behaviour = behaviourGmo.AddComponent <ScreenShotBehaviour>();

            this.captureSampler    = CustomSampler.Create("ScreenshotToProfiler.Capture");
            this.updateSampler     = CustomSampler.Create("ScreenshotToProfiler.Update");
            behaviour.captureFunc += this.Capture;
            behaviour.updateFunc  += this.Update;
#endif
        }
    void OnEnable()
    {
        if (m_Sampler == null)
        {
            m_Sampler = CustomSampler.Create("Update Custom Depth Buffer");
        }

        var shader = Shader.Find("HDRP/Unlit");

        m_Material = new Material(shader);
        m_Material.enableInstancing = true;
        m_CmdBuffer = new CommandBuffer();

        UpdateRenderingData();
    }
        private void Awake()
        {
            if (instance == null)
            {
                instance = this;
            }
            else if (instance != this)
            {
                Destroy(this);
                return;
            }

#if TOUCHSCRIPT_DEBUG
            pLogger = Debugging.TouchScriptDebugger.Instance.PointerLogger;
#endif

#if UNITY_5_4_OR_NEWER
            SceneManager.sceneLoaded += sceneLoadedHandler;
#endif

            gameObject.hideFlags = HideFlags.HideInHierarchy;
            DontDestroyOnLoad(gameObject);

            layerManager = LayerManager.Instance;

            UpdateResolution();

            StopAllCoroutines();
            StartCoroutine(lateAwake());

            pointerListPool.WarmUp(2);
            intListPool.WarmUp(3);

            _layerAddPointer    = layerAddPointer;
            _layerUpdatePointer = layerUpdatePointer;
            _layerRemovePointer = layerRemovePointer;
            _layerCancelPointer = layerCancelPointer;

#if UNITY_5_6_OR_NEWER
            samplerUpdateInputs    = CustomSampler.Create("[TouchScript] Update Inputs");
            samplerUpdateAdded     = CustomSampler.Create("[TouchScript] Added Pointers");
            samplerUpdatePressed   = CustomSampler.Create("[TouchScript] Press Pointers");
            samplerUpdateUpdated   = CustomSampler.Create("[TouchScript] Update Pointers");
            samplerUpdateReleased  = CustomSampler.Create("[TouchScript] Release Pointers");
            samplerUpdateRemoved   = CustomSampler.Create("[TouchScript] Remove Pointers");
            samplerUpdateCancelled = CustomSampler.Create("[TouchScript] Cancel Pointers");
#endif
        }
Ejemplo n.º 15
0
        internal PathProcessor(AstarPath astar, PathReturnQueue returnQueue, int processors, bool multithreaded)
        {
            this.astar       = astar;
            this.returnQueue = returnQueue;

            if (processors < 0)
            {
                throw new System.ArgumentOutOfRangeException("processors");
            }

            if (!multithreaded && processors != 1)
            {
                throw new System.Exception("Only a single non-multithreaded processor is allowed");
            }

            // Set up path queue with the specified number of receivers
            queue        = new ThreadControlQueue(processors);
            pathHandlers = new PathHandler[processors];

            for (int i = 0; i < processors; i++)
            {
                pathHandlers[i] = new PathHandler(i, processors);
            }

            if (multithreaded)
            {
#if UNITY_2017_3_OR_NEWER
                profilingSampler = CustomSampler.Create("Calculating Path");
#endif

                threads = new Thread[processors];

                // Start lots of threads
                for (int i = 0; i < processors; i++)
                {
                    var pathHandler = pathHandlers[i];
                    threads[i]              = new Thread(() => CalculatePathsThreaded(pathHandler));
                    threads[i].Name         = "Pathfinding Thread " + i;
                    threads[i].IsBackground = true;
                    threads[i].Start();
                }
            }
            else
            {
                // Start coroutine if not using multithreading
                threadCoroutine = CalculatePaths(pathHandlers[0]);
            }
        }
Ejemplo n.º 16
0
 internal void CreateInstance(World world)
 {
     this.OnBeforeCreateManagerInternal(world);
     try
     {
         this.OnCreateManager();
         Type type = base.GetType();
         this.m_Sampler = CustomSampler.Create($"{world.Name} {type.FullName}");
     }
     catch
     {
         this.OnBeforeDestroyManagerInternal();
         this.OnAfterDestroyManagerInternal();
         throw;
     }
 }
Ejemplo n.º 17
0
 public TimerNode(string name, bool isRoot = false)
 {
     m_FullName = name;
     if (isRoot)
     {
         // The root node is considered always running. This means that when we output stats, it'll
         // have a sensible value for total time (the running time since reset).
         // The root node doesn't have a sampler since that could interfere with the profiler.
         m_NumCalls  = 1;
         m_TickStart = DateTime.Now.Ticks;
     }
     else
     {
         m_Sampler = CustomSampler.Create(m_FullName);
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TouchHandler" /> class.
        /// </summary>
        /// <param name="input">An input source to init new pointers with.</param>
        /// <param name="addPointer">A function called when a new pointer is detected.</param>
        /// <param name="updatePointer">A function called when a pointer is moved or its parameter is updated.</param>
        /// <param name="pressPointer">A function called when a pointer touches the surface.</param>
        /// <param name="releasePointer">A function called when a pointer is lifted off.</param>
        /// <param name="removePointer">A function called when a pointer is removed.</param>
        /// <param name="cancelPointer">A function called when a pointer is cancelled.</param>
        public TouchHandler(IInputSource input, PointerDelegate addPointer, PointerDelegate updatePointer, PointerDelegate pressPointer, PointerDelegate releasePointer, PointerDelegate removePointer, PointerDelegate cancelPointer)
        {
            this.input          = input;
            this.addPointer     = addPointer;
            this.updatePointer  = updatePointer;
            this.pressPointer   = pressPointer;
            this.releasePointer = releasePointer;
            this.removePointer  = removePointer;
            this.cancelPointer  = cancelPointer;

            touchPool      = new ObjectPool <TouchPointer>(10, newPointer, null, resetPointer, "TouchHandler/Touch");
            touchPool.Name = "Touch";

#if UNITY_5_6_OR_NEWER
            updateSampler = CustomSampler.Create("[TouchScript] Update Touch");
#endif
        }
Ejemplo n.º 19
0
 // 個別終了待ち合わせできない低機能スレッドプール
 public ThreadPool(int threadCount, int jobCapacity = 128)
 {
     _threads           = new Thread[threadCount];
     _jobStartSemaphore = new Semaphore(0, jobCapacity);
     _jobEndSemaphore   = new Semaphore(0, jobCapacity);
     _queue             = new Queue <System.Action>();
     _idleSamplers      = new CustomSampler[threadCount];
     _jobSamplers       = new CustomSampler[threadCount];
     for (int i = 0; i < threadCount; i++)
     {
         _threads[i]          = new Thread(ThreadFunc);
         _threads[i].Priority = System.Threading.ThreadPriority.BelowNormal;
         _idleSamplers[i]     = CustomSampler.Create("MyThreadPool.Idle");
         _jobSamplers[i]      = CustomSampler.Create("MyThreadPool.Job");
         _threads[i].Start(i);
     }
 }
Ejemplo n.º 20
0
    void OnTriggerEnter2D(Collider2D other)
    {
        Debug.LogError(offset);
        playerLastPos = GetComponentInParent <Player>().transform.position;

        //margin between the distances
        offset = other.transform.position.y - transform.position.y;

        //the position to instantiate at
        Vector2 posToInstantiate = new Vector2(Random.Range(-levelWidth, levelWidth), offset + GetComponentInParent <Player>().transform.position.y + 2);

        Debug.LogError("POZITIA ESTE: " + posToInstantiate);

        //Starting the profiling
        sampler = CustomSampler.Create("Collision Instantiating");
        sampler.Begin();

        if (other.tag == "Ledge")
        {
            other.transform.position = posToInstantiate;
        }

        if (other.tag == "DestructiveLedge")
        {
            Debug.Log("ELSE");
            Destroy(other.gameObject);
            //    Instantiate(destructivePlatformPrefab, posToInstantiate, Quaternion.identity);
        }
        if (Random.Range(1, 50) == 5)
        {
            instantiatedObj = Instantiate(boostPlatformPrefab, posToInstantiate, Quaternion.identity);

            if (x == 0)
            {
                Instantiate(destructivePlatformPrefab, posToInstantiate, Quaternion.identity);
                x = 1;
            }
        }
        if (other.tag == "BoostLedge")
        {
            Destroy(other.gameObject);
        }

        //end zone of profiling
        sampler.End();
    }
Ejemplo n.º 21
0
        public void ReadBackSyncAtIdx(int idx)
        {
            if (idx < 0 || idx >= FRAME_NUM)
            {
                return;
            }
            var rt = frames[idx].renderTexture;

            if (rt == null)
            {
                return;
            }
            if (syncUpdateSampler == null)
            {
                this.syncUpdateSampler = CustomSampler.Create("SyncUpdate");
            }

            syncUpdateSampler.Begin();
            if (syncTexCache != null &&
                (syncTexCache.width != rt.width || syncTexCache.height != rt.height))
            {
                Object.Destroy(syncTexCache);
                syncTexCache = null;
            }

            Texture2D tex2d = syncTexCache;

            if (tex2d == null)
            {
                tex2d = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
            }
            RenderTexture.active = rt;
            tex2d.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
            tex2d.Apply();
            var bytes = tex2d.GetRawTextureData <byte>();

            Profiler.EmitFrameMetaData(ScreenShotToProfiler.MetadataGuid,
                                       frames[idx].id, bytes);

            syncTexCache = tex2d;

            frames[idx].isRequest = false;
            frames[idx].fromEnd   = 0;
            syncUpdateSampler.End();
        }
Ejemplo n.º 22
0
    // Start is called before the first frame update
    void Start()
    {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        Samples = CustomSampler.Create("Fluid Update");
#endif

        _TileMap = transform.parent.GetComponent <TileMap3D>();
        _Lib     = GetComponent <FluidLibrary>();

        UpdateScheduling();
        BuildDataStrcutres();
        Instance = this;
        if (WaterMat != null)
        {
            WaterMat = new Material(WaterMat);
            WaterMat.SetFloat("Vector1_FF411F1A", 1.0f);
        }
    }
        private void Start()
        {
            CreateMatrices();
            SpawnBoids();

            parallelAddToDictFunc = ParallelAddToDict;
            parallelSteeringFunc  = ParallelSteering;

            ConcurrencyLevel    = SystemInfo.processorCount;
            boidsDictConcurrent = new ConcurrentDictOfLists <Boid>(ConcurrencyLevel);
            parallelOpts.MaxDegreeOfParallelism = ConcurrencyLevel;
            Debug.Log("System has " + SystemInfo.processorCount + " hardware threads, setting concurrency level...");

            guiStyle                  = new GUIStyle();
            guiStyle.fontSize         = 27;
            guiStyle.normal.textColor = Color.white;
            boidsSampler              = CustomSampler.Create("BoidsSimulation");
        }
Ejemplo n.º 24
0
        internal void CreateInstance(World world)
        {
            OnBeforeCreateManagerInternal(world);
            try
            {
                OnCreateManager();
#if UNITY_EDITOR
                var type = GetType();
                m_Sampler = CustomSampler.Create($"{world.Name} {type.FullName}");
#endif
            }
            catch
            {
                OnBeforeDestroyManagerInternal();
                OnAfterDestroyManagerInternal();
                throw;
            }
        }
    void Start()
    {
        sampler = CustomSampler.Create("NTj");

        int C = randomList.Length;

        for (int i = 0; i < C; i++)
        {
            randomList[i] = Random.Range(0, 20);
        }

        setTexture = new RenderThreadSyncObject(Receive);

        senderThread = new Thread(SenderThread);
        senderThread.Start();
        receiverThread = new Thread(ReceiverThread);
        receiverThread.Start();
    }
Ejemplo n.º 26
0
    public static int Create_s(IntPtr l)
    {
        int result;

        try
        {
            string name;
            LuaObject.checkType(l, 1, out name);
            CustomSampler o = CustomSampler.Create(name);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, o);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 27
0
        public ThreadPool(int threadCount, int jobCapacity = 128)
        {
            jobStartSemaphore = new Semaphore(0, jobCapacity);
            jobEndSemaphore   = new Semaphore(0, jobCapacity);
            queue             = new Queue <IJob>();
#if !UNITY_WEBGL
            threads = new Thread[threadCount];
#endif
            jobSamplers = new CustomSampler[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                jobSamplers[i] = CustomSampler.Create("MyThreadPool.Job");
#if !UNITY_WEBGL
                threads[i]          = new Thread(ThreadFunc);
                threads[i].Priority = System.Threading.ThreadPriority.BelowNormal;
                threads[i].Start(i);
#endif
            }
        }
Ejemplo n.º 28
0
        private void Awake()
        {
            if (instance == null)
            {
                instance = this;
            }
            else if (instance != this)
            {
                Destroy(this);
                return;
            }

            gameObject.hideFlags = HideFlags.HideInHierarchy;
            DontDestroyOnLoad(gameObject);

            gestureListPool.WarmUp(20);
            pointerListPool.WarmUp(20);
            transformListPool.WarmUp(1);

            gestureSampler = CustomSampler.Create("[TouchScript] Update Gestures");
        }
        public void EnableMultithreading()
        {
#if !UNITY_WEBGL
            if (graphUpdateThread == null || !graphUpdateThread.IsAlive)
            {
#if UNITY_2017_3_OR_NEWER && !UNITY_WEBGL
                asyncUpdateProfilingSampler = CustomSampler.Create("Graph Update");
#endif

                graphUpdateThread = new Thread(ProcessGraphUpdatesAsync);
                graphUpdateThread.IsBackground = true;

                // Set the thread priority for graph updates
                // Unless compiling for windows store or windows phone which does not support it
#if !UNITY_WINRT
                graphUpdateThread.Priority = System.Threading.ThreadPriority.Lowest;
#endif
                graphUpdateThread.Start();
            }
#endif
        }
    void Start()
    {
        sampler  = CustomSampler.Create("GPURecorder_Example", true);
        recorder = sampler.GetRecorder();

        CommandBuffer cmd = new CommandBuffer();

        cmd.name = "GPURecorder_Example";
        cmd.BeginSample(sampler);
        cmd.ClearRenderTarget(false, true, Color.green);
        cmd.EndSample(sampler);

        if (cam == null)
        {
            cam = Camera.main;
        }
        if (cam != null)
        {
            cam.AddCommandBuffer(evt, cmd);
        }
    }