Ejemplo n.º 1
0
        public bool Raised(long timeout)
        {
            if (timeout == 0)
            {
                WaitSyncStatus s = WaitSyncStatus.WaitFailed;
                while (s != WaitSyncStatus.ConditionSatisfied && s != WaitSyncStatus.AlreadySignaled)
                {
                    s = GL.ClientWaitSync(id, ClientWaitSyncFlags.SyncFlushCommandsBit, 10);
                }
                return(true);
            }
            else
            {
                WaitSyncStatus s = GL.ClientWaitSync(id, ClientWaitSyncFlags.SyncFlushCommandsBit, timeout);

                if (s == WaitSyncStatus.ConditionSatisfied || s == WaitSyncStatus.AlreadySignaled)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
        private bool BlockingWait(long timeInNanoSecs)
        {
            WaitSyncStatus status = GL.ClientWaitSync(ObjectPtr, mWaitOption, timeInNanoSecs);

            // BLOCKING WAITING
            if (status == WaitSyncStatus.WaitFailed)
            {
                throw new InvalidOperationException("GPU BlockingWait sync failed - surplus actions completed");
            }
            // HAS NOT COMPLETED
            return(status == WaitSyncStatus.ConditionSatisfied || status == WaitSyncStatus.AlreadySignaled);
        }
Ejemplo n.º 3
0
        private void Sync()
        {
            GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit);

            IntPtr         sync       = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None);
            WaitSyncStatus syncResult = GL.ClientWaitSync(sync, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000);

            if (syncResult == WaitSyncStatus.TimeoutExpired)
            {
                Logger.Error?.PrintMsg(LogClass.Gpu, $"Failed to sync persistent buffer state within 1000ms. Continuing...");
            }

            GL.DeleteSync(sync);
        }
Ejemplo n.º 4
0
        private bool NonBlockingWait()
        {
            // only on the first time
            ClientWaitSyncFlags waitOption = ClientWaitSyncFlags.SyncFlushCommandsBit;

            WaitSyncStatus result = GL.ClientWaitSync(ObjectPtr, waitOption, 0);

            waitOption = ClientWaitSyncFlags.None;
            if (result == WaitSyncStatus.WaitFailed)
            {
                throw new InvalidOperationException("GPU NonBlockingWait sync failed - surplus actions incomplete");
            }
            return(!(result == WaitSyncStatus.ConditionSatisfied || result == WaitSyncStatus.AlreadySignaled));
        }
Ejemplo n.º 5
0
        public void Cleanup()
        {
            // Iterate through handles and remove any that have already been signalled.

            while (true)
            {
                SyncHandle first = null;
                lock (Handles)
                {
                    first = Handles.FirstOrDefault();
                }

                if (first == null)
                {
                    break;
                }

                WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 0);

                if (syncResult == WaitSyncStatus.AlreadySignaled)
                {
                    // Delete the sync object.
                    lock (Handles)
                    {
                        lock (first)
                        {
                            _firstHandle = first.ID + 1;
                            Handles.RemoveAt(0);
                            GL.DeleteSync(first.Handle);
                            first.Handle = IntPtr.Zero;
                        }
                    }
                }
                else
                {
                    // This sync handle and any following have not been reached yet.
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        public void Wait(ulong id)
        {
            SyncHandle result = null;

            lock (Handles)
            {
                if ((long)(_firstHandle - id) > 0)
                {
                    return; // The handle has already been signalled or deleted.
                }

                foreach (SyncHandle handle in Handles)
                {
                    if (handle.ID == id)
                    {
                        result = handle;
                        break;
                    }
                }
            }

            if (result != null)
            {
                lock (result)
                {
                    if (result.Handle == IntPtr.Zero)
                    {
                        return;
                    }

                    WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000);

                    if (syncResult == WaitSyncStatus.TimeoutExpired)
                    {
                        Logger.Error?.PrintMsg(LogClass.Gpu, $"GL Sync Object {result.ID} failed to signal within 1000ms. Continuing...");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private bool BlockingWait()
        {
            int times = 0;

            ++TotalBlockingWaits;
            do
            {
                WaitSyncStatus status = GL.ClientWaitSync(ObjectPtr, ClientWaitSyncFlags.None, Duration);
                // BLOCKING WAITING
                if (status == WaitSyncStatus.WaitFailed)
                {
                    throw new InvalidOperationException("GPU BlockingWait sync failed - surplus actions completed");
                }
                else if (status == WaitSyncStatus.ConditionSatisfied || status == WaitSyncStatus.AlreadySignaled)
                {
                    return(false);
                }
                ++times;
            }while (times < BlockingRetries);

            ++TotalFailures;
            // still waiting
            return(true);
        }