/// <summary> /// Creates a new instance of the buffer. /// </summary> /// <param name="context">GPU context that the buffer belongs to</param> /// <param name="physicalMemory">Physical memory where the buffer is mapped</param> /// <param name="address">Start address of the buffer</param> /// <param name="size">Size of the buffer in bytes</param> /// <param name="baseBuffers">Buffers which this buffer contains, and will inherit tracking handles from</param> public Buffer(GpuContext context, PhysicalMemory physicalMemory, ulong address, ulong size, IEnumerable <Buffer> baseBuffers = null) { _context = context; _physicalMemory = physicalMemory; Address = address; Size = size; Handle = context.Renderer.CreateBuffer((int)size); _useGranular = size > GranularBufferThreshold; IEnumerable <IRegionHandle> baseHandles = null; if (baseBuffers != null) { baseHandles = baseBuffers.SelectMany(buffer => { if (buffer._useGranular) { return(buffer._memoryTrackingGranular.GetHandles()); } else { return(Enumerable.Repeat(buffer._memoryTracking.GetHandle(), 1)); } }); } if (_useGranular) { _memoryTrackingGranular = physicalMemory.BeginGranularTracking(address, size, baseHandles); _memoryTrackingGranular.RegisterPreciseAction(address, size, PreciseAction); } else { _memoryTracking = physicalMemory.BeginTracking(address, size); if (baseHandles != null) { _memoryTracking.Reprotect(false); foreach (IRegionHandle handle in baseHandles) { if (handle.Dirty) { _memoryTracking.Reprotect(true); } handle.Dispose(); } } _memoryTracking.RegisterPreciseAction(PreciseAction); } _externalFlushDelegate = new RegionSignal(ExternalFlush); _loadDelegate = new Action <ulong, ulong>(LoadRegion); _modifiedDelegate = new Action <ulong, ulong>(RegionModified); }
/// <summary> /// Creates a new instance of the GPU memory manager. /// </summary> /// <param name="physicalMemory">Physical memory that this memory manager will map into</param> internal MemoryManager(PhysicalMemory physicalMemory) { Physical = physicalMemory; CounterCache = new CounterCache(); _pageTable = new ulong[PtLvl0Size][]; MemoryUnmapped += Physical.TextureCache.MemoryUnmappedHandler; MemoryUnmapped += Physical.BufferCache.MemoryUnmappedHandler; MemoryUnmapped += CounterCache.MemoryUnmappedHandler; }
/// <summary> /// Creates a new instance of the buffer manager. /// </summary> /// <param name="context">The GPU context that the buffer manager belongs to</param> /// <param name="physicalMemory">Physical memory where the cached buffers are mapped</param> public BufferCache(GpuContext context, PhysicalMemory physicalMemory) { _context = context; _physicalMemory = physicalMemory; _buffers = new RangeList <Buffer>(); _bufferOverlaps = new Buffer[OverlapsBufferInitialCapacity]; _dirtyCache = new Dictionary <ulong, BufferCacheEntry>(); }
/// <summary> /// Creates a new MultiRangeWritableBlock. /// </summary> /// <param name="range">The MultiRange to write to</param> /// <param name="physicalMemory">The PhysicalMemory the given MultiRange addresses</param> public MultiRangeWritableBlock(MultiRange range, PhysicalMemory physicalMemory) { _range = range; _physicalMemory = physicalMemory; }