Exemplo n.º 1
0
            public void AddVFetch(RawMemoryBlock block, GPUVertexFetch vfetch)
            {
                // find matching stream
                Stream stream = null;

                foreach (var it in Streams)
                {
                    if (it.Block == block && it.Stride == (vfetch.stride * 4))
                    {
                        stream = it;
                        break;
                    }
                }

                // create new stream
                if (stream == null)
                {
                    stream           = new Stream();
                    stream.Stride    = vfetch.stride * 4; // vfetch stride is in DWORDS, we need stride in BYTES
                    stream.Block     = block;
                    stream.Endianess = GPUEndianFormat.Format8in32;
                    Streams.Add(stream);
                }

                // add fetch entry to the stream itself
                Elem elem = new Elem();

                elem.DataType = vfetch.dataType;
                elem.Format   = vfetch.format;
                elem.Offset   = vfetch.offset * 4; // vfetch offset is in DWORDS, we need offset in BYTES
                stream.Elements.Add(elem);
            }
Exemplo n.º 2
0
        public GPUShader DecompileShader(bool pixel, RawMemoryBlock block)
        {
            // local search
            foreach (var entry in _Entries)
            {
                if (entry._Pixel == pixel && entry._RawMemory == block)
                {
                    return(entry._Shader);
                }
            }

            // convert memory
            GPUShader shader = null;
            {
                var words = block.LoadAllDataAs32BE();

                try
                {
                    shader = GPUShader.Decompile(pixel, words);
                }
                catch (Exception)
                {
                }
            }

            // create new entry
            GPUShaderCacheEntry newEntry = new GPUShaderCacheEntry();

            newEntry._Pixel     = pixel;
            newEntry._RawMemory = block;
            newEntry._Shader    = shader;
            _Entries.Add(newEntry);

            return(shader);
        }
Exemplo n.º 3
0
 private static String MakeShaderAddr(RawMemoryBlock block, bool pixel)
 {
     if (block != null)
     {
         return(String.Format("<a href=\"{0}shader,{1}\">0x{2:X6}</a>",
                              pixel ? "pixel" : "vertex",
                              block.LocalIndex,
                              block.Adress));
     }
     else
     {
         return("NONE");
     }
 }
Exemplo n.º 4
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);
        }