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 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)); }
GLSlang.IShader CompileShader(IShader shader) { if (shader is HLSLShader) { // pass the shader through GLSLang's hlsl front end HLSLShader hlsl = shader as HLSLShader; return(m_GLSLang.CompileHLSL(shader.Code, hlsl.CompileOptions, m_GLSLangConfig, shader.SourceFilePath)); } else if (shader is GLSLShader) { GLSLShader glsl = shader as GLSLShader; return(m_GLSLang.Compile(shader.Code, glsl.CompileOptions.ShaderType, m_GLSLangConfig, glsl.SourceFilePath)); } else { throw new System.Exception("Bad shader type?!?"); } }
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 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)); }
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); } }
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 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); } }
public FXCResultSet(HLSLShader shader) { m_Panel = new FXCResultsPanel(shader); }
public FXCResultsPanel(HLSLShader shader) { string error = shader.Messages; IDXShaderBlob blob = shader.CompiledBlob; m_Shader = blob; InitializeComponent(); txtMessages.Text = error; if (blob == null) { tabControl1.TabPages.Remove(hexPage); tabControl1.TabPages.Remove(asmPage); } else { txtASM.Text = blob.Disassemble(); // generate a blob dump try { byte[] rawBytes = blob.ReadBytes(); StringBuilder str = new StringBuilder(); str.AppendFormat("Blob size is {0} ({1:X}) bytes", rawBytes.Length, rawBytes.Length); str.AppendLine(); HexBumpBlob(str, rawBytes); if (blob is IDXBCShaderBlob) { IDXBCShaderBlob blobDXBC = blob as IDXBCShaderBlob; IDXBCShaderBlob strip = blobDXBC.Strip(); IDXBCShaderBlob sig = strip.GetSignatureBlob(); byte[] stripBytes = strip.ReadBytes(); byte[] sigBytes = sig.ReadBytes(); str.AppendFormat("Stripped blob size is {0} ({1:x}) bytes", stripBytes.Length, stripBytes.Length); str.AppendLine(); HexBumpBlob(str, stripBytes); str.AppendFormat("Signature blob size is {0} ({1:x}) bytes", sigBytes.Length, sigBytes.Length); str.AppendLine(); HexBumpBlob(str, sigBytes); } txtHex.Text = str.ToString(); } catch (Exception ex) { txtHex.Text = String.Format("EXCEPTION while generating hex dump: {0}", ex.Message); } } IDXBlob rsBlob = shader.CompiledRootSig; m_RootSignature = rsBlob; txtMessages.Text = String.Concat(txtMessages.Text, shader.RootSigMessages); if (rsBlob == null) { tabControl1.TabPages.Remove(rootSigPage); } else { try { byte[] rawBytes = rsBlob.ReadBytes(); StringBuilder str = new StringBuilder(); str.AppendFormat("RootSig blob size is {0} ({1:X}) bytes", rawBytes.Length, rawBytes.Length); str.AppendLine(); HexBumpBlob(str, rawBytes); txtRootSig.Text = str.ToString(); } catch (Exception ex) { txtRootSig.Text = String.Format("EXCEPTION while generating rootsig dump: {0}", ex.Message); } } }
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); }