Exemplo n.º 1
0
        /// <summary>
        /// Serializes this description to a blob.
        /// </summary>
        /// <returns>A serialized version of this description.</returns>
        private unsafe Result Serialize(out Blob result, out string errorText)
        {
            Blob error;

            errorText = null;
            fixed(void *pParameters = Parameters.managedParameters)
            fixed(void *pSamplers = StaticSamplers.managedParameters)
            {
                __Native native;

                native.ParameterCount    = Parameters.Count;
                native.ParametersPointer = Parameters.nativeParameters;
                if (Parameters.managedParameters != null)
                {
                    native.ParametersPointer = (IntPtr)pParameters;
                }
                native.StaticSamplerCount   = StaticSamplers.Count;
                native.StaticSamplerPointer = StaticSamplers.nativeParameters;
                if (StaticSamplers.managedParameters != null)
                {
                    native.StaticSamplerPointer = (IntPtr)pSamplers;
                }
                native.Flags = Flags;
                var hresult = D3D12.SerializeRootSignature(new IntPtr(&native), RootSignatureVersion.V1, out result, out error);

                // TODO: check hresult or just rely on error?
                if (error != null)
                {
                    errorText = Utilities.BlobToString(error);
                }
                return(hresult);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the debug interface.
 /// </summary>
 /// <returns></returns>
 public static DebugInterface Get()
 {
     if (debugInterface == null)
     {
         IntPtr debugInterfacePtr;
         D3D12.GetDebugInterface(Utilities.GetGuidFromType(typeof(DebugInterface)), out debugInterfacePtr);
         debugInterface = new DebugInterface(debugInterfacePtr);
     }
     return(debugInterface);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Serializes this description to a blob.
        /// </summary>
        /// <returns>A serialized version of this description.</returns>
        /// <msdn-id>dn859363</msdn-id>
        /// <unmanaged>HRESULT D3D12SerializeRootSignature([In] const void* pRootSignature,[In] D3D_ROOT_SIGNATURE_VERSION Version,[Out] ID3D10Blob** ppBlob,[Out, Optional] ID3D10Blob** ppErrorBlob)</unmanaged>
        /// <unmanaged-short>D3D12SerializeRootSignature</unmanaged-short>
        private unsafe Result Serialize(out Blob result, out string errorText)
        {
            Blob error;

            errorText = null;

            int length         = 0;
            var rootParameters = (RootParameter.__Native *) 0;
            var pinnedTables   = new List <GCHandle>();

            try
            {
                if (Parameters != null)
                {
                    length         = Parameters.Length;
                    rootParameters = (RootParameter.__Native *)Utilities.AllocateMemory(length * Utilities.SizeOf <RootParameter.__Native>());
                    for (int i = 0; i < length; i++)
                    {
                        rootParameters[i] = Parameters[i].native;
                        if (rootParameters[i].ParameterType == RootParameterType.DescriptorTable && Parameters[i].DescriptorTable != null)
                        {
                            var handle = GCHandle.Alloc(Parameters[i].DescriptorTable, GCHandleType.Pinned);
                            pinnedTables.Add(handle);
                            rootParameters[i].Union.DescriptorTable.DescriptorRangeCount    = Parameters[i].DescriptorTable.Length;
                            rootParameters[i].Union.DescriptorTable.DescriptorRangesPointer = handle.AddrOfPinnedObject();
                        }
                    }
                }

                fixed(void *pSamplers = StaticSamplers)
                {
                    __Native native;

                    native.ParameterCount    = length;
                    native.ParametersPointer = new IntPtr(rootParameters);
                    if (StaticSamplers != null)
                    {
                        native.StaticSamplerCount   = StaticSamplers.Length;
                        native.StaticSamplerPointer = new IntPtr(pSamplers);
                    }
                    native.Flags = Flags;

                    var hresult = D3D12.SerializeRootSignature(new IntPtr(&native), RootSignatureVersion.Version1, out result, out error);

                    // TODO: check hresult or just rely on error?
                    if (error != null)
                    {
                        errorText = Utilities.BlobToString(error);
                    }
                    return(hresult);
                }
            }
            finally
            {
                if (new IntPtr(rootParameters) != IntPtr.Zero)
                {
                    Utilities.FreeMemory(new IntPtr(rootParameters));
                }
                foreach (var handle in pinnedTables)
                {
                    handle.Free();
                }
            }
        }
Exemplo n.º 4
0
 private static void CreateDevice(Adapter adapter, FeatureLevel minFeatureLevel, Device instance)
 {
     D3D12.CreateDevice(adapter, minFeatureLevel, Utilities.GetGuidFromType(typeof(Device)), instance).CheckError();
 }
Exemplo n.º 5
0
 private static void CreateDevice(Adapter adapter, DriverType driverType, DeviceCreationFlags flags,
                                  FeatureLevel minFeatureLevel, Device instance)
 {
     D3D12.CreateDevice(adapter, driverType, flags, minFeatureLevel, D3D12.SdkVersion, Utilities.GetGuidFromType(typeof(Device)), instance).CheckError();
 }