private void debugToolStripMenuItem_Click(object sender, EventArgs e) { if (events.SelectedNode == null) { return; } var node = events.SelectedNode; if (node.Tag is EventTag) { EventTag tag = (EventTag)node.Tag; m_Core.SetEventID(this, m_Core.CurFrame, tag.EID); ShaderDebugTrace trace = null; ShaderReflection shaderDetails = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Pixel); m_Core.Renderer.Invoke((ReplayRenderer r) => { trace = r.DebugPixel((UInt32)pixel.X, (UInt32)pixel.Y, sample, tag.Primitive); }); if (trace == null || trace.states.Length == 0) { MessageBox.Show("Error debugging pixel.", "Debug Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.BeginInvoke(new Action(() => { string debugContext = String.Format("Pixel {0},{1}", pixel.X, pixel.Y); ShaderViewer s = new ShaderViewer(m_Core, shaderDetails, ShaderStageType.Pixel, trace, debugContext); s.Show(this.DockPanel); })); } }
public ShaderViewer(Core core, ShaderReflection shader, ShaderStageType stage, ShaderDebugTrace trace) { InitializeComponent(); Icon = global::renderdocui.Properties.Resources.icon; this.SuspendLayout(); mainLayout.Dock = DockStyle.Fill; m_Core = core; m_ShaderDetails = shader; m_Trace = trace; m_Stage = null; switch (stage) { case ShaderStageType.Vertex: m_Stage = m_Core.CurD3D11PipelineState.m_VS; break; case ShaderStageType.Domain: m_Stage = m_Core.CurD3D11PipelineState.m_DS; break; case ShaderStageType.Hull: m_Stage = m_Core.CurD3D11PipelineState.m_HS; break; case ShaderStageType.Geometry: m_Stage = m_Core.CurD3D11PipelineState.m_GS; break; case ShaderStageType.Pixel: m_Stage = m_Core.CurD3D11PipelineState.m_PS; break; case ShaderStageType.Compute: m_Stage = m_Core.CurD3D11PipelineState.m_CS; break; } var disasm = shader.Disassembly; if (m_Core.Config.ShaderViewer_FriendlyNaming) { for (int i = 0; i < m_ShaderDetails.ConstantBlocks.Length; i++) { var stem = string.Format("cb{0}", i); var cbuf = m_ShaderDetails.ConstantBlocks[i]; if (cbuf.variables.Length == 0) { continue; } disasm = FriendlyName(disasm, stem, cbuf.variables); } foreach (var r in m_ShaderDetails.Resources) { if (r.IsSRV) { var needle = string.Format(", t{0}([^0-9])", r.bindPoint); var replacement = string.Format(", {0}$1", r.name); Regex rgx = new Regex(needle); disasm = rgx.Replace(disasm, replacement); } if (r.IsSampler) { var needle = string.Format(", s{0}([^0-9])", r.bindPoint); var replacement = string.Format(", {0}$1", r.name); Regex rgx = new Regex(needle); disasm = rgx.Replace(disasm, replacement); } if (r.IsUAV) { var needle = string.Format(", u{0}([^0-9])", r.bindPoint); var replacement = string.Format(", {0}$1", r.name); Regex rgx = new Regex(needle); disasm = rgx.Replace(disasm, replacement); } } } { m_DisassemblyView = MakeEditor("scintillaDisassem", disasm, false); m_DisassemblyView.IsReadOnly = true; m_DisassemblyView.TabIndex = 0; m_DisassemblyView.KeyDown += new KeyEventHandler(m_DisassemblyView_KeyDown); m_DisassemblyView.Markers[CURRENT_MARKER].BackColor = System.Drawing.Color.LightCoral; m_DisassemblyView.Markers[CURRENT_MARKER].Symbol = ScintillaNET.MarkerSymbol.Background; m_DisassemblyView.Markers[CURRENT_MARKER + 1].BackColor = System.Drawing.Color.LightCoral; m_DisassemblyView.Markers[CURRENT_MARKER + 1].Symbol = ScintillaNET.MarkerSymbol.ShortArrow; CurrentLineMarkers.Add(CURRENT_MARKER); CurrentLineMarkers.Add(CURRENT_MARKER + 1); m_DisassemblyView.Markers[FINISHED_MARKER].BackColor = System.Drawing.Color.LightSlateGray; m_DisassemblyView.Markers[FINISHED_MARKER].Symbol = ScintillaNET.MarkerSymbol.Background; m_DisassemblyView.Markers[FINISHED_MARKER + 1].BackColor = System.Drawing.Color.LightSlateGray; m_DisassemblyView.Markers[FINISHED_MARKER + 1].Symbol = ScintillaNET.MarkerSymbol.RoundRectangle; FinishedMarkers.Add(FINISHED_MARKER); FinishedMarkers.Add(FINISHED_MARKER + 1); m_DisassemblyView.Markers[BREAKPOINT_MARKER].BackColor = System.Drawing.Color.Red; m_DisassemblyView.Markers[BREAKPOINT_MARKER].Symbol = ScintillaNET.MarkerSymbol.Background; m_DisassemblyView.Markers[BREAKPOINT_MARKER + 1].BackColor = System.Drawing.Color.Red; m_DisassemblyView.Markers[BREAKPOINT_MARKER + 1].Symbol = ScintillaNET.MarkerSymbol.Circle; BreakpointMarkers.Add(BREAKPOINT_MARKER); BreakpointMarkers.Add(BREAKPOINT_MARKER + 1); m_Scintillas.Add(m_DisassemblyView); var w = Helpers.WrapDockContent(dockPanel, m_DisassemblyView, "Disassembly"); w.DockState = DockState.Document; w.Show(); w.CloseButton = false; w.CloseButtonVisible = false; } if (shader.DebugInfo.entryFunc != "" && shader.DebugInfo.files.Length > 0) { Text = shader.DebugInfo.entryFunc + "()"; DockContent sel = null; foreach (var f in shader.DebugInfo.files) { var name = Path.GetFileName(f.filename); ScintillaNET.Scintilla scintilla1 = MakeEditor("scintilla" + name, f.filetext, true); scintilla1.IsReadOnly = true; scintilla1.Tag = name; var w = Helpers.WrapDockContent(dockPanel, scintilla1, name); w.CloseButton = false; w.CloseButtonVisible = false; w.Show(dockPanel); m_Scintillas.Add(scintilla1); if (f.filetext.Contains(shader.DebugInfo.entryFunc)) { sel = w; } } if (trace != null || sel == null) { sel = (DockContent)m_DisassemblyView.Parent; } sel.Show(); } ShowConstants(); ShowVariables(); ShowWatch(); ShowErrors(); editStrip.Visible = false; m_ErrorsDock.Hide(); if (trace == null) { debuggingStrip.Visible = false; m_ConstantsDock.Hide(); m_VariablesDock.Hide(); m_WatchDock.Hide(); var insig = Helpers.WrapDockContent(dockPanel, inSigBox); insig.CloseButton = insig.CloseButtonVisible = false; var outsig = Helpers.WrapDockContent(dockPanel, outSigBox); outsig.CloseButton = outsig.CloseButtonVisible = false; insig.Show(dockPanel, DockState.DockBottom); outsig.Show(insig.Pane, DockAlignment.Right, 0.5); foreach (var s in m_ShaderDetails.InputSig) { string name = s.varName == "" ? s.semanticName : String.Format("{0} ({1})", s.varName, s.semanticName); var node = inSig.Nodes.Add(new object[] { name, s.semanticIndex, s.regIndex, s.TypeString, s.systemValue.ToString(), SigParameter.GetComponentString(s.regChannelMask), SigParameter.GetComponentString(s.channelUsedMask) }); } bool multipleStreams = false; for (int i = 0; i < m_ShaderDetails.OutputSig.Length; i++) { if (m_ShaderDetails.OutputSig[i].stream > 0) { multipleStreams = true; break; } } foreach (var s in m_ShaderDetails.OutputSig) { string name = s.varName == "" ? s.semanticName : String.Format("{0} ({1})", s.varName, s.semanticName); if (multipleStreams) { name = String.Format("Stream {0} : {1}", s.stream, name); } var node = outSig.Nodes.Add(new object[] { name, s.semanticIndex, s.regIndex, s.TypeString, s.systemValue.ToString(), SigParameter.GetComponentString(s.regChannelMask), SigParameter.GetComponentString(s.channelUsedMask) }); } } else { inSigBox.Visible = false; outSigBox.Visible = false; m_DisassemblyView.Margins.Margin1.Width = 20; m_DisassemblyView.Margins.Margin2.Width = 0; m_DisassemblyView.Margins.Margin3.Width = 20; m_DisassemblyView.Margins.Margin3.IsMarkerMargin = true; m_DisassemblyView.Margins.Margin3.IsFoldMargin = false; m_DisassemblyView.Margins.Margin3.Type = ScintillaNET.MarginType.Symbol; m_DisassemblyView.Margins.Margin1.Mask = (int)m_DisassemblyView.Markers[BREAKPOINT_MARKER + 1].Mask; m_DisassemblyView.Margins.Margin3.Mask &= ~((int)m_DisassemblyView.Markers[BREAKPOINT_MARKER + 1].Mask); m_DisassemblyView.KeyDown += new KeyEventHandler(scintilla1_DebuggingKeyDown); watchRegs.Items.Add(new ListViewItem(new string[] { "", "", "" })); } CurrentStep = 0; this.ResumeLayout(false); }