Exemple #1
0
        public H1GpuResourceSegmented CreatePlacedResourceSegmented(H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            H1GpuHeapResourceInfo newResSingle = CreatePlacedResourceSegmentedPlatformDependent(resourceDesc, defaultUsage);

            m_ResourceSegmenteds.Add(newResSingle);

            return(newResSingle.Resource as H1GpuResourceSegmented);
        }
        // static method for more general creat page for texture resided in GPU memory
        protected virtual Boolean CreatePage(H1PixelFormat format, Int32 width, Int32 height, Int32 depthOrArraySize, H1OptionalParametersForTexture options = null)
        {
            // invalid call for create page
            if (Owner.PageType != H1GpuMemoryPageType.Normal)
            {
                return(false);
            }

            // create resource encapsulated GPU API layer
            H1HeapType       heapType = H1HeapType.Unknown;
            H1ResourceStates usage    = H1ResourceStates.Invalid;

            if (Owner.Type != H1GpuMemoryType.GpuWritable)
            {
                // invalid gpu memory type
                // CpuWritable type should be H1GpuMemoryPageSegmented type
                return(false);
            }

            // GPU-writable
            heapType = H1HeapType.Default;
            H1GpuResourceDesc resourceDesc = new H1GpuResourceDesc();

            resourceDesc.Alignment        = 0; // depends on GDI decision for choosing appropriate alignment
            resourceDesc.Width            = Convert.ToUInt32(width);
            resourceDesc.Height           = Convert.ToUInt32(height);
            resourceDesc.DepthOrArraySize = Convert.ToUInt16(depthOrArraySize);
            resourceDesc.Format           = format;

            // these description properties are default values
            resourceDesc.SampleDesc.Count   = 1;
            resourceDesc.SampleDesc.Quality = 0;
            resourceDesc.Layout             = H1TextureLayout.RowMajor;
            resourceDesc.MipLevels          = 1;

            // apply optional parameters
            if (options != null)
            {
                resourceDesc.Flags = options.ResourceFlags;
                usage = options.ResourceStates;

                // resource description optional parameters
                resourceDesc.MipLevels = options.MipLevels;
                resourceDesc.Layout    = options.Layout;

                // struct copy (shallow copy should be occurred)
                resourceDesc.SampleDesc = options.SampleDesc;
            }

            // create new page resource
            //if (!Resource.CreateResource(heapType, resourceDesc, usage))
            {
                return(false);
            }

            //return true;
        }
Exemple #3
0
        public static H1GpuResourceSegmented CreateGpuResource(H1HeapType heapType, H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            H1GpuResourceSegmented newRes = new H1GpuResourceSegmented();

            if (!newRes.CreateResource(heapType, resourceDesc, defaultUsage))
            {
                newRes = null;
            }
            return(newRes);
        }
Exemple #4
0
        public static H1GpuResourceSingle CreateGpuResource(H1HeapType heapType, H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            H1GpuResourceSingle newRes = new H1GpuResourceSingle();

            if (!newRes.CreateResource(heapType, resourceDesc, defaultUsage))
            {
                newRes = null; // nullify newly created resource
            }
            return(newRes);
        }
        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 #6
0
        protected Boolean CreateResource(H1HeapType heapType, H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            Int32 totalSizeInBytes = CreateResourcePlatformDependent(heapType, resourceDesc, defaultUsage);

            if (m_GpuResource == null)
            {
                return(false);
            }

            // based on created platform dependent resource information, create alloc policy
            RegisterAllocPolicy(totalSizeInBytes);

            return(true);
        }
        // generic version for page creation
        protected virtual Boolean CreatePage(Int64 sizeInBytes, H1OptionalParameters options = null)
        {
            // invalid call for create page
            if (Owner.PageType != H1GpuMemoryPageType.Normal)
            {
                return(false);
            }

            // create resource encapsulated GPU API layer
            H1HeapType       heapType = H1HeapType.Unknown;
            H1ResourceStates usage    = H1ResourceStates.Invalid;

            H1GpuResourceDesc resourceDesc = new H1GpuResourceDesc();

            resourceDesc.Alignment          = 0; // depends on GDI decision for choosing appropriate alignment
            resourceDesc.Height             = 1;
            resourceDesc.DepthOrArraySize   = 1;
            resourceDesc.MipLevels          = 1;
            resourceDesc.Format             = H1PixelFormat.Unknown;
            resourceDesc.SampleDesc.Count   = 1;
            resourceDesc.SampleDesc.Quality = 0;
            resourceDesc.Layout             = H1TextureLayout.RowMajor;

            if (Owner.Type != H1GpuMemoryType.GpuWritable)
            {
                // invalid gpu memory type
                // CpuWritable type should be H1GpuMemoryPageSegmented type
                return(false);
            }

            // GPU-writable
            heapType           = H1HeapType.Default;
            resourceDesc.Width = Convert.ToUInt32(sizeInBytes);

            // apply optional parameters
            if (options != null)
            {
                resourceDesc.Flags = options.ResourceFlags;
                usage = options.ResourceStates;
            }

            // create new page resource
            //if (!Resource.CreateResource(heapType, resourceDesc, usage))
            {
                return(false);
            }

            //return true;
        }
        static void CreatePlatformDependent(Vector4 clearValue, H1Texture2D.Description desc, H1SubresourceData initialData, ref H1GpuTexture2D result)
        {
            // get device for directX 12
            Device deviceDX12 = H1Global <H1ManagedRenderer> .Instance.Device;

            H1GpuResourceDesc desc12         = H1RHIDefinitionHelper.Texture2DDescToGpuResourceDesc(desc);
            H1HeapType        heapType       = H1RHIDefinitionHelper.GetHeapTypeFromTexture2DDesc(desc);
            H1ResourceStates  resourceStates = H1RHIDefinitionHelper.GetResourceStatesFromTexture2DDesc(desc);

            // generate resource
            //if (result != null)
            //    result.Resource.CreateResource(heapType, desc12, resourceStates);

            // generate RHI resource description (need resource description for generating UAV or SRV or etc.)
            result.CreateResourceDescription(desc12);
        }
        public static ResourceDescription ConvertToResourceDescDx12(H1GpuResourceDesc resourceDesc)
        {
            ResourceDescription result = new ResourceDescription();

            result.Dimension = (ResourceDimension)DimensionMapper[Convert.ToInt32(resourceDesc.Dimension)];
            result.Alignment = resourceDesc.Alignment;
            result.Width     = resourceDesc.Width;
            result.Height    = Convert.ToInt32(resourceDesc.Height);
            result.MipLevels = Convert.ToInt16(resourceDesc.MipLevels);
            result.SampleDescription.Count   = Convert.ToInt32(resourceDesc.SampleDesc.Count);
            result.SampleDescription.Quality = Convert.ToInt32(resourceDesc.SampleDesc.Quality);
            result.Format           = H1RHIDefinitionHelper.ConvertToFormat(resourceDesc.Format);
            result.Flags            = (ResourceFlags)ResourceFlagsMapper[Convert.ToInt32(resourceDesc.Flags)];
            result.DepthOrArraySize = Convert.ToInt16(resourceDesc.DepthOrArraySize);

            return(result);
        }
        public virtual Boolean CreateResourceDescription(H1GpuResourceDesc desc)
        {
            // API level specific resource description
            m_Description.Alignment                 = desc.Alignment;
            m_Description.DepthOrArraySize          = Convert.ToInt16(desc.DepthOrArraySize);
            m_Description.Dimension                 = (ResourceDimension)H1GpuResource.DimensionMapper[Convert.ToInt32(desc.Dimension)];
            m_Description.Flags                     = H1RHIDefinitionHelper.FormatToResourceFlags(desc.Flags);
            m_Description.Format                    = H1RHIDefinitionHelper.ConvertToFormat(desc.Format);
            m_Description.Width                     = Convert.ToInt32(desc.Width);
            m_Description.Height                    = Convert.ToInt32(desc.Height);
            m_Description.Layout                    = (TextureLayout)H1GpuResource.TextureLayoutMapper[Convert.ToInt32(desc.Layout)];
            m_Description.MipLevels                 = Convert.ToInt16(desc.MipLevels);
            m_Description.SampleDescription.Count   = Convert.ToInt32(desc.SampleDesc.Count);
            m_Description.SampleDescription.Quality = Convert.ToInt32(desc.SampleDesc.Quality);

            return(true);
        }
        Int32 CreateResourcePlatformDependent(H1HeapType heapType, H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            HeapProperties heapProps = new HeapProperties();

            heapProps.CPUPageProperty      = CpuPageProperty.Unknown;
            heapProps.MemoryPoolPreference = MemoryPool.Unknown;
            heapProps.CreationNodeMask     = 1;
            heapProps.VisibleNodeMask      = 1;

            // convert to H1HeapType to HeapType for dx12
            switch (heapType)
            {
            case H1HeapType.Default:
                heapProps.Type = HeapType.Default;
                break;

            case H1HeapType.Readback:
                heapProps.Type = HeapType.Readback;
                break;

            case H1HeapType.Upload:
                heapProps.Type = HeapType.Upload;
                break;
            }

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

            Device deviceDX11 = H1Global <H1ManagedRenderer> .Instance.Device;

            m_GpuResource = deviceDX11.CreateCommittedResource(heapProps, HeapFlags.None, resourceDescDX12, defaultStates);

            Int32 elementSize = Convert.ToInt32(H1RHIDefinitionHelper.ElementTypeToSize(resourceDesc.Format));

            if (elementSize == 0)
            {
                throw new InvalidOperationException("there is no appropriate format is implemented in ElementTypeToSize()!");
            }

            Int32 totalSizeInBytes = elementSize * Convert.ToInt32(resourceDesc.Width * resourceDesc.Height * resourceDesc.DepthOrArraySize);

            return(totalSizeInBytes);
        }
        // newly override method called 'CreatePage(...)'
        public new static H1GpuMemoryPageSegmented CreatePage(H1GpuMemoryChunk memoryChunk)
        {
            H1GpuMemoryPageSegmented newPage = new H1GpuMemoryPageSegmented(memoryChunk);

            // create resource encapsulated GPU API layer
            H1HeapType       heapType = H1HeapType.Unknown;
            H1ResourceStates usage    = H1ResourceStates.Invalid;

            H1GpuResourceDesc resourceDesc = new H1GpuResourceDesc();

            resourceDesc.Alignment          = 0;
            resourceDesc.Height             = 1;
            resourceDesc.DepthOrArraySize   = 1;
            resourceDesc.MipLevels          = 1;
            resourceDesc.Format             = H1PixelFormat.Unknown;
            resourceDesc.SampleDesc.Count   = 1;
            resourceDesc.SampleDesc.Quality = 0;
            resourceDesc.Layout             = H1TextureLayout.RowMajor;

            // CPU-writable
            if (newPage.Owner.Type == H1GpuMemoryType.GpuWritable)
            {
                heapType = H1HeapType.Default;

                resourceDesc.Width = Convert.ToUInt32(H1GpuMemoryPageSize.GpuWritablePageSize);
                resourceDesc.Flags = H1ResourceFlags.AllowUnorderedAccess;
                resourceDesc.Flags = H1ResourceFlags.Unknown;

                usage = H1ResourceStates.UnorderedAccess;
            }

            // GPU-writable
            else if (newPage.Owner.Type == H1GpuMemoryType.CpuWritable)
            {
                // cpu writable is mainly for upload page (it could be 'readback' property)
                heapType = H1HeapType.Upload;

                resourceDesc.Width = Convert.ToUInt32(H1GpuMemoryPageSize.CpuWritablePageSize);
                resourceDesc.Flags = H1ResourceFlags.Unknown;

                usage = H1ResourceStates.GenericRead;
            }

            // @TODO - handle 'Readback' heap type
            else
            {
                // invalid type is assigned!
                return(null);
            }

            // create new page resource
            //if (!newPage.Resource.CreateResource(heapType, resourceDesc, usage))
            {
                return(null);
            }

            // initialize the properties of the gpu memory page
            Int32 segmentCounts = -1;

            // calculate segment counts
            // @TODO - need to consider further for choosing segment counts (kinda magic number)
            if (newPage.Owner.Type == H1GpuMemoryType.GpuWritable)
            {
                segmentCounts = 1 << 8; // 256 segments
                newPage.m_PageSegmentCounts = segmentCounts;
                newPage.m_PageSegmentSize   = Convert.ToInt32(H1GpuMemoryPageSize.GpuWritablePageSize) / newPage.m_PageSegmentCounts;
            }

            else if (newPage.Owner.Type == H1GpuMemoryType.CpuWritable)
            {
                segmentCounts = 1 << 10; // 1024 segments
                newPage.m_PageSegmentCounts = segmentCounts;
                newPage.m_PageSegmentSize   = Convert.ToInt32(H1GpuMemoryPageSize.CpuWritablePageSize) / newPage.m_PageSegmentCounts;
            }

            if (!SetupPageSegments(newPage, segmentCounts))
            {
                return(null);
            }

            return(newPage);
        }
 H1GpuHeapResourceInfo CreatePlacedResourceSegmentedPlatformDependent(H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
 {
     // @TODO - need to implemented
     throw new NotImplementedException();
 }