예제 #1
0
파일: Device.cs 프로젝트: ichsanrp/SharpDX
        /// <summary>
        /// No documentation for Direct3D12
        /// </summary>
        /// <param name="descRef">No documentation.</param>
        /// <param name="riid">No documentation.</param>
        /// <returns>No documentation.</returns>
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateGraphicsPipelineState']/*"/>
        /// <unmanaged>HRESULT ID3D12Device::CreateGraphicsPipelineState([In] const void* pDesc,[In] const GUID&amp; riid,[Out] ID3D12PipelineState** ppPipelineState)</unmanaged>
        /// <unmanaged-short>ID3D12Device::CreateGraphicsPipelineState</unmanaged-short>
        public unsafe SharpDX.Direct3D12.PipelineState CreateGraphicsPipelineState(SharpDX.Direct3D12.GraphicsPipelineStateDescription desc)
        {
            // Use a custom marshalling routine for this class
            var nativeDesc = new GraphicsPipelineStateDescription.__Native();

            desc.__MarshalTo(ref nativeDesc);

            // Pin buffers if necessary
            fixed(void *pVertexShader = desc.VertexShader.Buffer)
            fixed(void *pGeometryShader = desc.GeometryShader.Buffer)
            fixed(void *pDomainShader   = desc.DomainShader.Buffer)
            fixed(void *pHullShader     = desc.HullShader.Buffer)
            fixed(void *pPixelShader    = desc.PixelShader.Buffer)
            {
                // Transfer pin buffer address to marshal
                desc.VertexShader.UpdateNative(ref nativeDesc.VertexShader, (IntPtr)pVertexShader);
                desc.GeometryShader.UpdateNative(ref nativeDesc.GeometryShader, (IntPtr)pGeometryShader);
                desc.DomainShader.UpdateNative(ref nativeDesc.DomainShader, (IntPtr)pDomainShader);
                desc.HullShader.UpdateNative(ref nativeDesc.HullShader, (IntPtr)pHullShader);
                desc.PixelShader.UpdateNative(ref nativeDesc.PixelShader, (IntPtr)pPixelShader);

                // Marshal input elements
                var elements       = desc.InputLayout.Elements;
                var nativeElements = (InputElement.__Native *) 0;

                if (elements != null && elements.Length > 0)
                {
                    var ptr = stackalloc InputElement.__Native[elements.Length];
                    nativeElements = ptr;
                    for (int i = 0; i < elements.Length; i++)
                    {
                        elements[i].__MarshalTo(ref nativeElements[i]);
                    }

                    nativeDesc.InputLayout.InputElementsPointer = new IntPtr(nativeElements);
                    nativeDesc.InputLayout.ElementCount         = elements.Length;
                }

                try
                {
                    // Create the pipeline state
                    return(CreateGraphicsPipelineState(new IntPtr(&nativeDesc), Utilities.GetGuidFromType(typeof(PipelineState))));
                }
                finally
                {
                    if (elements != null)
                    {
                        for (int i = 0; i < elements.Length; i++)
                        {
                            nativeElements[i].__MarshalFree();
                        }
                    }
                }
            }
        }
예제 #2
0
파일: Device.cs 프로젝트: TomAtWork/SharpDX
        /// <summary>	
        /// No documentation for Direct3D12	
        /// </summary>	
        /// <param name="descRef">No documentation.</param>	
        /// <param name="riid">No documentation.</param>	
        /// <returns>No documentation.</returns>	
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateGraphicsPipelineState']/*"/>	
        /// <unmanaged>HRESULT ID3D12Device::CreateGraphicsPipelineState([In] const void* pDesc,[In] const GUID&amp; riid,[Out] ID3D12PipelineState** ppPipelineState)</unmanaged>	
        /// <unmanaged-short>ID3D12Device::CreateGraphicsPipelineState</unmanaged-short>	
        public unsafe SharpDX.Direct3D12.PipelineState CreateGraphicsPipelineState(SharpDX.Direct3D12.GraphicsPipelineStateDescription desc)
        {
            // Use a custom marshalling routine for this class
            var nativeDesc = new GraphicsPipelineStateDescription.__Native();
            desc.__MarshalTo(ref nativeDesc);

            // Pin buffers if necessary
            fixed (void* pVertexShader = desc.VertexShader.Buffer)
            fixed (void* pGeometryShader = desc.GeometryShader.Buffer)
            fixed (void* pDomainShader = desc.DomainShader.Buffer)
            fixed (void* pHullShader = desc.HullShader.Buffer)
            fixed (void* pPixelShader = desc.PixelShader.Buffer)
            {
                // Transfer pin buffer address to marshal
                desc.VertexShader.UpdateNative(ref nativeDesc.VertexShader, (IntPtr)pVertexShader);
                desc.GeometryShader.UpdateNative(ref nativeDesc.GeometryShader, (IntPtr)pGeometryShader);
                desc.DomainShader.UpdateNative(ref nativeDesc.DomainShader, (IntPtr)pDomainShader);
                desc.HullShader.UpdateNative(ref nativeDesc.HullShader, (IntPtr)pHullShader);
                desc.PixelShader.UpdateNative(ref nativeDesc.PixelShader, (IntPtr)pPixelShader);

                // Marshal input elements
                var elements = desc.InputLayout.Elements;
                var nativeElements = (InputElement.__Native*)0;
                if (elements != null && elements.Length > 0)
                {
                    var ptr = stackalloc InputElement.__Native[elements.Length];
                    nativeElements = ptr;
                    for (int i = 0; i < elements.Length; i++)
                    {
                        elements[i].__MarshalTo(ref nativeElements[i]);
                    }

                    nativeDesc.InputLayout.InputElementsPointer = new IntPtr(nativeElements);
                    nativeDesc.InputLayout.ElementCount = elements.Length;
                }

                //Marshal stream output elements
                var streamOutElements = desc.StreamOutput.Elements;
                var nativeStreamOutElements = (StreamOutputElement.__Native*)0;
                if (streamOutElements != null && streamOutElements.Length > 0)
                {
                    var ptr = stackalloc StreamOutputElement.__Native[streamOutElements.Length];
                    nativeStreamOutElements = ptr;
                    for (int i = 0; i < streamOutElements.Length; i++)
                    {
                        streamOutElements[i].__MarshalTo(ref nativeStreamOutElements[i]);
                    }

                    nativeDesc.StreamOutput.StreamOutputEntriesPointer = new IntPtr(nativeStreamOutElements);
                    nativeDesc.StreamOutput.EntrieCount = streamOutElements.Length;
                }

                try
                {
                    // Create the pipeline state
                    return CreateGraphicsPipelineState(new IntPtr(&nativeDesc), Utilities.GetGuidFromType(typeof(PipelineState)));
                }
                finally
                {
                    if (elements != null)
                    {
                        for (int i = 0; i < elements.Length; i++)
                        {
                            nativeElements[i].__MarshalFree();
                        }
                    }

                    if (streamOutElements != null)
                    {
                        for (int i = 0; i < streamOutElements.Length; i++)
                        {
                            nativeStreamOutElements[i].__MarshalFree();
                        }
                    }
                }
            }
        }