public static H1GpuMemoryPageTexture3D CreatePage(H1GpuMemoryChunk owner, H1Texture3D.Description desc)
        {
            H1GpuMemoryPageTexture3D newTexture3D = new H1GpuMemoryPageTexture3D(owner);

            // convert texture1D description to appropriate input parameters to create texture1D
            H1PixelFormat format           = desc.Format;
            Int32         width            = Convert.ToInt32(desc.Width);
            Int32         height           = Convert.ToInt32(desc.Height);
            Int32         depthOrArraySize = Convert.ToInt32(desc.Depth);

            H1OptionalParametersForTexture options = null;

            if (desc.MipLevels != 1) // if there is any optional property to apply
            {
                options = new H1OptionalParametersForTexture()
                {
                    MipLevels = Convert.ToUInt16(desc.MipLevels),
                };
            }

            if (!newTexture3D.CreatePage(format, width, height, depthOrArraySize, options))
            {
                return(null);
            }

            return(newTexture3D);
        }
        public static H1GpuMemoryPageBuffer CreatePage(H1GpuMemoryChunk memoryChunk, Int64 sizeInBytes, H1OptionalParameters options = null)
        {
            H1GpuMemoryPageBuffer newGpuMemoryPageBuffer = new H1GpuMemoryPageBuffer(memoryChunk);

            if (!newGpuMemoryPageBuffer.CreatePage(sizeInBytes, options))
            {
                return(null);
            }

            return(newGpuMemoryPageBuffer);
        }
        // constructor for memory page with normal type
        public H1GpuMemoryAllocInfo(H1GpuMemoryPage newPage)
        {
            m_MemoryPageRef = newPage;

            // this constructor should trigger by normal type only
            if (m_MemoryPageRef.PageType != H1GpuMemoryPageType.Normal)
            {
                throw new InvalidOperationException("Invalid parameter for this constructor!");
            }

            // set appropriate properties with memory chunk
            H1GpuMemoryChunk chunk = m_MemoryPageRef.Owner;

            SetProperties(chunk);
        }
        // constructor for memory page with segmented type
        public H1GpuMemoryAllocInfo(H1GpuMemoryBlock newBlock)
        {
            m_MemoryBlockRef = newBlock;

            H1GpuMemoryPage page = m_MemoryBlockRef.MemoryPage;

            // this constructor should trigger by segmented type only
            if (page.PageType != H1GpuMemoryPageType.Segmented)
            {
                throw new InvalidOperationException("Invalid parameter for this constructor!");
            }

            // set appropriate properties with memory chunk
            H1GpuMemoryChunk chunk = page.Owner;

            SetProperties(chunk);
        }
        protected void SetProperties(H1GpuMemoryChunk chunkRef)
        {
            switch (chunkRef.PageType)
            {
            case H1GpuMemoryPageType.Normal:
                m_Properties |= H1GpuMemoryAllocInfoProperties.Normal;
                break;

            case H1GpuMemoryPageType.Segmented:
                m_Properties |= H1GpuMemoryAllocInfoProperties.Segmented;
                break;
            }

            switch (chunkRef.Type)
            {
            case H1GpuMemoryType.CpuWritable:
                m_Properties |= H1GpuMemoryAllocInfoProperties.CpuWritable;
                break;

            case H1GpuMemoryType.GpuWritable:
                m_Properties |= H1GpuMemoryAllocInfoProperties.GpuWritable;
                break;
            }
        }
        // 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);
        }
 protected H1GpuMemoryPageSegmented(H1GpuMemoryChunk chunkRef)
     : base(chunkRef)
 {
     m_Type = H1GpuMemoryPageType.Segmented;
 }
 protected H1GpuMemoryPageTexture3D(H1GpuMemoryChunk owner)
     : base(owner)
 {
 }
 protected H1GpuMemoryPageBuffer(H1GpuMemoryChunk owner)
     : base(owner)
 {
     m_ResourceType = H1GpuMemoryPageResourceType.Buffer;
 }
 // H1GpuMemoryPage is only initialized by static method called 'CreatePage'
 protected H1GpuMemoryPage(H1GpuMemoryChunk chunkRef)
 {
     m_ChunkRef = chunkRef;
 }