CBuffer window is a dialog now, with ability to set custom layout

This commit is contained in:
baldurk
2014-09-11 23:51:20 +01:00
parent d9104b73c3
commit bda68c8ba6
15 changed files with 1083 additions and 744 deletions
+156
View File
@@ -0,0 +1,156 @@
namespace renderdocui.Windows.Dialogs
{
partial class BufferFormatSpecifier
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.GroupBox groupBox1;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BufferFormatSpecifier));
this.formatText = new System.Windows.Forms.TextBox();
this.helpText = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.errors = new System.Windows.Forms.Label();
this.apply = new System.Windows.Forms.Button();
this.hideHelp = new System.Windows.Forms.Button();
groupBox1 = new System.Windows.Forms.GroupBox();
groupBox1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(this.formatText);
groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
groupBox1.Location = new System.Drawing.Point(3, 195);
groupBox1.Name = "groupBox1";
groupBox1.Size = new System.Drawing.Size(556, 227);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Format";
//
// formatText
//
this.formatText.Dock = System.Windows.Forms.DockStyle.Fill;
this.formatText.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.formatText.Location = new System.Drawing.Point(3, 16);
this.formatText.Multiline = true;
this.formatText.Name = "formatText";
this.formatText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.formatText.Size = new System.Drawing.Size(550, 208);
this.formatText.TabIndex = 0;
this.formatText.Text = "float4 asd; // blah blah\r\nfloat3 bar;";
this.formatText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.formatText_KeyDown);
//
// helpText
//
this.helpText.AutoSize = true;
this.helpText.Location = new System.Drawing.Point(8, 8);
this.helpText.Margin = new System.Windows.Forms.Padding(8);
this.helpText.Name = "helpText";
this.helpText.Size = new System.Drawing.Size(517, 130);
this.helpText.TabIndex = 1;
this.helpText.Text = resources.GetString("helpText.Text");
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(groupBox1, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.helpText, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.errors, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.apply, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.hideHelp, 1, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(643, 425);
this.tableLayoutPanel1.TabIndex = 0;
//
// errors
//
this.tableLayoutPanel1.SetColumnSpan(this.errors, 2);
this.errors.Dock = System.Windows.Forms.DockStyle.Fill;
this.errors.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.errors.ForeColor = System.Drawing.Color.DarkRed;
this.errors.Location = new System.Drawing.Point(3, 146);
this.errors.Name = "errors";
this.errors.Size = new System.Drawing.Size(637, 46);
this.errors.TabIndex = 3;
//
// apply
//
this.apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.apply.Location = new System.Drawing.Point(572, 394);
this.apply.Margin = new System.Windows.Forms.Padding(8);
this.apply.Name = "apply";
this.apply.Size = new System.Drawing.Size(63, 23);
this.apply.TabIndex = 1;
this.apply.Text = "Apply";
this.apply.UseVisualStyleBackColor = true;
this.apply.Click += new System.EventHandler(this.apply_Click);
//
// hideHelp
//
this.hideHelp.Location = new System.Drawing.Point(565, 3);
this.hideHelp.Name = "hideHelp";
this.hideHelp.Size = new System.Drawing.Size(75, 23);
this.hideHelp.TabIndex = 4;
this.hideHelp.Text = "Hide Help";
this.hideHelp.UseVisualStyleBackColor = true;
this.hideHelp.Click += new System.EventHandler(this.hideHelp_Click);
//
// BufferFormatSpecifier
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tableLayoutPanel1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "BufferFormatSpecifier";
this.Size = new System.Drawing.Size(643, 425);
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TextBox formatText;
private System.Windows.Forms.Button apply;
private System.Windows.Forms.Label errors;
private System.Windows.Forms.Button hideHelp;
private System.Windows.Forms.Label helpText;
}
}
@@ -0,0 +1,89 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using renderdoc;
namespace renderdocui.Windows.Dialogs
{
public partial class BufferFormatSpecifier : UserControl
{
IBufferFormatProcessor m_Viewer = null;
public BufferFormatSpecifier(IBufferFormatProcessor viewer, string format)
{
InitializeComponent();
// WHY THE HELL do you require \r\n in text boxes?
formatText.Text = format.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
errors.Visible = false;
m_Viewer = viewer;
}
private void apply_Click(object sender, EventArgs e)
{
SetErrors("");
m_Viewer.ProcessBufferFormat(formatText.Text);
}
public void SetErrors(string err)
{
errors.Text = err;
if (errors.Text == "")
errors.Visible = false;
else
errors.Visible = true;
}
private void formatText_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A && e.Control)
{
e.SuppressKeyPress = true;
formatText.SelectAll();
}
}
private void hideHelp_Click(object sender, EventArgs e)
{
helpText.Visible = !helpText.Visible;
}
}
public interface IBufferFormatProcessor
{
void ProcessBufferFormat(string formatText);
}
}
@@ -117,4 +117,19 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="groupBox1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<data name="helpText.Text" xml:space="preserve">
<value>Type in a buffer format declaration. Comments and {} braces are skipped, : semantics are ignored.
Declare each element as an hlsl variable, e.g: "float4 first; float2 second; uint2 third;"
Basic types accepted: bool, byte, short, int, half, float, double.
Unsigned integer types: ubyte, ushort, uint
Hex-formatted integer types: xbyte, xshort, xint
Additionally special formats: unorm[hb] (half, byte) and snorm[hb], and uintten/unormten (10:10:10:2 packing)
Vectors (e.g. float4), matrices ([rowmajor] half3x4) and arrays (float[16]) are supported.</value>
</data>
</root>
-111
View File
@@ -1,111 +0,0 @@
namespace renderdocui.Controls
{
partial class ConstantBufferPreviewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
TreelistView.TreeListColumn treeListColumn1 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarName", "Name")));
TreelistView.TreeListColumn treeListColumn2 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarValue", "Value")));
TreelistView.TreeListColumn treeListColumn3 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarType", "Type")));
this.slotLabel = new System.Windows.Forms.Label();
this.nameLabel = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.variables = new TreelistView.TreeListView();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.variables)).BeginInit();
this.SuspendLayout();
//
// slotLabel
//
this.slotLabel.AutoSize = true;
this.slotLabel.Location = new System.Drawing.Point(3, 0);
this.slotLabel.Name = "slotLabel";
this.slotLabel.Padding = new System.Windows.Forms.Padding(5);
this.slotLabel.Size = new System.Drawing.Size(10, 23);
this.slotLabel.TabIndex = 0;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(19, 0);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Padding = new System.Windows.Forms.Padding(5);
this.nameLabel.Size = new System.Drawing.Size(10, 23);
this.nameLabel.TabIndex = 1;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Controls.Add(this.slotLabel, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.nameLabel, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.variables, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(499, 357);
this.tableLayoutPanel1.TabIndex = 0;
//
// variables
//
treeListColumn1.AutoSizeMinSize = 0;
treeListColumn1.Width = 175;
treeListColumn2.AutoSize = true;
treeListColumn2.AutoSizeMinSize = 0;
treeListColumn2.Width = 50;
treeListColumn3.AutoSizeMinSize = 0;
treeListColumn3.Width = 50;
this.variables.Columns.AddRange(new TreelistView.TreeListColumn[] {
treeListColumn1,
treeListColumn2,
treeListColumn3});
this.variables.ColumnsOptions.LeftMargin = 0;
this.tableLayoutPanel1.SetColumnSpan(this.variables, 2);
this.variables.Cursor = System.Windows.Forms.Cursors.Arrow;
this.variables.Dock = System.Windows.Forms.DockStyle.Fill;
this.variables.Location = new System.Drawing.Point(3, 26);
this.variables.Name = "variables";
this.variables.RowOptions.ShowHeader = false;
this.variables.Size = new System.Drawing.Size(493, 328);
this.variables.TabIndex = 2;
this.variables.Text = "treeListView1";
this.variables.KeyDown += new System.Windows.Forms.KeyEventHandler(this.variables_KeyDown);
//
// ConstantBufferPreviewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "ConstantBufferPreviewer";
this.Size = new System.Drawing.Size(499, 357);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.variables)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private TreelistView.TreeListView variables;
private System.Windows.Forms.Label slotLabel;
private System.Windows.Forms.Label nameLabel;
}
}
@@ -1,270 +0,0 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using renderdocui.Code;
using renderdoc;
using WeifenLuo.WinFormsUI.Docking;
namespace renderdocui.Controls
{
public partial class ConstantBufferPreviewer : UserControl, ILogViewerForm
{
private Core m_Core;
public ConstantBufferPreviewer(Core c, ShaderStageType stage, UInt32 slot)
{
InitializeComponent();
m_Core = c;
Stage = stage;
Slot = slot;
shader = m_Core.CurPipelineState.GetShader(stage);
UpdateLabels();
uint offs = 0;
uint size = 0;
m_Core.CurPipelineState.GetConstantBuffer(Stage, Slot, out cbuffer, out offs, out size);
m_Core.Renderer.BeginInvoke((ReplayRenderer r) =>
{
SetVariables(r.GetCBufferVariableContents(shader, Slot, cbuffer, offs));
});
m_Core.AddLogViewer(this);
}
private static List<DockContent> m_Docks = new List<DockContent>();
public static DockContent Has(ShaderStageType stage, UInt32 slot)
{
foreach (var d in m_Docks)
{
ConstantBufferPreviewer cb = d.Controls[0] as ConstantBufferPreviewer;
if(cb.Stage == stage && cb.Slot == slot)
return cb.Parent as DockContent;
}
return null;
}
public static void ShowDock(DockContent dock, DockPane pane, DockAlignment align, double proportion)
{
dock.FormClosed += new FormClosedEventHandler(dock_FormClosed);
if (m_Docks.Count > 0)
dock.Show(m_Docks[0].Pane, m_Docks[0]);
else
dock.Show(pane, align, proportion);
m_Docks.Add(dock);
}
static void dock_FormClosed(object sender, FormClosedEventArgs e)
{
DockContent p = sender as DockContent;
m_Docks.Remove(p);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
m_Core.RemoveLogViewer(this);
}
base.Dispose(disposing);
}
public void OnLogfileClosed()
{
variables.BeginUpdate();
variables.Nodes.Clear();
variables.EndUpdate();
variables.Invalidate();
}
public void OnLogfileLoaded()
{
variables.BeginUpdate();
variables.Nodes.Clear();
variables.EndUpdate();
variables.Invalidate();
}
private void AddVariables(TreelistView.NodeCollection root, ShaderVariable[] vars)
{
foreach (var v in vars)
{
TreelistView.Node n = root.Add(new TreelistView.Node(new object[] { v.name, v, v.TypeString() }));
if (v.rows > 1)
{
for (int i = 0; i < v.rows; i++)
{
n.Nodes.Add(new TreelistView.Node(new object[] { String.Format("{0}.row{1}", v.name, i), v.Row(i), v.RowTypeString() }));
}
}
if (v.members.Length > 0)
{
AddVariables(n.Nodes, v.members);
}
}
}
private void SetVariables(ShaderVariable[] vars)
{
if (variables.InvokeRequired)
{
this.BeginInvoke(new Action(() => { SetVariables(vars); }));
return;
}
variables.BeginUpdate();
variables.Nodes.Clear();
if(vars != null && vars.Length > 0)
AddVariables(variables.Nodes, vars);
variables.EndUpdate();
variables.Invalidate();
}
public void OnEventSelected(UInt32 frameID, UInt32 eventID)
{
uint offs = 0;
uint size = 0;
m_Core.CurPipelineState.GetConstantBuffer(Stage, Slot, out cbuffer, out offs, out size);
shader = m_Core.CurPipelineState.GetShader(Stage);
var reflection = m_Core.CurPipelineState.GetShaderReflection(Stage);
UpdateLabels();
if (reflection == null || reflection.ConstantBlocks.Length <= Slot)
{
SetVariables(null);
return;
}
m_Core.Renderer.BeginInvoke((ReplayRenderer r) =>
{
SetVariables(r.GetCBufferVariableContents(shader, Slot, cbuffer, offs));
});
}
private string BufferName = "";
private ResourceId cbuffer;
private ResourceId shader;
private ShaderStageType Stage;
private UInt32 Slot = 0;
public override string Text
{
get
{
return String.Format("{0} CB {1}", Stage.ToString(), Slot);
}
}
private void UpdateLabels()
{
BufferName = "";
bool needName = true;
foreach (var b in m_Core.CurBuffers)
{
if (b.ID == cbuffer)
{
BufferName = b.name;
if(b.customName)
needName = false;
}
}
var reflection = m_Core.CurPipelineState.GetShaderReflection(Stage);
if (reflection != null)
{
if (needName &&
Slot < reflection.ConstantBlocks.Length &&
reflection.ConstantBlocks[Slot].name != "")
BufferName = "<" + reflection.ConstantBlocks[Slot].name + ">";
}
nameLabel.Text = BufferName;
slotLabel.Text = Stage.ToString();
slotLabel.Text += " Shader Slot " + Slot;
}
private void variables_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control)
{
int[] width = new int[] { 0, 0, 0 };
foreach (var n in variables.NodesSelection)
{
width[0] = Math.Max(width[0], n[0].ToString().Length);
width[1] = Math.Max(width[1], n[1].ToString().Length);
width[2] = Math.Max(width[2], n[2].ToString().Length);
}
width[0] = Math.Min(50, width[0]);
width[1] = Math.Min(50, width[1]);
width[2] = Math.Min(50, width[2]);
string fmt = "{0,-" + width[0] + "} {1,-" + width[1] + "} {2,-" + width[2] + "}" + Environment.NewLine;
string text = "";
foreach (var n in variables.NodesSelection)
{
text += string.Format(fmt, n[0], n[1], n[2]);
}
Clipboard.SetText(text);
}
}
}
}