Jump to content

VSYNC is not working


Recommended Posts

Actually, removing my comment, after additional tests:

The real problem was related with the real FPS calculation.

Hello,

The feature VSYNC in settings is not working during the main rendering, is working for example in main menu and settings.

Is settings.cfg I have:

  • SYNC_VBL = 1

I have 3 monitors with 144Hz, the main one the one that is rendering KSP 1.8.1 at full-screen 1920x1080@144Hz, is getting FPS between 145 and 149Hz, which prove that VSYNC is not working at all.

Of-course get high FPS is "always" (not always) good, but if there is a setting in Menu to limit the VSYNC it should work, is there as dummy setting that don't work, using some settings of 60 , 75 or 100 depending the monitor/card level that should work as well and don't work at all.

ZN3Suze.png

Even better than fast FPS is the smooth a real VSYNC working and this is just a line of code:

// ----------------------------------------------------------------------------------------------
bool DX11Class::createSwapChainDX11device (    HWND hwnd, int screenWidth, int screenHeight, BOOL vsync,
                                            BOOL fullscreen, BOOL g_UseDoubleBuffering, BOOL g_AllowResize,
                                            UINT numerator, UINT denominator)
// ----------------------------------------------------------------------------------------------
{
    HRESULT result = S_OK;

    ASSERT (hwnd); // FATAL ERROR: Create Main Window first!

    // Fill out the description of the swap chain
    // ==========================================
    // Initialize the swap chain description:
    DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};    // ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

    // Set to a single/double-buffering back buffer:
    swapChainDesc.BufferCount = (g_UseDoubleBuffering) ? 2 : 1; // Use double-buffering to minimize latency.

    // Set the width and height of the back buffer:
    swapChainDesc.BufferDesc.Width = screenWidth;    
    swapChainDesc.BufferDesc.Height = screenHeight;

    // The default: 32-bit surface for the back buffer: (RGB + A) 8 bits each (This is the most common swap chain format)
    swapChainDesc.BufferDesc.Format = BUFFER_COLOR_FORMAT; // Default: DXGI_FORMAT_R8G8B8A8_UNORM

    // Set the refresh rate of the back buffer:
    swapChainDesc.BufferDesc.RefreshRate.Numerator = (vsync) ? numerator : 0;
    swapChainDesc.BufferDesc.RefreshRate.Denominator = (vsync) ? denominator : 1;

    // Set the default usage of the back buffer:
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;

    swapChainDesc.Windowed = !fullscreen;    // Set to "Fullscreen" or "Windowed Mode":

    // Default: 0, This member is used to tell Direct3D how to perform multisample anti-aliased (MSAA) rendering    
    swapChainDesc.SampleDesc.Count = ReqMSAAmultiSampleCount;
    swapChainDesc.SampleDesc.Quality = ReqMSAAquality - 1;        // MSAA

    swapChainDesc.Flags = (g_AllowResize) ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;

    // Set the scan line ordering and scaling to unspecified:
    //swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    //swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    // Discard the back buffer contents after presenting:
    //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    IDXGIDevice* pDXGIDevice = NULL;
    result = m_device->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
    if( FAILED( result ) ) return false;

#if defined DXGI1_1 || defined DXGI1_2
    pDXGIDevice->SetGPUThreadPriority(7);
#endif

    IDXGIAdapterN* pDXGIAdapter = NULL;
    result = pDXGIDevice->GetParent(__uuidof(IDXGIAdapterN), (void **)&pDXGIAdapter);
    if( FAILED( result ) ) return false;    

    if (pDXGIAdapter)
    {
        DXGI_ADAPTER_DESC sDXGIAdapterDesc;
        pDXGIAdapter->GetDesc(&sDXGIAdapterDesc);
        m_sCapabilities.nTotalAvailableGPUMemory = sDXGIAdapterDesc.DedicatedVideoMemory; //unit: bytes
    }

    IDXGIFactoryN* pIDXGIFactory = NULL;
    result = pDXGIAdapter->GetParent(__uuidof(IDXGIFactoryN), (void **)&pIDXGIFactory);
    if( FAILED( result ) ) return false;    

    // For each Monitor:
    for (int i = 0; i < SystemHandle->windowsArray.size(); i++)
    {
        DXwindowDataContainer DXwindow;
        DXwindow.m_swapChain = NULL;
        DXwindow.m_backBuffer = NULL;
        DXwindow.m_renderTargetView = NULL;
        DXwindow.m_depthStencilView = NULL;

        swapChainDesc.OutputWindow = SystemHandle->windowsArray.hWnd;        // Set the handle for the window to render to.
        result = pIDXGIFactory->CreateSwapChain(m_device,&swapChainDesc,&DXwindow.m_swapChain); // Turn Screen to Black
        if (FAILED(result)) return false;

        DX11windowsArray.push_back(DXwindow);
    }

    if (!g_AllowResize)
        pIDXGIFactory->MakeWindowAssociation(SystemHandle->windowsArray[0].hWnd, DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER); //Prevent DXGI from responding to an alt-enter sequence.

    SAFE_RELEASE(pDXGIDevice);
    SAFE_RELEASE(pDXGIAdapter);
    SAFE_RELEASE(pIDXGIFactory);

    return true;
}

 

Using it:

// ----------------------------------------------------------------------------------------------
void DX11Class::EndScene(UINT monitorWindow)
// ----------------------------------------------------------------------------------------------
{
    // <PRINT THE 3D SCENE TO SCREEN> to Swap Chain (wait from VSYNC refresh rate, if it is the case)
    DX11windowsArray[monitorWindow].m_swapChain->Present(m_VSYNC_ENABLED, 0);
}

Edited by pmborg
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...