Ejemplo n.º 1
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);
            }
        }
    }
    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.º 3
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.º 4
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.º 5
0
    public unsafe Result Compile <T>(string source, string[] arguments, IDxcIncludeHandler includeHandler, out T?result) where T : ComObject
    {
        IntPtr  shaderSourcePtr = Marshal.StringToHGlobalAnsi(source);
        IntPtr *argumentsPtr    = (IntPtr *)0;

        DxcBuffer buffer = new()
        {
            Ptr      = shaderSourcePtr,
            Size     = source.Length,
            Encoding = Dxc.DXC_CP_ACP
        };

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

            Result hr = Compile(ref buffer, (IntPtr)argumentsPtr, argumentsCount, includeHandler, typeof(T).GUID, out IntPtr nativePtr);
            if (hr.Failure)
            {
                result = default;
                return(hr);
            }

            result = MarshallingHelpers.FromPointer <T>(nativePtr);
            return(hr);
        }
        finally
        {
            if (shaderSourcePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(shaderSourcePtr);
            }

            if (argumentsPtr != null)
            {
                Interop.Free(argumentsPtr);
            }
        }
    }
Ejemplo n.º 6
0
        private static byte[] Compile(ShaderStage shaderStage, string source, string entryPoint, string sourceName, DxcCompilerOptions options)
        {
            //IDxcOperationResult result = DxcCompiler.Compile((DxcShaderStage)shaderStage, source, entryPoint, sourceName, options);

            string shaderProfile = GetShaderProfile(shaderStage, options.ShaderModel);

            List <string> arguments = new List <string>();

            if (options.PackMatrixInColumnMajor)
            {
                arguments.Add("-Zpc");
            }
            else if (options.PackMatrixInRowMajor)
            {
                arguments.Add("-Zpr");
            }

            IDxcLibrary        library        = Dxc.CreateDxcLibrary();
            IDxcBlobEncoding   sourceBlob     = Dxc.CreateBlobForText(library, source);
            IDxcIncludeHandler includeHandler = library.CreateIncludeHandler();

            IDxcCompiler        compiler = Dxc.CreateDxcCompiler();
            IDxcOperationResult result   = compiler.Compile(
                sourceBlob,
                sourceName,
                entryPoint,
                shaderProfile,
                arguments.ToArray(),
                arguments.Count,
                null,
                0,
                includeHandler);

            if (result.GetStatus() == 0)
            {
                IDxcBlob blob = result.GetResult();
                return(Dxc.GetBytesFromBlob(blob));
            }
            else
            {
                string resultText = Dxc.GetStringFromBlob(library, result.GetErrors());
                throw new Exception(resultText);
            }
        }
Ejemplo n.º 7
0
    public unsafe Result Compile(IDxcBlob source,
                                 string sourceName,
                                 string entryPoint,
                                 string targetProfile,
                                 string[] arguments,
                                 int argumentsCount,
                                 DxcDefine[] defines,
                                 IDxcIncludeHandler includeHandler,
                                 out IDxcOperationResult?result)
    {
        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,
                                includeHandler,
                                out result);

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

            return(hr);
        }
        finally
        {
            if (argumentsPtr != null)
            {
                Interop.Free(argumentsPtr);
            }
        }
    }
 public Result CompileWithDebug(IDxcBlob source,
                                string sourceName,
                                string entryPoint,
                                string targetProfile,
                                string[] arguments,
                                DxcDefine[] defines,
                                IDxcIncludeHandler includeHandler,
                                out IDxcOperationResult?result, out string?debugBlobName, out IDxcBlob?debugBlob)
 {
     return(CompileWithDebug(
                source,
                sourceName,
                entryPoint,
                targetProfile,
                arguments,
                arguments?.Length ?? 0,
                defines,
                includeHandler,
                out result, out debugBlobName, out debugBlob));
 }
Ejemplo n.º 9
0
 public unsafe IDxcResult Compile(string source, string[] arguments, IDxcIncludeHandler includeHandler)
 {
     Compile(source, arguments, includeHandler, out IDxcResult? result).CheckError();
     return(result !);
 }