public string applyFormat(string[] name,FormatElement[] format) { System.Diagnostics.Debug.Assert(name.Length == 2); string firstName = name[0]; string lastname = name[1]; string result = ""; foreach(FormatElement f in format) { if(f == FormatElement.FirstName) result += firstName; else if(f == FormatElement.LastName) result += lastname; else if(f == FormatElement.FirstInitial) result += firstName[0]; else if(f == FormatElement.LastInitial) result += lastname[0]; else if(f == FormatElement.space) result += " "; else if(f == FormatElement.tab) result += "\t"; else if(f == FormatElement.comma) result += ","; else System.Diagnostics.Debug.Fail("Unknown formatting enum: "+f.ToString()); } return result; }
public void ParseColorString() { Assert.AreEqual(FormatNoContentElement.Element, FormatElement.Parse("[green:]")); Assert.AreEqual(new FormatTextElement("hello world"), FormatElement.Parse("[:hello world]")); Assert.AreEqual(new FormatTextElement("hello world"), FormatElement.Parse("[hello world]")); Assert.AreEqual(new FormatColorElement("green", new FormatTextElement("hello world")), FormatElement.Parse("[green:hello world]")); Assert.AreEqual(new FormatColorElement("green", new FormatTextElement("hello world")), FormatElement.Parse("[green:hello ][green:world]")); Assert.AreEqual(new FormatColorElement("green", new FormatTextElement("hello world")), FormatElement.Parse("[green:hello world")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatColorElement("green", new FormatTextElement("hello world")) }), FormatElement.Parse("text1[green:hello world]")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatColorElement("green", new FormatTextElement("hello world")), new FormatTextElement("text2") }), FormatElement.Parse("[green:hello world]text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatColorElement("green", new FormatTextElement("hello world")), new FormatTextElement("text2") }), FormatElement.Parse("text1[green:hello world]text2")); }
public static bool FormatDateTime(this IDateTime self, StringBuilder builder, FormatElement elem) { if (!FormatDate(self, builder, elem)) { return(FormatTime(self, builder, elem)); } return(true); }
public void ParseVariableString() { Assert.AreEqual(new FormatVariableElement("variable", FormatVariablePaddings.None), FormatElement.Parse("$variable")); Assert.AreEqual(new FormatVariableElement("variable", FormatVariablePaddings.PadLeft), FormatElement.Parse("$+variable")); Assert.AreEqual(new FormatVariableElement("variable", FormatVariablePaddings.PadRight), FormatElement.Parse("$variable+")); Assert.AreEqual(new FormatVariableElement("variable", FormatVariablePaddings.PadBoth), FormatElement.Parse("$+variable+")); Assert.AreEqual(new FormatVariableElement("variable1", FormatVariablePaddings.None), FormatElement.Parse("$variable1")); Assert.AreEqual(new FormatTextElement("$1variable"), FormatElement.Parse("$1variable")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.None), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$variable\text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.PadLeft), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$+variable\text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.PadRight), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$variable+\text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.PadBoth), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$+variable+\text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.PadRight), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$variable+text2")); Assert.AreEqual(new FormatConcatenationElement(new FormatElement[] { new FormatTextElement("text1"), new FormatVariableElement("variable", FormatVariablePaddings.PadBoth), new FormatTextElement("text2") }), FormatElement.Parse(@"text1$+variable+text2")); }
public void ParseEscapedString() { Assert.AreEqual(new FormatTextElement("hello world"), FormatElement.Parse(@"hello \world")); Assert.AreEqual(new FormatTextElement("hello $world"), FormatElement.Parse(@"hello \$world")); Assert.AreEqual(new FormatTextElement("hello @world"), FormatElement.Parse(@"hello \@world")); Assert.AreEqual(new FormatTextElement("hello ?world"), FormatElement.Parse(@"hello \?world")); Assert.AreEqual(new FormatTextElement("hello [world]"), FormatElement.Parse(@"hello \[world]")); Assert.AreEqual(new FormatTextElement("hello [world]"), FormatElement.Parse(@"hello \[world\]")); Assert.AreEqual(new FormatTextElement("hello {world}"), FormatElement.Parse(@"hello \{world}")); Assert.AreEqual(new FormatTextElement("hello {world}"), FormatElement.Parse(@"hello \{world\}")); }
public static string Format(long val, FormatElement fe) { val = Math.Abs(val); if (fe.Padding == 0 && val == 0) { return(string.Empty); } return(fe.Padding > 1 ? val.ToString().PadLeft(fe.Padding, '0') : val.ToString()); }
public void ParseFunctionString() { Assert.AreEqual(new FormatFunctionElement("func", new[] { FormatNoContentElement.Element }), FormatElement.Parse("@func{}")); Assert.AreEqual(new FormatFunctionElement("func1", new[] { FormatNoContentElement.Element }), FormatElement.Parse("@func1{}")); Assert.AreEqual(new FormatTextElement("@1func{}"), FormatElement.Parse("@1func{}")); Assert.AreEqual(new FormatFunctionElement("func", new[] { FormatNoContentElement.Element }), FormatElement.Parse("@func{")); Assert.AreEqual(new FormatFunctionElement("func", new[] { new FormatTextElement("arg1") }), FormatElement.Parse("@func{arg1}")); Assert.AreEqual(new FormatFunctionElement("func", new[] { new FormatTextElement("arg1"), new FormatTextElement("arg2") }), FormatElement.Parse("@func{arg1,arg2}")); }
public void ParseConditionString() { Assert.AreEqual(new FormatConditionElement("cond", false, FormatNoContentElement.Element), FormatElement.Parse("?cond{}")); Assert.AreEqual(new FormatConditionElement("cond", true, FormatNoContentElement.Element), FormatElement.Parse("?!cond{}")); Assert.AreEqual(new FormatConditionElement("cond", false, new FormatTextElement("text")), FormatElement.Parse("?cond{text}")); Assert.AreEqual(new FormatConditionElement("cond", true, new FormatTextElement("text")), FormatElement.Parse("?!cond{text}")); Assert.AreEqual(new FormatConditionElement("cond", false, FormatNoContentElement.Element), FormatElement.Parse("?cond{")); Assert.AreEqual(new FormatTextElement("?1cond{}"), FormatElement.Parse("?1cond{}")); Assert.AreEqual(new FormatTextElement("?1cond{text}"), FormatElement.Parse("?1cond{text}")); Assert.AreEqual(new FormatConditionElement("cond1", false, FormatNoContentElement.Element), FormatElement.Parse("?cond1{}")); Assert.AreEqual(new FormatConditionElement("cond1", true, new FormatTextElement("text")), FormatElement.Parse("?!cond1{text}")); }
public static bool FormatDate(this IDate self, StringBuilder builder, FormatElement elem) { switch (elem.Kind) { case Year: if (elem.Padding == 1) { builder.Append(self.Year % 100); } else if (elem.Padding == 2) { builder.Append((self.Year % 100).ToString().PadLeft(2, '0')); } else if (elem.Padding == 3) { builder.Append(self.Year.ToString().PadLeft(3, '0')); } else if (elem.Padding == 4) { builder.Append(self.Year.ToString().PadLeft(4, '0')); } return(true); case MonthAbbrev: builder.Append(new DateTime(self.Year, self.Month, self.Day).ToString("MMM", SystemCulture)); return(true); case MonthName: builder.Append(new DateTime(self.Year, self.Month, self.Day).ToString("MMMM", SystemCulture)); return(true); case Month: builder.Append(Format(self.Month, elem)); return(true); case Day: builder.Append(Format(self.Day, elem)); return(true); case Literal: builder.Append(elem.Value); return(true); default: return(false); } }
private static string Stringify(IFormatElement element, IDisposable sessionContext, Func <string, string, string, object> argumentsCallback) { if (element is StringElement) { return(element.Content.ToString()); } FormatElement fe = (FormatElement)element; object val = null; if (fe.Content.Equals(".")) { fe.Content.Clear(); fe.Content.Append("$data"); } if (fe.CodeType == CodeType.Expression || fe.CodeType == CodeType.RecursiveExpression) { val = ExpressionParser.Parse(fe.Content.ToString(), sessionContext); } else { val = ExpressionParser.ParseBlock(fe.Content.ToString(), sessionContext); } if (fe.CodeType == CodeType.RecursiveExpression || fe.CodeType == CodeType.RecursiveBlock) { if (val is string recVal && !string.IsNullOrEmpty(recVal)) { val = FormatText(sessionContext, recVal); } } var fint = fe.FormatHint.ToString(); bool useFormat = fe.FormatHint.Length != 0 && !customFormatHints.ContainsKey(fint); bool preFormat = fe.FormatHint.Length != 0 && customFormatHints.ContainsKey(fint); if (preFormat) { val = customFormatHints[fint].ApplyFormat(fe.Content.ToString(), val, (a, b, c) => argumentsCallback?.Invoke(a, b, c)); } return (string.Format( $"{{0{(fe.FormatLength.Length != 0 ? $",{fe.FormatLength}" : "")}{(useFormat ? $":{fe.FormatHint}" : "")}}}", val)); }
public static bool FormatInterval(this IInterval self, StringBuilder builder, FormatElement elem) { switch (elem.Kind) { case Sign: if (self.TotalTicks > 0) { builder.Append('+'); } else if (self.TotalTicks < 0) { builder.Append('-'); } return(true); case Day: builder.Append(Format(self.Days, elem)); return(true); default: return(FormatTime(self, builder, elem)); } }
public void ProcessBufferFormat(string formatText) { if (formatText.Length == 0) { m_FormatOverride = null; if (m_FormatSpecifier != null) { m_FormatSpecifier.SetErrors(""); } } else { string errors = ""; m_FormatOverride = FormatElement.ParseFormatString(formatText, 0, false, out errors); if (m_FormatSpecifier != null) { m_FormatSpecifier.SetErrors(errors); } } OnEventSelected(m_Core.CurEvent); }
public void ParseBasicString() { Assert.AreEqual(new FormatTextElement("hello world"), FormatElement.Parse("hello world")); }
public void ViewRawBuffer(ResourceId buff, string formatString) { if (m_Core.CurBuffers == null) return; m_FormatText = formatString; Text = "Buffer Contents"; foreach (var b in m_Core.CurBuffers) { if (b.ID == buff) { Text = b.name + " - Contents"; break; } } var elems = new List<FormatElement>(); var formatReader = new StringReader(formatString); // regex doesn't account for trailing or preceeding whitespace, or comments var regExpr = @"^(row_major\s+)?" + // row_major matrix @"(" + @"uintten|unormten" + @"|unormh|unormb" + @"|snormh|snormb" + @"|bool|byte|ubyte|short|ushort|int|uint|half|float|double" + // basic types last since they're most the most common match @")" + @"([1-9])?" + // might be a vector @"(x[1-9])?" + // or a matrix @"(\s+[A-Za-z_][A-Za-z0-9_]*)?" + // get identifier name @"(\[[0-9]+\])?" + // optional array dimension @"(\s*:\s*[A-Za-z_][A-Za-z0-9_]*)?" + // optional semantic @"$"; Regex regParser = new Regex(regExpr, RegexOptions.Compiled); bool success = true; string errors = ""; Input input = new Input(); input.Strides = new uint[] { 0 }; var text = formatReader.ReadToEnd(); text = text.Replace("{", "").Replace("}", ""); Regex c_comments = new Regex(@"/\*[^*]*\*+(?:[^*/][^*]*\*+)*/", RegexOptions.Compiled); text = c_comments.Replace(text, ""); Regex cpp_comments = new Regex(@"//.*", RegexOptions.Compiled); text = cpp_comments.Replace(text, ""); // get each line and parse it to determine the format the user wanted foreach (var l in text.Split(';')) { var line = l; line = line.Trim(); if (line == "") continue; var match = regParser.Match(line); if (!match.Success) { errors = "Couldn't parse line:\n" + line; success = false; break; } var basetype = match.Groups[2].Value; bool row_major = match.Groups[1].Success; var vectorDim = match.Groups[3].Success ? match.Groups[3].Value : "1"; var matrixDim = match.Groups[4].Success ? match.Groups[4].Value.Substring(1) : "1"; var name = match.Groups[5].Success ? match.Groups[5].Value.Trim() : "data"; var arrayDim = match.Groups[6].Success ? match.Groups[6].Value.Trim() : "[1]"; arrayDim = arrayDim.Substring(1, arrayDim.Length - 2); if(match.Groups[4].Success) { var a = vectorDim; vectorDim = matrixDim; matrixDim = a; } ResourceFormat fmt = new ResourceFormat(FormatComponentType.None, 0, 0); FormatComponentType type = FormatComponentType.Float; uint count = 0; uint arrayCount = 1; uint matrixCount = 0; uint width = 0; // calculate format { if (!uint.TryParse(vectorDim, out count)) { errors = "Invalid vector dimension on line:\n" + line; success = false; break; } if (!uint.TryParse(arrayDim, out arrayCount)) { arrayCount = 1; } arrayCount = Math.Max(0, arrayCount); if (!uint.TryParse(matrixDim, out matrixCount)) { errors = "Invalid matrix second dimension on line:\n" + line; success = false; break; } if (basetype == "bool") { type = FormatComponentType.UInt; width = 4; } else if (basetype == "byte") { type = FormatComponentType.SInt; width = 1; } else if (basetype == "ubyte") { type = FormatComponentType.UInt; width = 1; } else if (basetype == "short") { type = FormatComponentType.SInt; width = 2; } else if (basetype == "ushort") { type = FormatComponentType.UInt; width = 2; } else if (basetype == "int") { type = FormatComponentType.SInt; width = 4; } else if (basetype == "uint") { type = FormatComponentType.UInt; width = 4; } else if (basetype == "half") { type = FormatComponentType.Float; width = 2; } else if (basetype == "float") { type = FormatComponentType.Float; width = 4; } else if (basetype == "double") { type = FormatComponentType.Float; width = 8; } else if (basetype == "unormh") { type = FormatComponentType.UNorm; width = 2; } else if (basetype == "unormb") { type = FormatComponentType.UNorm; width = 1; } else if (basetype == "snormh") { type = FormatComponentType.SNorm; width = 2; } else if (basetype == "snormb") { type = FormatComponentType.SNorm; width = 1; } else if (basetype == "uintten") { fmt = new ResourceFormat(FormatComponentType.UInt, 4 * count, 1); fmt.special = true; fmt.specialFormat = SpecialFormat.R10G10B10A2; } else if (basetype == "unormten") { fmt = new ResourceFormat(FormatComponentType.UNorm, 4 * count, 1); fmt.special = true; fmt.specialFormat = SpecialFormat.R10G10B10A2; } else { errors = "Unrecognised basic type on line:\n" + line; success = false; break; } } if(fmt.compType == FormatComponentType.None) fmt = new ResourceFormat(type, count * arrayCount, width); FormatElement elem = new FormatElement(name, 0, input.Strides[0], false, row_major, matrixCount, fmt); elems.Add(elem); input.Strides[0] += elem.ByteSize; } if (!success || elems.Count == 0) { elems.Clear(); var fmt = new ResourceFormat(FormatComponentType.UInt, 4, 4); elems.Add(new FormatElement("data", 0, input.Strides[0], false, false, 1, fmt)); input.Strides[0] = elems.Last().ByteSize; } input.Buffers = new ResourceId[] { buff }; input.Offsets = new uint[] { 0 }; input.IndexBuffer = ResourceId.Null; input.BufferFormats = elems.ToArray(); input.IndexOffset = 0; m_VSIn.m_Input = input; ShowFormatSpecifier(); m_FormatSpecifier.SetErrors(errors); ClearStoredData(); m_Core.Renderer.BeginInvoke((ReplayRenderer r) => { var contents = RT_FetchBufferContents(MeshDataStage.VSIn, r, input); this.BeginInvoke(new Action(() => { UI_SetRowsData(MeshDataStage.VSIn, contents); UI_SetColumns(MeshDataStage.VSIn, input.BufferFormats); })); }); }
public void ParseEmptyString() { Assert.AreEqual(FormatNoContentElement.Element, FormatElement.Parse(string.Empty)); }
public static bool FormatLocalDateTime(this ILocalDateTime self, StringBuilder builder, FormatElement elem) { if (!FormatDate(self, builder, elem)) { if (!FormatTime(self, builder, elem)) { if (elem.Kind == Offset) { if (self.Interval.TotalTicks == 0) { return(true); } else if (self.Interval.TotalTicks < 0) { builder.Append('-'); } else { builder.Append('+'); } if (elem.Padding == 1) { builder.Append(Math.Abs(self.Interval.Hours)); return(true); } else if (elem.Padding == 2) { builder.Append(Math.Abs(self.Interval.Hours).ToString().PadLeft(2, '0')); return(true); } else if (elem.Padding == 3) { builder.Append(Math.Abs(self.Interval.Hours).ToString().PadLeft(2, '0')); builder.Append(SystemCulture.DateTimeFormat.TimeSeparator); builder.Append(Math.Abs(self.Interval.Minutes).ToString().PadLeft(2, '0')); return(true); } } } } return(false); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as DocumentReference; if (dest != null) { base.CopyTo(dest); if (MasterIdentifier != null) { dest.MasterIdentifier = (Hl7.Fhir.Model.Identifier)MasterIdentifier.DeepCopy(); } if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (Type != null) { dest.Type = (Hl7.Fhir.Model.CodeableConcept)Type.DeepCopy(); } if (Class != null) { dest.Class = (Hl7.Fhir.Model.CodeableConcept)Class.DeepCopy(); } if (FormatElement != null) { dest.FormatElement = new List <Hl7.Fhir.Model.FhirUri>(FormatElement.DeepCopy()); } if (Author != null) { dest.Author = new List <Hl7.Fhir.Model.ResourceReference>(Author.DeepCopy()); } if (Custodian != null) { dest.Custodian = (Hl7.Fhir.Model.ResourceReference)Custodian.DeepCopy(); } if (Authenticator != null) { dest.Authenticator = (Hl7.Fhir.Model.ResourceReference)Authenticator.DeepCopy(); } if (CreatedElement != null) { dest.CreatedElement = (Hl7.Fhir.Model.FhirDateTime)CreatedElement.DeepCopy(); } if (IndexedElement != null) { dest.IndexedElement = (Hl7.Fhir.Model.Instant)IndexedElement.DeepCopy(); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.DocumentReference.DocumentReferenceStatus>)StatusElement.DeepCopy(); } if (DocStatus != null) { dest.DocStatus = (Hl7.Fhir.Model.CodeableConcept)DocStatus.DeepCopy(); } if (RelatesTo != null) { dest.RelatesTo = new List <Hl7.Fhir.Model.DocumentReference.DocumentReferenceRelatesToComponent>(RelatesTo.DeepCopy()); } if (DescriptionElement != null) { dest.DescriptionElement = (Hl7.Fhir.Model.FhirString)DescriptionElement.DeepCopy(); } if (Confidentiality != null) { dest.Confidentiality = new List <Hl7.Fhir.Model.CodeableConcept>(Confidentiality.DeepCopy()); } if (Content != null) { dest.Content = new List <Hl7.Fhir.Model.Attachment>(Content.DeepCopy()); } if (Context != null) { dest.Context = (Hl7.Fhir.Model.DocumentReference.DocumentReferenceContextComponent)Context.DeepCopy(); } return(dest); } else { throw new ArgumentException("Can only copy to an object of the same type", "other"); } }
public static bool FormatTime(this ITime self, StringBuilder builder, FormatElement elem) { switch (elem.Kind) { case Hour24: builder.Append(Format(self.Hours, elem)); return(true); case Hour: { var dt = new DateTime(1, 1, 1, self.Hours, self.Minutes, self.Seconds); if (elem.Padding == 1) { builder.Append(dt.ToString("%h", SystemCulture)); } else if (elem.Padding == 2) { builder.Append(dt.ToString("hh", SystemCulture)); } return(true); } case Minute: builder.Append(Format(self.Minutes, elem)); return(true); case Second: builder.Append(Format(self.Seconds, elem)); return(true); case Decisecond: builder.Append(Format(self.Milliseconds / 100, elem)); return(true); case Centisecond: builder.Append(Format(self.Milliseconds / 10, elem)); return(true); case Millisecond: builder.Append(Format(self.Milliseconds, elem)); return(true); case TenthThousandth: builder.Append(Format(self.Microseconds / 100, elem)); return(true); case HundredthThousandth: builder.Append(Format(self.Microseconds / 10, elem)); return(true); case Microsecond: builder.Append(Format(self.Microseconds, elem)); return(true); case Tick: builder.Append(Format(self.Ticks, elem)); return(true); case PmAm: { if (self.Hours >= 12) { builder.Append(elem.Padding == 1 ? "P" : "PM"); } else { builder.Append(elem.Padding == 1 ? "A" : "AM"); } return(true); } case Literal: builder.Append(elem.Value); return(true); default: return(false); } }
public void OnEventSelected(UInt32 frameID, UInt32 eventID) { ClearStoredData(); var draw = m_Core.CurDrawcall; byteOffset.Enabled = false; instanceIdxToolitem.Enabled = (draw != null && draw.numInstances > 1); if (!instanceIdxToolitem.Enabled) instanceIdxToolitem.Text = "0"; if (MeshView && draw == null) { m_VSIn.AbortThread(); m_VSOut.AbortThread(); m_GSOut.AbortThread(); return; } int[] horizscroll = new int[] { m_VSIn.m_GridView.HorizontalScrollingOffset, m_VSOut.m_GridView.HorizontalScrollingOffset, m_GSOut.m_GridView.HorizontalScrollingOffset, }; int curReq = m_ReqID; uint byteoffs = ByteOffset; m_Core.Renderer.BeginInvoke((ReplayRenderer r) => { m_VSIn.AbortThread(); m_VSOut.AbortThread(); m_GSOut.AbortThread(); if (curReq != m_ReqID) return; if (MeshView) { MeshDataStage[] stages = new MeshDataStage[] { MeshDataStage.VSIn, MeshDataStage.VSOut, MeshDataStage.GSOut }; FormatElement[] prevPos = new FormatElement[3]; FormatElement[] prevSecond = new FormatElement[3]; for (int i = 0; i < 3; i++) { prevPos[i] = GetPosHighlightFormatElement(stages[i]); prevSecond[i] = GetSecondHighlightFormatElement(stages[i]); } m_VSIn.m_Input = GetCurrentMeshInput(draw, MeshDataStage.VSIn); m_VSOut.m_Input = GetCurrentMeshInput(draw, MeshDataStage.VSOut); m_GSOut.m_Input = GetCurrentMeshInput(draw, MeshDataStage.GSOut); for(int i=0; i < 3; i++) { FormatElement curPos = GetPosHighlightFormatElement(stages[i]); FormatElement curSecond = GetSecondHighlightFormatElement(stages[i]); if (prevPos[i] == null || prevPos[i] != curPos) UI_AutoFetchRenderComponents(stages[i], true); if (prevSecond[i] == null || prevSecond[i] != curSecond) UI_AutoFetchRenderComponents(stages[i], false); } } var contentsVSIn = RT_FetchBufferContents(MeshDataStage.VSIn, r, m_VSIn.m_Input, byteoffs); var contentsVSOut = RT_FetchBufferContents(MeshDataStage.VSOut, r, m_VSOut.m_Input, byteoffs); var contentsGSOut = RT_FetchBufferContents(MeshDataStage.GSOut, r, m_GSOut.m_Input, byteoffs); if (curReq != m_ReqID) return; this.BeginInvoke(new Action(() => { if (curReq != m_ReqID) return; m_VSIn.AbortThread(); m_VSOut.AbortThread(); m_GSOut.AbortThread(); if (m_VSIn.m_Input != null) UI_SetRowsData(MeshDataStage.VSIn, contentsVSIn, horizscroll[0]); if (m_VSOut.m_Input != null) UI_SetRowsData(MeshDataStage.VSOut, contentsVSOut, horizscroll[1]); if (m_GSOut.m_Input != null) UI_SetRowsData(MeshDataStage.GSOut, contentsGSOut, horizscroll[2]); if (MeshView) UI_UpdateMeshRenderComponents(); UI_SetAllColumns(); camGuess_PropChanged(); render.Invalidate(); })); }); }
private void UI_UpdateMeshColumns(MeshDataStage type, FormatElement[] el) { bool active = (type == m_MeshDisplay.type); bool input = (type == MeshDataStage.VSIn); var bufView = GetUIState(type).m_GridView; if (bufView.ColumnCount == 0) return; int colidx = 2; // skip VTX and IDX columns Color defaultCol = bufView.Columns[0].DefaultCellStyle.BackColor; for (int e = 0; e < el.Length; e++) { for (int i = 0; i < el[e].format.compCount; i++) { if (colidx >= bufView.ColumnCount) return; DataGridViewColumn col = bufView.Columns[colidx]; colidx++; if (e == m_PosElement[(int)type] && active) { if (i != 3 || !input) col.DefaultCellStyle.BackColor = Color.SkyBlue; else col.DefaultCellStyle.BackColor = Color.LightCyan; } else if (e == m_SecondElement[(int)type] && active && m_MeshDisplay.solidShadeMode == SolidShadeMode.Secondary) { if ((m_MeshDisplay.secondary.showAlpha && i == 3) || (!m_MeshDisplay.secondary.showAlpha && i != 3)) col.DefaultCellStyle.BackColor = Color.LightGreen; else col.DefaultCellStyle.BackColor = Color.FromArgb(200, 238, 200); } else col.DefaultCellStyle.BackColor = defaultCol; } } }
private void UI_SetMeshColumns(MeshDataStage type, FormatElement[] el) { var bufView = GetUIState(type).m_GridView; bufView.Columns.Clear(); DataGridViewTextBoxColumn Column = new DataGridViewTextBoxColumn(); Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; Column.HeaderText = "VTX"; Column.ReadOnly = true; Column.Frozen = true; Column.Width = 50; Column.DividerWidth = 0; Column.SortMode = DataGridViewColumnSortMode.Programmatic; Column.DefaultCellStyle.Padding = new Padding(0, 2, 0, 2); bufView.Columns.Add(Column); Column = new DataGridViewTextBoxColumn(); Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; Column.HeaderText = "IDX"; Column.ReadOnly = true; Column.Frozen = true; Column.Width = 50; Column.DividerWidth = 10; Column.SortMode = DataGridViewColumnSortMode.Programmatic; Column.DefaultCellStyle.Padding = new Padding(0, 2, 0, 2); bufView.Columns.Add(Column); for(int e=0; e < el.Length; e++) { for (int i = 0; i < el[e].format.compCount; i++) { DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; col.MinimumWidth = 50; col.HeaderText = el[e].name; col.ReadOnly = true; col.SortMode = DataGridViewColumnSortMode.Programmatic; col.DefaultCellStyle.Padding = new Padding(0, 2, 0, 2); bufView.Columns.Add(col); } if (e < el.Length-1) bufView.Columns[bufView.Columns.Count - 1].DividerWidth = 10; } UI_UpdateMeshColumns(type, el); }
private void UI_SetRawColumns(FormatElement[] el) { vsInBufferView.Columns.Clear(); DataGridViewTextBoxColumn Column = new DataGridViewTextBoxColumn(); Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; Column.HeaderText = "Element"; Column.ReadOnly = true; Column.Frozen = true; Column.Width = 70; Column.DividerWidth = 10; Column.SortMode = DataGridViewColumnSortMode.Programmatic; Column.DefaultCellStyle.WrapMode = DataGridViewTriState.True; Column.DefaultCellStyle.Padding = new Padding(0, 2, 0, 2); vsInBufferView.Columns.Add(Column); for (int e = 0; e < el.Length; e++) { for (int i = 0; i < el[e].format.compCount; i++) { DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; col.MinimumWidth = 50; col.HeaderText = el[e].name; col.ReadOnly = true; col.SortMode = DataGridViewColumnSortMode.Programmatic; col.DefaultCellStyle.WrapMode = DataGridViewTriState.True; col.DefaultCellStyle.Padding = new Padding(0, 2, 0, 2); vsInBufferView.Columns.Add(col); } if (e < el.Length - 1) vsInBufferView.Columns[vsInBufferView.Columns.Count - 1].DividerWidth = 10; } }
private void UI_SetColumns(MeshDataStage type, FormatElement[] el) { if (MeshView) UI_SetMeshColumns(type, el); else UI_SetRawColumns(el); }
// used for the mesh view, to get the format of the mesh input from whichever stage that // we're looking at private Input GetCurrentMeshInput(FetchDrawcall draw, MeshDataStage type) { if (!MeshView) return null; Input ret = new Input(); ret.Drawcall = draw; ret.Topology = draw.topology; ResourceId ibuffer = ResourceId.Null; ulong ioffset = 0; m_Core.CurPipelineState.GetIBuffer(out ibuffer, out ioffset); if (draw != null && (draw.flags & DrawcallFlags.UseIBuffer) == 0) { ibuffer = ResourceId.Null; ioffset = 0; } ret.IndexBuffer = ibuffer; ret.IndexOffset = ioffset; ret.IndexRestart = m_Core.CurPipelineState.IsStripRestartEnabled(); ret.IndexRestartValue = m_Core.CurPipelineState.GetStripRestartIndex(draw != null ? draw.indexByteWidth : 0); if (type != MeshDataStage.VSIn) { ShaderReflection details = null; if (type == MeshDataStage.VSOut) details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Vertex); else if (type == MeshDataStage.GSOut) { details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Geometry); if (details == null) details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Domain); } if (details == null) return null; List<FormatElement> f = new List<FormatElement>(); int posidx = -1; for (int i = 0; i < details.OutputSig.Length; i++) { var sig = details.OutputSig[i]; f.Add(new FormatElement()); f[i].buffer = 0; f[i].name = details.OutputSig[i].varName.Length > 0 ? details.OutputSig[i].varName : details.OutputSig[i].semanticIdxName; f[i].format.compByteWidth = sizeof(float); f[i].format.compCount = sig.compCount; f[i].format.compType = sig.compType; f[i].format.special = false; f[i].format.rawType = 0; f[i].perinstance = false; f[i].instancerate = 1; f[i].rowmajor = false; f[i].matrixdim = 1; f[i].systemValue = sig.systemValue; if(f[i].systemValue == SystemAttribute.Position) posidx = i; } // shift position attribute up to first, keeping order otherwise // the same if (posidx > 0) { FormatElement pos = f[posidx]; f.RemoveAt(posidx); f.Insert(0, pos); } uint offset = 0; for (int i = 0; i < details.OutputSig.Length; i++) { uint numComps = f[i].format.compCount; uint elemSize = f[i].format.compType == FormatComponentType.Double ? 8U : 4U; if (m_Core.CurPipelineState.HasAlignedPostVSData) { if (numComps == 2) offset = offset.AlignUp(2U * elemSize); else if (numComps > 2) offset = offset.AlignUp(4U * elemSize); } f[i].offset = offset; offset += numComps * elemSize; } ret.BufferFormats = f.ToArray(); ret.Strides = new uint[] { offset }; ret.Offsets = new ulong[] { 0 }; ret.Buffers = null; return ret; } BoundVBuffer[] vbs = m_Core.CurPipelineState.GetVBuffers(); ResourceId[] bs = new ResourceId[vbs.Length]; uint[] s = new uint[vbs.Length]; ulong[] o = new ulong[vbs.Length]; for (int i = 0; i < vbs.Length; i++) { bs[i] = vbs[i].Buffer; s[i] = vbs[i].ByteStride; o[i] = vbs[i].ByteOffset; } { FormatElement[] f = null; var vinputs = m_Core.CurPipelineState.GetVertexInputs(); f = new FormatElement[vinputs.Length]; ret.GenericValues = new object[vinputs.Length][]; int numinputs = vinputs.Length; int i = 0; foreach (var a in vinputs) { if (!a.Used) { numinputs--; Array.Resize(ref f, numinputs); Array.Resize(ref ret.GenericValues, numinputs); continue; } f[i] = new FormatElement(a.Name, a.VertexBuffer, a.RelativeByteOffset, a.PerInstance, a.InstanceRate, false, // row major matrix 1, // matrix dimension a.Format, false); ret.GenericValues[i] = a.GenericValue; i++; } ret.BufferFormats = f; ret.Strides = s; ret.Offsets = o; ret.Buffers = bs; } return ret; }
ConsoleString IFormatter <T> .Format(FormatElement format, T item) => Visit(format, item);
private static IFormatElement[] TokenizeString(string s) { Stack <ParseState> parserStack = new Stack <ParseState>(); ParseState currentState = ParseState.String; IFormatElement currentElement = new StringElement(); int len = s.Length; List <IFormatElement> elements = new List <IFormatElement>(); for (int i = 0; i < len; i++) { string o = s.Substring(i, 1); string t = ""; if (i < len - 1) { t = s.Substring(i, i < len - 1 ? 2 : 1); } string t2 = ""; if (i < len - 2 && (t == "$[" || t == "£[" || t == "$£")) { t2 = s.Substring(i, 3); } string t3 = ""; if (i < len - 3 && t2 == "$£[") { t3 = s.Substring(i, 4); } switch (currentState) { case ParseState.String: if (o == "[" && t != "[[") { if (currentElement.Length != 0) { elements.Add(currentElement); } currentElement = new FormatElement { Start = i }; parserStack.Push(currentState); currentState = ParseState.FormatExpression; } else if (o == "$" && t == "$[" && t2 != "$[[") { i++; if (currentElement.Length != 0) { elements.Add(currentElement); } currentElement = new FormatElement { Start = i, CodeType = CodeType.Block }; parserStack.Push(currentState); currentState = ParseState.FormatExpression; } else if (o == "£" && t == "£[" && t2 != "£[[") { i++; if (currentElement.Length != 0) { elements.Add(currentElement); } currentElement = new FormatElement { Start = i, CodeType = CodeType.RecursiveExpression }; parserStack.Push(currentState); currentState = ParseState.FormatExpression; } else if (o == "$" && t == "$£" && t2 == "$£[" && t3 != "$£[[") { i += 2; if (currentElement.Length != 0) { elements.Add(currentElement); } currentElement = new FormatElement { Start = i, CodeType = CodeType.RecursiveBlock }; parserStack.Push(currentState); currentState = ParseState.FormatExpression; } else { currentElement.Length++; if (t != "[[" && t != "]]" && t != "$$" && t != "££") { currentElement.Content.Append(o); } else { i++; currentElement.Content.Append(o); } } break; case ParseState.FormatExpression: if (o == "(") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatParenthesis; } else if (o == "[") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatIndexer; } else if (o == "{") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatBracket; } else if (o == "@" && t == "@\"") { currentElement.Length += 2; currentElement.Content.Append(t); parserStack.Push(currentState); i++; currentState = ParseState.FormatVerbatimString; } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatString; } else if (o == "?" && t != "?." && t != "?[") //Exclude Null-Propagations { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatTerentary; } else if (o == ":") { currentElement.Length++; parserStack.Push(currentState); currentState = ParseState.FormatterHint; } else if (o == ",") { currentElement.Length++; parserStack.Push(currentState); currentState = ParseState.FormatterLength; } else if (o == "]") { if (currentElement.Length != 0) { elements.Add(currentElement); } currentElement = new StringElement(); currentElement.Start = i + 1; currentState = parserStack.Pop(); if (currentState != ParseState.String) { throw new FormatException($"Unexpected Token @{i}!"); } } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatParenthesis: if (o == "@" && t == "@\"") { currentElement.Length += 2; currentElement.Content.Append(t); parserStack.Push(currentState); i++; currentState = ParseState.FormatVerbatimString; } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatString; } else if (o == "(") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatParenthesis; } else if (o == ")") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatBracket: if (o == "@" && t == "@\"") { currentElement.Length += 2; currentElement.Content.Append(t); parserStack.Push(currentState); i++; currentState = ParseState.FormatVerbatimString; } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatString; } else if (o == "{") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatBracket; } else if (o == "}") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatIndexer: if (o == "@" && t == "@\"") { currentElement.Length += 2; currentElement.Content.Append(t); parserStack.Push(currentState); i++; currentState = ParseState.FormatVerbatimString; } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatString; } else if (o == "[") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatIndexer; } else if (o == "]") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatString: if (t == "\\\"") { i++; currentElement.Length += 2; currentElement.Content.Append(t); } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatVerbatimString: if (t == "\"\"") { i++; currentElement.Length += 2; currentElement.Content.Append(t); } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatTerentary: if (o == "@" && t == "@\"") { currentElement.Length += 2; currentElement.Content.Append(t); parserStack.Push(currentState); i++; currentState = ParseState.FormatVerbatimString; } else if (o == "\"") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatString; } else if (o == "?" && t != "?." && t != "?[") { currentElement.Length++; currentElement.Content.Append(o); parserStack.Push(currentState); currentState = ParseState.FormatTerentary; } else if (o == ":") { currentElement.Length++; currentElement.Content.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; currentElement.Content.Append(o); } break; case ParseState.FormatterHint: if (o == "]") { i--; currentState = parserStack.Pop(); } else if (o == ",") { currentElement.Length++; currentState = ParseState.FormatterLength; } else { currentElement.Length++; ((FormatElement)currentElement).FormatHint.Append(o); } break; case ParseState.FormatterHintString: if (t == "\\\"") { i++; currentElement.Length += 2; ((FormatElement)currentElement).FormatHint.Append(t); } else if (o == "\"") { currentElement.Length++; ((FormatElement)currentElement).FormatHint.Append(o); currentState = parserStack.Pop(); } else { currentElement.Length++; ((FormatElement)currentElement).FormatHint.Append(o); } break; case ParseState.FormatterLength: if (o == "]") { i--; currentState = parserStack.Pop(); } else { currentElement.Length++; ((FormatElement)currentElement).FormatLength.Append(o); } break; default: throw new ArgumentOutOfRangeException(); } } if (currentState != ParseState.String) { throw new FormatException("Formatstring was not well-formed!"); } if (currentElement.Length != 0) { elements.Add(currentElement); } return(elements.ToArray()); }
// used for the mesh view, to get the format of the mesh input from whichever stage that // we're looking at private Input GetCurrentMeshInput(FetchDrawcall draw, MeshDataStage type) { if (!MeshView) return null; FormatElement[] f = null; Input ret = new Input(); ret.Drawcall = draw; ret.Topology = m_Core.CurPipelineState.DrawTopology; if (type != MeshDataStage.VSIn) { ShaderReflection details = null; if (type == MeshDataStage.VSOut) details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Vertex); else if (type == MeshDataStage.GSOut) { details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Geometry); if (details == null) details = m_Core.CurPipelineState.GetShaderReflection(ShaderStageType.Domain); } if (details == null) return null; f = new FormatElement[details.OutputSig.Length]; uint offset = 0; for (int i = 0; i < details.OutputSig.Length; i++) { var sig = details.OutputSig[i]; f[i] = new FormatElement(); f[i].buffer = 0; f[i].name = details.OutputSig[i].varName != "" ? details.OutputSig[i].varName : details.OutputSig[i].semanticIdxName; f[i].format.compByteWidth = sizeof(float); f[i].format.compCount = sig.compCount; f[i].format.compType = sig.compType; f[i].format.special = false; f[i].format.rawType = 0; f[i].offset = offset; f[i].perinstance = false; f[i].rowmajor = false; f[i].matrixdim = 1; offset += details.OutputSig[i].compCount * sizeof(float); } ret.BufferFormats = f; ret.Strides = new uint[] { offset }; ret.Offsets = new uint[] { 0 }; ret.Buffers = null; ret.IndexBuffer = ResourceId.Null; return ret; } CommonPipelineState.VBuffer[] vbs = m_Core.CurPipelineState.GetVBuffers(); ResourceId[] bs = new ResourceId[vbs.Length]; uint[] s = new uint[vbs.Length]; uint[] o = new uint[vbs.Length]; for (int i = 0; i < vbs.Length; i++) { bs[i] = vbs[i].Buffer; s[i] = vbs[i].ByteStride; o[i] = vbs[i].ByteOffset; } { var vinputs = m_Core.CurPipelineState.GetVertexInputs(); f = new FormatElement[vinputs.Length]; int i = 0; foreach (var a in vinputs) { f[i] = new FormatElement(a.Name, a.VertexBuffer, a.RelativeByteOffset, a.PerInstance, false, // row major matrix 1, // matrix dimension a.Format); i++; } } ResourceId ibuffer = ResourceId.Null; uint ioffset = 0; ResourceFormat ifmt = null; m_Core.CurPipelineState.GetIBuffer(out ibuffer, out ioffset, out ifmt); if (draw != null && (draw.flags & DrawcallFlags.UseIBuffer) == 0) { ibuffer = ResourceId.Null; ioffset = 0; } ret.BufferFormats = f; ret.Strides = s; ret.Offsets = o; ret.Buffers = bs; ret.IndexFormat = new FormatElement("", 0, 0, false, false, 1, ifmt); ret.IndexBuffer = ibuffer; ret.IndexOffset = ioffset; return ret; }
private string ElementString(FormatElement el, object o) { if (o is float) { // pad with space on left if sign is missing, to better align float f = (float)o; if (f < 0.0f) return Formatter.Format(f); else if (f > 0.0f) return " " + Formatter.Format(f); else if (float.IsNaN(f)) return " NaN"; else return " " + Formatter.Format(0.0f); // force negative and positive 0 together } else if (o is double) { // pad with space on left if sign is missing, to better align double f = (double)o; if (f < 0.0) return Formatter.Format(f); else if (f > 0.0) return " " + Formatter.Format(f); else if (double.IsNaN(f)) return " NaN"; else return " " + Formatter.Format(0.0); // force negative and positive 0 together } else if (o is uint) { uint u = (uint)o; if (el.format.compByteWidth == 4) return String.Format(el.hex ? "{0:X8}" : "{0}", u); if (el.format.compByteWidth == 2) return String.Format(el.hex ? "{0:X4}" : "{0}", u); if (el.format.compByteWidth == 1) return String.Format(el.hex ? "{0:X2}" : "{0}", u); return String.Format("{0}", (uint)o); } else if (o is int) { return String.Format("{0}", (int)o); } return o.ToString(); }
private string ElementString(FormatElement el, object o) { if (o is float) { return Formatter.Format((float)o); } else if (o is uint) { uint u = (uint)o; if (el.format.compByteWidth == 4) String.Format(el.hex ? "{0:X8}" : "{0}", u); if (el.format.compByteWidth == 2) String.Format(el.hex ? "{0:X4}" : "{0}", u); if (el.format.compByteWidth == 1) String.Format(el.hex ? "{0:X2}" : "{0}", u); return String.Format("{0}", (uint)o); } else if (o is int) { return String.Format("{0}", (int)o); } return o.ToString(); }