Migrate ProfilerGPU to new lightweight queries API

This commit is contained in:
Wojtek Figat
2026-01-16 13:24:56 +01:00
parent 0d7c04682d
commit 847f6411e7
5 changed files with 44 additions and 55 deletions

View File

@@ -583,7 +583,7 @@ uint64 GPUContextDX11::BeginQuery(GPUQueryType type)
auto& query = _device->_queries.AddOne();
query.Type = type;
D3D11_QUERY_DESC queryDesc;
queryDesc.Query = D3D11_QUERY_TIMESTAMP;
queryDesc.Query = type == GPUQueryType::Occlusion ? D3D11_QUERY_OCCLUSION : D3D11_QUERY_TIMESTAMP;
queryDesc.MiscFlags = 0;
HRESULT hr = _device->GetDevice()->CreateQuery(&queryDesc, &query.Query);
LOG_DIRECTX_RESULT_WITH_RETURN(hr, 0);
@@ -608,7 +608,7 @@ uint64 GPUContextDX11::BeginQuery(GPUQueryType type)
auto& query = _device->_queries[queryIndex];
ASSERT_LOW_LAYER(query.State == GPUQueryDataDX11::Ready);
ASSERT_LOW_LAYER(query.Type == type);
query.State = GPUQueryDataDX11::Active;
query.State = GPUQueryDataDX11::Begin;
auto context = _device->GetIM();
if (type == GPUQueryType::Timer)
{
@@ -633,6 +633,8 @@ void GPUContextDX11::EndQuery(uint64 queryID)
GPUQueryDX11 q;
q.Raw = queryID;
auto& query = _device->_queries[q.Index];
ASSERT_LOW_LAYER(query.State == GPUQueryDataDX11::Begin);
query.State = GPUQueryDataDX11::End;
auto context = _device->GetIM();
context->End(query.Query);
if (q.Type == (uint16)GPUQueryType::Timer)

View File

@@ -921,6 +921,7 @@ bool GPUDeviceDX11::GetQueryResult(uint64 queryID, uint64& result, bool wait)
result = query.Result;
return true;
}
ASSERT_LOW_LAYER(query.State == GPUQueryDataDX11::End);
auto context = GetIM();
RETRY:
@@ -935,7 +936,7 @@ RETRY:
context->GetData(query.TimerBeginQuery, &timeBegin, sizeof(timeBegin), 0);
context->GetData(query.Query, &timeEnd, sizeof(timeEnd), 0);
if (disjointData.Disjoint == FALSE)
if (disjointData.Disjoint == FALSE && disjointData.Frequency > 0)
{
result = timeEnd > timeBegin ? (timeEnd - timeBegin) * 1000000ull / disjointData.Frequency : 0;
}

View File

@@ -41,7 +41,7 @@ struct GPUQueryDataDX11
ID3D11Query* TimerBeginQuery = nullptr;
ID3D11Query* DisjointQuery = nullptr;
uint64 Result = 0;
enum States { Ready, Active, Finished } State = Ready;
enum States { Ready, Begin, End, Finished } State = Ready;
GPUQueryType Type = GPUQueryType::MAX;
void Release();