Add new GPU Query API that is lightweight and supports occlusion queries
This commit is contained in:
@@ -20,9 +20,7 @@ void GPUTimerQueryDX12::OnReleaseGPU()
|
||||
void GPUTimerQueryDX12::Begin()
|
||||
{
|
||||
const auto context = _device->GetMainContextDX12();
|
||||
auto& heap = _device->TimestampQueryHeap;
|
||||
heap.EndQuery(context, _begin);
|
||||
|
||||
_query = context->BeginQuery(GPUQueryType::Timer);
|
||||
_hasResult = false;
|
||||
_endCalled = false;
|
||||
}
|
||||
@@ -31,14 +29,8 @@ void GPUTimerQueryDX12::End()
|
||||
{
|
||||
if (_endCalled)
|
||||
return;
|
||||
|
||||
const auto context = _device->GetMainContextDX12();
|
||||
auto& heap = _device->TimestampQueryHeap;
|
||||
heap.EndQuery(context, _end);
|
||||
|
||||
const auto queue = _device->GetCommandQueue()->GetCommandQueue();
|
||||
VALIDATE_DIRECTX_CALL(queue->GetTimestampFrequency(&_gpuFrequency));
|
||||
|
||||
context->EndQuery(_query);
|
||||
_endCalled = true;
|
||||
}
|
||||
|
||||
@@ -48,33 +40,16 @@ bool GPUTimerQueryDX12::HasResult()
|
||||
return false;
|
||||
if (_hasResult)
|
||||
return true;
|
||||
|
||||
auto& heap = _device->TimestampQueryHeap;
|
||||
return heap.IsReady(_end) && heap.IsReady(_begin);
|
||||
uint64 result;
|
||||
return _device->GetQueryResult(_query, result, false);
|
||||
}
|
||||
|
||||
float GPUTimerQueryDX12::GetResult()
|
||||
{
|
||||
if (_hasResult)
|
||||
{
|
||||
return _timeDelta;
|
||||
}
|
||||
|
||||
const uint64 timeBegin = *(uint64*)_device->TimestampQueryHeap.ResolveQuery(_begin);
|
||||
const uint64 timeEnd = *(uint64*)_device->TimestampQueryHeap.ResolveQuery(_end);
|
||||
|
||||
// Calculate event duration in milliseconds
|
||||
if (timeEnd > timeBegin)
|
||||
{
|
||||
const uint64 delta = timeEnd - timeBegin;
|
||||
const double frequency = double(_gpuFrequency);
|
||||
_timeDelta = static_cast<float>((delta / frequency) * 1000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeDelta = 0.0f;
|
||||
}
|
||||
|
||||
uint64 result;
|
||||
_timeDelta = _device->GetQueryResult(_query, result, true) ? (float)((double)result / 1000.0) : 0.0f;
|
||||
_hasResult = true;
|
||||
return _timeDelta;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user