public static EffectAnnotation Parse(BytecodeReader reader, BytecodeReader annotationReader, ShaderVersion version) { var result = new EffectAnnotation(); var nameOffset = annotationReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var typeOffset = annotationReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); //Note: Points to 27 and "foo" in Texture2D tex<int bla=27;string blu="foo";>; /// Value format and stride depends on Type var valueOffset = annotationReader.ReadUInt32(); var defaultValueReader = reader.CopyAtOffset((int)valueOffset); if (result.Type.EffectVariableType == EffectVariableType.Numeric) { for (int i = 0; i < result.Type.PackedSize / 4; i++) { result.DefaultNumericValue.Add(Number.Parse(defaultValueReader)); } } else { for (int i = 0; i < result.ElementCount; i++) { result.DefaultStringValue.Add(defaultValueReader.ReadString()); } } return(result); }
public static EffectMember Parse(BytecodeReader reader, BytecodeReader memberReader, ShaderVersion version) { var result = new EffectMember(); var nameOffset = memberReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); var semanticNameOffset = memberReader.ReadUInt32(); if (semanticNameOffset != 0) { var semanticNameReader = reader.CopyAtOffset((int)semanticNameOffset); result.Semantic = semanticNameReader.ReadString(); } else { result.Semantic = ""; } result.BufferOffset = memberReader.ReadUInt32(); var typeOffset = memberReader.ReadUInt32(); var typeReader = reader.CopyAtOffset((int)typeOffset); result.Type = EffectType.Parse(reader, typeReader, version); return(result); }
internal static EffectInterfaceVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version) { var result = new EffectInterfaceVariable(); 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); //Pointer to InterfaceInitializer var defaultValueOffset = variableReader.ReadUInt32(); var initializerReader = reader.CopyAtOffset((int)defaultValueOffset); var instanceNameOffset = initializerReader.ReadUInt32(); var instanceNameReader = reader.CopyAtOffset((int)instanceNameOffset); result.InstanceName = instanceNameReader.ReadString(); result.Flags = variableReader.ReadUInt32(); var annotationCount = variableReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version)); } return(result); }
internal static EffectNumericVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version, bool isShared) { var result = new EffectNumericVariable(); 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 = result.SemanticOffset = variableReader.ReadUInt32(); if (semanticOffset != 0) { var semanticReader = reader.CopyAtOffset((int)semanticOffset); result.Semantic = semanticReader.ReadString(); } else { result.Semantic = ""; } result.BufferOffset = variableReader.ReadUInt32(); var defaultValueOffset = variableReader.ReadUInt32(); List <Number> defaultValue = null; var size = result.Type.PackedSize; if (defaultValueOffset != 0) { defaultValue = new List <Number>(); var defaultValueReader = reader.CopyAtOffset((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(4))); } } result.DefaultValue = defaultValue; if (!isShared) { result.ExplicitBindPoint = variableReader.ReadUInt32(); } var annotationCount = variableReader.ReadUInt32(); for (int i = 0; i < annotationCount; i++) { result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version)); } return(result); }
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); }