{"action":"created","issue":{"url":"https://api.github.com/repos/simias/rustation/issues/31","repository_url":"https://api.github.com/repos/simias/rustation","labels_url":"https://api.github.com/repos/simias/rustation/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/simias/rustation/issues/31/comments","events_url":"https://api.github.com/repos/simias/rustation/issues/31/events","html_url":"https://github.com/simias/rustation/issues/31","id":156624033,"number":31,"title":"Visual GPU debugger","user":{"login":"simias","id":7925386,"avatar_url":"https://avatars.githubusercontent.com/u/7925386?v=3","gravatar_id":"","url":"https://api.github.com/users/simias","html_url":"https://github.com/simias","followers_url":"https://api.github.com/users/simias/followers","following_url":"https://api.github.com/users/simias/following{/other_user}","gists_url":"https://api.github.com/users/simias/gists{/gist_id}","starred_url":"https://api.github.com/users/simias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simias/subscriptions","organizations_url":"https://api.github.com/users/simias/orgs","repos_url":"https://api.github.com/users/simias/repos","events_url":"https://api.github.com/users/simias/events{/privacy}","received_events_url":"https://api.github.com/users/simias/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/simias/rustation/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-05-24T22:28:44Z","updated_at":"2016-05-25T20:35:32Z","closed_at":null,"body":"This a project I've been thinking about for a while but I have so much stuff on my todo list at the moment that I can't imagine tackling it anytime soon. I would like an external tool that could take PlayStation GPU command logs and lets me see what individual commands draw. I'd also like to be able to navigate the commands, go back in time etc... That would be a huge time saver when tracking down certain graphical bugs.\r\n\r\nI'm posting this here in case somebody else wants to give it a try, it's a relatively simple, well bounded and, in my opinion, fun project for somebody who likes making user interfaces and wants to try their hands at emulation. It's not super performance-critical either so you can really use the language and environment of your choice (although portability is strongly encouraged...).\r\n\r\nThis tool would be useful in the development of Rustation but it need not be tied to it and could be used for other emulators or even a real console as long as you're able to dump incoming GPU command words.\r\n\r\n# Context\r\n\r\nFrom a high level perspective the PlayStation GPU is fairly simple. It has 1Megabyte of VRAM laid out as a 1024x512 16bits-per-pixel video buffer. The GPU draws lines, triangles and quadrilaterals to this buffer and then sends a portion of it to the video output.\r\n\r\nIn order to control it the GPU has two 32bit registers called `GP0` and `GP1`. The CPU and/or DMA sends command words through those registers and the GPU executes them.\r\n\r\nHere's the `GP0` decoding function in rustation https://github.com/simias/rustation/blob/master/src/gpu/mod.rs#L592-L659\r\n\r\nAnd here's `GP1`'s: https://github.com/simias/rustation/blob/master/src/gpu/mod.rs#L1220-L1252\r\n\r\nNo$ is also a good source for understanding the GPU and its commands: http://problemkaputt.de/psx-spx.htm#graphicsprocessingunitgpu\r\n\r\nYou can see that `GP0` commands are mainly draw commands like \"draw a triangle at these coordinates\", \"draw a line at these coordinates\", \"fill this rectangle in VRAM with this color\" etc... It's relatively straightforward.\r\n\r\n`GP1` on the other hand is more for configuration, things like turning the video output on or off or configuring which part of the VRAM is displayed on the screen.\r\n\r\n# The problem\r\n\r\nMy current problem is that linking a visual glitch on the output with an actual individual GPU command in the emulator can be very tedious and time consuming without any kind of tool to assist me.\r\n\r\nFor instance [here's the complete log of GP0 and GP1 commands during the first few seconds after boot](https://svkt.org/~simias/rustation/gpu-log.txt).\r\n\r\nThat's 19162 individual command words making up 2756 GP0 and 2282 GP1 commands. And all it does is draw [the little animation of the \"Sony Computer Entertainment\" logo on boot](https://www.youtube.com/watch?v=zIA0kaGFIhQ).\r\n\r\nFor instance if you dig into the log you'll find the following sequence:\r\n\r\n```\r\nGP0 0x300000b2\r\nGP0 0x00f101bd\r\nGP0 0xca008cb2\r\nGP0 0x00740140\r\nGP0 0xca008cb2\r\nGP0 0x016e0140\r\n```\r\n\r\nThis draws one of the shaded triangles. Took me a little while to extract it out. The general form of this command is:\r\n\r\n```\r\nGP0 0x30BBGGRR <- 0x30 is the command opcode, followed by the 24bit RGB color of the 1st vertex\r\nGP0 0xYYYYXXXX <- 1st vertex X and Y coordinates\r\nGP0 0xXXBBGGRR <- 2nd vertex 24bit RGB color (high byte is ignored)\r\nGP0 0xYYYYXXXX <- 1st vertex X and Y coordinates\r\nGP0 0xXXBBGGRR <- 3rd vertex 24bit RGB color (high byte is ignored)\r\nGP0 0xYYYYXXXX <- 3rd vertex X and Y coordinates\r\n```\r\n\r\nNow you can go back to the previous command and manually decode it if you want. As you can see this is pretty time consuming.\r\n\r\nNow here's an actual bug I'm trying to fix right now:\r\n\r\n![retroarch-0524-013225](https://cloud.githubusercontent.com/assets/7925386/15487664/9024e1de-214f-11e6-8e0a-949c0b2d7dfe.png)\r\n\r\nCrash's shadow on the ground is made up of two triangles, and you can see that one of them has the wrong transparency applied.\r\n\r\nIn order to fix this I'd like to be able to track the individual draw command responsible for this particular triangle and figure out why I don't interpreted it correctly. Isolating a single command from the thousands of calls making up each Crash Bandicoot frame is very tedious. Parsing [the log I posted above](https://svkt.org/~simias/rustation/gpu-log.txt) is already non-trivial and it's only drawing a dozen triangles in a simple animation.\r\n\r\nWhat I'd like is a visual tool that would take this command stream and show me what they do directly on the screen. [No$](http://problemkaputt.de/psx.htm) seems to have something like that already:\r\n\r\n![psxdebug](https://cloud.githubusercontent.com/assets/7925386/15521840/57e1d9e8-220e-11e6-9304-e913b826a9c7.gif)\r\n\r\nYou can see that the \"Vram Viewer\" window has a list of commands at the upper right and seems to highlight the selected quadrilateral in the main view. Using a tool like this I could track down the bogus command in my Crash Bandicoot screenshot in seconds. This looks like a great tool but unfortunately it's closed source as far as I know.\r\n\r\nSo if somebody wants to give this a try or wants more precisions don't hesitate to ask for my help."},"comment":{"url":"https://api.github.com/repos/simias/rustation/issues/comments/221699078","html_url":"https://github.com/simias/rustation/issues/31#issuecomment-221699078","issue_url":"https://api.github.com/repos/simias/rustation/issues/31","id":221699078,"user":{"login":"simias","id":7925386,"avatar_url":"https://avatars.githubusercontent.com/u/7925386?v=3","gravatar_id":"","url":"https://api.github.com/users/simias","html_url":"https://github.com/simias","followers_url":"https://api.github.com/users/simias/followers","following_url":"https://api.github.com/users/simias/following{/other_user}","gists_url":"https://api.github.com/users/simias/gists{/gist_id}","starred_url":"https://api.github.com/users/simias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simias/subscriptions","organizations_url":"https://api.github.com/users/simias/orgs","repos_url":"https://api.github.com/users/simias/repos","events_url":"https://api.github.com/users/simias/events{/privacy}","received_events_url":"https://api.github.com/users/simias/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T20:35:31Z","updated_at":"2016-05-25T20:35:31Z","body":"I'll give it a try, thanks."}}
{"actor":{"display_login":"simias"}}