Commit ccdc59da authored by Joshua Ashton's avatar Joshua Ashton 🐸

[d3d9] Hook up new signal system for frame latency

parent e27868a9
......@@ -42,7 +42,6 @@ namespace dxvk {
: m_adapter ( pAdapter )
, m_dxvkDevice ( dxvkDevice )
, m_csThread ( dxvkDevice->createContext() )
, m_frameLatency ( DefaultFrameLatency )
, m_csChunk ( AllocCsChunk() )
, m_parent ( pParent )
, m_deviceType ( DeviceType )
......@@ -64,11 +63,6 @@ namespace dxvk {
m_initializer = new D3D9Initializer(m_dxvkDevice);
m_converter = new D3D9FormatHelper(m_dxvkDevice);
m_frameLatencyCap = m_d3d9Options.maxFrameLatency;
for (uint32_t i = 0; i < m_frameEvents.size(); i++)
m_frameEvents[i] = new sync::Signal(true);
EmitCs([
cDevice = m_dxvkDevice
] (DxvkContext* ctx) {
......@@ -3189,8 +3183,8 @@ namespace dxvk {
if (MaxLatency == 0)
MaxLatency = DefaultFrameLatency;
if (MaxLatency > m_frameEvents.size())
MaxLatency = m_frameEvents.size();
if (MaxLatency > MaxFrameLatency)
MaxLatency = MaxFrameLatency;
m_frameLatency = MaxLatency;
......@@ -3812,22 +3806,6 @@ namespace dxvk {
}
Rc<sync::Signal> D3D9DeviceEx::GetFrameSyncEvent(UINT BufferCount) {
uint32_t frameLatency = m_frameLatency;
if (BufferCount != 0
&& BufferCount <= frameLatency)
frameLatency = BufferCount;
if (m_frameLatencyCap != 0
&& m_frameLatencyCap <= frameLatency)
frameLatency = m_frameLatencyCap;
uint32_t frameId = m_frameId++ % frameLatency;
return m_frameEvents[frameId];
}
DxvkDeviceFeatures D3D9DeviceEx::GetDeviceFeatures(const Rc<DxvkAdapter>& adapter) {
DxvkDeviceFeatures supported = adapter->features();
DxvkDeviceFeatures enabled = {};
......
......@@ -653,8 +653,6 @@ namespace dxvk {
return m_dxvkDevice;
}
Rc<sync::Signal> GetFrameSyncEvent(UINT BufferCount);
D3D9_VK_FORMAT_MAPPING LookupFormat(
D3D9Format Format) const;
......@@ -868,11 +866,7 @@ namespace dxvk {
DxvkCsThread m_csThread;
bool m_csIsBusy = false;
uint32_t m_frameLatencyCap;
uint32_t m_frameLatency;
uint32_t m_frameId = 0;
std::array<Rc<sync::Signal>,
MaxFrameLatency> m_frameEvents;
uint32_t m_frameLatency = DefaultFrameLatency;
D3D9Initializer* m_initializer = nullptr;
D3D9FormatHelper* m_converter = nullptr;
......@@ -1040,6 +1034,10 @@ namespace dxvk {
}
}
inline uint32_t GetFrameLatency() {
return m_frameLatency;
}
template <
DxsoProgramType ProgramType,
D3D9ConstantType ConstantType,
......
......@@ -26,7 +26,9 @@ namespace dxvk {
const D3DDISPLAYMODEEX* pFullscreenDisplayMode)
: D3D9SwapChainExBase(pDevice)
, m_device (pDevice->GetDXVKDevice())
, m_context (m_device->createContext()) {
, m_context (m_device->createContext())
, m_frameLatencyCap (pDevice->GetOptions()->maxFrameLatency)
, m_frameLatencySignal(new sync::Fence(m_frameId)) {
UpdateMonitorInfo();
this->NormalizePresentParameters(pPresentParams);
......@@ -409,8 +411,8 @@ namespace dxvk {
m_parent->Flush();
// Wait for the sync event so that we respect the maximum frame latency
auto syncEvent = m_parent->GetFrameSyncEvent(m_presentParams.BackBufferCount);
syncEvent->wait();
uint64_t frameId = ++m_frameId;
m_frameLatencySignal->wait(frameId - GetActualFrameLatency());
if (m_hud != nullptr)
m_hud->update();
......@@ -517,7 +519,7 @@ namespace dxvk {
m_hud->render(m_context, info.imageExtent);
if (i + 1 >= SyncInterval)
m_context->queueSignal(syncEvent);
m_context->signal(m_frameLatencySignal, frameId);
SubmitPresent(sync);
}
......@@ -923,6 +925,18 @@ namespace dxvk {
}
uint32_t D3D9SwapChainEx::GetActualFrameLatency() {
uint32_t maxFrameLatency = m_parent->GetFrameLatency();
if (m_frameLatencyCap)
maxFrameLatency = std::min(maxFrameLatency, m_frameLatencyCap);
maxFrameLatency = std::min(maxFrameLatency, m_presentParams.BackBufferCount + 1);
return maxFrameLatency;
}
uint32_t D3D9SwapChainEx::PickFormats(
D3D9Format Format,
VkSurfaceFormatKHR* pDstFormats) {
......
......@@ -5,6 +5,8 @@
#include "../dxvk/hud/dxvk_hud.h"
#include "../util/sync/sync_signal.h"
#include <vector>
namespace dxvk {
......@@ -130,6 +132,11 @@ namespace dxvk {
std::vector<Rc<DxvkImageView>> m_imageViews;
uint64_t m_frameId = D3D9DeviceEx::MaxFrameLatency;
uint32_t m_frameLatencyCap = 0;
Rc<sync::Fence> m_frameLatencySignal;
bool m_dirty = true;
bool m_vsync = true;
......@@ -171,6 +178,8 @@ namespace dxvk {
void InitRamp();
uint32_t GetActualFrameLatency();
uint32_t PickFormats(
D3D9Format Format,
VkSurfaceFormatKHR* pDstFormats);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment