RE: [Algorithms] Multithreading with Hardware Acceleration
Brought to you by:
vexxed72
From: Tom F. <to...@mu...> - 2000-08-21 04:02:54
|
Yes, lots of people do this for various reasons, amongst them this one. In D3D there are a variety of places you can do this sort of code: while ( TRUE ) { res = DoAnOperation(); if ( res == WORKED ) { break; } Sleep(0); } I'm specifically thinking of Flip, Blt and Lock here. So there is certainly possibilities there. Sadly, so many apps have been written with this style: DoAnOperation(); //Assume it worked without checking any flag or anything. that many drivers have had to simply block internally and not return the "can't do it just yet or it would block" error. And because of the special thing that a driver is on most OSes, they often can't do the equivalent of Sleep(0). So yet another good idea ruined by dodgy apps I'm afraid. Still, some drivers do do this properly, which is cool. The other way to do it, which does always work as far as I know, is code such as the following: while ( !ReadyToDoBlt() ) { Sleep (0); } res = Blt(); // Should only get actual _errors_ back from this. This is certainly a good way to give way to other threads. Some people go mad with threads and create them all over the place, e.g. one for each AI character. That's possibly a little over the top, but can work. You need to beware of the pitfalls of threading as well as the advantages, but it sounds like you're aware of some of the problems already. Tom Forsyth - Muckyfoot bloke. Whizzing and pasting and pooting through the day. -----Original Message----- From: Chris Brodie [mailto:Chr...@ma...] Sent: 21 August 2000 04:39 To: 'gda...@li...' Subject: [Algorithms] Multithreading with Hardware Acceleration I've had a thought for a while. If I ran my main loop in a thread and the video rendering in a separate thread (with a bit of sync'ing) I could net a bit of time during hardware blocks to start preparing the next frame, maybe do a bit of extra occlusion culling\tesselation or AI. Of course I have no idea about video cards and blocking. (Like maybe on a T&L card it would just gather it's data and go off for a while doing things and not bother the CPU. If the card however keeps accessing the ram however the context switches might bite back at any gains you make) Does anyone know if this is a worth the effort? (I'm already threading the network and file system queues so there is no learning involved) Chris Brodie (I apologise for the HTML. My mail department says your not getting it :) ) |