Peto
Založen: 01. 08. 2007 Příspěvky: 206 Bydliště: Košice
|
Zaslal: 17. leden 2015, 09:22:46 Předmět: DirectX11 - SwapChain->Present() synchronizacia |
|
|
Nemali ste nahodou niekto problem s SwapChain->Present(), resp s FPS v DirectX11. Ide o to ze mam 2 verzie enginu, DX9 a DX11... daval som si fakt bacha na to aby DX11 neslo pomalsie ako DX9, co sa mi aj podarilo, avsak len na niektorych PC, na niektorych PC DX11 ide pomalsie (resp FPS je nestabilne)... na vine bude zrejme SwapChain->Present().. chyba sa prejavuje tak ze hra proste masivne seka, par framov ide OK, potom nasleduje zasek na SwapChain->Present()
Kvoli tejto chybe je proste hra nehratelna, da sa to opravit jedine
kód: |
IDXGIDevice1* idxgiDevice = NULL;
g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice1), (void**)&idxgiDevice);
idxgiDevice->SetMaximumFrameLatency(1);
|
Co sposobi sice potlacenie problemu az tak ze skoro nieje vidiet, ale predsa tam nejaky ten zasek je
Zaujimave je ze na mojom PC, sa akoby ta funkcia ani neberie do uvahy, mozem tam dat aj SetMaximumFrameLatency(15) a nic sa nestane, ak vsak na problematickych PC specifikujem SetMaximumFrameLatency(15) tak sa problem asi este stonasobne zhorsi
Viem ze v dokumentacii sa pise ze odporucaju pouzivat DXGI 1.2 alebo 1.3 kde to vyzera ze to nejako uz vychytali mozno.. ale tak vydat hru iba na Windows 8 si fakt dovolit dnes asi nikto nemoze..
Inak v DX9 vsetko bezi vsade.. problem dokonca pretrvava aj na uplne jednoduchych scenach takze bud som urobil niekde chybu na uplne low level urovni (napr v tom ze pouzivam Effect11 ) alebo je ta "chyba" niekde mimo mna..
Nemate s tym niekto skusenosti? ... inak tu su moje kody na vytvaranie swap chain:
kód: |
unsigned int numerator, denominator;
HRESULT result;
IDXGIFactory1* factory;// Create a DirectX graphics interface factory.
result = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory);
if(FAILED(result))
{
C3DLog_PrintError("CreateDXGIFactory: FAILED");
return 1;
}
if(m_Settings.VSync)
{
IDXGIAdapter1* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i;
DXGI_MODE_DESC* displayModeList;
// Use the factory to create an adapter for the primary graphics interface (video card).
result = factory->EnumAdapters1(0, &adapter);
if(FAILED(result))
{
C3DLog_PrintError("EnumAdapters: FAILED");
return 1;
}
// Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
{
C3DLog_PrintError("EnumOutputs: FAILED");
return 1;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if(FAILED(result))
{
C3DLog_PrintError("GetDisplayModeList: FAILED");
return 1;
}
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
// Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
{
C3DLog_PrintError("GetDisplayModeList: FAILED");
return 1;
}
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
for(i=0; i<numModes; i++)
{
if(displayModeList[i].Width == (unsigned int)m_Settings.DisplayWidth)
{
if(displayModeList[i].Height == (unsigned int)m_Settings.DisplayHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// Release the display mode list.
delete [] displayModeList;
displayModeList = 0;
// Release the adapter output.
adapterOutput->Release();
adapterOutput = 0;
// Release the adapter.
adapter->Release();
adapter = 0;
}
HRESULT hr = S_OK;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = m_Settings.DisplayWidth;
sd.BufferDesc.Height = m_Settings.DisplayHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
if(m_Settings.VSync)
{
sd.BufferDesc.RefreshRate.Numerator = numerator;
sd.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
sd.BufferDesc.RefreshRate.Numerator = 0;
sd.BufferDesc.RefreshRate.Denominator = 1;
}
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = m_Settings.WHandle;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
if (m_Settings.Windowed)
sd.Windowed = 1;
else
sd.Windowed = 0;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
{
C3DLog_PrintError("D3D11CreateDeviceAndSwapChain: FAILED");
return 1;
}
// Create a render target view
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
{
C3DLog_PrintError("g_pSwapChain->GetBuffer: FAILED");
return 1;
}
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release();
if( FAILED( hr ) )
{
C3DLog_PrintError("g_pd3dDevice->CreateRenderTargetView: FAILED");
return 2;
}
// Create depth stencil texture
D3D11_TEXTURE2D_DESC descDepth;
ZeroMemory( &descDepth, sizeof(descDepth) );
descDepth.Width = m_Settings.DisplayWidth;
descDepth.Height = m_Settings.DisplayHeight;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &g_pDepthStencil );
if( FAILED( hr ) )
{
C3DLog_PrintError("g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &g_pDepthStencil ): FAILED");
return 3;
}
// Create the depth stencil view
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
ZeroMemory( &descDSV, sizeof(descDSV) );
descDSV.Format = descDepth.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
hr = g_pd3dDevice->CreateDepthStencilView( g_pDepthStencil, &descDSV, &g_pDepthStencilView );
if( FAILED( hr ) )
{
C3DLog_PrintError("g_pd3dDevice->CreateDepthStencilView( g_pDepthStencil, &descDSV, &g_pDepthStencilView: FAILED");
return 3;
}
// Set Render Target & Depth Stencil
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView );
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)m_Settings.DisplayWidth;
vp.Height = (FLOAT)m_Settings.DisplayHeight;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports( 1, &vp );
m_Type = C3DAPI_DEVICE_D3D11;
//null attached
g_pRenderTargetViewAttached.clear();
g_pDepthStencilViewAttached = NULL;
//window association
factory->MakeWindowAssociation(m_Settings.WHandle,DXGI_MWA_NO_WINDOW_CHANGES );
IDXGIDevice1* idxgiDevice = NULL;
g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice1), (void**)&idxgiDevice);
idxgiDevice->SetMaximumFrameLatency(1);
|
Present:
kód: |
if (m_Settings.VSync)
g_pSwapChain->Present( 1, 0 );
else
g_pSwapChain->Present( 0, 0 );
|
_________________ Code or die!
|
|