Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualErik Rufelt

Posted 12 November 2012 - 11:15 AM

I just tried this myself, and I get the same problem as you with DXGI. However, I get correct behavior using DirectDraw (for vsync only, drawing with D3D11 / DXGISwapChain.

You can try it like this:
#include <ddraw.h>

typedef HRESULT (WINAPI * PFNDIRECTDRAWCREATE)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);

load() {
	HMODULE hDDrawLib = LoadLibrary(TEXT("ddraw.dll"));
	if(hDDrawLib == NULL) {
		// fail
	}

	PFNDIRECTDRAWCREATE pDirectDrawCreate = (PFNDIRECTDRAWCREATE)GetProcAddress(hDDrawLib, "DirectDrawCreate");
	if(pDirectDrawCreate == NULL) {
		// fail
	}

	LPDIRECTDRAW pDDraw;
	HRESULT hResult = pDirectDrawCreate(NULL, &pDDraw, NULL);
	if(FAILED(hResult)) {
		// fail
	}
}

vsync() {
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL);
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}

vsync_alternative() {
	BOOL vb = TRUE;
	while(vb == TRUE)
		pDDraw->GetVerticalBlankStatus(&vb);
	while(vb == FALSE)
		pDDraw->GetVerticalBlankStatus(&vb);
}

release() {
	pDDraw->Release();
	FreeLibrary(hDDrawLib);
}

loop() {
	vsync();
	pSwapChain->Present(0, 0);
}

#3Erik Rufelt

Posted 12 November 2012 - 11:12 AM

I just tried this myself, and I get the same problem as you with DXGI. However, I get correct behavior using DirectDraw (for vsync only, drawing with D3D11 / DXGISwapChain.

You can try it like this:
#include <ddraw.h>

typedef HRESULT (WINAPI * PFNDIRECTDRAWCREATE)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);

load() {
	HMODULE hDDrawLib = LoadLibrary(TEXT("ddraw.dll"));
	if(hDDrawLib == NULL) {
		// fail
	}

	PFNDIRECTDRAWCREATE pDirectDrawCreate = (PFNDIRECTDRAWCREATE)GetProcAddress(hDDrawLib, "DirectDrawCreate");
	if(pDirectDrawCreate == NULL) {
		// fail
	}

	LPDIRECTDRAW pDDraw;
	HRESULT hResult = pDirectDrawCreate(NULL, &pDDraw, NULL);
	if(FAILED(hResult)) {
		// fail
	}
}

vsync() {
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL);
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}

vsync_alternative() {
	BOOL vb = TRUE;
	while(vb == TRUE)
		pDDraw->GetVerticalBlankStatus(&vb);
	while(vb == FALSE)
		pDDraw->GetVerticalBlankStatus(&vb);
}

release() {
	pDDraw->Release();
	FreeLibrary(hDDrawLib);
}

loop() {
	vsync();
	pSwapChain->Present(0, 0);
}

I'm not sure how well this plays with frame-buffering.. perhaps you want to query your device for an IDXGIDevice1, and if it exists use SetMaximumFrameLatency(1).

#2Erik Rufelt

Posted 12 November 2012 - 11:11 AM

I just tried this myself, and I get the same problem as you with DXGI. However, I get correct behavior using DirectDraw.

You can try it like this:
#include <ddraw.h>

typedef HRESULT (WINAPI * PFNDIRECTDRAWCREATE)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);

load() {
	HMODULE hDDrawLib = LoadLibrary(TEXT("ddraw.dll"));
	if(hDDrawLib == NULL) {
		// fail
	}
  
	PFNDIRECTDRAWCREATE pDirectDrawCreate = (PFNDIRECTDRAWCREATE)GetProcAddress(hDDrawLib, "DirectDrawCreate");
	if(pDirectDrawCreate == NULL) {
		// fail
	}
  
	LPDIRECTDRAW pDDraw;
	HRESULT hResult = pDirectDrawCreate(NULL, &pDDraw, NULL);
	if(FAILED(hResult)) {
		// fail
	}
}

vsync() {
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL);
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}

vsync_alternative() {
	BOOL vb = TRUE;
	while(vb == TRUE)
		pDDraw->GetVerticalBlankStatus(&vb);
	while(vb == FALSE)
		pDDraw->GetVerticalBlankStatus(&vb);
}

release() {
	pDDraw->Release();
	FreeLibrary(hDDrawLib);
}

loop() {
	vsync();
	pSwapChain->Present(0, 0);
}

I'm not sure how well this plays with frame-buffering.. perhaps you want to query your device for an IDXGIDevice1, and if it exists use SetMaximumFrameLatency(1).

#1Erik Rufelt

Posted 12 November 2012 - 11:11 AM

I just tried this myself, and I get the same problem as you with DXGI. However, I get correct behavior using DirectDraw.

You can try it like this:
#include <ddraw.h>
typedef HRESULT (WINAPI * PFNDIRECTDRAWCREATE)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);
load() {
    HMODULE hDDrawLib = LoadLibrary(TEXT("ddraw.dll"));
    if(hDDrawLib == NULL) {
	    // fail
    }
   
    PFNDIRECTDRAWCREATE pDirectDrawCreate = (PFNDIRECTDRAWCREATE)GetProcAddress(hDDrawLib, "DirectDrawCreate");
    if(pDirectDrawCreate == NULL) {
	    // fail
    }
   
    LPDIRECTDRAW pDDraw;
    HRESULT hResult = pDirectDrawCreate(NULL, &pDDraw, NULL);
    if(FAILED(hResult)) {
	    // fail
    }
}
vsync() {
    pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL);
    pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}
vsync_alternative() {
    BOOL vb = TRUE;
    while(vb == TRUE)
	    pDDraw->GetVerticalBlankStatus(&vb);
    while(vb == FALSE)
	    pDDraw->GetVerticalBlankStatus(&vb);
}
release() {
    pDDraw->Release();
    FreeLibrary(hDDrawLib);
}
loop() {
    vsync();
    pSwapChain->Present(0, 0);
}

I'm not sure how well this plays with frame-buffering.. perhaps you want to query your device for an IDXGIDevice1, and if it exists use SetMaximumFrameLatency(1).

PARTNERS