Pb with d3d9

Started by
6 comments, last by Kippesoep 18 years, 7 months ago
Hi all, I want to present images (surfaces) on the screen but in a synchronous mode : I have a LPDIRECT3DSURFACE9 created in video memory with D3DPOOL_DEFAULT I want to copy that LPDIRECT3DSURFACE9 in the BackBuffer : I use StretchRect but it's asynchronous : I want to wait for the end of that operation before continue. (LPDIRECT3DDEVICE9)...->Present( NULL, NULL, NULL, NULL ) write data on the parallel port (I know) What is the faster method to present images? Must I use DirectDraw? [Edited by - tq9799 on September 14, 2005 12:19:03 PM]
Advertisement
The fastest method to display images is to simply allow asynchronous behaviour. What's the point of being synchronous anyway? Synchronising and fast may be pretty much mutually exclusive.

If you absolutely must do this, you can force DX to flush its command buffers by accessing the back buffer directly:

IDirect3DSurface9 *tmp = NULL;dev->GetBackBuffer (0, 0, D3DBACKBUFFERTYPE_MONO, &tmp);if (tmp) tmp->Release ();


Since the command buffer is then empty when Present is called, the present will be virtually immediate (assuming you have disabled VSync), which is as close to synchronous as you can get.
Kippesoep
I not sure my explanation was clear

I want to copy a surface to the backbuffer and display it when it's finished, I wait for VBlank in order to be synchonized with the display's spot

pDevice->StretchRect( ( pSurface ), NULL, pBackBuffer, NULL, D3DTEXF_NONE );

do {
pDevice->GetRasterStatus( 0, &rasterStatus );
} while( !rasterStatus.InVBlank );
pDevice->Present( NULL, NULL, NULL, NULL );

WriteParPort( 255 );
delay_ms( 1.0 );
WriteParPort( 0 );

I use PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE

I want a top on the parallel port at the begining of the display of the image.

Whith my method, I obtain tearing : StretchRect isn't finished when the backbuffer is displayed...
If you want to ensure that the StretchRect is finished, then just call the code I posted after it.

The way you're using the vsync is rather unusual and, IMHO, way too cumbersome. When creating the device, simply set the appropriate swap interval in the present parameters.
Kippesoep
I have tried but it doesn't work better...

I have tried :

D3DPRESENT_INTERVAL_DEFAULT
pDevice->StretchRect( pSurface, NULL, pBackBuffer, NULL, D3DTEXF_NONE );
pDevice->Present( NULL, NULL, NULL, NULL );

WaitVBlankDevice( 1 );
WriteParPort( 255 );
delay_ms( 1.0 );
WriteParPort( 0 );

It seems to work, but it's not really elegant!

Anybody have a better idea?

If that doesn't work, something else is going wrong (or at least, does not work the way you suspect it should work). Perhaps you've disabled VSync in your driver settings. StretchRect must finish before a Present can be done. Present always ensures that all prior operations have completed, because otherwise there would be artifacts. Tearing may occur if VSync is disabled (either by your program or by a setting in the driver), but not because of operations not being completed. If that happens (and I very much doubt it), you've discovered a serious bug.

BTW, what's the deal with the parallel port? I don't even have one anymore.
Kippesoep
I have controled with an oscilloscope,
with D3DPRESENT_INTERVAL_IMMEDIATE, StretchRect has not finished before present()!

The parallel port is to synchronize the video with external devices...
Many thanks for your responses.
Correction: with the "immediate" present interval, the stretchrect will have completed in time, but it is too fast. What happens is something like this:

- stretchrect into buffer 1 begins
- stretchrect completes
- present begins, making buffer 1 the front buffer
- monitor begins displaying front buffer
- stretchrect into buffer 2 begins
- stretchrect completes
- present begins, making buffer 2 the front buffer, even though the monitor hadn't finished displaying buffer 1 yet
tearing occurs here, because the monitor gets signals from 2 different buffers
- monitor finishes displaying front buffer

It's important to understand that that is what's happening, because otherwise you won't have any idea on how to fix it.
Kippesoep

This topic is closed to new replies.

Advertisement