24 November 2020, 15:53 | #1 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
BLITHOG and Interrupts
I have a triple buffered display system that uses a copper interrupt to change the displayed buffer before the vertical blank happens.
I am using the blitter to clear my back buffer. My WaitForBlitter function currently turns on BLITHOG while it's waiting. Is this a mistake? If I'm waiting for the blitter with BLITHOG on and the blit goes on past when the copper interrupt should trigger, will the interrupt be delayed until later, possibly late enough to cause issues, or will it just not happen at all? If it's the former then I need to change stuff, if it's the latter, I probably need to think more and maybe do some tests and timings. Edit: How dangerous would it be to have the copper turn off BLITHOG just after triggering its interrupt? Last edited by Ernst Blofeld; 24 November 2020 at 17:19. |
24 November 2020, 17:46 | #2 | |
Registered User
Join Date: Jun 2020
Location: Brno
Posts: 90
|
Quote:
Depends if CPU opcodes are read from chip or fast memory. CPU will be interrupted in any case (I think INTREQ bits are just compared with INTENA bits and CPU is interrupted accordingly, INTREQ bits are set by devices). In the first case, if there are no free memory cycles available for CPU then it will just wait. Even if a new same-level interrupt request arrives (INTREQ bit is set by a device again) it doesn't do anything because CPU must clear INTREQ bit first for interrupt to be triggered. And a bit clearing can't happen because CPU is waiting to get access to fetch a new instruction opcode. I think your interrupt code will be handled immediately after CPU will get the time to proceed. In the latter case, CPU can fetch opcodes immediately therefore CPU will do all interrupt procedures immediately (storing return address, fetching jump address, ...). Or maybe I'm completely wrong and therefore I apologize. |
|
24 November 2020, 18:43 | #3 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,216
|
Quote:
In particular, the Os requires(!) regular interrupt processing, which you cannot guarantee in such a setup, so it is in general not recommended. This would allow the CPU to process the interrupt, at least. Otherwise, the interrupt will be delayed until the CPU receives the bus to retrieve the interrupt auto vector. |
|
24 November 2020, 19:03 | #4 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
This sounds like a low risk option to try. If it doesn't work out, I'll drop using BLITHOG completely. The only thing that concerns me is whether there are any race conditions around the setting and clearing of BLITHOG, that's just something I don't yet know about well enough yet.
|
25 November 2020, 10:54 | #5 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Be careful that you don't end up with something where (on rare occasion) the cpu could enable blithog just when the copper disabled it (and just before the actual cpu interrupt is triggered), thus locking itself out.
|
25 November 2020, 11:55 | #6 |
Registered User
Join Date: Jun 2020
Location: Brno
Posts: 90
|
May I ask you why do you turn the blitter-nasty bit on and off? I'm just curious. I know there was a long discussion about this bit here. It's often suggested to enable it so that the blitter can use (almost?) every available time cycle for the job. And sometimes it's better to let it be off so that CPU and blitter run in parallel...
Also, why do you use interrupts? Isn't it a waste of CPU time to go in and out of interrupt code? Again, I'm just curious what your scenario is. |
25 November 2020, 12:19 | #7 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,411
|
Waiting with BLITHOG on is normally more efficient than waiting without it for certain blits (compared to waiting with BLITHOG off). However, it's not always faster and causes some issues with interrupt handling as discussed above. If you're running with the OS & multitasking up I'd strongly recommend against doing this.
Regarding interrupt based blitting, this is generally less efficient on low-spec Amiga's than polling due to the high overhead for interrupts compared to other options. However, there are advantages as well so it may still be a good option. It all depends |
25 November 2020, 12:27 | #8 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
Regarding interrupts, they are how I make sure I switch display buffers at the right time, just before vertical blank, without busy waiting. |
|
25 November 2020, 12:52 | #9 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
25 November 2020, 13:02 | #10 | |
Registered User
Join Date: Jun 2020
Location: Brno
Posts: 90
|
Quote:
Thank you. Now I understand. Is it possible to swap buffers (copper-list) directly by the copper instead of doing it by CPU? |
|
25 November 2020, 13:14 | #11 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
I haven't thought it through any more than that. I suspect you may need more than three buffers to make it work though. |
|
25 November 2020, 13:20 | #12 | |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,411
|
Quote:
It can even be worthwhile to use the CPU to clear some part of the bitmap you're clearing with the Blitter at the same time as the clear runs (in the optimal case this can greatly increase the clearing speed). |
|
25 November 2020, 13:31 | #13 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
I've thought about that too, and I may be regretting using interleaved bitmaps as I can't easily get the blitter to do some of them while I draw a background with the CPU into the others.
|
25 November 2020, 13:40 | #14 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,411
|
You could instead clear the top of the bitmap with the Blitter and bottom with the CPU (or vice versa) - no problems with interleaved that way
|
25 November 2020, 13:42 | #15 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
25 November 2020, 13:45 | #16 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,411
|
I feel that I might be missing something here, because I'm not sure why that would be. If you run both CPU and Blitter at the same time, you'll should get the benefit irrespective of whether you do it by plane or by Y position (for Blitter clearing that is).
Maybe I misunderstood what you wanted to do? |
25 November 2020, 14:05 | #17 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
I have a vague idea about mixing 3D polygon objects with blitted objects, which is why I chose interleaved, to make the blitted stuff faster and easier. I think I need to flesh that out before deciding the details on screen clearing. |
|
25 November 2020, 14:17 | #18 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,411
|
Oh, I see what you mean. I thought you wanted both CPU & Blitter to just clear. It does change a bit if you want one to clear and the other to draw. Anyway, I fully agree it's best to flesh out your idea further before committing to a detail such as how to clear the screen.
However, I do want to point out that it is in fact possible to clear/draw on just a some bitplanes using interleaved mode (albeit it's a bit less intuitive than having fully separated bitplanes in memory). All you really need to do is calculate the correct modulo value to add between planes when you move forward a line and you should be able to address single bitplanes in the bitmap just fine. It gets a bit harder when you want to address multiple bitplanes in the same blit, but even that can be worked around to a certain degree (for instance, it's fairly simple to blit to either all the odd or even bitplanes if you have an even number of bitplanes in use). |
25 November 2020, 14:31 | #19 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
I'm not sure why that didn't occur to me as I already have to pretend that my screen is twice as wide as it is to get around the 10:6 limit of BLTSIZE. I'm going to go and check my maths, and maybe just implement it now, as it's an easy win. |
|
25 November 2020, 15:18 | #20 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
Code:
void FillScreen(void) { WaitForBlitter(); custom->bltcon0 = DEST | 0xff; custom->bltcon1 = 0x0000; custom->bltdpt = currentBuffer; custom->bltdmod = DISPLAY_WIDTH_IN_BYTES; custom->bltsize = (DISPLAY_HEIGHT << 6) + 3 * DISPLAY_WIDTH_IN_WORDS; ULONG * p = (ULONG *) currentBuffer; for (UWORD i = 0; i < DISPLAY_HEIGHT; i++) { p += 3 * DISPLAY_WIDTH_IN_LONGS; for (UWORD j = 0; j < DISPLAY_WIDTH_IN_LONGS; j++) *p++ = 0xFFFFFFFF; } } So, I have successfully removed the idle time my code spent waiting for the blitter. My frames per second have increased... from 9.01 to 9.05. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBL interrupts (VBCC) | LastManStanding | Coders. C/C++ | 14 | 14 October 2020 12:14 |
Damn Interrupts | mcgeezer | Coders. Asm / Hardware | 10 | 24 March 2019 16:50 |
CIA interrupts... | bloodline | Coders. System | 6 | 18 January 2018 10:33 |
Blithog behavior | ovale | Coders. Asm / Hardware | 5 | 12 January 2015 08:05 |
Advice on interrupts and jumps | alexh | Coders. General | 11 | 20 May 2008 09:42 |
|
|