Пример #1
0
        /// <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);
        }
Пример #2
0
        public Pool(GpuContext context, ulong address, int maximumId)
        {
            Context   = context;
            MaximumId = maximumId;

            int count = maximumId + 1;

            ulong size = (ulong)(uint)count * DescriptorSize;;

            Items = new T[count];

            Address = address;
            Size    = size;

            _memoryTracking = context.PhysicalMemory.BeginGranularTracking(address, size);
        }
Пример #3
0
        public Pool(GpuContext context, ulong address, int maximumId)
        {
            Context   = context;
            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   = context.PhysicalMemory.BeginGranularTracking(address, size);
            _modifiedDelegate = RegionModified;
        }
Пример #4
0
        /// <summary>
        /// Creates a new instance of the buffer.
        /// </summary>
        /// <param name="context">GPU context that the buffer belongs to</param>
        /// <param name="address">Start address of the buffer</param>
        /// <param name="size">Size of the buffer in bytes</param>
        public Buffer(GpuContext context, ulong address, ulong size)
        {
            _context = context;
            Address  = address;
            Size     = size;

            Handle = context.Renderer.CreateBuffer((int)size);

            _useGranular = size > GranularBufferThreshold;

            if (_useGranular)
            {
                _memoryTrackingGranular = context.PhysicalMemory.BeginGranularTracking(address, size);
            }
            else
            {
                _memoryTracking = context.PhysicalMemory.BeginTracking(address, size);
            }

            _modifiedDelegate = new Action <ulong, ulong>(RegionModified);
        }