Page 1 of 1

What happens when you write to GP0 when the GPU is busy?

Posted: August 4th, 2014, 1:44 pm
by mistershrubber
Hey guys,

I'm working on a PSX project and I was wondering: what happens when you write to GP0 when the GPU is not ready to receive a command weird? Does what you write go to a buffer and gets processed later? What if the buffer is full? Or does it just get discarded?

Thanks in advance!

Re: What happens when you write to GP0 when the GPU is busy?

Posted: August 5th, 2014, 6:35 am
by AmiDog
First of all, there is a 16-word command buffer, so it's always safe to write 16 values to GP0. The GPU will fetch commands from the buffer until it's empty. However, the GPU is a superscalar design, which make things somewhat more interesting. It seems to be able to fetch and process up to two commands from the buffer at once, so you can usually write two full commands + 16 additional words to GP0 without messing things up. If you perform too many writes, you will end up overwriting the beginning of the buffer.

I'm abusing this in a silly demo I wrote where I write block-fill -> sprite -> block-fill -> lots-of-nops to GP0. The first two commands will be processed, while the second block-fill, which remained in the buffer, will be overwritten by the nops. This produces a sprite on real hardware while all emulators I've tried renders all commands and just give a black screen...

Re: What happens when you write to GP0 when the GPU is busy?

Posted: August 5th, 2014, 6:49 am
by mistershrubber
Thank you very much for your answer! That clarified a lot of open questions I had in one go :) Especially the part of the buffer being circular (if I understood correctly that is how you are overwriting the whole buffer with NOPs while the first two commands are being processed) is very interesting.

Thanks again!