internal static string GetStringFromBlob(IDxcLibrary library, IDxcBlob blob) { unsafe { blob = library.GetBlobAstUf16(blob); return(new string(blob.GetBufferPointer(), 0, (int)(blob.GetBufferSize() / 2) - 1)); } }
static Dxc() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _createInstanceFn = LoadDxcCreateInstanceWindows(); } Library = CreateDxcLibrary(); }
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)); }
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); } }