public static EffectObjectVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version, bool isShared = false) { var result = new EffectObjectVariable(); var nameOffset = variableReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var typeOffset = variableReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); var semanticOffset = variableReader.ReadUInt32(); if (semanticOffset != 0) { var semanticReader = reader.CopyAtOffset((int)semanticOffset); result.Semantic = semanticReader.ReadString(); } else { result.Semantic = ""; } result.BufferOffset = variableReader.ReadUInt32(); if (isShared) { return(result); } // Initializer data if (result.Type.ObjectType == EffectObjectType.String) { for (int i = 0; i < result.ElementCount; i++) { var stringValueOffset = variableReader.ReadUInt32(); var stringValueReader = reader.CopyAtOffset((int)stringValueOffset); result.Strings.Add(stringValueReader.ReadString()); } } if (IfHasAssignments(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { var assignmentCount = variableReader.ReadUInt32(); var assignments = new List <EffectAssignment>(); result.Assignments.Add(assignments); for (int j = 0; j < assignmentCount; j++) { assignments.Add(EffectAssignment.Parse(reader, variableReader)); } } } if (result.Type.ObjectType == EffectObjectType.GeometryShaderWithStream) { for (int i = 0; i < result.ElementCount; i++) { result.GSSOInitializers.Add(EffectGSSOInitializer.Parse(reader, variableReader)); } } else if (IsShader5(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { result.ShaderData5.Add(EffectShaderData5.Parse(reader, variableReader)); } } else if (IsShader(result.Type)) { for (int i = 0; i < result.ElementCount; i++) { result.ShaderData.Add(EffectShaderData.Parse(reader, variableReader)); } } var annotationCount = variableReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version)); } return(result); }
public static EffectType Parse(BytecodeReader reader, BytecodeReader typeReader, ShaderVersion version) { var result = new EffectType(); var typeNameOffset = typeReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)typeNameOffset); result.TypeName = nameReader.ReadString(); //I suspect this is object type, 1 for numeric, 2 for object, 3 for struct result.EffectVariableType = (EffectVariableType)typeReader.ReadUInt32(); result.ElementCount = typeReader.ReadUInt32(); result.UnpackedSize = typeReader.ReadUInt32(); result.Stride = typeReader.ReadUInt32(); result.PackedSize = typeReader.ReadUInt32(); if (result.EffectVariableType == EffectVariableType.Numeric) { var type = result.PackedType = typeReader.ReadUInt32(); 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(); 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(); for (int i = 0; i < result.MemberCount; i++) { result.Members.Add(EffectMember.Parse(reader, typeReader, version)); } if (version.MajorVersion == 5) { result.BaseClassType = typeReader.ReadUInt32(); result.InterfaceCount = typeReader.ReadUInt32(); for (int i = 0; i < result.InterfaceCount; i++) { var interfaceOffset = typeReader.ReadUInt32(); var interfaceReader = reader.CopyAtOffset((int)interfaceOffset); result.InterfaceTypes.Add(EffectType.Parse(reader, interfaceReader, version)); } } } else if (result.EffectVariableType == EffectVariableType.Interface) { result.VariableClass = ShaderVariableClass.InterfaceClass; result.ObjectType = EffectObjectType.Interface; } return(result); }