/// <summary> /// Ensure that the modified range list exists. /// </summary> private void EnsureRangeList() { if (_modifiedRanges == null) { _modifiedRanges = new BufferModifiedRangeList(_context); } }
/// <summary> /// Inherit ranges from another modified range list. /// </summary> /// <param name="ranges">The range list to inherit from</param> /// <param name="rangeAction">The action to call for each modified range</param> public void InheritRanges(BufferModifiedRangeList ranges, Action <ulong, ulong> rangeAction) { BufferModifiedRange[] inheritRanges; lock (ranges._lock) { inheritRanges = ranges.ToArray(); } lock (_lock) { foreach (BufferModifiedRange range in inheritRanges) { Add(range); } } ulong currentSync = _context.SyncNumber; foreach (BufferModifiedRange range in inheritRanges) { if (range.SyncNumber != currentSync) { rangeAction(range.Address, range.Size); } } }
/// <summary> /// Inherit modified ranges from another buffer. /// </summary> /// <param name="from">The buffer to inherit from</param> public void InheritModifiedRanges(Buffer from) { if (from._modifiedRanges != null) { if (from._syncActionRegistered && !_syncActionRegistered) { _context.RegisterSyncAction(SyncAction); _syncActionRegistered = true; } Action <ulong, ulong> registerRangeAction = (ulong address, ulong size) => { if (_useGranular) { _memoryTrackingGranular.RegisterAction(address, size, _externalFlushDelegate); } else { _memoryTracking.RegisterAction(_externalFlushDelegate); } }; if (_modifiedRanges == null) { _modifiedRanges = from._modifiedRanges; _modifiedRanges.ReregisterRanges(registerRangeAction); from._modifiedRanges = null; } else { _modifiedRanges.InheritRanges(from._modifiedRanges, registerRangeAction); } } }
/// <summary> /// Called when part of the memory for this buffer has been unmapped. /// Calls are from non-GPU threads. /// </summary> /// <param name="address">Start address of the unmapped region</param> /// <param name="size">Size of the unmapped region</param> public void Unmapped(ulong address, ulong size) { BufferModifiedRangeList modifiedRanges = _modifiedRanges; modifiedRanges?.Clear(address, size); UnmappedSequence++; }