Exemple #1
0
        public override H1GpuResAllocRange Allocate(Int64 sizeInBytes)
        {
            // calculate number of segments needed to allocate
            Int32 numberOfSegments = Convert.ToInt32((sizeInBytes + m_SegmentSize - 1) / m_SegmentSize);

            // find contiguous blocks matching number of segments needed
            Int32 startOffset = -1;

            // 1. starting from m_NextBitSearchStartIndex to the end
            startOffset = SearchAllocBits(m_NextBitSearchStartIndex, Convert.ToInt32(m_SegmentCount), numberOfSegments);

            // 2. still didn't find proper contiguous blocks starting from 0 to m_NextBitSearchStartIndex
            if (startOffset == -1)
            {
                startOffset = SearchAllocBits(0, m_NextBitSearchStartIndex, numberOfSegments);
            }

            // return result
            if (startOffset == -1) // still failed to find the blocks
            {
                return(null);
            }

            // mark as allocated
            MarkRangeAllocBits(true, startOffset, numberOfSegments);

            // update next bit to search
            m_NextBitSearchStartIndex = startOffset + numberOfSegments;

            return(H1GpuResAllocRange.CreateAllocRangeForSegmented(startOffset, numberOfSegments));
        }
Exemple #2
0
        public override void Deallocate(H1GpuResAllocRange allocRange)
        {
            // mark as deallocated
            MarkRangeAllocBits(false, allocRange.StartOffset, allocRange.Count);

            // update next bit to search
            m_NextBitSearchStartIndex = allocRange.StartOffset;
        }
        H1GpuHeapResourceInfo CreatePlacedResourceSinglePlatformDependent(H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            // get device ptr from the renderer
            Device deviceDX12 = H1Global <H1ManagedRenderer> .Instance.Device;

            H1GpuResourceSingle newRes = H1GpuResourceSingle.CreateEmptyGpuResource();

            // convert H1ResourceDesc to ResourceDesc for dx12
            ResourceDescription resourceDescDX12 = H1GpuResource.ConvertToResourceDescDx12(resourceDesc);
            ResourceStates      defaultStates    = (ResourceStates)H1GpuResource.ResourceStateMapper[Convert.ToInt32(defaultUsage)];

            // get resource allocation info and find proper resource size and alignments
            ResourceAllocationInformation allocInfo = deviceDX12.GetResourceAllocationInfo(0, resourceDescDX12);
            Int64 sizeInBytes = allocInfo.SizeInBytes;
            Int64 alignment   = allocInfo.Alignment;

            if (alignment > 512)
            {
                throw new InvalidOperationException("alignment is bigger than 512 bytes, please check!");
            }

            // request number of segments to resource alloc policy (segments)
            H1GpuResAllocRange newRange = m_HeapResAllocPolicy.Allocate(sizeInBytes);

            if (newRange == null) // there is no current available blocks to allocate
            {
                return(null);
            }

            // with new range,
            Int64    offsetInBytes = newRange.StartOffset * H1GpuResAllocPolicySegmented.DefaultSegmentSizeForHeap;
            Resource newResDX12    = deviceDX12.CreatePlacedResource(m_HeapInstance, offsetInBytes, resourceDescDX12, defaultStates);

            if (newResDX12 == null) // failed to create placed resource
            {
                return(null);
            }

            // set GpuResource for newly created placed resource
            newRes.SetPlacedResourcePlatformDependent(newResDX12);

            // create heap resource info
            H1GpuHeapResourceInfo newResourceInfo = new H1GpuHeapResourceInfo()
            {
                Resource           = newRes,
                ResourceAllocRange = newRange
            };

            return(newResourceInfo);
        }
Exemple #4
0
 public override void Deallocate(H1GpuResAllocRange allocRange = null)
 {
     // nothing to do
 }
Exemple #5
0
 public override H1GpuResAllocRange Allocate(long sizeInBytes = 0)
 {
     return(H1GpuResAllocRange.CreateAllocRangeForSingle());
 }
Exemple #6
0
 public virtual void Deallocate(H1GpuResAllocRange allocRange)
 {
     throw new NotImplementedException("Need to override and proper call needed!");
 }
Exemple #7
0
        public static H1GpuResAllocRange CreateAllocRangeForSegmented(Int32 offset, Int32 count)
        {
            H1GpuResAllocRange newAllocRange = new H1GpuResAllocRange(offset, count);

            return(newAllocRange);
        }