public static H1PixelFormat ConvertToPixelFormat(H1VertexElementType vertexElementType)
        {
            H1PixelFormat pixelFormat = new H1PixelFormat();

            switch (vertexElementType)
            {
            case H1VertexElementType.Float2:
                pixelFormat = H1PixelFormat.R32G32_FLOAT;
                break;

            case H1VertexElementType.Float3:
                pixelFormat = H1PixelFormat.R32G32B32_FLOAT;
                break;

            case H1VertexElementType.Float4:
                pixelFormat = H1PixelFormat.R32G32B32A32_FLOAT;
                break;

            case H1VertexElementType.Int4:
                pixelFormat = H1PixelFormat.R32G32B32A32_SINT;
                break;
            }

            return(pixelFormat);
        }
        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);
        }
Ejemplo n.º 3
0
 void ConstructPlatformIndependentMembers(Int64 bufferLocation, H1PixelFormat format, Int32 sizeInBytes)
 {
     m_Type           = H1GpuViewTypes.IndexBufferView;
     m_BufferLocation = bufferLocation;
     m_Format         = format;
     m_SizeInBytes    = sizeInBytes;
 }
Ejemplo n.º 4
0
        public void SetRenderTargetFormat(H1PixelFormat rtvFormat, H1PixelFormat dsvFormat, Int32 msaaCount, Int32 msaaQuality)
        {
            List <H1PixelFormat> rtvFormats = new List <H1PixelFormat>();

            rtvFormats.Add(rtvFormat);

            SetRenderTargetFormats(rtvFormats.ToArray(), dsvFormat, msaaCount, msaaQuality);
        }
Ejemplo n.º 5
0
 void ConstructPlatformDependentMembers(Int64 bufferLocation, H1PixelFormat format, Int32 sizeInBytes)
 {
     m_IBVDesc = new IndexBufferView()
     {
         BufferLocation = bufferLocation,
         Format         = H1RHIDefinitionHelper.ConvertToFormat(format),
         SizeInBytes    = sizeInBytes,
     };
 }
        // 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;
        }
Ejemplo n.º 7
0
 public H1Texture2D(H1GPUResourceManager manager, uint index, H1PixelFormat elementType, int width, int height)
     : base(manager, Convert.ToUInt32(H1RHIDefinitionHelper.ElementTypeToSize(elementType) * width * height))
 {
     m_Index = index;
     m_Description.Format = elementType;
     m_Description.Width  = Convert.ToUInt32(width);
     m_Description.Height = Convert.ToUInt32(height);
     // @TODO - I need to add initial variables like NumMips, NumSamples and TextureName
 }
Ejemplo n.º 8
0
        public H1Texture2D CreateTexture2D(H1PixelFormat elementType, int width, int height, Vector4 clearValue, H1SubresourceData[] initialData)
        {
            int index = m_ResourceManager.CreateTexture2D(elementType, width, height, clearValue, initialData);

            if (index == -1) // if it failed to create the texture2D, return null
            {
                return(null);
            }
            return(new H1Texture2D(m_ResourceManager, Convert.ToUInt32(index), elementType, width, height));
        }
        public static uint ElementTypeToSize(H1PixelFormat textureElementType)
        {
            uint size = 0;

            switch (textureElementType)
            {
            case H1PixelFormat.R8G8B8A8:
                size = 4;
                break;
            }

            return(size);
        }
Ejemplo n.º 10
0
        public void SetRenderTargetFormats(H1PixelFormat[] rtvFormats, H1PixelFormat dsvFormat, Int32 msaaCount, Int32 msaaQuality)
        {
            for (Int32 i = 0; i < rtvFormats.Count(); ++i)
            {
                m_GraphicsPipelineStateDesc.RenderTargetFormats[i] = H1RHIDefinitionHelper.ConvertToFormat(rtvFormats[i]);
            }
            for (Int32 i = rtvFormats.Count(); i < m_GraphicsPipelineStateDesc.RenderTargetCount; ++i)
            {
                m_GraphicsPipelineStateDesc.RenderTargetFormats[i] = SharpDX.DXGI.Format.Unknown;
            }

            m_GraphicsPipelineStateDesc.RenderTargetCount         = rtvFormats.Count();
            m_GraphicsPipelineStateDesc.DepthStencilFormat        = H1RHIDefinitionHelper.ConvertToFormat(dsvFormat);
            m_GraphicsPipelineStateDesc.SampleDescription.Count   = msaaCount;
            m_GraphicsPipelineStateDesc.SampleDescription.Quality = msaaQuality;
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public static SharpDX.Direct3D12.ClearValue FormatToClearValue(H1PixelFormat pixelFormat, Boolean bDepth)
        {
            SharpDX.Direct3D12.ClearValue clearValue;

            clearValue.Color.X = 0.0f;
            clearValue.Color.Y = 0.0f;
            clearValue.Color.Z = 0.0f;
            clearValue.Color.W = 0.0f;

            clearValue.Format = H1RHIDefinitionHelper.ConvertToFormat(pixelFormat);
            if (clearValue.Format == SharpDX.DXGI.Format.R32_Typeless)
            {
                clearValue.Format = bDepth ? SharpDX.DXGI.Format.D32_Float : SharpDX.DXGI.Format.R32_Float;
            }

            clearValue.DepthStencil.Depth   = 0.0f;
            clearValue.DepthStencil.Stencil = 0;

            return(clearValue);
        }
Ejemplo n.º 13
0
        public static SharpDX.DXGI.Format ConvertToFormat(H1PixelFormat textureElementType)
        {
            SharpDX.DXGI.Format format = new SharpDX.DXGI.Format();
            switch (textureElementType)
            {
            case H1PixelFormat.Unknown:
                format = SharpDX.DXGI.Format.Unknown;
                break;

            case H1PixelFormat.R8G8B8A8:
                format = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
                break;

            case H1PixelFormat.R32_UINT:
                format = SharpDX.DXGI.Format.R32_UInt;
                break;

            case H1PixelFormat.R32G32_FLOAT:
                format = SharpDX.DXGI.Format.R32G32_Float;
                break;

            case H1PixelFormat.R32G32B32_FLOAT:
                format = SharpDX.DXGI.Format.R32G32B32_Float;
                break;

            case H1PixelFormat.R32G32B32A32_FLOAT:
                format = SharpDX.DXGI.Format.R32G32B32A32_Float;
                break;

            case H1PixelFormat.R32G32B32A32_SINT:
                format = SharpDX.DXGI.Format.R32G32B32A32_SInt;
                break;

            case H1PixelFormat.R32_TYPELESS:
                format = SharpDX.DXGI.Format.R32_Typeless;
                break;
            }

            return(format);
        }
Ejemplo n.º 14
0
 public H1IndexBufferView(H1GpuResource resourceRef, Int64 bufferLocation, H1PixelFormat format, Int32 sizeInBytes)
     : base(resourceRef)
 {
     ConstructPlatformIndependentMembers(bufferLocation, format, sizeInBytes);
     ConstructPlatformDependentMembers(bufferLocation, format, sizeInBytes);
 }