public bool Run(TextDocument document) { Debug.Assert(document.Uri != null, "The document needs to be saved before NVShaderPerf can be run."); Logger.Info(CultureInfo.InvariantCulture, "Running NVShaderPerf.exe for \"{0}\".", Path.GetFileName(document.Uri.LocalPath)); string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); string shaderPerfFileName = Path.Combine(programFilesPath, @"NVIDIA Corporation\NVIDIA ShaderPerf\NVShaderPerf.exe"); if (!File.Exists(shaderPerfFileName)) { string message = "NVIDIA ShaderPerf (NVShaderPerf.exe) not found."; Logger.Error(message); _outputService.WriteLine(message); return false; } using (var processRunner = new ProcessRunner()) { processRunner.OutputDataReceived += (s, e) => _outputService.WriteLine(e.Data); processRunner.ErrorDataReceived += (s, e) => _outputService.WriteLine(e.Data); // Analyze the passes in the effect. var shaderParser = new ShaderParser(new HlslIntelliSense()); var techniquesAndPasses = shaderParser.GetTechniquesAndPasses(document.AvalonEditDocument.CreateSnapshot()); foreach (var techniqueAndPasses in techniquesAndPasses) { string technique = techniqueAndPasses.Item1; foreach (string pass in techniqueAndPasses.Item2) { _outputService.WriteLine(string.Format(CultureInfo.InvariantCulture, "NVShaderPerf.exe -g G80 -t {0} -p {1} {2}\n", technique, pass, Path.GetFileName(document.Uri.LocalPath))); processRunner.Start(shaderPerfFileName, string.Format(CultureInfo.InvariantCulture, "-g G80 -t {0} -p {1} -include \"{2}\" \"{3}\"", technique, pass, Path.GetDirectoryName(document.Uri.LocalPath), document.Uri.LocalPath)); processRunner.WaitForExit(); if (processRunner.ExitCode != 0) { // Break on error. Logger.Info("Failed."); //_outputService.WriteLine(); return false; } } } Logger.Info("Success."); //_outputService.WriteLine(); return true; } }
//-------------------------------------------------------------- protected ShaderIntelliSense() { EffectStateValues = new NamedObjectCollection<NamedCompletionData>(); SamplerStates10 = new NamedObjectCollection<NamedCompletionData>(); SamplerStates = new NamedObjectCollection<NamedCompletionData>(); RasterizerStates = new NamedObjectCollection<NamedCompletionData>(); DepthStencilStates = new NamedObjectCollection<NamedCompletionData>(); BlendStates = new NamedObjectCollection<NamedCompletionData>(); EffectStates = new NamedObjectCollection<NamedCompletionData>(); EffectFunctions = new NamedObjectCollection<NamedCompletionData>(); Methods = new NamedObjectCollection<NamedCompletionData>(); Functions = new NamedObjectCollection<NamedCompletionData>(); Macros = new NamedObjectCollection<NamedCompletionData>(); Constants = new List<NamedCompletionData>(); EffectTypes = new NamedObjectCollection<NamedCompletionData>(); SpecialTypes = new NamedObjectCollection<NamedCompletionData>(); ScalarTypes = new NamedObjectCollection<NamedCompletionData>(); Types = new NamedObjectCollection<NamedCompletionData>(); Keywords = new NamedObjectCollection<NamedCompletionData>(); PreprocessorDirectives = new List<NamedCompletionData>(); Snippets = new Dictionary<string, SnippetCompletionData>(); // Initialize IntelliSense info that is identical in HLSL and Cg here. InitializeSnippets(); InitializePreprocessorDirectives(); InitializeKeywords(); InitializeTypes(); InitializeConstants(); // Create shader parser _parser = new ShaderParser(this); }