Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/DX12SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ HRESULT DX12SwapChain::GetDevice(REFIID uuid, void** ppDevice)
return swapChain->GetDevice(uuid, ppDevice);
}

float DX12SwapChain::GetFrameTime() const
{
// Calculate frame time based on swap chain presentation
static float lastPresentTime = 0.0f;
static float frameTime = 1.0f / 60.0f; // Default to 60 fps
static LARGE_INTEGER frequency = {};
static LARGE_INTEGER currentTime = {};

if (frequency.QuadPart == 0) {
QueryPerformanceFrequency(&frequency);
}

QueryPerformanceCounter(&currentTime);
float time = static_cast<float>(currentTime.QuadPart) / static_cast<float>(frequency.QuadPart);

if (lastPresentTime > 0.0f) {
frameTime = time - lastPresentTime;
}
lastPresentTime = time;

return frameTime;
}

WrappedResource::WrappedResource(D3D11_TEXTURE2D_DESC a_texDesc, ID3D11Device5* a_d3d11Device, ID3D12Device* a_d3d12Device)
{
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
Expand Down
3 changes: 3 additions & 0 deletions src/DX12SwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class DX12SwapChain

DXGISwapChainProxy* swapChainProxy = nullptr;

// Returns the current frame time (in seconds) for accurate FPS calculation when frame generation is active
float GetFrameTime() const;

void CreateD3D12Device(IDXGIAdapter* a_adapter);
void CreateSwapChain(IDXGIAdapter* adapter, DXGI_SWAP_CHAIN_DESC swapChainDesc);

Expand Down
Loading