public static H1GpuResourceDesc Texture2DDescToGpuResourceDesc(H1Texture2D.Description desc)
        {
            H1GpuResourceDesc result = new H1GpuResourceDesc();

            result.Format           = desc.Format;
            result.Width            = desc.Width;
            result.Height           = desc.Height;
            result.DepthOrArraySize = Convert.ToUInt16(desc.ArraySize);
            result.MipLevels        = Convert.ToUInt16(desc.MipLevels);
            result.Flags            = H1ResourceFlags.Unknown;
            result.Layout           = H1TextureLayout.Unknown;
            result.Dimension        = H1Dimension.Texture2D;

            // setting sample description
            result.SampleDesc.Count   = desc.SampleDesc.Count;
            result.SampleDesc.Quality = desc.SampleDesc.Quality;

            // setting resource flag
            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.UnorderedAccess)) != 0)
            {
                result.Flags |= H1ResourceFlags.AllowUnorderedAccess;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.DepthStencil)) != 0)
            {
                result.Flags |= H1ResourceFlags.AllowDepthStencil;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.RenderTarget)) != 0)
            {
                result.Flags |= H1ResourceFlags.AllowRenderTarget;
            }

            return(result);
        }
        public static H1HeapType GetHeapTypeFromTexture2DDesc(H1Texture2D.Description desc)
        {
            H1HeapType result = H1HeapType.Default;

            if (desc.Usage == H1Usage.Staging)
            {
                result = H1HeapType.Readback;
            }

            else if (desc.Usage == H1Usage.Dynamic)
            {
                result = H1HeapType.Upload;
            }

            if (desc.CPUAccessFlags != 0)
            {
                if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Write))
                {
                    result = H1HeapType.Upload;
                }

                if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Write))
                {
                    result = H1HeapType.Readback;
                }
            }

            return(result);
        }
Esempio n. 3
0
        public int CreateTexture2D(H1PixelFormat elementType, int width, int height, Vector4 clearValue, H1SubresourceData[] subResources)
        {
            // @TODO - I will change change this more flexible memory management with 'Heap' class in SharpDX
            HeapProperties heapProperties = new HeapProperties(
                HeapType.Upload // specifies a heap for uploading, it has CPU access optimized for uploading to the GPU - best for CPU-write-once, GPU-read-once
                );

            // HeapType (from msdn)
            // 1. Upload Heaps - a heap for loading data from the CPU to the GPU, typically containing vertex, index or constant buffers or textures and other resources
            // 2. Readback Heaps - a heap for loading data back from the GPU to the CPU. Typically data that would be collected by the GPU and downloaded to the CPU would be image data from
            //                     a captured screen shot and statistical and performance data such as counters and timings
            // 3. Default Heaps - a heap which supports all GPU operations. This resource heap is focused on containing data that is persistently required by the GPU, such as index and vertex data that maybe required for many frames

            // Resources (from msdn)
            // 1. Commited resources
            //    - commited resources are the most common idea of D3D resources over the generations.
            //    - creating such a resource allocates virtual address range, an implicit heap large enough to fit the whole resource and commits the virtual address range to the physical memory encapsulated by the heap
            //    - the implicit heap properties must be passed to match functional parity with previous D3D versions.
            // 2. Reserved resources
            //    - Reserved resources are equivalent to D3D11 tiled resources.
            //    - On their creation, only a virtual address range is allocated and not mapped to any heap.
            //    - the application will map such resources to heaps latere
            //    - the capabilities of such resources are currently unchanged over D3D11, as they can be mapped to a heap at a 64KB tile granularity with 'UpdateTileMappings'
            // 3. Placed resources
            //    - new for D3D12, applications may create heaps seperate from resources.
            //    - afterward, the application may locate multiple resources within a single heap.
            //    - this can be done without creating tiled or reserved resources, enabling the capabilities for all resource types able to be created directly by applications.
            //    - multiple resources may overlap, and the application must use the 'TiledResourceBarrier' to re-use physical memory correctly.

            // create new resource
            H1Texture2D.Description desc = new H1Texture2D.Description();
            desc.Width              = Convert.ToUInt32(width);
            desc.Height             = Convert.ToUInt32(height);
            desc.Format             = elementType;
            desc.SampleDesc.Count   = 1;
            desc.SampleDesc.Quality = 0;
            desc.MipLevels          = 0;
            desc.ArraySize          = 1;

            Direct3D12.H1DX12Texture2D texture2D = Direct3D12.H1DX12Texture2D.Create(Device, clearValue, desc, subResources);

            Int32 index = m_Texture2Ds.Count;

            m_Texture2Ds.Add(texture2D);

            return(index);
        }
        public static H1ResourceStates GetResourceStatesFromTexture2DDesc(H1Texture2D.Description desc)
        {
            H1ResourceStates result = H1ResourceStates.CopyDestination;

            if (desc.Usage == H1Usage.Dynamic)
            {
                result = H1ResourceStates.GenericRead;
            }

            if (desc.CPUAccessFlags != 0)
            {
                if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Write))
                {
                    result = H1ResourceStates.GenericRead;
                }

                if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Write))
                {
                    result = H1ResourceStates.CopyDestination;
                }

                else
                {
                    return(H1ResourceStates.Invalid);
                }
            }

            // setting resource flag
            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.UnorderedAccess)) != 0)
            {
                result = H1ResourceStates.UnorderedAccess;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.DepthStencil)) != 0)
            {
                result = H1ResourceStates.DepthWrite;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.RenderTarget)) != 0)
            {
                result = H1ResourceStates.RenderTarget;
            }

            return(result);
        }