BsGPUProfiler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "BsProfilerFwd.h"
  5. namespace BansheeEngine
  6. {
  7. struct GPUProfilerReport
  8. {
  9. struct Sample
  10. {
  11. String name; /**< Name of the sample for easier identification. */
  12. float timeMs; /**< Time in milliseconds it took to execute the sampled block. */
  13. UINT32 numDrawCalls; /**< Number of draw calls that happened. */
  14. UINT32 numRenderTargetChanges; /**< How many times was render target changed. */
  15. UINT32 numPresents; /**< How many times did a buffer swap happen on a double buffered render target. */
  16. UINT32 numClears; /**< How many times was render target cleared. */
  17. UINT32 numVertices; /**< Total number of vertices sent to the GPU. */
  18. UINT32 numTriangles; /**< Total number of triangles sent to the GPU. */
  19. UINT32 numDrawnSamples; /**< Number of samples drawn by the GPU. */
  20. UINT32 numBlendStateChanges; /**< How many times did the blend state change. */
  21. UINT32 numRasterizerStateChanges; /**< How many times did the rasterizer state change. */
  22. UINT32 numDepthStencilStateChanges; /**< How many times did the depth stencil state change. */
  23. UINT32 numTextureBinds; /**< How many times was a texture bound. */
  24. UINT32 numSamplerBinds; /**< How many times was a sampler bound. */
  25. UINT32 numVertexBufferBinds; /**< How many times was a vertex buffer bound. */
  26. UINT32 numIndexBufferBinds; /**< How many times was an index buffer bound. */
  27. UINT32 numGpuParamBufferBinds; /**< How many times was an GPU parameter buffer bound. */
  28. UINT32 numGpuProgramBinds; /**< How many times was a GPU program bound. */
  29. UINT32 numResourceWrites; /**< How many times were GPU resources written to. */
  30. UINT32 numResourceReads; /**< How many times were GPU resources read from. */
  31. UINT32 numObjectsCreated; /**< How many GPU objects were created. */
  32. UINT32 numObjectsDestroyed; /**< How many GPU objects were destroyed. */
  33. };
  34. Sample frameSample; /**< Sample containing data for entire frame. */
  35. Vector<Sample> samples;
  36. };
  37. /**
  38. * @brief Profiler that measures time and amount of various GPU operations.
  39. *
  40. * @note Sim thread only. However most operations will be queued on the core thread or
  41. * on the GPU itself so the results will not be immediately available.
  42. */
  43. class CM_EXPORT GPUProfiler : public Module<GPUProfiler>
  44. {
  45. /**
  46. * @brief Signals a start of a new frame. Every frame will generate a separate profiling report.
  47. * This call must be followed by "endFrame", and any sampling operations must happen between
  48. * beginFrame and endFrame.
  49. */
  50. void beginFrame();
  51. /**
  52. * @brief Signals an end of the currently sampled frame. Results of the sampling will be available
  53. * once getNumAvailableReports increments. This may take a while as the sampling is scheduled on
  54. * the core thread and on the GPU.
  55. */
  56. void endFrame();
  57. /**
  58. * @brief Begins sample measurement. Must be followed by endSample.
  59. *
  60. * @param name Unique name for the sample you can later use to find the sampling data.
  61. *
  62. * @note Must be called between beginFrame/endFrame calls.
  63. */
  64. void beginSample(const ProfilerString& name);
  65. /**
  66. * @brief Ends sample measurement.
  67. *
  68. * @param name Unique name for the sample.
  69. *
  70. * @note Unique name is primarily needed to more easily identify mismatched
  71. * begin/end sample pairs. Otherwise the name in beginSample would be enough.
  72. * Must be called between beginFrame/endFrame calls.
  73. */
  74. void endSample(const ProfilerString& name);
  75. /**
  76. * @brief Returns number of profiling reports that are ready but haven't been
  77. * retrieved yet.
  78. *
  79. * @note There is an internal limit of maximum number of available reports, where oldest ones will
  80. * get deleted so make sure to call this often if you don't want to miss some.
  81. */
  82. UINT32 getNumAvailableReports();
  83. /**
  84. * @brief Gets the oldest report available and removes it from the internal list.
  85. * Throws an exception if no reports are available.
  86. */
  87. const GPUProfilerReport& getNextReport();
  88. };
  89. }