public H1GpuResourceSegmented CreatePlacedResourceSegmented(H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage) { H1GpuHeapResourceInfo newResSingle = CreatePlacedResourceSegmentedPlatformDependent(resourceDesc, defaultUsage); m_ResourceSegmenteds.Add(newResSingle); return(newResSingle.Resource as H1GpuResourceSegmented); }
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); }