protected void ParseInstance(DebugBytecodeReader reader, uint chunkSize) { Version = DebugShaderVersion.ParseShex(reader); var sizeInUint32 = reader.ReadUInt32("SizeInUint32"); var dxilMagic = reader.ReadUInt32("DxilMagic"); DxilVersion = reader.ReadUInt32("DxilVersion"); var bitcodeOffset = reader.ReadUInt32("BitcodeOffset"); var bitcodeLength = reader.ReadInt32("BitcodeLength"); var bitcodeReader = reader.CopyAtCurrentPosition("BitcodeReader", reader); Bitcode = bitcodeReader.ReadBytes("Bitcode", bitcodeLength); }
public static DebugShaderProgramChunk Parse(DebugBytecodeReader reader) { var program = new DebugShaderProgramChunk { Version = DebugShaderVersion.ParseShex(reader), Length = reader.ReadUInt32("Length") }; while (!reader.EndOfBuffer) { var opcodeIndex = program.Tokens.Count; var opcodeToken0 = reader.PeakUint32(); var opcodeHeader = new DebugOpcodeHeader { OpcodeType = opcodeToken0.DecodeValue <OpcodeType>(0, 10), Length = opcodeToken0.DecodeValue(24, 30), IsExtended = (opcodeToken0.DecodeValue(31, 31) == 1) }; DebugOpcodeToken opcodeToken = null; if (opcodeHeader.Length == 0 && opcodeHeader.OpcodeType != OpcodeType.CustomData) { throw new Exception("Error parsing shader"); } if (opcodeHeader.OpcodeType == OpcodeType.CustomData) { //opcodeToken = DebugCustomDataToken.Parse(reader, opcodeToken0); var customDataClass = opcodeToken0.DecodeValue <CustomDataClass>(11, 31); var length = reader.PeakUInt32Ahead(4); if (length == 0) { throw new Exception("Error parsing shader"); } var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType}-{customDataClass})", (int)length * 4); } else if (opcodeHeader.OpcodeType.IsDeclaration()) { var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4); } else // Not custom data or declaration, so must be instruction. { var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4); } program.Tokens.Add(opcodeToken); } return(program); }
public static DebugShaderProgramChunk Parse(DebugBytecodeReader reader) { var program = new DebugShaderProgramChunk { Version = DebugShaderVersion.ParseShex(reader), Length = reader.ReadUInt32("Length") }; while (!reader.EndOfBuffer) { var opcodeIndex = program.Tokens.Count; var opcodeToken0 = reader.PeakUint32(); var opcodeHeader = new DebugOpcodeHeader { OpcodeType = opcodeToken0.DecodeValue <OpcodeType>(0, 10), Length = opcodeToken0.DecodeValue(24, 30), IsExtended = (opcodeToken0.DecodeValue(31, 31) == 1) }; reader.AddIndent(opcodeHeader.OpcodeType.ToString()); if (opcodeHeader.Length == 0 && opcodeHeader.OpcodeType != OpcodeType.CustomData) { throw new Exception("Error parsing shader"); } DebugOpcodeToken opcodeToken; if (opcodeHeader.OpcodeType == OpcodeType.CustomData) { opcodeToken = DebugCustomDataToken.Parse(reader, opcodeToken0); } else if (opcodeHeader.OpcodeType.IsDeclaration()) { opcodeToken = DebugDeclarationToken.Parse(reader, opcodeHeader.OpcodeType, program.Version); } else // Not custom data or declaration, so must be instruction. { opcodeToken = DebugInstructionToken.Parse(reader, opcodeHeader); } program.Tokens.Add(opcodeToken); reader.RemoveIndent(); } return(program); }