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 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); }
public static DebugFxlc Parse(DebugBytecodeReader reader, uint size) { var result = new DebugFxlc(); var basePosition = reader._reader.BaseStream.Position; var tokenCount = reader.ReadUInt32("TokenCount"); for (int i = 0; i < tokenCount; i++) { var token = reader.PeakUint32(); var type = (FxlcOpcode)token.DecodeValue(20, 30); reader.AddIndent($"Token{i}({type})"); result.Tokens.Add(DebugFxlcToken.Parse(reader)); reader.RemoveIndent(); } var padding = reader.ReadBytes($"Padding", 8); var paddingUint64 = BitConverter.ToInt64(padding, 0); var expected = 0x0F0F0f0FF0F0F0F0; Debug.Assert(paddingUint64 == expected); return(result); }
public static DebugBinaryData Parse(DebugBytecodeReader reader, DebugBytecodeReader blobReader) { var result = new DebugBinaryData(); result.Index = blobReader.ReadUInt32("Index"); result.Size = blobReader.ReadUInt32("Size"); var startPosition = blobReader._reader.BaseStream.Position; var header = blobReader.PeakUint32(); var shaderType = (ShaderType)(header >> 16); var paddedSize = result.Size + (result.Size % 4 == 0 ? 0 : 4 - result.Size % 4); if (shaderType == ShaderType.Pixel || shaderType == ShaderType.Vertex || shaderType == ShaderType.Expression) { var shaderReader = blobReader.CopyAtCurrentPosition("ShaderReader", blobReader); result.Shader = DebugShaderModel.Parse(shaderReader); } else if (result.Size > 0) { blobReader.ReadBytes("Value", (int)paddedSize); } blobReader._reader.BaseStream.Position = startPosition + paddedSize; return(result); }