public FormatElement(string Name, int buf, uint offs, bool pi, bool rowMat, uint matDim, ResourceFormat f, bool h) { name = Name; buffer = buf; offset = offs; format = f; perinstance = pi; rowmajor = rowMat; matrixdim = matDim; hex = h; }
public FormatElement() { name = ""; buffer = 0; offset = 0; perinstance = false; rowmajor = false; matrixdim = 0; format = new ResourceFormat(); hex = false; }
public FormatElement(string Name, int buf, uint offs, bool pi, int ir, bool rowMat, uint matDim, ResourceFormat f, bool h) { name = Name; buffer = buf; offset = offs; format = f; perinstance = pi; instancerate = ir; rowmajor = rowMat; matrixdim = matDim; hex = h; systemValue = SystemAttribute.None; }
public FormatElement() { name = ""; buffer = 0; offset = 0; perinstance = false; instancerate = 1; rowmajor = false; matrixdim = 0; format = new ResourceFormat(); hex = false; systemValue = SystemAttribute.None; }
static public FormatElement[] ParseFormatString(string formatString, bool tightPacking, out string errors) { 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" + // bool is stored as 4-byte int in hlsl @"|byte|short|int" + // signed ints @"|ubyte|ushort|uint" + // unsigned ints @"|xbyte|xshort|xint" + // hex ints @"|half|float|double" + // float types @")" + @"([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; errors = ""; 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, ""); uint offset = 0; // 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); bool hex = false; 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" || basetype == "xbyte") { type = FormatComponentType.UInt; width = 1; } else if (basetype == "short") { type = FormatComponentType.SInt; width = 2; } else if (basetype == "ushort" || basetype == "xshort") { type = FormatComponentType.UInt; width = 2; } else if (basetype == "int") { type = FormatComponentType.SInt; width = 4; } else if (basetype == "uint" || basetype == "xint") { 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 (basetype == "xint" || basetype == "xshort" || basetype == "xbyte") hex = true; if (fmt.compType == FormatComponentType.None) fmt = new ResourceFormat(type, count, width); if (arrayCount == 1) { FormatElement elem = new FormatElement(name, 0, offset, false, row_major, matrixCount, fmt, hex); uint advance = elem.ByteSize; if (!tightPacking) { // cbuffer packing always works in floats advance = (advance + 3U) & (~3U); // cbuffer packing doesn't allow elements to cross float4 boundaries, nudge up if this was the case if (offset / 16 != (offset + elem.ByteSize - 1) / 16) { elem.offset = offset = (offset + 0xFU) & (~0xFU); } } elems.Add(elem); offset += advance; } else { // when cbuffer packing, arrays are always aligned at float4 boundary if (!tightPacking) { if (offset % 16 != 0) { offset = (offset + 0xFU) & (~0xFU); } } for (uint a = 0; a < arrayCount; a++) { FormatElement elem = new FormatElement(String.Format("{0}[{1}]", name, a), 0, offset, false, row_major, matrixCount, fmt, hex); elems.Add(elem); uint advance = elem.ByteSize; // cbuffer packing each array element is always float4 aligned if (!tightPacking) { advance = (advance + 0xFU) & (~0xFU); } offset += advance; } } } if (!success || elems.Count == 0) { elems.Clear(); var fmt = new ResourceFormat(FormatComponentType.UInt, 4, 4); elems.Add(new FormatElement("data", 0, 0, false, false, 1, fmt, true)); } return elems.ToArray(); }
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 GetIBuffer(out ResourceId buf, out uint ByteOffset, out ResourceFormat IndexFormat) { if (LogLoaded) { if (IsLogD3D11) { buf = m_D3D11.m_IA.ibuffer.Buffer; ByteOffset = m_D3D11.m_IA.ibuffer.Offset; IndexFormat = m_D3D11.m_IA.ibuffer.Format; return; } else if (IsLogGL) { buf = m_GL.m_VtxIn.ibuffer.Buffer; ByteOffset = m_GL.m_VtxIn.ibuffer.Offset; IndexFormat = m_GL.m_VtxIn.ibuffer.Format; return; } } buf = ResourceId.Null; ByteOffset = 0; IndexFormat = new ResourceFormat(FormatComponentType.UInt, 1, 2); }
private string ModificationValueString(ModificationValue val, ResourceFormat fmt, bool depth) { string s = ""; bool uintTex = (fmt.compType == FormatComponentType.UInt); bool sintTex = (fmt.compType == FormatComponentType.SInt); int numComps = (int)(fmt.compCount); if (!depth) { if (uintTex) { for (int i = 0; i < numComps; i++) s += colourLetterPrefix[i] + val.col.value.u[i].ToString() + "\n"; } else if (sintTex) { for (int i = 0; i < numComps; i++) s += colourLetterPrefix[i] + val.col.value.i[i].ToString() + "\n"; } else { for (int i = 0; i < numComps; i++) s += colourLetterPrefix[i] + Formatter.Format(val.col.value.f[i]) + "\n"; } } if (val.depth >= 0.0f) s += "\nD: " + Formatter.Format(val.depth); else if (val.depth < -1.5f) s += "\nD: ?"; else s += "\nD: -"; if (val.stencil >= 0) s += String.Format("\nS: 0x{0:X2}", val.stencil); else if (val.stencil == -2) s += "\nS: ?"; else s += "\nS: -"; return s; }
private TreelistView.Node MakeFragmentNode(PixelModification mod) { bool uintTex = (texture.format.compType == FormatComponentType.UInt); bool sintTex = (texture.format.compType == FormatComponentType.SInt); bool floatTex = (!uintTex && !sintTex); bool depth = false; if (texture.format.compType == FormatComponentType.Depth || (texture.format.special && texture.format.specialFormat == SpecialFormat.D16S8) || (texture.format.special && texture.format.specialFormat == SpecialFormat.D24S8) || (texture.format.special && texture.format.specialFormat == SpecialFormat.D32S8) || (texture.format.special && texture.format.specialFormat == SpecialFormat.S8)) depth = true; TreelistView.Node node = null; if (mod.uavWrite) { string name = "Potential UAV/Copy write"; string preModVal = "Tex Before\n\n" + ModificationValueString(mod.preMod, texture.format, depth); string postModVal = "Tex After\n\n" + ModificationValueString(mod.postMod, texture.format, depth); if (mod.preMod.col.value.u[0] == mod.postMod.col.value.u[0] && mod.preMod.col.value.u[1] == mod.postMod.col.value.u[1] && mod.preMod.col.value.u[2] == mod.postMod.col.value.u[2] && mod.preMod.col.value.u[3] == mod.postMod.col.value.u[3]) { name += "\nNo change in tex value"; } node = new TreelistView.Node(new object[] { name, preModVal, "", postModVal, "" }); } else { string name = String.Format("Primitive {0}\n", mod.primitiveID); if (mod.shaderDiscarded) name += FailureString(mod); ResourceFormat fmt = new ResourceFormat(floatTex ? FormatComponentType.Float : texture.format.compType, 4, 4); string shadOutVal; string postModVal = "Tex After\n\n" + ModificationValueString(mod.postMod, texture.format, depth); if (mod.unboundPS) shadOutVal = "No Pixel\nShader\nBound"; else shadOutVal = "Shader Out\n\n" + ModificationValueString(mod.shaderOut, fmt, depth); if (!mod.EventPassed() && hideFailedEventsToolStripMenuItem.Checked) return null; node = new TreelistView.Node(new object[] { name, shadOutVal, "", postModVal, "" }); if (mod.shaderDiscarded) node.DefaultBackColor = Color.FromArgb(255, 235, 235); } node.Tag = new EventTag(mod.eventID, mod.uavWrite ? uint.MaxValue : mod.primitiveID); if (floatTex || depth) { node.IndexedBackColor[2] = ModificationValueColor(mod.shaderOut, depth); node.IndexedBackColor[4] = ModificationValueColor(mod.postMod, depth); } return node; }
public ViewTexTag(ResourceFormat f, UInt32 bm, UInt32 bl, UInt32 nm, UInt32 nl, FetchTexture t) { fmt = f; baseMip = bm; baseLayer = bl; numMip = nm; numLayer = nl; tex = t; }