Ejemplo n.º 1
0
        public unsafe IDxcOperationResult Compile(IDxcBlob source,
                                                  string sourceName,
                                                  string entryPoint,
                                                  string targetProfile,
                                                  string[] arguments,
                                                  int argumentsCount,
                                                  DxcDefine[] defines,
                                                  int defineCount,
                                                  IDxcIncludeHandler includeHandler)
        {
            IntPtr *argumentsPtr = (IntPtr *)0;

            try
            {
                if (arguments != null && argumentsCount > 0)
                {
                    argumentsPtr = Interop.AllocToPointers(arguments, argumentsCount);
                }

                Result hr = Compile(source, sourceName,
                                    entryPoint, targetProfile,
                                    (IntPtr)argumentsPtr, argumentsCount,
                                    defines, defineCount,
                                    includeHandler,
                                    out IDxcOperationResult result);

                if (hr.Failure)
                {
                    result = default;
                    return(default);
Ejemplo n.º 2
0
 public Span <byte> GetObjectBytecode(out IDxcBlobUtf16 outputName)
 {
     using (IDxcBlob blob = GetOutput <IDxcBlob>(DxcOutKind.Object, out outputName))
     {
         return(blob.AsByte());
     }
 }
Ejemplo n.º 3
0
 public Span <byte> GetObjectBytecode()
 {
     using (IDxcBlob blob = GetOutput(DxcOutKind.Object))
     {
         return(blob.AsByte());
     }
 }
Ejemplo n.º 4
0
        public unsafe IDxcOperationResult Compile(IDxcBlob source,
                                                  string sourceName,
                                                  string entryPoint,
                                                  string targetProfile,
                                                  string[] arguments,
                                                  int argumentsCount,
                                                  DxcDefine[] defines,
                                                  IDxcIncludeHandler includeHandler)
        {
            IntPtr *argumentsPtr = (IntPtr *)0;

            try
            {
                if (arguments != null && argumentsCount > 0)
                {
                    argumentsPtr = Interop.AllocToPointers(arguments, argumentsCount);
                }

                Compile(source, sourceName,
                        entryPoint, targetProfile,
                        (IntPtr)argumentsPtr, argumentsCount,
                        defines,
                        includeHandler,
                        out IDxcOperationResult? result).CheckError();
                return(result !);
            }
            finally
            {
                if (argumentsPtr != null)
                {
                    Interop.Free(argumentsPtr);
                }
            }
        }
Ejemplo n.º 5
0
        public unsafe IDxcOperationResult?Preprocess(IDxcBlob source,
                                                     string sourceName,
                                                     string[] arguments,
                                                     int argumentsCount,
                                                     DxcDefine[] defines,
                                                     IDxcIncludeHandler includeHandler)
        {
            IntPtr *argumentsPtr = (IntPtr *)0;

            try
            {
                if (arguments != null && argumentsCount > 0)
                {
                    argumentsPtr = Interop.AllocToPointers(arguments, argumentsCount);
                }

                Result hr = Preprocess(source, sourceName,
                                       (IntPtr)argumentsPtr, argumentsCount,
                                       defines,
                                       includeHandler,
                                       out IDxcOperationResult? result);

                if (hr.Failure)
                {
                    result = default;
                    return(default);
Ejemplo n.º 6
0
 public static string GetStringFromBlob(IDxcLibrary library, IDxcBlob blob)
 {
     unsafe
     {
         blob = library.GetBlobAstUf16(blob);
         return(new string(blob.GetBufferPointer(), 0, (int)(blob.GetBufferSize() / 2)));
     }
 }
Ejemplo n.º 7
0
        public unsafe Result CompileWithDebug(IDxcBlob source,
                                              string sourceName,
                                              string entryPoint,
                                              string targetProfile,
                                              string[] arguments,
                                              int argumentsCount,
                                              DxcDefine[] defines,
                                              IDxcIncludeHandler includeHandler,
                                              out IDxcOperationResult?result,
                                              out string?debugBlobName, out IDxcBlob?debugBlob)
        {
            IntPtr *argumentsPtr = (IntPtr *)0;

            try
            {
                IntPtr debugBlobNameOut = default;

                if (arguments != null && argumentsCount > 0)
                {
                    argumentsPtr = Interop.AllocToPointers(arguments, argumentsCount);
                }

                Result hr = CompileWithDebug(source, sourceName,
                                             entryPoint, targetProfile,
                                             (IntPtr)argumentsPtr, argumentsCount,
                                             defines,
                                             includeHandler,
                                             out result,
                                             new IntPtr(&debugBlobNameOut),
                                             out debugBlob);

                if (debugBlobNameOut != IntPtr.Zero)
                {
                    debugBlobName = Marshal.PtrToStringUni(debugBlobNameOut);
                }
                else
                {
                    debugBlobName = string.Empty;
                }

                if (hr.Failure)
                {
                    result = default;
                    return(hr);
                }

                return(hr);
            }
            finally
            {
                if (argumentsPtr != null)
                {
                    Interop.Free(argumentsPtr);
                }
            }
        }
Ejemplo n.º 8
0
        public T CreateReflection <T>(IDxcBlob blob) where T : ComObject
        {
            DxcBuffer reflectionData = new DxcBuffer
            {
                Ptr      = blob.GetBufferPointer(),
                Size     = blob.GetBufferSize(),
                Encoding = Dxc.DXC_CP_ACP
            };

            CreateReflection(ref reflectionData, typeof(T).GUID, out IntPtr nativePtr).CheckError();
            return(MarshallingHelpers.FromPointer <T>(nativePtr));
        }
Ejemplo n.º 9
0
 public IDxcOperationResult?Preprocess(IDxcBlob source,
                                       string sourceName,
                                       string[] arguments,
                                       DxcDefine[] defines,
                                       IDxcIncludeHandler includeHandler)
 {
     return(Preprocess(
                source,
                sourceName,
                arguments,
                arguments?.Length ?? 0,
                defines,
                includeHandler));
 }
Ejemplo n.º 10
0
 public IDxcOperationResult?Compile(IDxcBlob source,
                                    string sourceName,
                                    string entryPoint,
                                    string targetProfile,
                                    string[] arguments,
                                    DxcDefine[] defines,
                                    IDxcIncludeHandler includeHandler)
 {
     return(Compile(
                source,
                sourceName,
                entryPoint,
                targetProfile,
                arguments,
                arguments?.Length ?? 0,
                defines,
                includeHandler));
 }
Ejemplo n.º 11
0
        public static byte[] GetBytesFromBlob(IDxcBlob blob)
        {
            unsafe
            {
                byte * pMem   = (byte *)blob.GetBufferPointer();
                uint   size   = blob.GetBufferSize();
                byte[] result = new byte[size];
                fixed(byte *pTarget = result)
                {
                    for (uint i = 0; i < size; ++i)
                    {
                        pTarget[i] = pMem[i];
                    }
                }

                return(result);
            }
        }
Ejemplo n.º 12
0
 public IDxcOperationResult?CompileWithDebug(IDxcBlob source,
                                             string sourceName,
                                             string entryPoint,
                                             string targetProfile,
                                             string[] arguments,
                                             DxcDefine[] defines,
                                             IDxcIncludeHandler includeHandler,
                                             out string?debugBlobName, out IDxcBlob?debugBlob)
 {
     return(CompileWithDebug(
                source,
                sourceName,
                entryPoint,
                targetProfile,
                arguments,
                arguments?.Length ?? 0,
                defines,
                includeHandler,
                out debugBlobName, out debugBlob));
 }
Ejemplo n.º 13
0
        public Result CreateReflection <T>(IDxcBlob blob, out T?reflection) where T : ComObject
        {
            DxcBuffer reflectionData = new DxcBuffer
            {
                Ptr      = blob.GetBufferPointer(),
                Size     = blob.GetBufferSize(),
                Encoding = Dxc.DXC_CP_ACP
            };

            Result result = CreateReflection(ref reflectionData, typeof(T).GUID, out IntPtr nativePtr);

            if (result.Failure)
            {
                reflection = default;
                return(result);
            }

            reflection = MarshallingHelpers.FromPointer <T>(nativePtr);
            return(result);
        }
Ejemplo n.º 14
0
 public IDxcOperationResult CompileWithDebug(IDxcBlob source,
                                             string sourceName,
                                             string entryPoint,
                                             string targetProfile,
                                             string[] arguments,
                                             int argumentsCount,
                                             DxcDefine[] defines,
                                             IDxcIncludeHandler includeHandler,
                                             out string debugBlobName, out IDxcBlob debugBlob)
 {
     return(CompileWithDebug(
                source,
                sourceName,
                entryPoint,
                targetProfile,
                arguments,
                argumentsCount,
                defines,
                defines != null ? defines.Length : 0,
                includeHandler,
                out debugBlobName, out debugBlob));
 }
Ejemplo n.º 15
0
 public IDxcOperationResult Validate(IDxcBlob shader, int flags)
 {
     Validate(shader, flags, out IDxcOperationResult result).CheckError();
     return(result);
 }
Ejemplo n.º 16
0
 public IDxcBlobEncoding Disassemble(IDxcBlob source)
 {
     Disassemble(source, out IDxcBlobEncoding result).CheckError();
     return(result);
 }
Ejemplo n.º 17
0
 public IDxcBlob CreateBlobFromBlob(IDxcBlob blob, int offset, int length)
 {
     CreateBlobFromBlob(blob, offset, length, out IDxcBlob result).CheckError();
     return(result);
 }
Ejemplo n.º 18
0
 public IDxcBlobEncoding GetBlobAsUtf16(IDxcBlob blob)
 {
     GetBlobAsUtf16(blob, out IDxcBlobEncoding result).CheckError();
     return(result);
 }
Ejemplo n.º 19
0
 public IStream CreateStreamFromBlobReadOnly(IDxcBlob blob)
 {
     CreateStreamFromBlobReadOnly(blob, out IStream result).CheckError();
     return(result);
 }