Exemple #1
0
        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);
        }
Exemple #2
0
        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)
                };
                DebugOpcodeToken opcodeToken = null;
                if (opcodeHeader.Length == 0 && opcodeHeader.OpcodeType != OpcodeType.CustomData)
                {
                    throw new Exception("Error parsing shader");
                }
                if (opcodeHeader.OpcodeType == OpcodeType.CustomData)
                {
                    //opcodeToken = DebugCustomDataToken.Parse(reader, opcodeToken0);
                    var customDataClass = opcodeToken0.DecodeValue <CustomDataClass>(11, 31);
                    var length          = reader.PeakUInt32Ahead(4);
                    if (length == 0)
                    {
                        throw new Exception("Error parsing shader");
                    }
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType}-{customDataClass})", (int)length * 4);
                }
                else if (opcodeHeader.OpcodeType.IsDeclaration())
                {
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4);
                }
                else                 // Not custom data or declaration, so must be instruction.
                {
                    var data = reader.ReadBytes($"Opcode{opcodeIndex}({opcodeHeader.OpcodeType})", (int)opcodeHeader.Length * 4);
                }
                program.Tokens.Add(opcodeToken);
            }
            return(program);
        }
        public static DebugBytecodeChunk Parse(DebugBytecodeReader reader, uint chunkSize)
        {
            var size  = chunkSize / sizeof(uint);
            var magic = reader.PeakUInt32Ahead(8);

            if (magic == "DXIL".ToFourCc())
            {
                return(Dxil.DebugDxilReflectionChunk.Parse(reader, chunkSize));
            }
            var result = new DebugStatisticsChunk
            {
                InstructionCount            = reader.ReadUInt32("InstructionCount"),
                TempRegisterCount           = reader.ReadUInt32("TempRegisterCount"),
                DefineCount                 = reader.ReadUInt32("DefineCount"),
                DeclarationCount            = reader.ReadUInt32("DeclarationCount"),
                FloatInstructionCount       = reader.ReadUInt32("FloatInstructionCount"),
                IntInstructionCount         = reader.ReadUInt32("IntInstructionCount"),
                UIntInstructionCount        = reader.ReadUInt32("UIntInstructionCount"),
                StaticFlowControlCount      = reader.ReadUInt32("StaticFlowControlCount"),
                DynamicFlowControlCount     = reader.ReadUInt32("DynamicFlowControlCount"),
                MacroInstructionCount       = reader.ReadUInt32("MacroInstructionCount"),           // Guessed
                TempArrayCount              = reader.ReadUInt32("TempArrayCount"),
                ArrayInstructionCount       = reader.ReadUInt32("ArrayInstructionCount"),
                CutInstructionCount         = reader.ReadUInt32("CutInstructionCount"),
                EmitInstructionCount        = reader.ReadUInt32("EmitInstructionCount"),
                TextureNormalInstructions   = reader.ReadUInt32("TextureNormalInstructions"),
                TextureLoadInstructions     = reader.ReadUInt32("TextureLoadInstructions"),
                TextureCompInstructions     = reader.ReadUInt32("TextureCompInstructions"),
                TextureBiasInstructions     = reader.ReadUInt32("TextureBiasInstructions"),
                TextureGradientInstructions = reader.ReadUInt32("TextureGradientInstructions"),
                MovInstructionCount         = reader.ReadUInt32("MovInstructionCount"),
                MovCInstructionCount        = reader.ReadUInt32("MovCInstructionCount"),
                ConversionInstructionCount  = reader.ReadUInt32("ConversionInstructionCount")
            };

            //TODO
            var unknown0 = reader.ReadUInt32("StatisticsChunkUnknown0");

            result.InputPrimitive = (Primitive)reader.ReadUInt32("InputPrimitive");
            result.GeometryShaderOutputTopology       = reader.ReadEnum32 <PrimitiveTopology>("GeometryShaderOutputTopology");
            result.GeometryShaderMaxOutputVertexCount = reader.ReadUInt32("GeometryShaderMaxOutputVertexCount");

            var unknown1 = reader.ReadUInt32("StatisticsChunkUnknown1");
            //if (unknown1 == 0 || unknown1 == 1 || unknown1 == 3) throw new System.Exception($"unknown1 is {unknown1}");
            //TODO: CheckAccessFullyMapped textures have large unknown1
            //Texture_Texture2D, Texture_Texture2DArray, Texture_TextureCube, Texture_TextureCubeArray

            var unknown2 = reader.ReadUInt32("StatisticsChunkUnknown2");

            //if (unknown2 != 0 && unknown2 != 2) throw new System.Exception($"unknown2 is {unknown2}");

            result.IsSampleFrequencyShader = (reader.ReadUInt32("IsSampleFrequencyShader") == 1);

            // DX10 stat size
            if (size == 29)
            {
                return(result);
            }

            result.GeometryShaderInstanceCount = reader.ReadUInt32("GeometryShaderInstanceCount");
            result.ControlPoints             = reader.ReadUInt32("ControlPoints");
            result.HullShaderOutputPrimitive = reader.ReadEnum32 <TessellatorOutputPrimitive>("HullShaderOutputPrimitive");
            result.HullShaderPartitioning    = reader.ReadEnum32 <TessellatorPartitioning>("HullShaderPartitioning");
            result.TessellatorDomain         = reader.ReadEnum32 <TessellatorDomain>("TessellatorDomain");

            result.BarrierInstructions      = reader.ReadUInt32("BarrierInstructions");
            result.InterlockedInstructions  = reader.ReadUInt32("InterlockedInstructions");
            result.TextureStoreInstructions = reader.ReadUInt32("TextureStoreInstructions");

            // DX11 stat size.
            if (size == 37)
            {
                return(result);
            }

            throw new ParseException("Unhandled stat size: " + chunkSize);
        }