mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 04:23:51 +00:00
Implemented GPU synchronization protocol
This commit is contained in:
parent
660f2cec7f
commit
c768068ee7
@ -50,8 +50,8 @@ namespace tracy
|
|||||||
|
|
||||||
bool m_initialized = false;
|
bool m_initialized = false;
|
||||||
|
|
||||||
ID3D12Device* m_device;
|
ID3D12Device* m_device = nullptr;
|
||||||
ID3D12CommandQueue* m_queue;
|
ID3D12CommandQueue* m_queue = nullptr;
|
||||||
uint8_t m_context;
|
uint8_t m_context;
|
||||||
Microsoft::WRL::ComPtr<ID3D12QueryHeap> m_queryHeap;
|
Microsoft::WRL::ComPtr<ID3D12QueryHeap> m_queryHeap;
|
||||||
Microsoft::WRL::ComPtr<ID3D12Resource> m_readbackBuffer;
|
Microsoft::WRL::ComPtr<ID3D12Resource> m_readbackBuffer;
|
||||||
@ -65,6 +65,9 @@ namespace tracy
|
|||||||
Microsoft::WRL::ComPtr<ID3D12Fence> m_payloadFence;
|
Microsoft::WRL::ComPtr<ID3D12Fence> m_payloadFence;
|
||||||
std::queue<D3D12QueryPayload> m_payloadQueue;
|
std::queue<D3D12QueryPayload> m_payloadQueue;
|
||||||
|
|
||||||
|
int64_t m_prevCalibration = 0;
|
||||||
|
int64_t m_qpcToNs = int64_t{ 1000000000 / GetFrequencyQpc() };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
D3D12QueueCtx(ID3D12Device* device, ID3D12CommandQueue* queue)
|
D3D12QueueCtx(ID3D12Device* device, ID3D12CommandQueue* queue)
|
||||||
: m_device(device)
|
: m_device(device)
|
||||||
@ -98,6 +101,9 @@ namespace tracy
|
|||||||
assert(false && "Failed to get queue clock calibration.");
|
assert(false && "Failed to get queue clock calibration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the device cpu timestamp, not the profiler's timestamp.
|
||||||
|
m_prevCalibration = cpuTimestamp * m_qpcToNs;
|
||||||
|
|
||||||
cpuTimestamp = Profiler::GetTime();
|
cpuTimestamp = Profiler::GetTime();
|
||||||
|
|
||||||
D3D12_QUERY_HEAP_DESC heapDesc{};
|
D3D12_QUERY_HEAP_DESC heapDesc{};
|
||||||
@ -233,6 +239,34 @@ namespace tracy
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_readbackBuffer->Unmap(0, nullptr);
|
m_readbackBuffer->Unmap(0, nullptr);
|
||||||
|
|
||||||
|
// Recalibrate to account for drift.
|
||||||
|
|
||||||
|
uint64_t cpuTimestamp;
|
||||||
|
uint64_t gpuTimestamp;
|
||||||
|
|
||||||
|
if (FAILED(m_queue->GetClockCalibration(&gpuTimestamp, &cpuTimestamp)))
|
||||||
|
{
|
||||||
|
assert(false && "Failed to get queue clock calibration.");
|
||||||
|
}
|
||||||
|
|
||||||
|
cpuTimestamp *= m_qpcToNs;
|
||||||
|
|
||||||
|
const auto cpuDelta = cpuTimestamp - m_prevCalibration;
|
||||||
|
if (cpuDelta > 0)
|
||||||
|
{
|
||||||
|
m_prevCalibration = cpuTimestamp;
|
||||||
|
cpuTimestamp = Profiler::GetTime();
|
||||||
|
|
||||||
|
auto* item = Profiler::QueueSerial();
|
||||||
|
MemWrite(&item->hdr.type, QueueType::GpuCalibration);
|
||||||
|
MemWrite(&item->gpuCalibration.gpuTime, gpuTimestamp);
|
||||||
|
MemWrite(&item->gpuCalibration.cpuTime, cpuTimestamp);
|
||||||
|
MemWrite(&item->gpuCalibration.cpuDelta, cpuDelta);
|
||||||
|
MemWrite(&item->gpuCalibration.context, m_context);
|
||||||
|
|
||||||
|
Profiler::QueueSerialFinish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user