/// <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 resource pool. /// </summary> /// <param name="context">GPU context that the pool belongs to</param> /// <param name="physicalMemory">Physical memory where the resource descriptors are mapped</param> /// <param name="address">Address of the pool in physical memory</param> /// <param name="maximumId">Maximum index of an item on the pool (inclusive)</param> public Pool(GpuContext context, PhysicalMemory physicalMemory, ulong address, int maximumId) { Context = context; PhysicalMemory = physicalMemory; MaximumId = maximumId; int count = maximumId + 1; ulong size = (ulong)(uint)count * DescriptorSize; Items = new T1[count]; DescriptorCache = new T2[count]; Address = address; Size = size; _memoryTracking = physicalMemory.BeginGranularTracking(address, size); _memoryTracking.RegisterPreciseAction(address, size, PreciseAction); _modifiedDelegate = RegionModified; }