public IResultSet Compile(IShader shader, IBackendOptions options) { if (shader.Language == Languages.HLSL) { return(CompileHLSL(shader as HLSLShader, options)); } else { return(null); } }
public IResultSet Compile(IShader shader, IBackendOptions options) { if ( !(shader is GLSLShader ) ) return null; GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; if (glOpts.OptimizerOptions == null) return null; GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget]; return new GLSLOptimizerResultSet( optimizer.Optimize(sh.Code, glOpts.OptimizerOptions) ); }
public IResultSet Compile(IShader shaderObj, IBackendOptions options) { if ( !(shaderObj is HLSLShader ) ) return null; HLSLShader shaderHLSL = shaderObj as HLSLShader; IHLSLOptions hlslOpts = shaderHLSL.CompileOptions; AMDDriverBackendOptions backendOptions = options as AMDDriverBackendOptions; string shader = shaderObj.Code; if (shaderHLSL.WasCompiledWithErrors) return null; try { // compile here if we must. Recycle existing blob if we can IDXShaderBlob blob = shaderHLSL.CompiledBlob; if ( blob == null ) { if (!shaderHLSL.Compile(m_FXC)) return null; blob = shaderHLSL.CompiledBlob; } IDXShaderReflection reflect = blob.Reflect(); IDXShaderBlob exe = blob.GetExecutableBlob(); if (exe == null) return null; byte[] bytes = exe.ReadBytes(); AMDDriverResultSet rs = new AMDDriverResultSet(reflect ); foreach (IAMDAsic a in m_Driver.Asics) { if (CompileForAsic(backendOptions.Asics, a.Name)) { IAMDShader sh = m_Driver.CompileDXBlob(a, bytes, reflect); rs.Add(sh); } } return rs; } catch( System.Exception ex ) { MessageBox.Show(ex.Message); return null; } }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is GLSLShader) ) return null; GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = glOpts.ShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts); return new GLSLangResultSet(result); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader ) ) return null; HLSLShader hlsl = (HLSLShader)shader; IHLSLOptions hlslOpts = hlsl.CompileOptions; string text = hlsl.Code; if (!hlsl.WasCompiled) hlsl.Compile(m_Compiler); return new FXCResultSet(hlsl.Messages, hlsl.CompiledBlob); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is GLSLShader)) { return(null); } GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = glOpts.ShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts); return(new GLSLangResultSet(result)); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is GLSLShader)) { return(null); } GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; if (glOpts.OptimizerOptions == null) { return(null); } GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget]; return(new GLSLOptimizerResultSet(optimizer.Optimize(sh.Code, glOpts.OptimizerOptions))); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader)) { return(null); } HLSLShader hlsl = (HLSLShader)shader; IHLSLOptions hlslOpts = hlsl.CompileOptions; string text = hlsl.Code; if (!hlsl.WasCompiled) { hlsl.Compile(m_Compiler); } return(new FXCResultSet(hlsl.Messages, hlsl.CompiledBlob)); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (!(shader is HLSLShader)) { return(null); } HLSLShader hlsl = (HLSLShader)shader; IHLSLOptions hlslOpts = hlsl.CompileOptions; string text = hlsl.Code; if (!hlsl.WasCompiled) { hlsl.Compile(m_Compiler, m_DXIL); } if (!hlsl.RootSigWasCompiled) { hlsl.CompileRootSignature(m_DXIL); } return(new FXCResultSet(hlsl)); }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (shader is GLSLShader) { GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; GLSlang.IShader result = m_Compiler.Compile(sh.Code, glOpts.ShaderType, m_Config, shader.SourceFilePath); return(new GLSLangResultSet(result)); } else if (shader is HLSLShader) { HLSLShader sh = (HLSLShader)shader; IHLSLOptions hlslOpts = sh.CompileOptions; GLSlang.IShader result = m_Compiler.CompileHLSL(sh.Code, hlslOpts, m_Config, shader.SourceFilePath); return(new GLSLangResultSet(result)); } else { return(null); } }
public IResultSet Compile(IShader sh, IBackendOptions options) { if (sh.Language != Languages.GLSL) { return(null); } GLSLShader glShader = (GLSLShader)sh; IGLSLOptions glOpts = glShader.CompileOptions; string shader = glShader.Code; 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 IResultSet CompileHLSL(HLSLShader shader, IBackendOptions opts) { // if we've got a compiled blob from FXC backend, then use that if (shader.CompiledBlob != null) { try { MysteryToolResultSet rs = new MysteryToolResultSet(); // send it to a temp file string tmpFile = Path.Combine(m_TempPath, "MysteryToolShader"); File.WriteAllBytes(tmpFile, shader.CompiledBlob.ReadBytes()); // shell out to the tool // TODO: Mystery tool is kinda slow.... // So lets only do the default SKU for now /* * foreach (string sku in m_SKUs) * { * string commandline = String.Format("--shader_binary={0} --show_assembly --show_input_output_info --sku={1}", tmpFile, sku); * * * ProcessStartInfo pi = new ProcessStartInfo(); * pi.RedirectStandardOutput = true; * pi.RedirectStandardInput = false; * pi.RedirectStandardError = true; * pi.CreateNoWindow = true; * pi.Arguments = commandline; * pi.FileName = m_ToolPath; * pi.UseShellExecute = false; * * Process p = Process.Start(pi); * * rs.Add(sku, p.StandardOutput.ReadToEnd()); * * p.WaitForExit(); * * p.Close(); * } */ string commandline = String.Format("--shader_binary={0} --show_assembly --show_input_output_info", tmpFile); ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = false; pi.RedirectStandardError = true; pi.CreateNoWindow = true; pi.Arguments = commandline; pi.FileName = m_ToolPath; pi.UseShellExecute = false; Process p = Process.Start(pi); // NOTE: Must read stdout before waiting for exit // If we don't, then the process will hang if some stdout buffer fills up // lame.... rs.Add("default", p.StandardOutput.ReadToEnd()); p.WaitForExit(); p.Close(); // cleanup the temp file File.Delete(tmpFile); return(rs); } catch (Exception ex) { MessageBox.Show(ex.Message, "uh-oh, Couldn't run mystery tool", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // TODO: Don't have an HLSL shader. // have them compile it for us. They know how.... } return(null); }
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 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 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; }
public IResultSet Compile(IShader shader, IBackendOptions options) { if (shader is GLSLShader) { GLSLShader sh = (GLSLShader)shader; IGLSLOptions glOpts = sh.CompileOptions; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = glOpts.ShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts); return(new GLSLangResultSet(result)); } else if (shader is HLSLShader) { HLSLShader sh = (HLSLShader)shader; IHLSLOptions hlslOpts = sh.CompileOptions; // turn HLSL shader profile into GLSL shader type GLSLShaderType eShaderType; string profile = hlslOpts.Target.ToString(); if (profile.StartsWith("vs")) { eShaderType = GLSLShaderType.VERTEX; } else if (profile.StartsWith("ps")) { eShaderType = GLSLShaderType.FRAGMENT; } else if (profile.StartsWith("gs")) { eShaderType = GLSLShaderType.GEOMETRY; } else if (profile.StartsWith("hs")) { eShaderType = GLSLShaderType.TESS_CONTROL; } else if (profile.StartsWith("ds")) { eShaderType = GLSLShaderType.TESS_EVALUATION; } else if (profile.StartsWith("cs")) { eShaderType = GLSLShaderType.COMPUTE; } else { throw new System.Exception("Don't know what this shader profile is"); } string EntryPoint = hlslOpts.EntryPoint; GLSlangOptions slangOpts = new GLSlangOptions(); slangOpts.ShaderType = eShaderType; slangOpts.Config = m_Config; GLSlang.IShader result = m_Compiler.CompileHLSL(sh.Code, slangOpts, EntryPoint); return(new GLSLangResultSet(result)); } else { return(null); } }
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 sh, IBackendOptions options) { if (sh.Language != Languages.GLSL) return null; GLSLShader glShader = (GLSLShader)sh; IGLSLOptions glOpts = glShader.CompileOptions; string shader = glShader.Code; 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; }
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); } }
private IResultSet CompileHLSL(HLSLShader shader, IBackendOptions opts) { if (shader.CompiledBlob == null) { return(null); } if (shader.CompiledBlob is IDXILShaderBlob && shader.CompiledRootSig == null) { return(null); } try { List <string> tempFilesToDelete = new List <string>(); string byteCodeFile = Path.Combine(m_TempPath, "IGCShader"); string rootSigFile = Path.Combine(m_TempPath, "IGCRS"); File.WriteAllBytes(byteCodeFile, shader.CompiledBlob.ReadBytes()); tempFilesToDelete.Add(byteCodeFile); if (shader.CompiledRootSig != null) { File.WriteAllBytes(rootSigFile, shader.CompiledRootSig.ReadBytes()); tempFilesToDelete.Add(rootSigFile); } string commandline11 = ""; string commandline12 = ""; if (shader.CompiledBlob is IDXBCShaderBlob) { commandline11 = String.Format("--api dx11 \"{0}\"", byteCodeFile); commandline12 = String.Format("--api dx12 \"{0}\" --rootsig_file \"{1}\"", byteCodeFile, rootSigFile); } else { commandline12 = String.Format("--api dx12 \"{0}\" --rootsig_file \"{1}\"", byteCodeFile, rootSigFile); } List <string> asics = GetAsicList(); foreach (string asic in asics) { commandline11 = String.Concat(commandline11, String.Format(" --asic {0} ", asic)); commandline12 = String.Concat(commandline12, String.Format(" --asic {0} ", asic)); } string isaDir11 = Path.Combine(m_TempPath, "IntelISA_11\\"); string isaDir12 = Path.Combine(m_TempPath, "IntelISA_12\\"); Directory.CreateDirectory(isaDir11); Directory.CreateDirectory(isaDir12); // NOTE: Extra \ is required because DOS command interpretter parses \" as a double quote commandline11 = String.Concat(commandline11, String.Format("--isa \"{0}\\\"", isaDir11)); commandline12 = String.Concat(commandline12, String.Format("--isa \"{0}\\\"", isaDir12)); string stdout = ""; List <string> dx11Files = new List <string>(); List <string> dx12Files = new List <string>(); // DX11 requires DXBC if (shader.CompiledBlob is IDXBCShaderBlob) { ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = false; pi.RedirectStandardError = true; pi.CreateNoWindow = true; pi.Arguments = commandline11; pi.FileName = m_ToolPath; pi.UseShellExecute = false; Process p = Process.Start(pi); int pid = p.Id; // NOTE: Must read stdout before waiting for exit // If we don't, then the process will hang if some stdout buffer fills up // lame.... stdout = String.Concat("DX11 COMMAND LINE:", commandline11, Environment.NewLine); stdout = String.Concat(stdout, p.StandardOutput.ReadToEnd()); p.WaitForExit(); p.Close(); foreach (string asic in asics) { dx11Files.Add(String.Concat(isaDir11, asic, ".asm")); } } // DX12 requires a root signature if (shader.CompiledRootSig != null) { ProcessStartInfo pi = new ProcessStartInfo(); pi.RedirectStandardOutput = true; pi.RedirectStandardInput = false; pi.RedirectStandardError = true; pi.CreateNoWindow = true; pi.Arguments = commandline12; pi.FileName = m_ToolPath; pi.UseShellExecute = false; Process p = Process.Start(pi); int pid = p.Id; // NOTE: Must read stdout before waiting for exit // If we don't, then the process will hang if some stdout buffer fills up // lame.... stdout = String.Concat(stdout, string.Concat("DX12 COMMAND LINE: ", commandline12, Environment.NewLine)); stdout = String.Concat(stdout, Environment.NewLine); stdout = String.Concat(stdout, p.StandardOutput.ReadToEnd()); p.WaitForExit(); p.Close(); foreach (string asic in asics) { dx12Files.Add(String.Concat(isaDir12, asic, ".asm")); } } tempFilesToDelete.AddRange(dx11Files); tempFilesToDelete.AddRange(dx12Files); IntelShaderAnalyzerResultsPanel panel = new IntelShaderAnalyzerResultsPanel(stdout, asics); panel.AddResults("DX11", dx11Files); panel.AddResults("DX12", dx12Files); // cleanup the temp files foreach (string file in tempFilesToDelete) { File.Delete(file); } Directory.Delete(Path.Combine(m_TempPath, "IntelISA_11")); Directory.Delete(Path.Combine(m_TempPath, "IntelISA_12")); return(new IntelShaderAnalyzerResultSet(panel)); } catch (Exception ex) { MessageBox.Show(ex.Message, "uh-oh, Couldn't run IntelShaderAnalyzer", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
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); } }
public IResultSet Compile(IShader sh, IBackendOptions options) { if (sh.Language != Languages.GLSL) { return(null); } GLSLShader glShader = (GLSLShader)sh; IGLSLOptions glOpts = glShader.CompileOptions; string shader = glShader.Code; 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); string asm = "No Output"; string output = p.StandardError.ReadToEnd(); string compiler = Path.GetFileNameWithoutExtension(s); p.WaitForExit(); 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); }
public IResultSet Compile(IShader sh, IBackendOptions options) { if (sh.Language != Languages.GLSL) return null; GLSLShader glShader = (GLSLShader)sh; IGLSLOptions glOpts = glShader.CompileOptions; string shader = glShader.Code; 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; }