public static DebugEffectTechnique Parse(DebugBytecodeReader reader, DebugBytecodeReader techniqueReader, DebugShaderVersion version) { var result = new DebugEffectTechnique(version); var nameOffset = result.NameOffset = techniqueReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", techniqueReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); result.PassCount = techniqueReader.ReadUInt32("PassCount"); result.AnnotationCount = techniqueReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { techniqueReader.AddIndent("Annotation"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, techniqueReader, version)); techniqueReader.RemoveIndent(); } for (int i = 0; i < result.PassCount; i++) { techniqueReader.AddIndent($"Pass {i}"); result.Passes.Add(DebugEffectPass.Parse(reader, techniqueReader, version)); techniqueReader.RemoveIndent(); } return(result); }
public static DebugEffectGroup Parse(DebugBytecodeReader reader, DebugBytecodeReader groupReader, DebugShaderVersion version) { var result = new DebugEffectGroup(); result.NameOffset = groupReader.ReadUInt32("NameOffset"); result.TechniqueCount = groupReader.ReadUInt32("TechniqueCount"); result.AnnotationCount = groupReader.ReadUInt32("AnnotationCount"); if (result.NameOffset != 0) { var nameReader = reader.CopyAtOffset("NameReader", groupReader, (int)result.NameOffset); result.Name = nameReader.ReadString("Name"); } else { result.Name = ""; } for (int i = 0; i < result.TechniqueCount; i++) { groupReader.AddIndent($"Technique {i}"); result.Techniques.Add(DebugEffectTechnique.Parse(reader, groupReader, version)); groupReader.RemoveIndent(); } for (int i = 0; i < result.AnnotationCount; i++) { groupReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, groupReader, version)); groupReader.RemoveIndent(); } 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 DebugEffectBuffer Parse(DebugBytecodeReader reader, DebugBytecodeReader bufferReader, DebugShaderVersion version, bool isShared) { var result = new DebugEffectBuffer(); var nameOffset = result.NameOffset = bufferReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", bufferReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); result.BufferSize = bufferReader.ReadUInt32("BufferSize"); result.BufferType = (ConstantBufferType)bufferReader.ReadUInt32("BufferType"); result.VariableCount = bufferReader.ReadUInt32("VariableCount"); result.RegisterNumber = bufferReader.ReadUInt32("RegisterNumber"); if (!isShared) { result.Unknown0 = bufferReader.ReadUInt32("Unknown0"); } //TODO: Unknown0 //Debug.Assert(result.Unknown0 == 0, $"EffectBuffer.Unknown0: {result.Unknown0}"); for (int i = 0; i < result.VariableCount; i++) { bufferReader.AddIndent($"BufferVariable {i}"); result.Variables.Add(DebugEffectNumericVariable.Parse(reader, bufferReader, version, isShared)); bufferReader.RemoveIndent(); } return(result); }
internal static DebugEffectInterfaceVariable Parse(DebugBytecodeReader reader, DebugBytecodeReader variableReader, DebugShaderVersion version) { var result = new DebugEffectInterfaceVariable(); var nameOffset = result.NameOffset = variableReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", variableReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); var typeOffset = result.TypeOffset = variableReader.ReadUInt32("TypeOffset"); var typeReader = reader.CopyAtOffset("TypeReader", variableReader, (int)typeOffset); result.Type = DebugEffectType.Parse(reader, typeReader, version); //Pointer to InterfaceInitializer result.DefaultValueOffset = variableReader.ReadUInt32("DefaultValueOffset"); var initializerReader = reader.CopyAtOffset("InitializerReader", variableReader, (int)result.DefaultValueOffset); var instanceNameOffset = result.InstanceNameOffset = initializerReader.ReadUInt32("InstanceNameOffset"); var instanceNameReader = reader.CopyAtOffset("InstanceNameReader", variableReader, (int)instanceNameOffset); result.InstanceName = instanceNameReader.ReadString("InstanceName"); result.Flags = variableReader.ReadUInt32("Flags"); result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { variableReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, variableReader, version)); variableReader.RemoveIndent(); } return(result); }
internal static DebugEffectNumericVariable Parse(DebugBytecodeReader reader, DebugBytecodeReader variableReader, DebugShaderVersion version, bool isShared) { var result = new DebugEffectNumericVariable(); var nameOffset = result.NameOffset = variableReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", variableReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); var typeOffset = result.TypeOffset = variableReader.ReadUInt32("TypeOffset"); var typeReader = reader.CopyAtOffset("TypeReader", variableReader, (int)typeOffset); result.Type = DebugEffectType.Parse(reader, typeReader, version); var semanticOffset = result.SemanticOffset = variableReader.ReadUInt32("SemeanticOffset"); if (semanticOffset != 0) { var semanticReader = reader.CopyAtOffset("SemanticReader", variableReader, (int)semanticOffset); result.Semantic = semanticReader.ReadString("Semantic"); } else { result.Semantic = ""; } result.BufferOffset = variableReader.ReadUInt32("BufferOffset"); var defaultValueOffset = result.DefaultValueOffset = variableReader.ReadUInt32("DefaultValueOffset"); List <Number> defaultValue = null; var size = result.Type.PackedSize; if (defaultValueOffset != 0) { defaultValue = new List <Number>(); var defaultValueReader = reader.CopyAtOffset("DefaultValueReader", variableReader, (int)defaultValueOffset); if (size % 4 != 0) { throw new ParseException("Can only deal with 4-byte default values at the moment."); } for (int i = 0; i < size; i += 4) { defaultValue.Add(new Number(defaultValueReader.ReadBytes("Number", 4))); } } result.DefaultValue = defaultValue; if (!isShared) { result.ExplicitBindPoint = variableReader.ReadUInt32("ExplicitBindPoint"); //TODO: Unknown1 //Debug.Assert(result.Unknown1 == 0, $"EffectBufferVariable.Unknown1 {result.Unknown1}"); } result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { variableReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, variableReader, version)); variableReader.RemoveIndent(); } return(result); }
bool ReadCommentToken(DebugBytecodeReader reader) { var fourCC = reader.PeakUInt32Ahead(4); if (KnownCommentTypes.ContainsKey(fourCC)) { reader.AddIndent(KnownCommentTypes[fourCC].ToString()); } else { return(false); } var instructionToken = reader.ReadUInt32("Token"); var startPosition = reader._reader.BaseStream.Position; var entry = reader.Members.Last(); Opcode opcode = (Opcode)(instructionToken & 0xffff); entry.AddNote("TokenOpcode", opcode.ToString()); var size = (int)((instructionToken >> 16) & 0x7FFF); entry.AddNote("TokenSize", size.ToString()); reader.ReadBytes("FourCC", 4); switch (KnownCommentTypes[fourCC]) { case CommentType.CTAB: ConstantTable = DebugConstantTable.Parse(reader); break; case CommentType.C**T: Cli = DebugCliToken.Parse(reader); break; case CommentType.FXLC: Fxlc = DebugFxlc.Parse(reader, (uint)size * 4); break; case CommentType.PRES: Preshader = DebugPreshader.Parse(reader); break; case CommentType.PRSI: Prsi = DebugPrsiToken.Parse(reader, (uint)size); break; default: return(false); } reader.RemoveIndent(); reader._reader.BaseStream.Position = startPosition + size * 4; return(true); }
public static DebugSamplerState Parse(DebugBytecodeReader reader, DebugBytecodeReader stateReader) { var result = new DebugSamplerState(); var assignmentCount = stateReader.ReadUInt32("AssignmentCount"); for (int j = 0; j < assignmentCount; j++) { stateReader.AddIndent($"Assignment {j}"); result.Assignments.Add(DebugAssignment.Parse(reader, stateReader)); stateReader.RemoveIndent(); } return(result); }
public static DebugEffectPass Parse(DebugBytecodeReader reader, DebugBytecodeReader passReader, DebugShaderVersion version) { var result = new DebugEffectPass(); var nameOffset = result.NameOffset = passReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", passReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); result.ShaderCount = passReader.ReadUInt32("ShaderCount"); result.AnnotationCount = passReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { passReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, passReader, version)); passReader.RemoveIndent(); } for (int i = 0; i < result.ShaderCount; i++) { passReader.AddIndent($"Shader {i}"); result.Assignments.Add(DebugEffectAssignment.Parse(reader, passReader)); passReader.RemoveIndent(); } return(result); }
public static DebugPass Parse(DebugBytecodeReader reader, DebugBytecodeReader passReader) { var result = new DebugPass(); result.NameOffset = passReader.ReadUInt32("NameOffset"); result.AnnotationCount = passReader.ReadUInt32("AnnoationCount"); result.AssignmentCount = passReader.ReadUInt32("AssignmentCount"); for (int i = 0; i < result.AnnotationCount; i++) { passReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugAnnotation.Parse(reader, passReader)); passReader.RemoveIndent(); } for (int i = 0; i < result.AssignmentCount; i++) { passReader.AddIndent($"Assignment {i}"); result.Assignments.Add(DebugAssignment.Parse(reader, passReader)); passReader.RemoveIndent(); } var nameReader = reader.CopyAtOffset("NameReader", passReader, (int)result.NameOffset); result.Name = nameReader.TryReadString("Name"); return(result); }
public static DebugTechnique Parse(DebugBytecodeReader reader, DebugBytecodeReader techniqueReader) { var result = new DebugTechnique(); result.NameOffset = techniqueReader.ReadUInt32("NameOffset"); result.AnnotationCount = techniqueReader.ReadUInt32("AnnotationCount"); result.PassCount = techniqueReader.ReadUInt32("PassCount"); for (int i = 0; i < result.AnnotationCount; i++) { techniqueReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugAnnotation.Parse(reader, techniqueReader)); techniqueReader.RemoveIndent(); } for (int i = 0; i < result.PassCount; i++) { techniqueReader.AddIndent($"Pass {i}"); result.Passes.Add(DebugPass.Parse(reader, techniqueReader)); techniqueReader.RemoveIndent(); } var nameReader = reader.CopyAtOffset("NameReader", techniqueReader, (int)result.NameOffset); result.Name = nameReader.TryReadString("Name"); 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) }; 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); }
/* * PRSI Tokens map preshader outputs to ConstantBuffer addresses * */ /* * maps * 0 => 0 * 1 => 4 * 1 => 2 * // add expr0, l12(0), g1 * // add expr8, l12(0), g3 * // add expr16, l12(0), g5 * * * // * // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 * // * // Parameters: * // * // float4 g1; * // float4 g3; * // float4 g5; * // * // * // Registers: * // * // Name Reg Size * // ------------ ----- ---- * // g1 c0 1 * // g3 c1 1 * // g5 c2 1 * // * * preshader * add c0, (5, 5, 5, 5), c0 * add c2, (5, 5, 5, 5), c1 * add c4, (5, 5, 5, 5), c2 * * // approximately 3 instructions used * // * // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 * vs_2_0 * def c5, 0, 0, 0, 0 * mov oPos, c0 * mov oD0, c5.x * mov oD1, c2 * mov oT0, c5.x * mov oT1, c4 * * // approximately 5 instruction slots used * }; */ public static DebugPrsiToken Parse(DebugBytecodeReader reader, uint size) { var result = new DebugPrsiToken(); Debug.Assert(size > 6, "PRSI size too small"); // Preshader outputs begin at this offset // eg RegisterOffset = 10 //preshader //mul c10.xyz, c0.xyz, c1.xyz var outputRegisterOffset = reader.ReadUInt32("RegisterOffset"); var unk1 = reader.ReadUInt32("Unk1"); var unk2 = reader.ReadUInt32("Unk2"); var outputRegisterCount = reader.ReadUInt32("OutputRegisterCount?"); var unk3 = reader.ReadUInt32("Unk3"); var unk4 = reader.ReadUInt32("Unk4"); var mappingCount = reader.ReadUInt32("MappingCount"); var unk5 = reader.ReadUInt32("Unk5"); var unk6 = reader.ReadUInt32("Unk6"); Debug.Assert(unk1 == 0, $"unk1={unk1}"); Debug.Assert(unk2 == 0, $"unk2={unk2}"); Debug.Assert(unk3 == 0, $"unk3={unk3}"); Debug.Assert(unk4 == 0, $"unk4={unk4}"); Debug.Assert(unk5 == outputRegisterOffset, $"unk5 ({unk5}) and OutputRegisterOffset ({outputRegisterOffset}) differ"); //Debug.Assert(unk6 == outputRegisterCount, // $"unk6 ({unk6}) and OutputRegisterCount ({outputRegisterCount}) differ"); for (int i = 0; i < mappingCount; i++) { reader.AddIndent($"Mapping{i}"); reader.ReadUInt32("ConstOutput"); reader.ReadUInt32("ConstInput"); reader.RemoveIndent(); } //if(size != 12) throw new System.Exception($"PRSI TOKEN Size {size}"); //Debug.Assert(true, "PRSI Token"); return(result); }
public static DebugVariable Parse(DebugBytecodeReader reader, DebugBytecodeReader variableReader) { var result = new DebugVariable(); result.ParameterOffset = variableReader.ReadUInt32("ParameterOffset"); result.DefaultValueOffset = variableReader.ReadUInt32("DefaultValueOffset"); result.IsShared = variableReader.ReadUInt32("IsShared"); result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { variableReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugAnnotation.Parse(reader, variableReader)); variableReader.RemoveIndent(); } var paramterReader = reader.CopyAtOffset("ParameterReader", variableReader, (int)result.ParameterOffset); result.Parameter = DebugParameter.Parse(reader, paramterReader); if (result.Parameter.ParameterType.IsSampler()) { var elementCount = result.Parameter.Elements > 0 ? result.Parameter.Elements : 1; var samplerStateReader = reader.CopyAtOffset("SamplerStateReader", variableReader, (int)result.DefaultValueOffset); for (int i = 0; i < elementCount; i++) { samplerStateReader.AddIndent($"SamplerState {i}"); result.SamplerStates.Add(DebugSamplerState.Parse(reader, samplerStateReader)); samplerStateReader.RemoveIndent(); } } else { var valueReader = reader.CopyAtOffset("ValueReader", variableReader, (int)result.DefaultValueOffset); result.Value = result.Parameter.ReadParameterValue(valueReader); } return(result); }
public static DebugInstructionToken Parse(DebugBytecodeReader reader, DebugOpcodeHeader header) { var instructionToken = new DebugInstructionToken(); // Advance to next token. var instructionEnd = reader.CurrentPosition + (header.Length * sizeof(uint)); var token0 = reader.ReadUInt32("token0"); DebugOpcodeHeader.AddNotes(reader, token0); if (header.OpcodeType == OpcodeType.Sync) { instructionToken.SyncFlags = token0.DecodeValue <SyncFlags>(11, 14); reader.AddNote("SyncFlags", instructionToken.SyncFlags); } else { instructionToken.ResInfoReturnType = token0.DecodeValue <ResInfoReturnType>(11, 12); instructionToken.Saturate = (token0.DecodeValue(13, 13) == 1); instructionToken.TestBoolean = token0.DecodeValue <InstructionTestBoolean>(18, 18); instructionToken.PreciseValueMask = token0.DecodeValue <ComponentMask>(19, 22); reader.AddNote("ResInfoReturnType", instructionToken.ResInfoReturnType); reader.AddNote("Saturate", instructionToken.Saturate); reader.AddNote("TestBoolean", instructionToken.TestBoolean); reader.AddNote("PreciseValueMask", instructionToken.PreciseValueMask); } bool extended = header.IsExtended; while (extended) { uint extendedToken = reader.ReadUInt32("extendedToken"); var extendedType = extendedToken.DecodeValue <InstructionTokenExtendedType>(0, 5); reader.AddNote("extendedType", extendedType); instructionToken.ExtendedTypes.Add(extendedType); extended = (extendedToken.DecodeValue(31, 31) == 1); reader.AddNote("extended", extended); switch (extendedType) { case InstructionTokenExtendedType.SampleControls: instructionToken.SampleOffsets[0] = extendedToken.DecodeSigned4BitValue(09, 12); instructionToken.SampleOffsets[1] = extendedToken.DecodeSigned4BitValue(13, 16); instructionToken.SampleOffsets[2] = extendedToken.DecodeSigned4BitValue(17, 20); reader.AddNote("SampleOffsets[0]", instructionToken.SampleOffsets[0]); reader.AddNote("SampleOffsets[1]", instructionToken.SampleOffsets[1]); reader.AddNote("SampleOffsets[2]", instructionToken.SampleOffsets[2]); break; case InstructionTokenExtendedType.ResourceDim: instructionToken.ResourceTarget = extendedToken.DecodeValue <ResourceDimension>(6, 10); instructionToken.ResourceStride = extendedToken.DecodeValue <ushort>(11, 22); reader.AddNote("ResourceTarget", instructionToken.ResourceTarget); reader.AddNote("ResourceStride", instructionToken.ResourceStride); break; case InstructionTokenExtendedType.ResourceReturnType: instructionToken.ResourceReturnTypes[0] = extendedToken.DecodeValue <ResourceReturnType>(06, 09); instructionToken.ResourceReturnTypes[1] = extendedToken.DecodeValue <ResourceReturnType>(10, 13); instructionToken.ResourceReturnTypes[2] = extendedToken.DecodeValue <ResourceReturnType>(14, 17); instructionToken.ResourceReturnTypes[3] = extendedToken.DecodeValue <ResourceReturnType>(18, 21); reader.AddNote("ResourceReturnTypes[0]", instructionToken.ResourceReturnTypes[0]); reader.AddNote("ResourceReturnTypes[1]", instructionToken.ResourceReturnTypes[1]); reader.AddNote("ResourceReturnTypes[2]", instructionToken.ResourceReturnTypes[2]); reader.AddNote("ResourceReturnTypes[3]", instructionToken.ResourceReturnTypes[3]); break; default: throw new ParseException("Unrecognised extended type: " + extendedType); } } if (header.OpcodeType == OpcodeType.InterfaceCall) { instructionToken.FunctionIndex = reader.ReadUInt32("FunctionIndex"); } while (reader.CurrentPosition < instructionEnd) { reader.AddIndent($"Operand{instructionToken.Operands.Count}"); var operand = DebugOperand.Parse(reader, header.OpcodeType); if (operand != null) { instructionToken.Operands.Add(operand); } reader.RemoveIndent(); } return(instructionToken); }
public static DebugEffectType Parse(DebugBytecodeReader reader, DebugBytecodeReader typeReader, DebugShaderVersion version) { var result = new DebugEffectType(); var typeNameOffset = result.TypeNameOffset = typeReader.ReadUInt32("TypeNameOffset"); var nameReader = reader.CopyAtOffset("NameReader", typeReader, (int)typeNameOffset); result.TypeName = nameReader.ReadString("TypeName"); result.EffectVariableType = typeReader.ReadEnum32 <EffectVariableType>("EffectVariableType"); result.ElementCount = typeReader.ReadUInt32("ElementCount"); result.UnpackedSize = typeReader.ReadUInt32("UnpackedSize"); result.Stride = typeReader.ReadUInt32("Stride"); result.PackedSize = typeReader.ReadUInt32("PackedSize"); if (result.EffectVariableType == EffectVariableType.Numeric) { var type = result.PackedType = typeReader.ReadUInt32("PackedType"); var numericType = result.NumericType = EffectNumericType.Parse(type); switch (numericType.NumericLayout) { case EffectNumericLayout.Scalar: result.VariableClass = ShaderVariableClass.Scalar; break; case EffectNumericLayout.Vector: result.VariableClass = ShaderVariableClass.Vector; break; case EffectNumericLayout.Matrix: result.VariableClass = type.DecodeValue(14, 14) == 1 ? ShaderVariableClass.MatrixColumns : ShaderVariableClass.MatrixRows; break; } switch (numericType.ScalarType) { case EffectScalarType.Float: result.ObjectType = EffectObjectType.Float; break; case EffectScalarType.Int: result.ObjectType = EffectObjectType.Int; break; case EffectScalarType.UInt: result.ObjectType = EffectObjectType.UInt; break; case EffectScalarType.Bool: result.ObjectType = EffectObjectType.Bool; break; } } else if (result.EffectVariableType == EffectVariableType.Object) { var type = result.PackedType = typeReader.ReadUInt32("PackedType"); result.VariableClass = ShaderVariableClass.Object; result.ObjectType = (EffectObjectType)type; } else if (result.EffectVariableType == EffectVariableType.Struct) { result.ObjectType = EffectObjectType.Void; result.VariableClass = ShaderVariableClass.Struct; result.MemberCount = typeReader.ReadUInt32("MemberCount"); for (int i = 0; i < result.MemberCount; i++) { typeReader.AddIndent($"Member {i}"); result.Members.Add(DebugEffectMember.Parse(reader, typeReader, version)); typeReader.RemoveIndent(); } if (version.MajorVersion == 5) { result.BaseClassType = typeReader.ReadUInt32("BaseClassType"); result.InterfaceCount = typeReader.ReadUInt32("InterfaceCount"); for (int i = 0; i < result.InterfaceCount; i++) { var interfaceOffset = typeReader.ReadUInt32($"InterfaceOffset{i}"); var interfaceReader = reader.CopyAtOffset($"Interface{i}", typeReader, (int)interfaceOffset); result.InterfaceTypes.Add(DebugEffectType.Parse(reader, interfaceReader, version)); } } } else if (result.EffectVariableType == EffectVariableType.Interface) { result.VariableClass = ShaderVariableClass.InterfaceClass; result.ObjectType = EffectObjectType.Interface; } return(result); }
public static DebugEffectObjectVariable Parse(DebugBytecodeReader reader, DebugBytecodeReader variableReader, DebugShaderVersion version, bool isShared = false) { var result = new DebugEffectObjectVariable(); var nameOffset = result.NameOffset = variableReader.ReadUInt32("NameOffset"); var nameReader = reader.CopyAtOffset("NameReader", variableReader, (int)nameOffset); result.Name = nameReader.ReadString("Name"); result.TypeOffset = variableReader.ReadUInt32("TypeOffset"); var typeReader = reader.CopyAtOffset("TypeReader", variableReader, (int)result.TypeOffset); result.Type = DebugEffectType.Parse(reader, typeReader, version); var semanticOffset = result.SemanticOffset = variableReader.ReadUInt32("SemanticOffset"); if (semanticOffset != 0) { var semanticReader = reader.CopyAtOffset("SemanticReader", variableReader, (int)semanticOffset); result.Semantic = semanticReader.ReadString("Semantic"); } else { result.Semantic = ""; } result.BufferOffset = variableReader.ReadUInt32("BufferOffset"); if (isShared) { return(result); } // Initializer data if (result.Type.ObjectType == EffectObjectType.String) { for (int i = 0; i < result.ElementCount; i++) { var stringValueOffset = variableReader.ReadUInt32($"StringValueOffset{i}"); var stringValueReader = reader.CopyAtOffset($"StringValueReader{i}", variableReader, (int)stringValueOffset); result.Strings.Add(stringValueReader.ReadString($"StringValue{i}")); } } if (IfHasAssignments(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { var assignmentCount = variableReader.ReadUInt32($"AssignmentCount{i}"); var assignments = new List <DebugEffectAssignment>(); result.Assignments.Add(assignments); for (int j = 0; j < assignmentCount; j++) { variableReader.AddIndent($"Assignment {i}"); assignments.Add(DebugEffectAssignment.Parse(reader, variableReader)); variableReader.RemoveIndent(); } } } if (result.Type.ObjectType == EffectObjectType.GeometryShaderWithStream) { for (int i = 0; i < result.ElementCount; i++) { variableReader.AddIndent($"GSSOInitializer {i}"); result.GSSOInitializers.Add(DebugEffectGSSOInitializer.Parse(reader, variableReader)); variableReader.RemoveIndent(); } } else if (IsShader5(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { variableReader.AddIndent($"ShaderData5 {i}"); result.ShaderData5.Add(DebugEffectShaderData5.Parse(reader, variableReader)); variableReader.RemoveIndent(); } } else if (IsShader(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { variableReader.AddIndent($"ShaderData {i}"); result.ShaderData.Add(DebugEffectShaderData.Parse(reader, variableReader)); variableReader.RemoveIndent(); } } result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount"); for (int i = 0; i < result.AnnotationCount; i++) { variableReader.AddIndent($"Annotation {i}"); result.Annotations.Add(DebugEffectAnnotation.Parse(reader, variableReader, version)); variableReader.RemoveIndent(); } return(result); }