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, m_FileName); break; case Languages.HLSL: shader = new HLSLShader(txtCode.Text, opts as IHLSLOptions, m_FileName); 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; } else if (backend is RGABackend) { options = new RGABackendOptions(m_Options); } 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 (!(options is RGABackendOptions)) { return(null); } if (!(shader is HLSLShader || shader is GLSLShader)) { return(null); } RGABackendOptions backendOptions = options as RGABackendOptions; string tmpFile = Path.Combine(m_TempPath, "PYRAMID_amdrga"); // pass the shader through GLSLang's hlsl front end GLSlang.IShader glShader = CompileShader(shader); if (glShader.HasErrors) { return(new GenericTextResultSet(this.Name, glShader.InfoLog)); } string sType = GetRGAShaderType(glShader.ShaderType); // get the SPIR-V SPIRV.IProgram spirv = glShader.CompileSPIRV(); if (spirv == null) { return(new GenericTextResultSet(this.Name, "Error generating SPIR-V")); } // dump the SPIR-V to disk try { File.WriteAllBytes(tmpFile, spirv.GetBytes()); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } // send the SPIR-V to RGA string CommandLine = String.Format(" -s vulkan-spv {0}", tmpFile); string isaPath = Path.Combine(m_TempPath, "pyramid.isa"); string analysisPath = Path.Combine(m_TempPath, "pyramid.analysis"); string ilPath = Path.Combine(m_TempPath, "pyramid.il"); string liveRegPath = Path.Combine(m_TempPath, "pyramid.livereg"); CommandLine = String.Concat(CommandLine, String.Format(" --isa \"{0}\" ", isaPath)); CommandLine = String.Concat(CommandLine, String.Format(" -a \"{0}\" ", analysisPath)); CommandLine = String.Concat(CommandLine, String.Format(" --il \"{0}\" ", ilPath)); CommandLine = String.Concat(CommandLine, String.Format(" --livereg \"{0}\" ", liveRegPath)); List <string> asicsToCompile = new List <String>(); foreach (string asic in m_SupportedAsics) { if (backendOptions.ShouldCompileForAsic(asic)) { asicsToCompile.Add(asic); CommandLine = String.Concat(CommandLine, " -c ", asic, " "); } } if (asicsToCompile.Count == 0) { return(null); } string defaultAsic = asicsToCompile[0]; ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = true; pi.RedirectStandardError = false; pi.CreateNoWindow = true; pi.Arguments = CommandLine; pi.FileName = m_RGAPath; pi.UseShellExecute = false; string output; try { Process p = Process.Start(pi); output = p.StandardOutput.ReadToEnd(); int TIMEOUT = 60000; p.WaitForExit(TIMEOUT); p.Close(); File.Delete(tmpFile); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't run CodeXL", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } output = String.Format(@"Arguments: ---------- {0} Output: ------- {1}", CommandLine, output); // Compile results are emitted in one set of files per asic RGAResultSet results = new RGAResultSet(this.Name, output); foreach (string asic in asicsToCompile) { string path = Path.Combine(m_TempPath, String.Format("{0}_{1}_pyramid", asic, sType)); try { RGAResult result = new RGAResult(asic, path); results.AddCompileResult(result); } catch (Exception ex) { // may occur on compile error } } if (results.ResultCount > 0) { results.DisplayAsic(defaultAsic); return(results); } else { return(null); } }