use filp() without Lock()ing the surface ?

Started by
11 comments, last by djsomers 22 years, 5 months ago
Can I Flip the primary surface without Locking it first, and also can I blit to secondary (offscreen) buffers and in vram buffers without locking their suraface first. I am advised that my locking - unlocking is very slow. djsomers
djsomers;)make it idiot proof and someone makes a better idiot!
Advertisement
you should only flip the back buffer to the primary if its not locked,

as for bliting you should lock the target, i dont remember but i dont think you need to lock the src, but you mite, read the SDK to find out


-VBLimits
Sorry about the Spelling..


Edited by - VBLimits on November 16, 2001 4:55:24 AM
-VBLimitsSorry about the Spelling..
Seems like u want to Flip/Blt surfaces without locking/unlock them everytime, right ?
Well... i got this little soluction for you... and yea it works !

If u r in Windowed Mode...things r pretty simple. Right after creating the back buffer, Lock it once
and store the surface pointer ( which may look something like g_pDDBackBufferPointer ) as a
global variable. Nows itz just a matter of using this global variable wherever u want to; you dont
have to lock surfaces for every frame now.

If u r in FullScreen mode... dont worry , all u have to do is write few more lines of codes. In fullscreen
mode, Surfaces are flipped rather than Blitting. While ur BackBuffer is Flipped with the FrontBuffer, the
surfaces pointers get swapped internally. So the solution is; when u Create ur BackBuffer and FrontBuffer lock
both of them once, get the pointer to global variables ( for example g_pDDBackBufferPointer and g_pDDFrontBufferPointer ). Now Swap these two pointer everytime u Flip !!. This is how u can skip the
whole process of Locking/Unlocking. And tell u what... it works !!!

Example:

HRESULT Present()
{

HRESULT hr = g_pDDFrontBuffer->(g_pDDBackBuffer,DDFLIP_WAIT);
if(FAILED(hr)) return hr;

// swap the global variables
VOID *pTemp;
pTemp = g_pDDFrontBufferPointer;
g_pDDFrontBufferPointer = g_pDDBackBufferPointer;
g_pDDBackBufferPointer = pTemp;

}

Now u can use the pointer g_pDDBackBufferPointer to write anything on the backbuffer cuz it
will always be pointing to the CURRENT backbuffer. Problem solved !! I hope this should improve
the speed of you program quite substantially.
Z
Something''s not right here. A couple of points...

1)Neither the primary nor back buffer should be locked when you flip. If either is, flip will fail.

2) If you are doing a hardware blit (IDirectDrawSurface*->blit()), then the surface should not be locked, otherwise the blit will fail (so, no, VBlimits, you should *NOT* lock the target for blitting). You only need to lock the surface if you are going to access surface memory yourself, for your own custom blit routines, line drawing routines, and what have you.

3) This one is directed to browny - there is absolutely no guarantee that saving a pointer to a locked surface will always point to that surface. A number of things could happen to cause that saved pointer to suddenly be pointing at garbage. You should *NEVER* rely on a surface pointer. Doing so is just asking for trouble - maybe not now, but probably later. That would be a hell of a debugging nightmare. Just because it works for you now doesn''t mean it will always work on every machine. There was considerable debate about this a while back and the common consensus was, don''t do it.

So, in answer to the original questions, yes and yes. If you are using the DDraw blit routines you can (and have to) blit without locking the surfaces.

I don't know where you guys get your information from, I ran some test on lock & unlock, its really not that slow, on my system it takes about the same amount of time as counting from 0 to 800 in a for loop. That's it, just counting, nothing else.

Sure if you were locking 1000 vertex buffers each frame or something, but who would do that anyway.

Have a look at my post.

http://www.gamedev.net/community/forums/topic.asp?topic_id=65990


Edited by - burp on November 16, 2001 3:29:03 PM
quote:Original post by burp
I don''t know where you guys get your information from, I ran some test on lock & unlock, its really not that slow, on my system it takes about the same amount of time as counting from 0 to 800 in a for loop. That''s it, just counting, nothing else.

Sure if you were locking 1000 vertex buffers each frame or something, but who would do that anyway.

Have a look at my post.

http://www.gamedev.net/community/forums/topic.asp?topic_id=65990


Edited by - burp on November 16, 2001 3:29:03 PM


It also depends on heavily loaded the memory on the card is, if it is PCI, AGP, AGPx2 and even how you have created the buffer (for vertex and indece buffers).

You need to run your tests on more than just one platform to get a more accurate picture.



D.V.

Carpe Diem
D.V.Carpe Diem
quote: DeltaVee, It also depends on heavily loaded the memory on the card is, if it is PCI, AGP, AGPx2 and even how you have created the buffer (for vertex and
indece buffers).


That''s true... Or is it? Does anyone know what a lock really is and how it works. I have some idea, but I''m looking for a technical explanation.

I have AGPx4, what do you have and how long does your lock unlock take?

Maybe we should create a program that would test locking and unlocking under different circumstances and have other members of GameDev run it, the results could then be tabulated and added to a GameDev tutorial or something.

Then we really would know for sure.
Surface locking is the same as locking a standard heap block, only DDraw has to get all the info on the surface as well (for the DDSURFACEDESC struct).

When a standard memory block is locked, a flag on it just has to be set so that nothing tries to move it (i.e. that the pointer you get stays constant).

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

quote:
Post by superpig

Surface locking is the same as locking a standard heap block, only DDraw has to get all the info on the surface as well (for the DDSURFACEDESC struct).

When a standard memory block is locked, a flag on it just has to be set so that nothing tries to move it (i.e. that the pointer you get stays constant).


That's what I was thinking too, its basically just the same thing as a IDirectDrawSurface7:ageLock, which it needed on some (all?) hardware to do DMA transfers.

So lock really has nothing to do with the graphics card per say, it has to do with Windows memory management.



Edited by - burp on November 16, 2001 10:52:58 PM
quote:
Post by burp
Sure if you were locking 1000 vertex buffers each frame or something, but who would do that anyway.

I once had a program that locked the vertex buffer around 480000 times a frame! However I reworked the engine so that it stores vertex information in arrays, and then those arrays are read and shoved into a vertex buffer once right before the engine renders... stupid voxel engines,
Cheers,
-Jesse

This topic is closed to new replies.

Advertisement