Пример #1
0
 public static unsafe void CreateBlob(PointerSize size, Blob blobOut)
 {
     IntPtr num = IntPtr.Zero;
       Result result = (Result) D3DCommon.D3DCreateBlob_((void*) size, (void*) &num);
       blobOut.NativePointer = num;
       result.CheckError();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
 /// </summary>
 /// <param name="blob">The BLOB.</param>
 public ShaderSignature(Blob blob)
 {
     Data = new byte[blob.BufferSize];
     Utilities.Read(blob.BufferPointer, Data, 0, Data.Length);
     blob.Dispose();
 }
        /// <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();
                }
            }
        }
 /// <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.Version1, out result, out error);
         // TODO: check hresult or just rely on error?
         if(error != null)
         {
             errorText = Utilities.BlobToString(error);
         }
         return hresult;
     }
 }