pix3.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. #pragma once
  4. #ifndef _PIX3_H_
  5. #define _PIX3_H_
  6. #include <sal.h>
  7. #ifndef __cplusplus
  8. #error "Only C++ files can include pix3.h. C is not supported."
  9. #endif
  10. #if !defined(USE_PIX_SUPPORTED_ARCHITECTURE)
  11. #if defined(_M_X64) || defined(USE_PIX_ON_ALL_ARCHITECTURES) || defined(_M_ARM64)
  12. #define USE_PIX_SUPPORTED_ARCHITECTURE
  13. #endif
  14. #endif
  15. #if !defined(USE_PIX)
  16. #if defined(USE_PIX_SUPPORTED_ARCHITECTURE) && (defined(_DEBUG) || DBG || defined(PROFILE) || defined(PROFILE_BUILD)) && !defined(_PREFAST_)
  17. #define USE_PIX
  18. #endif
  19. #endif
  20. #if defined(USE_PIX) && !defined(USE_PIX_SUPPORTED_ARCHITECTURE)
  21. #pragma message("Warning: Pix markers are only supported on AMD64 and ARM64")
  22. #endif
  23. // These flags are used by both PIXBeginCapture and PIXGetCaptureState
  24. #define PIX_CAPTURE_TIMING (1 << 0)
  25. #define PIX_CAPTURE_GPU (1 << 1)
  26. #define PIX_CAPTURE_FUNCTION_SUMMARY (1 << 2)
  27. #define PIX_CAPTURE_FUNCTION_DETAILS (1 << 3)
  28. #define PIX_CAPTURE_CALLGRAPH (1 << 4)
  29. #define PIX_CAPTURE_INSTRUCTION_TRACE (1 << 5)
  30. #define PIX_CAPTURE_SYSTEM_MONITOR_COUNTERS (1 << 6)
  31. #define PIX_CAPTURE_VIDEO (1 << 7)
  32. #define PIX_CAPTURE_AUDIO (1 << 8)
  33. #define PIX_CAPTURE_GPU_TRACE (1 << 9)
  34. #define PIX_CAPTURE_RESERVED (1 << 15)
  35. union PIXCaptureParameters
  36. {
  37. enum PIXCaptureStorage
  38. {
  39. Memory = 0,
  40. MemoryCircular = 1, // Xbox only
  41. FileCircular = 2, // PC only
  42. };
  43. struct GpuCaptureParameters
  44. {
  45. PCWSTR FileName;
  46. } GpuCaptureParameters;
  47. struct TimingCaptureParameters
  48. {
  49. PCWSTR FileName;
  50. UINT32 MaximumToolingMemorySizeMb;
  51. PIXCaptureStorage CaptureStorage;
  52. BOOL CaptureGpuTiming;
  53. BOOL CaptureCallstacks;
  54. BOOL CaptureCpuSamples;
  55. UINT32 CpuSamplesPerSecond;
  56. BOOL CaptureFileIO;
  57. BOOL CaptureVirtualAllocEvents;
  58. BOOL CaptureHeapAllocEvents;
  59. BOOL CaptureXMemEvents; // Xbox only
  60. BOOL CapturePixMemEvents;
  61. BOOL CapturePageFaultEvents;
  62. BOOL CaptureVideoFrames; // Xbox only
  63. } TimingCaptureParameters;
  64. struct GpuTraceParameters // Xbox Series and newer only
  65. {
  66. PWSTR FileName;
  67. UINT32 MaximumToolingMemorySizeMb;
  68. BOOL CaptureGpuOccupancy;
  69. } GpuTraceParameters;
  70. };
  71. typedef PIXCaptureParameters* PPIXCaptureParameters;
  72. #if defined(XBOX) || defined(_XBOX_ONE) || defined(_DURANGO) || defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT)
  73. #include "pix3_xbox.h"
  74. #else
  75. #include "pix3_win.h"
  76. #endif
  77. #if defined(XBOX) || defined(_XBOX_ONE) || defined(_DURANGO) || defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT)
  78. #define PIX_XBOX
  79. #if defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT)
  80. #define PIX_GAMING_XBOX
  81. #endif
  82. #endif
  83. #if !defined(PIX_USE_GPU_MARKERS_V2)
  84. #ifdef PIX_GAMING_XBOX
  85. #define PIX_USE_GPU_MARKERS_V2
  86. #endif
  87. #endif
  88. #if defined(USE_PIX_SUPPORTED_ARCHITECTURE) && (defined(USE_PIX) || defined(USE_PIX_RETAIL))
  89. #define PIX_EVENTS_ARE_TURNED_ON
  90. #include "PIXEventsCommon.h"
  91. #include "PIXEvents.h"
  92. #ifdef USE_PIX
  93. // Starts a programmatically controlled capture.
  94. // captureFlags uses the PIX_CAPTURE_* family of flags to specify the type of capture to take
  95. extern "C" HRESULT WINAPI PIXBeginCapture2(DWORD captureFlags, _In_opt_ const PPIXCaptureParameters captureParameters);
  96. inline HRESULT PIXBeginCapture(DWORD captureFlags, _In_opt_ const PPIXCaptureParameters captureParameters) { return PIXBeginCapture2(captureFlags, captureParameters); }
  97. // Stops a programmatically controlled capture
  98. // If discard == TRUE, the captured data is discarded
  99. // If discard == FALSE, the captured data is saved
  100. // discard parameter is not supported on Windows
  101. extern "C" HRESULT WINAPI PIXEndCapture(BOOL discard);
  102. extern "C" DWORD WINAPI PIXGetCaptureState();
  103. extern "C" void WINAPI PIXReportCounter(_In_ PCWSTR name, float value);
  104. #endif // USE_PIX
  105. #endif // (USE_PIX_SUPPORTED_ARCHITECTURE) && (USE_PIX || USE_PIX_RETAIL)
  106. #if !defined(USE_PIX_SUPPORTED_ARCHITECTURE) || !defined(USE_PIX)
  107. // Eliminate these APIs when not using PIX
  108. inline HRESULT PIXBeginCapture2(DWORD, _In_opt_ const PIXCaptureParameters*) { return S_OK; }
  109. inline HRESULT PIXBeginCapture(DWORD, _In_opt_ const PIXCaptureParameters*) { return S_OK; }
  110. inline HRESULT PIXEndCapture(BOOL) { return S_OK; }
  111. inline HRESULT PIXGpuCaptureNextFrames(PCWSTR, UINT32) { return S_OK; }
  112. inline HRESULT PIXSetTargetWindow(HWND) { return S_OK; }
  113. inline HRESULT PIXForceD3D11On12() { return S_OK; }
  114. inline HRESULT WINAPI PIXSetHUDOptions(PIXHUDOptions) { return S_OK; }
  115. inline bool WINAPI PIXIsAttachedForGpuCapture() { return false; }
  116. inline HINSTANCE WINAPI PIXOpenCaptureInUI(PCWSTR) { return 0; }
  117. inline HMODULE PIXLoadLatestWinPixGpuCapturerLibrary() { return nullptr; }
  118. inline HMODULE PIXLoadLatestWinPixTimingCapturerLibrary() { return nullptr; }
  119. inline DWORD PIXGetCaptureState() { return 0; }
  120. inline void PIXReportCounter(_In_ PCWSTR, float) {}
  121. inline void PIXNotifyWakeFromFenceSignal(_In_ HANDLE) {}
  122. #if !defined(USE_PIX_RETAIL)
  123. inline void PIXBeginEvent(UINT64, _In_ PCSTR, ...) {}
  124. inline void PIXBeginEvent(UINT64, _In_ PCWSTR, ...) {}
  125. inline void PIXBeginEvent(void*, UINT64, _In_ PCSTR, ...) {}
  126. inline void PIXBeginEvent(void*, UINT64, _In_ PCWSTR, ...) {}
  127. inline void PIXEndEvent() {}
  128. inline void PIXEndEvent(void*) {}
  129. inline void PIXSetMarker(UINT64, _In_ PCSTR, ...) {}
  130. inline void PIXSetMarker(UINT64, _In_ PCWSTR, ...) {}
  131. inline void PIXSetMarker(void*, UINT64, _In_ PCSTR, ...) {}
  132. inline void PIXSetMarker(void*, UINT64, _In_ PCWSTR, ...) {}
  133. inline void PIXBeginRetailEvent(void*, UINT64, _In_ PCSTR, ...) {}
  134. inline void PIXBeginRetailEvent(void*, UINT64, _In_ PCWSTR, ...) {}
  135. inline void PIXEndRetailEvent(void*) {}
  136. inline void PIXSetRetailMarker(void*, UINT64, _In_ PCSTR, ...) {}
  137. inline void PIXSetRetailMarker(void*, UINT64, _In_ PCWSTR, ...) {}
  138. inline void PIXScopedEvent(UINT64, _In_ PCSTR, ...) {}
  139. inline void PIXScopedEvent(UINT64, _In_ PCWSTR, ...) {}
  140. inline void PIXScopedEvent(void*, UINT64, _In_ PCSTR, ...) {}
  141. inline void PIXScopedEvent(void*, UINT64, _In_ PCWSTR, ...) {}
  142. #endif // !USE_PIX_RETAIL
  143. // don't show warnings about expressions with no effect
  144. #pragma warning(disable:4548)
  145. #pragma warning(disable:4555)
  146. #endif // !USE_PIX_SUPPORTED_ARCHITECTURE || !USE_PIX
  147. // Use these functions to specify colors to pass as metadata to a PIX event/marker API.
  148. // Use PIX_COLOR() to specify a particular color for an event.
  149. // Or, use PIX_COLOR_INDEX() to specify a set of unique event categories, and let PIX choose
  150. // the colors to represent each category.
  151. inline UINT32 PIX_COLOR(UINT8 r, UINT8 g, UINT8 b) { return 0xff000000u | ((UINT32)r << 16) | ((UINT32)g << 8) | (UINT32)b; }
  152. inline UINT8 PIX_COLOR_INDEX(UINT8 i) { return i; }
  153. const UINT8 PIX_COLOR_DEFAULT = PIX_COLOR_INDEX(0);
  154. #endif // _PIX3_H_