public static DebugConstantType Parse(DebugBytecodeReader reader, DebugBytecodeReader typeReader) { var result = new DebugConstantType(); result.ParameterClass = typeReader.ReadEnum16 <ParameterClass>("ParameterClass"); result.ParameterType = typeReader.ReadEnum16 <ParameterType>("ParameterType"); result.Rows = typeReader.ReadUInt16("Rows"); result.Columns = typeReader.ReadUInt16("Columns"); result.Elements = typeReader.ReadUInt16("Elements"); result.MemberCount = typeReader.ReadUInt16("Members"); var memberInfoOffset = typeReader.ReadUInt32("MemberInfoOffset"); if (memberInfoOffset != 0) { var memberInfoReader = reader.CopyAtOffset("MemberReader", typeReader, (int)memberInfoOffset); for (int i = 0; i < result.MemberCount; i++) { var nameOffset = memberInfoReader.ReadUInt32($"Member{i}NameOffset"); var nameReader = reader.CopyAtOffset($"Member{i}NameReader", memberInfoReader, (int)nameOffset); nameReader.ReadString("Name"); var typeOffset = memberInfoReader.ReadUInt32($"Member{i}TypeOffset"); var memberTypeReader = reader.CopyAtOffset($"Member{i}TypeReader", memberInfoReader, (int)typeOffset); result.Members.Add(DebugConstantType.Parse(reader, memberTypeReader)); } } return(result); }
public static DebugShaderModel Parse(DebugBytecodeReader reader) { var result = new DebugShaderModel(); result.MinorVersion = reader.ReadByte("MinorVersion"); result.MajorVersion = reader.ReadByte("MajorVersion"); result.Type = reader.ReadEnum16 <ShaderType>("ShaderType"); while (true) { var token = reader.PeakUint32(); Opcode opcode = (Opcode)(token & 0xffff); if (opcode == Opcode.Comment && result.ReadCommentToken(reader)) { continue; } reader.AddIndent($"T{result.Tokens.Count}"); var indent = reader.LocalMembers.OfType <DebugIndent>().Last(); IDebugToken instruction = result.ReadInstruction(reader); result.Tokens.Add(instruction); indent.Name += $" {instruction.Opcode} {string.Join(" ", instruction.Operands)}"; reader.RemoveIndent(); if (instruction.Opcode == Opcode.End) { break; } } return(result); }
public static DebugConstantDeclaration Parse(DebugBytecodeReader reader, DebugBytecodeReader decReader) { var result = new DebugConstantDeclaration(); var nameOffset = decReader.ReadUInt32("NameOffset"); result.RegisterSet = decReader.ReadEnum16 <RegisterSet>("RegisterSet"); result.RegisterIndex = decReader.ReadUInt16("RegisterIndex"); result.RegisterCount = decReader.ReadUInt16("RegisterCount"); decReader.ReadUInt16("Reserved"); var typeInfoOffset = decReader.ReadUInt32("TypeInfoOffset"); var defaultValueOffset = decReader.ReadUInt32("DefaultValueOffset"); var nameReader = reader.CopyAtOffset("NameReader", decReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); var typeReader = reader.CopyAtOffset("TypeReader", decReader, (int)typeInfoOffset); result.Type = DebugConstantType.Parse(reader, typeReader); if (defaultValueOffset != 0) { //Note: thre are corrisponding def instructions. TODO: check that they are the same var defaultValueReader = reader.CopyAtOffset("DefaultValueReader", decReader, (int)defaultValueOffset); var elementCount = result.Type.GetSize() / 4; for (int i = 0; i < elementCount; i++) { result.DefaultValue.Add(defaultValueReader.ReadSingle($"DefaultValue {i}")); } } return(result); }
public static DebugRuntimeConstantMapping Parse(DebugBytecodeReader reader) { var result = new DebugRuntimeConstantMapping(); result.ConstantDescription = reader.ReadEnum16 <RuntimeConstantDescription>("ConstantDescription"); result.TargetReg = reader.ReadUInt16("TargetReg"); return(result); }
public static DebugShaderType Parse(DebugBytecodeReader reader, DebugBytecodeReader typeReader, DebugShaderVersion target, int indent, bool isFirst, uint parentOffset) { var result = new DebugShaderType(indent, isFirst) { VariableClass = typeReader.ReadEnum16 <ShaderVariableClass>("VariableClass"), VariableType = typeReader.ReadEnum16 <ShaderVariableType>("VariableType"), Rows = typeReader.ReadUInt16("Rows"), Columns = typeReader.ReadUInt16("Columns"), ElementCount = typeReader.ReadUInt16("ElementCount") }; var memberCount = typeReader.ReadUInt16("memberCount"); var memberOffset = typeReader.ReadUInt32("memberOffset"); if (target.MajorVersion >= 5) { var subTypeOffset = typeReader.ReadInt32("subTypeOffset"); // Guessing if (subTypeOffset != 0) { var parentInterfaceReader = reader.CopyAtOffset("subtypeReader", typeReader, (int)subTypeOffset); result.SubType = DebugShaderType.Parse(reader, parentInterfaceReader, target, indent + 4, true, parentOffset); } var baseClassOffset = typeReader.ReadUInt32("baseClassOffset"); if (baseClassOffset != 0) { var baseClassReader = reader.CopyAtOffset("baseClassReader", typeReader, (int)baseClassOffset); result.BaseClass = DebugShaderType.Parse(reader, baseClassReader, target, indent + 4, true, parentOffset); } result.NumberOfInterfaces = typeReader.ReadUInt32("NumberOfInterfaces"); var interfaceSectionOffset = typeReader.ReadUInt32("InterfaceSectionOffset"); if (interfaceSectionOffset != 0) { var interfaceSectionReader = reader.CopyAtOffset("interfaceSectionReader", typeReader, (int)interfaceSectionOffset); for (int i = 0; i < result.NumberOfInterfaces; i++) { var interfaceTypeOffset = interfaceSectionReader.ReadUInt32($"UnkInterface{i}"); var interfaceReader = reader.CopyAtOffset($"InterfaceReader {i}", typeReader, (int)interfaceTypeOffset); result.Interfaces.Add(DebugShaderType.Parse(reader, interfaceReader, target, indent + 4, i == 0, parentOffset)); } } var parentNameOffset = typeReader.ReadUInt32("parentNameOffset"); if (parentNameOffset > 0) { var parentNameReader = reader.CopyAtOffset("parentNameOffset", typeReader, (int)parentNameOffset); result.BaseTypeName = parentNameReader.ReadString("BaseTypeName"); } } if (memberCount > 0) { var memberReader = reader.CopyAtOffset("memberReader", typeReader, (int)memberOffset); for (int i = 0; i < memberCount; i++) { memberReader.AddIndent($"Member {i}"); result.Members.Add(DebugShaderTypeMember.Parse(reader, memberReader, target, indent + 4, i == 0, parentOffset)); memberReader.RemoveIndent(); } } if (target.ProgramType == ProgramType.LibraryShader && target.MajorVersion == 4) { var unk1 = typeReader.ReadUInt32("Unk1"); var unk2 = typeReader.ReadUInt32("Unk2"); var unk3 = typeReader.ReadUInt32("Unk3"); var unk4 = typeReader.ReadUInt32("Unk4"); var typeNameOffset = typeReader.ReadUInt32("typeNameoffset"); var typeNameReader = reader.CopyAtOffset("TypeNameReader", typeReader, (int)typeNameOffset); typeNameReader.ReadString("TypeName"); Debug.Assert(unk1 == 0, $"ShaderType.Unk1={unk1}"); Debug.Assert(unk2 == 0, $"ShaderType.Unk2={unk2}"); Debug.Assert(unk3 == 0, $"ShaderType.Unk3={unk3}"); Debug.Assert(unk4 == 0, $"ShaderType.Unk4={unk4}"); } return(result); }