예제 #1
0
 internal static string GetStringFromBlob(IDxcLibrary library, IDxcBlob blob)
 {
     unsafe
     {
         blob = library.GetBlobAstUf16(blob);
         return(new string(blob.GetBufferPointer(), 0, (int)(blob.GetBufferSize() / 2) - 1));
     }
 }
예제 #2
0
        static Dxc()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                _createInstanceFn = LoadDxcCreateInstanceWindows();
            }

            Library = CreateDxcLibrary();
        }
예제 #3
0
        public static IDxcBlobEncoding CreateBlobForText(IDxcLibrary library, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            const uint CP_UTF16 = 1200;

            return(library.CreateBlobWithEncodingOnHeapCopy(text, (uint)(text.Length * 2), CP_UTF16));
        }
예제 #4
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);
            }
        }