public IResultSet Compile(string shader, ICompileOptions opts) { if (opts.Language != Languages.HLSL) return null; try { IDXShaderBlob blob; string messages; if (!m_FXC.Compile(shader, opts as IHLSLOptions, out blob, out messages)) return null; IDXShaderBlob exe = blob.GetExecutableBlob(); if (exe == null) return null; byte[] bytes = exe.ReadBytes(); AMDDriverResultSet rs = new AMDDriverResultSet(); foreach (IAMDAsic a in m_Driver.Asics) { IAMDShader sh = m_Driver.CompileDXBlob(a, bytes); rs.Add(sh); } return rs; } catch( System.Exception ex ) { MessageBox.Show(ex.Message); return null; } }
public IResultSet Compile(string shader, ICompileOptions opts) { if (opts.Language != Languages.GLSL) return null; IGLSLOptions glOpts = (IGLSLOptions)opts; if (glOpts.OptimizerOptions == null) return null; GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget]; return new GLSLOptimizerResultSet( optimizer.Optimize(shader, glOpts.OptimizerOptions) ); }
public IResultSet Compile(string text, ICompileOptions opts) { if (opts.Language != Languages.HLSL) return null; IHLSLOptions hlslOpts = (IHLSLOptions)opts; string error; IDXShaderBlob blob; m_Compiler.Compile(text, hlslOpts, out blob, out error); return new FXCResultSet(error, blob); }
public IResultSet Compile(string shader, ICompileOptions opts) { if (opts.Language != Languages.GLSL) return null; IGLSLOptions glOpts = (IGLSLOptions)opts; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = glOpts.ShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.Compile(shader, slangOpts); return new GLSLangResultSet(result); }
public IResultSet Compile(string shader, ICompileOptions opts) { if (opts.Language != Languages.GLSL) return null; IGLSLOptions glOpts = opts as IGLSLOptions; string shaderType = ""; switch( glOpts.ShaderType ) { case GLSLShaderType.VERTEX: shaderType = "--vertex"; break; case GLSLShaderType.FRAGMENT: shaderType = "--fragment"; break; case GLSLShaderType.COMPUTE: shaderType = "--compute"; break; default: return null; } string tmpFile = Path.Combine(m_TempPath, "PYRAMID_mali"); try { StreamWriter stream = File.CreateText(tmpFile); stream.Write(shader); stream.Close(); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } MaliSCResultSet rs = new MaliSCResultSet(); try { foreach (string asic in m_Asics) { string commandline = String.Format("-V {0} -c {1} {2}", shaderType, asic, tmpFile); ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = true; pi.RedirectStandardError = true; pi.EnvironmentVariables.Add("MALICM_LOCATION", m_MaliRoot); pi.CreateNoWindow = true; pi.Arguments = commandline; pi.FileName = Path.Combine(m_MaliRoot, "malisc.exe"); pi.UseShellExecute = false; Process p = Process.Start(pi); p.WaitForExit(); string output = p.StandardOutput.ReadToEnd(); rs.Add(asic, output); } } catch (System.Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't run MaliSC", MessageBoxButtons.OK, MessageBoxIcon.Error); } File.Delete(tmpFile); return rs; }
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( string text, ICompileOptions opts ) { if (opts.Language != Languages.HLSL) return null; IHLSLOptions hlslOpts = (IHLSLOptions) opts; 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 ilPath = Path.Combine(m_TempPath, "il"); string isaPath = Path.Combine(m_TempPath, "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( " --il \"{0}\"",ilPath )); 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_Asics) 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 error, output; try { Process p = Process.Start(pi); p.WaitForExit(); error = p.StandardError.ReadToEnd(); output = p.StandardOutput.ReadToEnd(); 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 CodeXLResultSet results = new CodeXLResultSet(); foreach (string asic in m_Asics) { string ilFile = String.Format( "{0}-{1}.amdisa", ilPath, asic ); string isaFile = String.Format( "{0}-{1}.amdisa", isaPath, asic ); try { string il = File.ReadAllText(ilFile); string isa = File.ReadAllText(isaFile); results.AddCompileResult(asic, il, isa); File.Delete(ilFile); 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(m_Asics[0]); return results; } else return null; }
public IResultSet Compile(string shader, ICompileOptions opts) { if (opts.Language != Languages.GLSL) return null; IGLSLOptions glOpts = opts as IGLSLOptions; if (glOpts == null) return null; string shaderSwitch = ""; switch (glOpts.ShaderType) { case GLSLShaderType.VERTEX: shaderSwitch = "-v"; break; case GLSLShaderType.FRAGMENT: shaderSwitch = "-f"; break; case GLSLShaderType.COMPUTE: shaderSwitch = "-c"; break; default: return null; } string tmpFile = Path.Combine(m_TempPath, "PYRAMID_pvr"); string dummyOutputFile = Path.Combine(m_TempPath, "PYRAMID_pvr.out"); string disasmFile = Path.Combine(m_TempPath, "PYRAMID_pvr.disasm"); try { StreamWriter stream = File.CreateText(tmpFile); stream.Write(shader); stream.Close(); } catch (Exception e) { MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } string args = String.Format("{0} {1} {2} -disasm", tmpFile, dummyOutputFile, shaderSwitch); PVRResultSet rs = new PVRResultSet(); foreach (string s in m_Compilers) { ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = true; pi.RedirectStandardError = true; pi.CreateNoWindow = true; pi.Arguments = args; pi.FileName = s; pi.UseShellExecute = false; try { Process p= Process.Start(pi); p.WaitForExit(); string asm = "No Output"; string output = p.StandardError.ReadToEnd(); string compiler = Path.GetFileNameWithoutExtension(s); if (File.Exists(disasmFile)) { asm = File.ReadAllText(disasmFile); File.Delete(disasmFile); } rs.PVRResultsPanel.AddResult(compiler, output, asm); } catch (System.Exception) { continue; } } File.Delete(tmpFile); return rs; }