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);
        }
Exemple #2
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);
        }