Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DX11Device::InitProfiling()
- {
- D3D11_QUERY_DESC desc;
- desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
- desc.MiscFlags = 0;
- this->device->CreateQuery(&desc, &this->profiling.disjointQuery);
- desc.Query = D3D11_QUERY_TIMESTAMP;
- this->device->CreateQuery(&desc, &this->profiling.startQuery);
- this->device->CreateQuery(&desc, &this->profiling.endQuery);
- this->profiling.inited = true;
- }
- void DX11Device::StartProfiling()
- {
- if (this->profiling.inited == false)
- {
- MyUtils::Logger::LogError("Profiling not inited.");
- return;
- }
- this->deviceContext->Begin(this->profiling.disjointQuery);
- this->deviceContext->End(this->profiling.startQuery);
- }
- void DX11Device::EndProfiling()
- {
- if (this->profiling.inited == false)
- {
- MyUtils::Logger::LogError("Profiling not inited.");
- return;
- }
- this->deviceContext->End(this->profiling.endQuery);
- this->deviceContext->End(this->profiling.disjointQuery);
- }
- float DX11Device::GetProfilingTime()
- {
- if (this->profiling.inited == false)
- {
- MyUtils::Logger::LogError("Profiling not inited.");
- return 0.0f;
- }
- // Get the query data
- UINT64 startTime = 0;
- while(this->deviceContext->GetData(this->profiling.startQuery, &startTime, sizeof(startTime), 0) != S_OK);
- UINT64 endTime = 0;
- while(this->deviceContext->GetData(this->profiling.endQuery, &endTime, sizeof(endTime), 0) != S_OK);
- D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData;
- while(this->deviceContext->GetData(this->profiling.disjointQuery, &disjointData, sizeof(disjointData), 0) != S_OK);
- float time = 0.0f;
- if(disjointData.Disjoint == FALSE)
- {
- UINT64 delta = endTime - startTime;
- float frequency = static_cast<float>(disjointData.Frequency);
- time = (delta / frequency) * 1000.0f;
- }
- return time;
- }
Advertisement
Add Comment
Please, Sign In to add comment