/// <summary> /// The RequestPage /// </summary> /// <returns>The <see cref="LinearAllocationPage"/></returns> public LinearAllocationPage RequestPage() { lock (_Mutex) { while (_RetiredPages.Count != 0 && Globals.CommandManager.IsFenceComplete(_RetiredPages.Peek().Item1)) { _AvailablePages.Enqueue(_RetiredPages.Peek().Item2); _RetiredPages.Dequeue(); } LinearAllocationPage page = null; if (_AvailablePages.Count != 0) { page = _AvailablePages.Dequeue(); } else { page = CreateNewPage(); _PagePool.Add(page); } return(page); } }
/// <summary> /// The Allocate /// </summary> /// <param name="sizeInBytes">The <see cref="long"/></param> /// <param name="alignement">The <see cref="long"/></param> /// <returns>The <see cref="DynAlloc"/></returns> public DynAlloc Allocate(long sizeInBytes, long alignement = Constants.DEFAULT_ALIGN) { var alignementMask = alignement - 1; Debug.Assert((alignementMask & alignement) == 0); var alignedSize = sizeInBytes.AlignUpWithMask(alignementMask); if (alignedSize > _PageSize) { return(AllocateLargePage(alignedSize)); } _CurrentOffset = _CurrentOffset.AlignUpWithMask(alignementMask); if (_CurrentOffset + alignedSize > _PageSize) { Debug.Assert(_CurPage != null); _RetiredPages.Add(_CurPage); _CurPage = null; } if (_CurPage == null) { _CurPage = _PageManager[(int)_Type].RequestPage(); _CurrentOffset = 0; } var ret = new DynAlloc(_CurPage, _CurrentOffset, alignedSize, new IntPtr(_CurPage.CPUVirtualAddress.ToInt64() + _CurrentOffset), _CurPage.GPUVirtualAddress + _CurrentOffset); _CurrentOffset += alignedSize; return(ret); }
/// <summary> /// The CleanUpPages /// </summary> /// <param name="fenceValue">The <see cref="long"/></param> public void CleanUpPages(long fenceValue) { if (_CurPage == null) { return; } _RetiredPages.Add(_CurPage); _CurPage = null; _CurrentOffset = 0; _PageManager[(int)_Type].DiscardPages(fenceValue, _RetiredPages); _RetiredPages.Clear(); _PageManager[(int)_Type].FreeLargePages(fenceValue, _LargePageList); _LargePageList.Clear(); }