Guest User

DX11 time measurement

a guest
Mar 23rd, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. void DX11Device::InitProfiling()
  2. {  
  3.     D3D11_QUERY_DESC desc;
  4.     desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
  5.     desc.MiscFlags = 0;
  6.     this->device->CreateQuery(&desc, &this->profiling.disjointQuery);
  7.  
  8.     desc.Query = D3D11_QUERY_TIMESTAMP;
  9.     this->device->CreateQuery(&desc, &this->profiling.startQuery);
  10.     this->device->CreateQuery(&desc, &this->profiling.endQuery);
  11.  
  12.     this->profiling.inited = true;
  13. }
  14.  
  15. void DX11Device::StartProfiling()
  16. {
  17.     if (this->profiling.inited == false)
  18.     {
  19.         MyUtils::Logger::LogError("Profiling not inited.");
  20.         return;
  21.     }
  22.     this->deviceContext->Begin(this->profiling.disjointQuery);
  23.     this->deviceContext->End(this->profiling.startQuery);
  24. }
  25.  
  26. void DX11Device::EndProfiling()
  27. {
  28.     if (this->profiling.inited == false)
  29.     {
  30.         MyUtils::Logger::LogError("Profiling not inited.");
  31.         return;
  32.     }
  33.     this->deviceContext->End(this->profiling.endQuery);
  34.     this->deviceContext->End(this->profiling.disjointQuery);
  35. }
  36.  
  37. float DX11Device::GetProfilingTime()
  38. {
  39.     if (this->profiling.inited == false)
  40.     {
  41.         MyUtils::Logger::LogError("Profiling not inited.");
  42.         return 0.0f;
  43.     }
  44.  
  45.     // Get the query data
  46.     UINT64 startTime = 0;
  47.     while(this->deviceContext->GetData(this->profiling.startQuery, &startTime, sizeof(startTime), 0) != S_OK);
  48.  
  49.     UINT64 endTime = 0;
  50.     while(this->deviceContext->GetData(this->profiling.endQuery, &endTime, sizeof(endTime), 0) != S_OK);
  51.  
  52.     D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData;
  53.     while(this->deviceContext->GetData(this->profiling.disjointQuery, &disjointData, sizeof(disjointData), 0) != S_OK);
  54.  
  55.     float time = 0.0f;
  56.     if(disjointData.Disjoint == FALSE)
  57.     {
  58.         UINT64 delta = endTime - startTime;
  59.         float frequency = static_cast<float>(disjointData.Frequency);
  60.         time = (delta / frequency) * 1000.0f;
  61.     }
  62.  
  63.     return time;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment