Esempio n. 1
0
        private void toolLoad_Click(object sender, EventArgs e)
        {
            // ask for file
            var res = openDumpDialog.ShowDialog();

            if (res != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            // try to load it
            var path    = openDumpDialog.FileName;
            var newData = RawDumpData.Load(path);

            if (newData == null)
            {
                MessageBox.Show(this, "Unable to load GPU trace from selected file");
            }

            // close current file
            if (!CloseCurrent())
            {
                return;
            }

            // set new raw view
            _RawData = newData;

            // create parsed view
            _Parsed = ParsedData.Parse(_RawData);

            // create new data viewer
            _DataViewer = new ResourceViewCollection(tabDataViews, _RawData);

            // refresh UI
            RebuildDrawCallTree();
            RefreshPacketDump();
            RefreshDrawCallDump();
            RefreshRegisterDump();
            RefreshStateDump();
        }
Esempio n. 2
0
        public static RawDumpData LoadFromFile(FileStream fs)
        {
            BinaryReader reader = new BinaryReader(fs);

            // load and verify header
            try
            {
                UInt32 magic   = reader.ReadUInt32();
                UInt32 version = reader.ReadUInt32();

                if (magic != 0x47505544 || version != 1)
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }

            // load header data
            var numBlocks          = reader.ReadUInt32();
            var blocksOffset       = reader.ReadUInt64();
            var numPackets         = reader.ReadUInt32();
            var packetsOffset      = reader.ReadUInt64();
            var numMemoryRefs      = reader.ReadUInt32();
            var memoryRefsOffset   = reader.ReadUInt64();
            var numMemoryBlocks    = reader.ReadUInt32();
            var memoryBlocksOffset = reader.ReadUInt64();
            var numDataRegs        = reader.ReadUInt32();
            var dataRegsOffset     = reader.ReadUInt64();

            // offset to actual memory dump data
            var memoryDumpOffset = reader.ReadUInt64();

            // create arrays
            RawDumpData ret = new RawDumpData();

            // load memory blocks - tempshit
            ret.AllMemoryBlocks = new RawMemoryBlock[numMemoryBlocks];
            for (UInt32 i = 0; i < numMemoryBlocks; ++i)
            {
                RawMemoryBlock elem = new RawMemoryBlock();
                ret.AllMemoryBlocks[i] = elem;

                elem.LocalIndex = i;
                elem.File       = fs;
                elem.CRC        = reader.ReadUInt64();
                elem.FileOffset = memoryDumpOffset + reader.ReadUInt64();
                elem.Adress     = reader.ReadUInt32();
                elem.Size       = reader.ReadUInt32();
            }

            // load memory references - tempshit
            RawMemoryRef[] memoryRefs = new RawMemoryRef[numMemoryRefs];
            for (UInt32 i = 0; i < numMemoryRefs; ++i)
            {
                RawMemoryRef elem = new RawMemoryRef();
                memoryRefs[i] = elem;

                elem.Block = ret.AllMemoryBlocks[reader.ReadUInt32()];

                var mode = reader.ReadUInt32();
                elem.Mode = (mode == 1) ? RawMemoryRefMode.Write : RawMemoryRefMode.Read;

                Byte[] tag = reader.ReadBytes(16);
                elem.Tag = System.Text.Encoding.ASCII.GetString(tag).Replace("\0", string.Empty);
            }

            // load reg data
            UInt32[] regData = new UInt32[numDataRegs];
            for (UInt32 i = 0; i < numDataRegs; ++i)
            {
                regData[i] = reader.ReadUInt32();
            }

            // load packets
            ret.AllPackets = new RawPacket[numPackets];
            for (UInt32 i = 0; i < numPackets; ++i)
            {
                RawPacket packet = new RawPacket();
                ret.AllPackets[i] = packet;

                // packet data word
                packet.Data = reader.ReadUInt32();

                // load additional data
                {
                    var firstWord = reader.ReadUInt32();
                    var numWords  = reader.ReadUInt32();

                    packet.Words = new UInt32[numWords];
                    if (numWords > 0)
                    {
                        for (UInt32 j = 0; j < numWords; ++j)
                        {
                            packet.Words[j] = regData[firstWord + j];
                        }
                    }
                }

                // load memory references
                {
                    var firstMemoryRef      = reader.ReadUInt32();
                    var numPacketMemoryRefs = reader.ReadUInt32();

                    packet.Memory = new RawMemoryRef[numPacketMemoryRefs];
                    if (numPacketMemoryRefs > 0)
                    {
                        for (UInt32 j = 0; j < numPacketMemoryRefs; ++j)
                        {
                            packet.Memory[j] = memoryRefs[firstMemoryRef + j];
                        }
                    }
                }
            }

            // create all blocks beforehand
            ret.AllBlocks = new RawBlock[numBlocks];
            for (UInt32 i = 0; i < numBlocks; ++i)
            {
                RawBlock block = new RawBlock();
                ret.AllBlocks[i] = block;
            }

            // load blocks
            for (UInt32 i = 0; i < numBlocks; ++i)
            {
                RawBlock block = ret.AllBlocks[i];

                Byte[] tag = reader.ReadBytes(16);
                block.Tag = System.Text.Encoding.ASCII.GetString(tag);

                // load sub blocks refs
                {
                    var firstSubBlock = reader.ReadUInt32();
                    var numSubBlocks  = reader.ReadUInt32();

                    block.SubBlocks = new RawBlock[numSubBlocks];
                    for (UInt32 j = 0; j < numSubBlocks; ++j)
                    {
                        block.SubBlocks[j] = ret.AllBlocks[firstSubBlock + j];
                    }
                }

                // load packets refs
                {
                    var firstSubPacket = reader.ReadUInt32();
                    var numSubPackets  = reader.ReadUInt32();

                    block.Packets = new RawPacket[numSubPackets];
                    for (UInt32 j = 0; j < numSubPackets; ++j)
                    {
                        block.Packets[j] = ret.AllPackets[firstSubPacket + j];
                    }
                }
            }

            // keep the file handle opened
            ret.FileHandle = fs;

            // raw data loaded
            return(ret);
        }
Esempio n. 3
0
        static public ParsedData Parse(RawDumpData raw)
        {
            ParsedData ret = new ParsedData();

            var packetsMap = new Dictionary <RawPacket, ParsedPacket>();

            // create drawcall list
            ret._ShaderCache = new GPUShaderCache();
            ret._DrawCalls   = new List <ParsedDrawCall>();
            ret._DrawGroups  = new List <ParsedDrawGroup>();

            // prepare GPU state for the duration of parsing
            GPUState    parseState = new GPUState(ret._ShaderCache);
            GPUExecutor parseExec  = new GPUExecutor(parseState);

            // parse all packets
            int             packedIndex    = 1;
            int             drawCallIndex  = 1;
            int             drawGroupIndex = 1;
            ParsedDrawCall  drawCall       = null;
            ParsedDrawGroup drawGroup      = null;

            foreach (var rawPacket in raw.Packets)
            {
                // start new drawcall
                if (drawCall == null)
                {
                    drawCall = new ParsedDrawCall(drawCallIndex);
                    ret._DrawCalls.Add(drawCall);
                    drawCallIndex += 1;
                }

                // execute packet
                GPUCommandOutput executeOutput = new GPUCommandOutput();
                var executionResult            = parseExec.ExecutePacket(rawPacket, executeOutput);
                if (executionResult != GPUExecutorResult.Invalid)
                {
                    // add data
                    packetsMap[rawPacket] = ParsedPacket.Parse(rawPacket, packedIndex, drawCall, executeOutput);
                    ++packedIndex;
                }

                // restart after each drawcall
                if (packetsMap[rawPacket].Output.IsDraw())
                {
                    // capture final state at each drawcall
                    if (drawCall != null)
                    {
                        drawCall.CapturedState = new GPUStateCapture(parseState);

                        // extract the viewport/render target settings for the draw call - required to match it to the draw group
                        var stateRenderTargets = new GPUStateRenderTargets(drawCall.CapturedState);
                        var stateViewport      = new GPUStateCaptureViewport(drawCall.CapturedState);

                        // determine if we should add this draw call to current draw group
                        if ((drawGroup != null) && drawGroup.Compatible(stateViewport, stateRenderTargets))
                        {
                            drawGroup.AddDrawCall(drawCall);
                        }
                        else
                        {
                            drawGroup = new ParsedDrawGroup(drawGroupIndex++, stateViewport, stateRenderTargets);
                            drawGroup.AddDrawCall(drawCall);
                            ret._DrawGroups.Add(drawGroup);
                        }
                    }

                    // reset
                    drawCall = null;
                }
            }

            return(ret);
        }