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); } }
// Loads the dxil.dll library, needed to create a pipeline state for a shader to dispatch static ShaderCompiler() { Dxil.LoadLibrary(); Library = Dxc.CreateDxcLibrary(); // This needs to be loaded after dxil.dll }
private static void TestDxc() { var library = Dxc.CreateDxcLibrary(); }