Speeding up readpixelfast?
Blitz3D Forums/Blitz3D Programming/Speeding up readpixelfast?
| ||
Are there any tricks that can be used to speed up a readpixelfast command? In this instance, I do not need the exact value, since I am only trying to find out if it is higher or lower than a threshold value. |
| ||
Backbuffer, Frontbuffer, Imagebuffers will differ in access speed. Just like Texturebuffers, where using Texture Flag 256 makes it much faster. Continously reading and writing pixels is also bad, you rather should read all pixels into an array or bank, then compute and writepixelfast the whole array (has something to do with cache optimation on the CPU level). |
| ||
Remember also to use the LockBuffer and UnlockBuffer commands, before and after your readpixelfast commands. |
| ||
BTW now this is really confusing me, I made a test to compare the speed of readpixelfast and writepixelfast in images and textures. Now it turned out using the flag 256 is making textures slower, where it should be faster. This is really strange. Maybe it has something to do with the quality settings of the Ati card that I have altered recently. I do however still recommended to test the speed of the flag 256 and not to use it untested. |
| ||
Yeah, it's varied amoungst cards. It offers a large speed up here. Amount of VRAM is also important. If your vrAM doesn't have alot of capacity in the first place, forcing a texture/image into it, will cause lots of swapping. |
| ||
Its slower on my 9700 as well if I use VRAM ... looks like it is mostly faster on system RAM based cards and old cards that were that slow and low memory that they normally were using the systemram through AGP RAM extension. |
| ||
Flag 256 is slower on my (ancient) GeForce256, but faster on my (semi-ancient) GeForce2 GTS. Both cards have 32MB VRAM. |
| ||
I guess the confusing results on differing video graphics cards, makes it imperative that we have in our programs a set/unset screen where features can be enabled or disabled, such that the user can implement corrective changes. Otherwise, how can we as programmers guess which card or graphics environment we're sending our programs into? |
| ||
Otherwise, how can we as programmers guess which card or graphics environment we're sending our programs into? Aye, there's the rub! :) |
| ||
you can guess it when you measure the time of both, that's pretty simple. something like:t=createtexture(512,512) setbuffer texturebuffer(t) t1=millisecs() lockbuffer() for i=0 to 100000 rgb=readpixelfast(rand(0,511),rand(0,511)) writepixelfast rand(0,511),rand(0,511),rand(0,$FFFFFF) next unlockbuffer() t2=millisecs() time1=t2-t1 freetexture t t=createtexture(512,512,256) setbuffer texturebuffer(t) t1=millisecs() lockbuffer() for i=0 to 100000 rgb=readpixelfast(rand(0,511),rand(0,511)) writepixelfast rand(0,511),rand(0,511),rand(0,$FFFFFF) next unlockbuffer() t2=millisecs() time2=t2-t1 freetexture t if time2<time1 then print "flag 256 is faster" else print "flag 256 is slower" endif The difrence between them is about 70% on my machine. So an image takes 130 ms, a texture with the 256 flag as well, without the flag only about 40ms. I am still confused since I think I clearly remember the flag 256 once used to speed pixel access up massively on exactly THIS machine. |
| ||
Maybe that was speed-up in a different area? Try writing (Text) to the textures in VRAM and not and see if that speed difference matches the copypixel situation or not? Well I've just tried that, and it makes no odds. Not in VRAM on my machine is consistently slower, but only by a few % at best, and sometimes all of 0.1% slower. There is a large discrepency between full-screen and windowed though. In windowed sometime buffers not in VRAM were faster than those in VRAM, and sometimes not. |
| ||
Depending on the card, drawing text to a VRAM texture will totally fail. Never count on anything beside lockbuffer with the pixel commands to work on VRAM textures. |
| ||
I only remember I made this realtime shadow demo for the code archives and after Flag 256 was added, a lot of people reported speed increase of about 70%. Maybe it's Copyrect to a texturebuffer that was used in the demo. |