| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "NvCoDx12CounterFence.h" |
| |
|
| | namespace nvidia { |
| | namespace Common { |
| |
|
| | Dx12CounterFence::~Dx12CounterFence() |
| | { |
| | if (m_event) |
| | { |
| | CloseHandle(m_event); |
| | } |
| | } |
| |
|
| | int Dx12CounterFence::init(ID3D12Device* device, uint64_t initialValue) |
| | { |
| | m_currentValue = initialValue; |
| |
|
| | NV_RETURN_ON_FAIL(device->CreateFence(m_currentValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence))); |
| | |
| | m_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); |
| | if (m_event == nullptr) |
| | { |
| | int res = HRESULT_FROM_WIN32(GetLastError()); |
| | return NV_FAILED(res) ? res : NV_FAIL; |
| | } |
| | return NV_OK; |
| | } |
| |
|
| | uint64_t Dx12CounterFence::nextSignal(ID3D12CommandQueue* commandQueue) |
| | { |
| | |
| | m_currentValue++; |
| | |
| | int res = commandQueue->Signal(m_fence.Get(), m_currentValue); |
| | if (NV_FAILED(res)) |
| | { |
| | printf("Signal failed"); |
| | } |
| | return m_currentValue; |
| | } |
| |
|
| | void Dx12CounterFence::waitUntilCompleted(uint64_t completedValue) |
| | { |
| | |
| | assert(completedValue <= m_currentValue); |
| |
|
| | |
| | while (m_fence->GetCompletedValue() < completedValue) |
| | { |
| | |
| | HRESULT res = m_fence->SetEventOnCompletion(completedValue, m_event); |
| | if (FAILED(res)) { assert(0); return; } |
| |
|
| | WaitForSingleObject(m_event, INFINITE); |
| | } |
| | } |
| |
|
| | void Dx12CounterFence::nextSignalAndWait(ID3D12CommandQueue* commandQueue) |
| | { |
| | waitUntilCompleted(nextSignal(commandQueue)); |
| | } |
| |
|
| | } |
| | } |
| |
|