Hooking into vblank irq for draw?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
bogglez
Moderator
Moderator
Posts: 578
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Hooking into vblank irq for draw?

Post by bogglez »

Recently I've been looking into the assembly programming of KOS and read more hardware documentation, and was curious about the vblank interrupt.

In a normal game loop, we do something like this:

Code: Select all

while(1) {
  update();
  draw();
  swap(); // waits for vblank
}
So the CPU is blocked, although we could already perform the next update() or other busy-work.
Would it make sense to instead use draw() as a vblank interrupt handler, in order to get asynchronous behavior without threads which have their own overhead?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Hooking into vblank irq for draw?

Post by BlueCrab »

There's actually stuff in KOS to schedule things to happen on vblank: link.

Just remember that these will run in the IRQ context of the vbl interrupt (i.e, interrupts disabled), so you shouldn't be doing lots of stuff in them.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: Hooking into vblank irq for draw?

Post by bogglez »

Yeah, that function is what I was referring to. Rendering does take a considerable amount of time of the frame (but not more than 1/60th or 1/30th of a second). Why would it be a bad idea to do things there? Would 1/30s in a worst case mess with the disc, audio, etc. components of KOS?
I assume rendering would be faster because the game state would be updated during the time that we usually wait for the vblank. The interrupt handler would basically just copy the TA render command list to the PVR or perform minor work in order to create such a render command list and copy it over.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Hooking into vblank irq for draw?

Post by BlueCrab »

It would be a bad idea to do things there because IRQs are disabled during the time when any interrupt is being serviced in KOS (KOS doesn't allow nested interrupts). Thus, you will screw up a lot of things by doing anything time intensive in that function. Timing, network communications, even parts of video rendering can rely on interrupts.

Plus, anything that would potentially cause you to sleep (memory allocation, for instance) will either not work properly or will hang the system entirely. This is since it'll be waiting on a lock that it will never be able to acquire unless another thread gets swapped in -- which can't happen until a timer interrupt -- which can't happen while IRQs are disabled.
Post Reply