Пример #1
0
        public static DebugEffectMember Parse(DebugBytecodeReader reader, DebugBytecodeReader memberReader, DebugShaderVersion version)
        {
            var result     = new DebugEffectMember();
            var nameOffset = result.NameOffset = memberReader.ReadUInt32("NameOffset");

            var nameReader = reader.CopyAtOffset("NameReader", memberReader, (int)nameOffset);

            result.Name = nameReader.ReadString("Name");

            result.SemanticNameOffset = memberReader.ReadUInt32("SemanticNameOffset");
            if (result.SemanticNameOffset != 0)
            {
                var semanticNameReader = reader.CopyAtOffset("SemanticNameReader", memberReader, (int)result.SemanticNameOffset);
                result.Semantic = semanticNameReader.ReadString("Semantic");
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = memberReader.ReadUInt32("BufferOffset");
            result.TypeOffset   = memberReader.ReadUInt32("TypeOffset");
            var typeReader = reader.CopyAtOffset("TypeReader", memberReader, (int)result.TypeOffset);

            result.Type = DebugEffectType.Parse(reader, typeReader, version);
            return(result);
        }
Пример #2
0
        public static DebugEffectAnnotation Parse(DebugBytecodeReader reader, DebugBytecodeReader annotationReader, DebugShaderVersion version)
        {
            var result     = new DebugEffectAnnotation();
            var nameOffset = result.NameOffset = annotationReader.ReadUInt32("NameOffset");
            var nameReader = reader.CopyAtOffset("NameReader", reader, (int)nameOffset);

            result.Name = nameReader.ReadString("Name");
            var typeOffset = result.TypeOffset = annotationReader.ReadUInt32("TypeOffset");
            var typeReader = reader.CopyAtOffset("TypeReader", annotationReader, (int)typeOffset);

            result.Type = DebugEffectType.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        = result.ValueOffset = annotationReader.ReadUInt32("ValueOffset");
            var defaultValueReader = reader.CopyAtOffset("DefaultValueReader", annotationReader, (int)valueOffset);

            if (result.Type.EffectVariableType == EffectVariableType.Numeric)
            {
                for (int i = 0; i < result.Type.PackedSize / 4; i++)
                {
                    result.DefaultNumericValue.Add(DebugNumber.Parse(defaultValueReader));
                }
            }
            else
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.DefaultStringValue.Add(defaultValueReader.ReadString($"DefaultValueString{i}"));
                }
            }
            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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }