private static void findFXC(TInput input, ContentProcessorContext context) { string[] tests = new string[] { "Utilities\\bin\\x86\\fxc.exe", "Utilities\\bin\\x64\\fxc.exe" }; foreach (string path in new string[] { "C:\\Program Files", "C:\\Program Files (x86)" }) { string[] dirs = Directory.GetDirectories(path, "Microsoft DirectX*"); foreach (string dir in dirs) { foreach (string test in tests) { string str = Path.Combine(dir, test); if (File.Exists(str)) { FXCName = str; Trace.WriteLine("Found FXC.EXE: " + FXCName); context.Logger.LogMessage("FOUND FXC: " + str); return; } } } } FXCName = "FXC.EXE"; context.Logger.LogWarning("", input.Identity, "FXC NOT FOUND!!!!!!!!!!!!"); }
public override CompiledEffectContent Process(Microsoft.Xna.Framework.Content.Pipeline.Graphics.EffectContent input, ContentProcessorContext context) { this.DebugMode = EffectProcessorDebugMode.Optimize; if (context.Parameters.ContainsKey("Defines")) { this.Defines = context.Parameters["Defines"].ToString(); } return(base.Process(input, context)); }
public override TOutput Process(TInput input, ContentProcessorContext context) { if (context.TargetPlatform == TargetPlatform.Windows) { Process p = new Process(); p.EnableRaisingEvents = false; p.StartInfo.FileName = FXCName; p.StartInfo.CreateNoWindow = true; string x = Path.GetFileNameWithoutExtension(input.Identity.SourceFilename) + "_fxc"; x = Path.Combine(context.IntermediateDirectory, x); OptLevel opt; #if DEBUG opt = debugOptLevel_; #else opt = releaseOptLevel_; #endif p.StartInfo.Arguments = String.Format("/T fx_2_0 /Zi /O{3} {5} /Fo \"{0}\" /Fe \"{1}\" /I \"{4}\" \"{2}\"", x + ".dat", x + ".err", input.Identity.SourceFilename, (int)opt, Path.GetDirectoryName(input.Identity.SourceFilename), opt == OptLevel.None ? "/Od" : ""); context.Logger.LogMessage("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments); p.Start(); if (!p.WaitForExit(1000 * timeoutSeconds_)) { throw new TimeoutException("FXC took more than 20 seconds to compile!"); } if (p.ExitCode != 0) { Trace.WriteLine("Exit code: " + p.ExitCode.ToString()); context.Logger.LogImportantMessage("Exit code: {0}", p.ExitCode); } byte[] bytes = File.ReadAllBytes(x + ".dat"); string text = File.ReadAllText(x + ".err"); if (p.ExitCode > 1 || p.ExitCode < 0 || text.Contains("error")) { if (text.Length == 0) { text = String.Format("FXC.EXE returned exit code {0}", p.ExitCode); } throw new InvalidContentException(text, input.Identity); } else if (text.Length != 0) { foreach (string ss in text.Split('\n', '\r')) { context.Logger.LogWarning("", input.Identity, "{0}", ss); } } return(new CompiledEffect(bytes, text)); } else { return(base.Process(input, context)); } }
public override TOutput Process(TInput input, ContentProcessorContext context) { if (!initialized) { findFXC(input, context); initialized = true; } if (context.TargetPlatform == TargetPlatform.Windows) { Process p = new Process(); p.EnableRaisingEvents = false; p.StartInfo.FileName = FXCName; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //p.StartInfo.RedirectStandardOutput = true; //p.StartInfo.UseShellExecute = false; string x = "Shaders/" + Path.GetFileNameWithoutExtension(input.Identity.SourceFilename) + "_fxc"; #if DEBUG string opt = "/Zi /Od"; #else string opt = "/Zi /O3"; #endif p.StartInfo.Arguments = String.Format("/T fx_2_0 {3} /Fo \"{0}\" /Fe \"{1}\" \"{2}\"", x + ".fxo", x + ".err", input.Identity.SourceFilename, opt); p.Start(); if (!p.WaitForExit(200000)) { throw new TimeoutException("FXC took more than 20 seconds to compile!"); } // Display returned console information if any //StreamReader srOut = p.StandardOutput; //string sOutput = srOut.ReadToEnd(); //srOut.Close(); //FileStream file = new FileStream(@"C:\Documents and Settings\KMan\My Documents\Visual Studio 2008\Projects\VolumeRayCasting\out.txt", FileMode.Create); //StreamWriter writer = new StreamWriter(file); //writer.WriteLine(sOutput); //writer.Close(); //file.Close(); if (p.ExitCode != 0) { Trace.WriteLine("Exit code: " + p.ExitCode.ToString()); context.Logger.LogWarning("", input.Identity, "Exit code: {0}", p.ExitCode); } byte[] bytes = File.ReadAllBytes(x + ".fxo"); string text = File.ReadAllText(x + ".err"); if (p.ExitCode != 0 || text.Contains("error")) { throw new InvalidContentException(text, input.Identity); } else { //print warnings context.Logger.LogWarning("", input.Identity, text); } return new CompiledEffect(bytes, text); } else { return base.Process(input, context); } }
public override TOutput Process(TInput input, ContentProcessorContext context) { if (context.TargetPlatform == TargetPlatform.Windows) { Process p = new Process(); p.EnableRaisingEvents = false; p.StartInfo.FileName = FXCName; p.StartInfo.CreateNoWindow = true; string x = Path.GetFileNameWithoutExtension(input.Identity.SourceFilename) + "_fxc"; x = Path.Combine(context.IntermediateDirectory, x); OptLevel opt; #if DEBUG opt = debugOptLevel_; #else opt = releaseOptLevel_; #endif p.StartInfo.Arguments = String.Format("/T fx_2_0 /Zi /O{3} {5} /Fo \"{0}\" /Fe \"{1}\" /I \"{4}\" \"{2}\"", x + ".dat", x + ".err", input.Identity.SourceFilename, (int)opt, Path.GetDirectoryName(input.Identity.SourceFilename), opt == OptLevel.None ? "/Od" : ""); context.Logger.LogMessage("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments); p.Start(); if (!p.WaitForExit(1000 * timeoutSeconds_)) { throw new TimeoutException("FXC took more than 20 seconds to compile!"); } if (p.ExitCode != 0) { Trace.WriteLine("Exit code: " + p.ExitCode.ToString()); context.Logger.LogImportantMessage("Exit code: {0}", p.ExitCode); } byte[] bytes = File.ReadAllBytes(x + ".dat"); string text = File.ReadAllText(x + ".err"); if (p.ExitCode > 1 || p.ExitCode < 0 || text.Contains("error")) { if (text.Length == 0) text = String.Format("FXC.EXE returned exit code {0}", p.ExitCode); throw new InvalidContentException(text, input.Identity); } else if (text.Length != 0) { foreach (string ss in text.Split('\n', '\r')) context.Logger.LogWarning("", input.Identity, "{0}", ss); } return new CompiledEffectContent(bytes); } else { return base.Process(input, context); } }
public override TOutput Process(TInput input, ContentProcessorContext context) { if (!initialized) { findFXC(input, context); initialized = true; } if (context.TargetPlatform == TargetPlatform.Windows) { Process p = new Process(); p.EnableRaisingEvents = false; p.StartInfo.FileName = FXCName; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //p.StartInfo.RedirectStandardOutput = true; //p.StartInfo.UseShellExecute = false; string x = "Shaders/" + Path.GetFileNameWithoutExtension(input.Identity.SourceFilename) + "_fxc"; #if DEBUG string opt = "/Zi /Od"; #else string opt = "/Zi /O3"; #endif p.StartInfo.Arguments = String.Format("/T fx_2_0 {3} /Fo \"{0}\" /Fe \"{1}\" \"{2}\"", x + ".fxo", x + ".err", input.Identity.SourceFilename, opt); p.Start(); if (!p.WaitForExit(200000)) { throw new TimeoutException("FXC took more than 20 seconds to compile!"); } // Display returned console information if any //StreamReader srOut = p.StandardOutput; //string sOutput = srOut.ReadToEnd(); //srOut.Close(); //FileStream file = new FileStream(@"C:\Documents and Settings\KMan\My Documents\Visual Studio 2008\Projects\VolumeRayCasting\out.txt", FileMode.Create); //StreamWriter writer = new StreamWriter(file); //writer.WriteLine(sOutput); //writer.Close(); //file.Close(); if (p.ExitCode != 0) { Trace.WriteLine("Exit code: " + p.ExitCode.ToString()); context.Logger.LogWarning("", input.Identity, "Exit code: {0}", p.ExitCode); } byte[] bytes = File.ReadAllBytes(x + ".fxo"); string text = File.ReadAllText(x + ".err"); if (p.ExitCode != 0 || text.Contains("error")) { throw new InvalidContentException(text, input.Identity); } else { //print warnings context.Logger.LogWarning("", input.Identity, text); } return(new CompiledEffect(bytes, text)); } else { return(base.Process(input, context)); } }