private void btnCompile_Click(object sender, EventArgs e) { if( m_CompileOptionsPanel == null ) return; this.UseWaitCursor = true; ClearResults(); IResultSet SelectedResultSet = null; ICompileOptions opts = m_CompileOptionsPanel.ReadOptions(); IShader shader = null; switch (opts.Language) { case Languages.GLSL: shader = new GLSLShader(txtCode.Text, opts as IGLSLOptions); break; case Languages.HLSL: shader = new HLSLShader(txtCode.Text, opts as IHLSLOptions); break; default: throw new System.Exception("Unsupported language"); } foreach (IBackend backend in m_Backends) { if (m_Options.IsBackendDisabled(backend.Name)) continue; IBackendOptions options = null; if (backend is AMDDriverBackend) { AMDDriverBackend amdBackend = backend as AMDDriverBackend; List<string> requestedAsics = new List<string>(); foreach (string asic in amdBackend.Asics) { if (!m_Options.IsAMDAsicDisabled(asic)) { requestedAsics.Add(asic); } } AMDDriverBackendOptions backendOptions = new AMDDriverBackendOptions(requestedAsics); options = backendOptions; } else if (backend is CodeXLBackend) { CodeXLBackend codeXLBackend = backend as CodeXLBackend; List<string> requestedAsics = new List<string>(); foreach (string asic in codeXLBackend.Asics) { if (!m_Options.IsCodeXLAsicDisabled(asic)) { requestedAsics.Add(asic); } } CodeXLBackendOptions backendOptions = new CodeXLBackendOptions(requestedAsics); options = backendOptions; } IResultSet r = backend.Compile(shader, options); if (r != null) { if (r.Name.Equals(m_LastBackend)) SelectedResultSet = r; cmbBackend.Items.Add(r); } } if (cmbBackend.Items.Count > 0) { if (SelectedResultSet != null) cmbBackend.SelectedIndex = cmbBackend.Items.IndexOf(SelectedResultSet); else cmbBackend.SelectedIndex = 0; } else { m_LastBackend = ""; } this.UseWaitCursor = false; }
private void btnCompile_Click(object sender, EventArgs e) { if (m_CompileOptionsPanel == null) { return; } this.UseWaitCursor = true; ClearResults(); IResultSet SelectedResultSet = null; ICompileOptions opts = m_CompileOptionsPanel.ReadOptions(); IShader shader = null; switch (opts.Language) { case Languages.GLSL: shader = new GLSLShader(txtCode.Text, opts as IGLSLOptions); break; case Languages.HLSL: shader = new HLSLShader(txtCode.Text, opts as IHLSLOptions); break; default: throw new System.Exception("Unsupported language"); } foreach (IBackend backend in m_Backends) { if (m_Options.IsBackendDisabled(backend.Name)) { continue; } IBackendOptions options = null; if (backend is AMDDriverBackend) { AMDDriverBackend amdBackend = backend as AMDDriverBackend; List <string> requestedAsics = new List <string>(); foreach (string asic in amdBackend.Asics) { if (!m_Options.IsAMDAsicDisabled(asic)) { requestedAsics.Add(asic); } } AMDDriverBackendOptions backendOptions = new AMDDriverBackendOptions(requestedAsics); options = backendOptions; } else if (backend is CodeXLBackend) { CodeXLBackend codeXLBackend = backend as CodeXLBackend; List <string> requestedAsics = new List <string>(); foreach (string asic in codeXLBackend.Asics) { if (!m_Options.IsCodeXLAsicDisabled(asic)) { requestedAsics.Add(asic); } } CodeXLBackendOptions backendOptions = new CodeXLBackendOptions(requestedAsics); options = backendOptions; } IResultSet r = backend.Compile(shader, options); if (r != null) { if (r.Name.Equals(m_LastBackend)) { SelectedResultSet = r; } cmbBackend.Items.Add(r); } } if (cmbBackend.Items.Count > 0) { if (SelectedResultSet != null) { cmbBackend.SelectedIndex = cmbBackend.Items.IndexOf(SelectedResultSet); } else { cmbBackend.SelectedIndex = 0; } } else { m_LastBackend = ""; } this.UseWaitCursor = false; }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader) || !(options is CodeXLBackendOptions)) { return(null); } // TODO: Modify CodeXL backend so that it re-uses blob from // FXC backend where available. It'd be nice not to have to // have CodeXL recompile it for us HLSLShader shaderHLSL = shader as HLSLShader; IHLSLOptions hlslOpts = shaderHLSL.CompileOptions; CodeXLBackendOptions backendOptions = options as CodeXLBackendOptions; string text = shader.Code; if (shaderHLSL.WasCompiledWithErrors) { return(null); } string tmpFile = Path.Combine(m_TempPath, "PYRAMID_amdcodexl"); try { StreamWriter stream = File.CreateText(tmpFile); stream.Write(text); stream.Close(); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } string isaPath = Path.Combine(m_TempPath, "pyramid.isa"); string analysisPath = Path.Combine(m_TempPath, "analysis"); string CommandLine = "-s \"HLSL\""; CommandLine = String.Concat(CommandLine, String.Format(" -p {0}", hlslOpts.Target.ToString())); CommandLine = String.Concat(CommandLine, String.Format(" -f {0} ", hlslOpts.EntryPoint)); CommandLine = String.Concat(CommandLine, String.Format(" --DXLocation \"{0}\"", m_D3DCompiler)); CommandLine = String.Concat(CommandLine, String.Format(" --isa \"{0}\"", isaPath)); CommandLine = String.Concat(CommandLine, String.Format(" -a \"{0}\"", analysisPath)); CommandLine = String.Concat(CommandLine, String.Format(" --DXFlags {0} ", hlslOpts.GetD3DCompileFlagBits())); CommandLine = String.Concat(CommandLine, tmpFile); foreach (string asic in m_SupportedAsics) { if (CompileForAsic(backendOptions.Asics, asic)) { CommandLine = String.Concat(CommandLine, " -c ", asic, " "); } } ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = true; pi.RedirectStandardError = true; pi.CreateNoWindow = true; pi.Arguments = CommandLine; pi.FileName = m_CodeXL; pi.UseShellExecute = false; string output; try { int TimeOut = 15000; // TODO: Put in options Process p = Process.Start(pi); output = p.StandardOutput.ReadToEnd(); if (p.WaitForExit(TimeOut)) { MessageBox.Show("CodeXL took more than 15 seconds"); } p.Close(); File.Delete(tmpFile); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't run CodeXL", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } // Compile results are emitted in one set of files per asic string defaultAsic = ""; CodeXLResultSet results = new CodeXLResultSet(); foreach (string asic in m_SupportedAsics) { if (!CompileForAsic(backendOptions.Asics, asic)) { continue; } if (defaultAsic == "") { defaultAsic = asic; } string isaFile = Path.Combine(m_TempPath, String.Format("{0}_pyramid.isa", asic)); try { string isa = File.ReadAllText(isaFile); results.AddCompileResult(asic, "CodeXL doesn't support IL output for HLSL", isa); File.Delete(isaFile); } catch (Exception) { // may occur in the event of a compile error. } } // Analysis results are emitted in a big CSV file try { string[] lines = File.ReadAllLines(analysisPath); File.Delete(analysisPath); try { // first line is column names string columns = lines[0]; string[] cols = columns.Split(','); // first column is asic, remaining columns are fields we want to display for (int i = 1; i < lines.Length; i++) { string[] data = lines[i].Split(','); string asic = data[0]; Dictionary <string, string> vals = new Dictionary <string, string>(); for (int j = 1; j < cols.Length; j++) { if (!String.IsNullOrEmpty(data[j]) && !String.IsNullOrEmpty(cols[j])) { vals.Add(cols[j], data[j]); } } results.AddAnalysisResult(asic, vals); } } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh. Couldn't parse CodeXL analysis file. Did it change?", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { // compile error } if (results.ResultCount > 0) { results.DisplayAsic(defaultAsic); return(results); } else { return(null); } }