PIXEvents.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. // Don't include this file directly - use pix3.h
  4. #pragma once
  5. #ifndef _PixEvents_H_
  6. #define _PixEvents_H_
  7. #ifndef _PIX3_H_
  8. # error Do not include this file directly - use pix3.h
  9. #endif
  10. #include "PIXEventsCommon.h"
  11. #if _MSC_VER < 1800
  12. # error This version of pix3.h is only supported on Visual Studio 2013 or higher
  13. #elif _MSC_VER < 1900
  14. # ifndef constexpr // Visual Studio 2013 doesn't support constexpr
  15. # define constexpr
  16. # define PIX3__DEFINED_CONSTEXPR
  17. # endif
  18. #endif
  19. // Xbox does not support CPU events for retail scenarios
  20. #if defined(USE_PIX) || !defined(PIX_XBOX)
  21. #define PIX_CONTEXT_EMIT_CPU_EVENTS
  22. #endif
  23. namespace PIXEventsDetail
  24. {
  25. inline void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit)
  26. {
  27. // nothing
  28. UNREFERENCED_PARAMETER(destination);
  29. UNREFERENCED_PARAMETER(limit);
  30. }
  31. template<typename ARG, typename... ARGS>
  32. void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, ARG const& arg, ARGS const&... args)
  33. {
  34. PIXCopyEventArgument(destination, limit, arg);
  35. PIXCopyEventArguments(destination, limit, args...);
  36. }
  37. template<typename ARG, typename... ARGS>
  38. void PIXCopyStringArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, ARG const& arg, ARGS const&... args)
  39. {
  40. PIXCopyStringArgument(destination, limit, arg);
  41. PIXCopyEventArguments(destination, limit, args...);
  42. }
  43. template<typename ARG, typename... ARGS>
  44. void PIXCopyStringArgumentsWithContext(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, void* context, ARG const& arg, ARGS const&... args)
  45. {
  46. #ifdef PIX_XBOX
  47. UNREFERENCED_PARAMETER(context);
  48. PIXCopyStringArgument(destination, limit, arg);
  49. PIXCopyEventArguments(destination, limit, args...);
  50. #else
  51. PIXCopyEventArgument(destination, limit, context);
  52. PIXCopyStringArgument(destination, limit, arg);
  53. PIXCopyEventArguments(destination, limit, args...);
  54. #endif
  55. }
  56. inline UINT8 PIXGetEventSize(const UINT64* end, const UINT64* start)
  57. {
  58. const UINT64 actualEventSize = end - start;
  59. return static_cast<UINT8>(actualEventSize > PIXEventsSizeMax ? PIXEventsSizeMax : actualEventSize);
  60. }
  61. template<typename STR>
  62. inline UINT8 PIXEncodeStringIsAnsi()
  63. {
  64. return PIX_EVENT_METADATA_NONE;
  65. }
  66. template<>
  67. inline UINT8 PIXEncodeStringIsAnsi<char*>()
  68. {
  69. return PIX_EVENT_METADATA_STRING_IS_ANSI;
  70. }
  71. template<>
  72. inline UINT8 PIXEncodeStringIsAnsi<const char*>()
  73. {
  74. return PIX_EVENT_METADATA_STRING_IS_ANSI;
  75. }
  76. template<typename STR, typename... ARGS>
  77. __declspec(noinline) void PIXBeginEventAllocate(PIXEventsThreadInfo* threadInfo, UINT64 color, STR formatString, ARGS... args)
  78. {
  79. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  80. if (!time)
  81. return;
  82. UINT64* destination = threadInfo->destination;
  83. UINT64* limit = threadInfo->biasedLimit;
  84. if (destination >= limit)
  85. return;
  86. limit += PIXEventsSafeFastCopySpaceQwords;
  87. UINT64* eventDestination = destination++;
  88. *destination++ = color;
  89. PIXCopyStringArguments(destination, limit, formatString, args...);
  90. *destination = PIXEventsBlockEndMarker;
  91. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  92. const UINT8 eventMetadata =
  93. PIX_EVENT_METADATA_HAS_COLOR |
  94. PIXEncodeStringIsAnsi<STR>();
  95. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  96. threadInfo->destination = destination;
  97. }
  98. template<typename STR, typename... ARGS>
  99. void PIXBeginEvent(UINT64 color, STR formatString, ARGS... args)
  100. {
  101. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  102. UINT64* limit = threadInfo->biasedLimit;
  103. if (limit != nullptr)
  104. {
  105. UINT64* destination = threadInfo->destination;
  106. if (destination < limit)
  107. {
  108. limit += PIXEventsSafeFastCopySpaceQwords;
  109. UINT64 time = PIXGetTimestampCounter();
  110. UINT64* eventDestination = destination++;
  111. *destination++ = color;
  112. PIXCopyStringArguments(destination, limit, formatString, args...);
  113. *destination = PIXEventsBlockEndMarker;
  114. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  115. const UINT8 eventMetadata =
  116. PIX_EVENT_METADATA_HAS_COLOR |
  117. PIXEncodeStringIsAnsi<STR>();
  118. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  119. threadInfo->destination = destination;
  120. }
  121. else
  122. {
  123. PIXBeginEventAllocate(threadInfo, color, formatString, args...);
  124. }
  125. }
  126. }
  127. template<typename STR, typename... ARGS>
  128. __declspec(noinline) void PIXBeginEventAllocate(PIXEventsThreadInfo* threadInfo, UINT8 color, STR formatString, ARGS... args)
  129. {
  130. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  131. if (!time)
  132. return;
  133. UINT64* destination = threadInfo->destination;
  134. UINT64* limit = threadInfo->biasedLimit;
  135. if (destination >= limit)
  136. return;
  137. limit += PIXEventsSafeFastCopySpaceQwords;
  138. UINT64* eventDestination = destination++;
  139. PIXCopyStringArguments(destination, limit, formatString, args...);
  140. *destination = PIXEventsBlockEndMarker;
  141. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  142. const UINT8 eventMetadata =
  143. PIXEncodeStringIsAnsi<STR>() |
  144. PIXEncodeIndexColor(color);
  145. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  146. threadInfo->destination = destination;
  147. }
  148. template<typename STR, typename... ARGS>
  149. void PIXBeginEvent(UINT8 color, STR formatString, ARGS... args)
  150. {
  151. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  152. UINT64* limit = threadInfo->biasedLimit;
  153. if (limit != nullptr)
  154. {
  155. UINT64* destination = threadInfo->destination;
  156. if (destination < limit)
  157. {
  158. limit += PIXEventsSafeFastCopySpaceQwords;
  159. UINT64 time = PIXGetTimestampCounter();
  160. UINT64* eventDestination = destination++;
  161. PIXCopyStringArguments(destination, limit, formatString, args...);
  162. *destination = PIXEventsBlockEndMarker;
  163. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  164. const UINT8 eventMetadata =
  165. PIXEncodeStringIsAnsi<STR>() |
  166. PIXEncodeIndexColor(color);
  167. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  168. threadInfo->destination = destination;
  169. }
  170. else
  171. {
  172. PIXBeginEventAllocate(threadInfo, color, formatString, args...);
  173. }
  174. }
  175. }
  176. template<typename STR, typename... ARGS>
  177. __declspec(noinline) void PIXSetMarkerAllocate(PIXEventsThreadInfo* threadInfo, UINT64 color, STR formatString, ARGS... args)
  178. {
  179. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  180. if (!time)
  181. return;
  182. UINT64* destination = threadInfo->destination;
  183. UINT64* limit = threadInfo->biasedLimit;
  184. if (destination >= limit)
  185. return;
  186. limit += PIXEventsSafeFastCopySpaceQwords;
  187. UINT64* eventDestination = destination++;
  188. *destination++ = color;
  189. PIXCopyStringArguments(destination, limit, formatString, args...);
  190. *destination = PIXEventsBlockEndMarker;
  191. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  192. const UINT8 eventMetadata =
  193. PIXEncodeStringIsAnsi<STR>() |
  194. PIX_EVENT_METADATA_HAS_COLOR;
  195. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  196. threadInfo->destination = destination;
  197. }
  198. template<typename STR, typename... ARGS>
  199. void PIXSetMarker(UINT64 color, STR formatString, ARGS... args)
  200. {
  201. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  202. UINT64* limit = threadInfo->biasedLimit;
  203. if (limit != nullptr)
  204. {
  205. UINT64* destination = threadInfo->destination;
  206. if (destination < limit)
  207. {
  208. limit += PIXEventsSafeFastCopySpaceQwords;
  209. UINT64 time = PIXGetTimestampCounter();
  210. UINT64* eventDestination = destination++;
  211. *destination++ = color;
  212. PIXCopyStringArguments(destination, limit, formatString, args...);
  213. *destination = PIXEventsBlockEndMarker;
  214. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  215. const UINT8 eventMetadata =
  216. PIXEncodeStringIsAnsi<STR>() |
  217. PIX_EVENT_METADATA_HAS_COLOR;
  218. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  219. threadInfo->destination = destination;
  220. }
  221. else
  222. {
  223. PIXSetMarkerAllocate(threadInfo, color, formatString, args...);
  224. }
  225. }
  226. }
  227. template<typename STR, typename... ARGS>
  228. __declspec(noinline) void PIXSetMarkerAllocate(PIXEventsThreadInfo* threadInfo, UINT8 color, STR formatString, ARGS... args)
  229. {
  230. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  231. if (!time)
  232. return;
  233. UINT64* destination = threadInfo->destination;
  234. UINT64* limit = threadInfo->biasedLimit;
  235. if (destination >= limit)
  236. return;
  237. limit += PIXEventsSafeFastCopySpaceQwords;
  238. UINT64* eventDestination = destination++;
  239. PIXCopyStringArguments(destination, limit, formatString, args...);
  240. *destination = PIXEventsBlockEndMarker;
  241. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  242. const UINT8 eventMetadata =
  243. PIXEncodeStringIsAnsi<STR>() |
  244. PIXEncodeIndexColor(color);
  245. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  246. threadInfo->destination = destination;
  247. }
  248. template<typename STR, typename... ARGS>
  249. void PIXSetMarker(UINT8 color, STR formatString, ARGS... args)
  250. {
  251. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  252. UINT64* limit = threadInfo->biasedLimit;
  253. if (limit != nullptr)
  254. {
  255. UINT64* destination = threadInfo->destination;
  256. if (destination < limit)
  257. {
  258. limit += PIXEventsSafeFastCopySpaceQwords;
  259. UINT64 time = PIXGetTimestampCounter();
  260. UINT64* eventDestination = destination++;
  261. PIXCopyStringArguments(destination, limit, formatString, args...);
  262. *destination = PIXEventsBlockEndMarker;
  263. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  264. const UINT8 eventMetadata =
  265. PIXEncodeStringIsAnsi<STR>() |
  266. PIXEncodeIndexColor(color);
  267. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  268. threadInfo->destination = destination;
  269. }
  270. else
  271. {
  272. PIXSetMarkerAllocate(threadInfo, color, formatString, args...);
  273. }
  274. }
  275. }
  276. template<typename STR, typename... ARGS>
  277. __declspec(noinline) void PIXBeginEventOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT64 color, STR formatString, ARGS... args)
  278. {
  279. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  280. if (!time)
  281. {
  282. eventDestination = nullptr;
  283. return;
  284. }
  285. UINT64* destination = threadInfo->destination;
  286. UINT64* limit = threadInfo->biasedLimit;
  287. if (destination >= limit)
  288. {
  289. eventDestination = nullptr;
  290. return;
  291. }
  292. limit += PIXEventsSafeFastCopySpaceQwords;
  293. eventDestination = destination++;
  294. *destination++ = color;
  295. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  296. *destination = PIXEventsBlockEndMarker;
  297. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  298. const UINT8 eventMetadata =
  299. PIX_EVENT_METADATA_ON_CONTEXT |
  300. PIXEncodeStringIsAnsi<STR>() |
  301. PIX_EVENT_METADATA_HAS_COLOR;
  302. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  303. threadInfo->destination = destination;
  304. }
  305. template<typename STR, typename... ARGS>
  306. void PIXBeginEventOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT64 color, STR formatString, ARGS... args)
  307. {
  308. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  309. UINT64* limit = threadInfo->biasedLimit;
  310. if (limit == nullptr)
  311. {
  312. eventDestination = nullptr;
  313. return;
  314. }
  315. UINT64* destination = threadInfo->destination;
  316. if (destination < limit)
  317. {
  318. limit += PIXEventsSafeFastCopySpaceQwords;
  319. UINT64 time = PIXGetTimestampCounter();
  320. eventDestination = destination++;
  321. *destination++ = color;
  322. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  323. *destination = PIXEventsBlockEndMarker;
  324. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  325. const UINT8 eventMetadata =
  326. PIX_EVENT_METADATA_ON_CONTEXT |
  327. PIXEncodeStringIsAnsi<STR>() |
  328. PIX_EVENT_METADATA_HAS_COLOR;
  329. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  330. threadInfo->destination = destination;
  331. }
  332. else
  333. {
  334. PIXBeginEventOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...);
  335. }
  336. }
  337. template<typename CONTEXT, typename STR, typename... ARGS>
  338. void PIXBeginEvent(CONTEXT* context, UINT64 color, STR formatString, ARGS... args)
  339. {
  340. UINT64* destination = nullptr;
  341. UINT8 eventSize = 0u;
  342. #ifdef PIX_CONTEXT_EMIT_CPU_EVENTS
  343. PIXBeginEventOnContextCpu(destination, eventSize, context, color, formatString, args...);
  344. #endif
  345. #ifdef PIX_USE_GPU_MARKERS_V2
  346. if (destination != nullptr)
  347. {
  348. PIXInsertTimingMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast<void*>(destination), eventSize * sizeof(UINT64));
  349. }
  350. else
  351. #endif
  352. {
  353. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  354. #ifdef PIX_USE_GPU_MARKERS_V2
  355. destination = buffer;
  356. UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords;
  357. UINT64* eventDestination = destination++;
  358. *destination++ = color;
  359. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  360. *destination = 0ull;
  361. eventSize = static_cast<const UINT8>(destination - buffer);
  362. const UINT8 eventMetadata =
  363. PIX_EVENT_METADATA_ON_CONTEXT |
  364. PIXEncodeStringIsAnsi<STR>() |
  365. PIX_EVENT_METADATA_HAS_COLOR;
  366. *eventDestination = PIXEncodeEventInfo(0, PIXEvent_BeginEvent, eventSize, eventMetadata);
  367. PIXInsertGPUMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  368. #else
  369. destination = PixEventsLegacy::EncodeBeginEventForContext(buffer, color, formatString, args...);
  370. PIXBeginGPUEventOnContext(context, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  371. #endif
  372. }
  373. }
  374. template<typename STR, typename... ARGS>
  375. __declspec(noinline) void PIXBeginEventOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT8 color, STR formatString, ARGS... args)
  376. {
  377. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  378. if (!time)
  379. {
  380. eventDestination = nullptr;
  381. return;
  382. }
  383. UINT64* destination = threadInfo->destination;
  384. UINT64* limit = threadInfo->biasedLimit;
  385. if (destination >= limit)
  386. {
  387. eventDestination = nullptr;
  388. return;
  389. }
  390. limit += PIXEventsSafeFastCopySpaceQwords;
  391. eventDestination = destination++;
  392. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  393. *destination = PIXEventsBlockEndMarker;
  394. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  395. const UINT8 eventMetadata =
  396. PIX_EVENT_METADATA_ON_CONTEXT |
  397. PIXEncodeStringIsAnsi<STR>() |
  398. PIXEncodeIndexColor(color);
  399. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  400. threadInfo->destination = destination;
  401. }
  402. template<typename STR, typename... ARGS>
  403. void PIXBeginEventOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT8 color, STR formatString, ARGS... args)
  404. {
  405. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  406. UINT64* limit = threadInfo->biasedLimit;
  407. if (limit == nullptr)
  408. {
  409. eventDestination = nullptr;
  410. return;
  411. }
  412. UINT64* destination = threadInfo->destination;
  413. if (destination < limit)
  414. {
  415. limit += PIXEventsSafeFastCopySpaceQwords;
  416. UINT64 time = PIXGetTimestampCounter();
  417. eventDestination = destination++;
  418. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  419. *destination = PIXEventsBlockEndMarker;
  420. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  421. const UINT8 eventMetadata =
  422. PIX_EVENT_METADATA_ON_CONTEXT |
  423. PIXEncodeStringIsAnsi<STR>() |
  424. PIXEncodeIndexColor(color);
  425. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata);
  426. threadInfo->destination = destination;
  427. }
  428. else
  429. {
  430. PIXBeginEventOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...);
  431. }
  432. }
  433. template<typename CONTEXT, typename STR, typename... ARGS>
  434. void PIXBeginEvent(CONTEXT* context, UINT8 color, STR formatString, ARGS... args)
  435. {
  436. UINT64* destination = nullptr;
  437. UINT8 eventSize = 0u;
  438. #ifdef PIX_CONTEXT_EMIT_CPU_EVENTS
  439. PIXBeginEventOnContextCpu(destination, eventSize, context, color, formatString, args...);
  440. #endif
  441. #ifdef PIX_USE_GPU_MARKERS_V2
  442. if (destination != nullptr)
  443. {
  444. PIXInsertTimingMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast<void*>(destination), eventSize * sizeof(UINT64));
  445. }
  446. else
  447. #endif
  448. {
  449. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  450. #ifdef PIX_USE_GPU_MARKERS_V2
  451. destination = buffer;
  452. UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords;
  453. UINT64* eventDestination = destination++;
  454. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  455. *destination = 0ull;
  456. eventSize = static_cast<const UINT8>(destination - buffer);
  457. const UINT8 eventMetadata =
  458. PIX_EVENT_METADATA_ON_CONTEXT |
  459. PIXEncodeStringIsAnsi<STR>() |
  460. PIXEncodeIndexColor(color);
  461. *eventDestination = PIXEncodeEventInfo(0, PIXEvent_BeginEvent, eventSize, eventMetadata);
  462. PIXInsertGPUMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  463. #else
  464. destination = PixEventsLegacy::EncodeBeginEventForContext(buffer, color, formatString, args...);
  465. PIXBeginGPUEventOnContext(context, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  466. #endif
  467. }
  468. }
  469. template<typename STR, typename... ARGS>
  470. __declspec(noinline) void PIXSetMarkerOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT64 color, STR formatString, ARGS... args)
  471. {
  472. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  473. if (!time)
  474. {
  475. eventDestination = nullptr;
  476. return;
  477. }
  478. UINT64* destination = threadInfo->destination;
  479. UINT64* limit = threadInfo->biasedLimit;
  480. if (destination >= limit)
  481. {
  482. eventDestination = nullptr;
  483. return;
  484. }
  485. limit += PIXEventsSafeFastCopySpaceQwords;
  486. eventDestination = destination++;
  487. *destination++ = color;
  488. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  489. *destination = PIXEventsBlockEndMarker;
  490. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  491. const UINT8 eventMetadata =
  492. PIX_EVENT_METADATA_ON_CONTEXT |
  493. PIXEncodeStringIsAnsi<STR>() |
  494. PIX_EVENT_METADATA_HAS_COLOR;
  495. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  496. threadInfo->destination = destination;
  497. }
  498. template<typename STR, typename... ARGS>
  499. void PIXSetMarkerOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT64 color, STR formatString, ARGS... args)
  500. {
  501. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  502. UINT64* limit = threadInfo->biasedLimit;
  503. if (limit == nullptr)
  504. {
  505. eventDestination = nullptr;
  506. return;
  507. }
  508. UINT64* destination = threadInfo->destination;
  509. if (destination < limit)
  510. {
  511. limit += PIXEventsSafeFastCopySpaceQwords;
  512. UINT64 time = PIXGetTimestampCounter();
  513. eventDestination = destination++;
  514. *destination++ = color;
  515. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  516. *destination = PIXEventsBlockEndMarker;
  517. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  518. const UINT8 eventMetadata =
  519. PIX_EVENT_METADATA_ON_CONTEXT |
  520. PIXEncodeStringIsAnsi<STR>() |
  521. PIX_EVENT_METADATA_HAS_COLOR;
  522. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  523. threadInfo->destination = destination;
  524. }
  525. else
  526. {
  527. PIXSetMarkerOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...);
  528. }
  529. }
  530. template<typename CONTEXT, typename STR, typename... ARGS>
  531. void PIXSetMarker(CONTEXT* context, UINT64 color, STR formatString, ARGS... args)
  532. {
  533. UINT64* destination = nullptr;
  534. UINT8 eventSize = 0u;
  535. #ifdef PIX_CONTEXT_EMIT_CPU_EVENTS
  536. PIXSetMarkerOnContextCpu(destination, eventSize, context, color, formatString, args...);
  537. #endif
  538. #ifdef PIX_USE_GPU_MARKERS_V2
  539. if (destination != nullptr)
  540. {
  541. PIXInsertTimingMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast<void*>(destination), eventSize * sizeof(UINT64));
  542. }
  543. else
  544. #endif
  545. {
  546. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  547. #ifdef PIX_USE_GPU_MARKERS_V2
  548. destination = buffer;
  549. UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords;
  550. UINT64* eventDestination = destination++;
  551. *destination++ = color;
  552. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  553. *destination = 0ull;
  554. eventSize = static_cast<const UINT8>(destination - buffer);
  555. const UINT8 eventMetadata =
  556. PIX_EVENT_METADATA_ON_CONTEXT |
  557. PIXEncodeStringIsAnsi<STR>() |
  558. PIX_EVENT_METADATA_HAS_COLOR;
  559. *eventDestination = PIXEncodeEventInfo(0, PIXEvent_SetMarker, eventSize, eventMetadata);
  560. PIXInsertGPUMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  561. #else
  562. destination = PixEventsLegacy::EncodeSetMarkerForContext(buffer, color, formatString, args...);
  563. PIXSetGPUMarkerOnContext(context, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  564. #endif
  565. }
  566. }
  567. template<typename STR, typename... ARGS>
  568. __declspec(noinline) void PIXSetMarkerOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT8 color, STR formatString, ARGS... args)
  569. {
  570. UINT64 time = PIXEventsReplaceBlock(threadInfo, false);
  571. if (!time)
  572. {
  573. eventDestination = nullptr;
  574. return;
  575. }
  576. UINT64* destination = threadInfo->destination;
  577. UINT64* limit = threadInfo->biasedLimit;
  578. if (destination >= limit)
  579. {
  580. eventDestination = nullptr;
  581. return;
  582. }
  583. limit += PIXEventsSafeFastCopySpaceQwords;
  584. eventDestination = destination++;
  585. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  586. *destination = PIXEventsBlockEndMarker;
  587. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  588. const UINT8 eventMetadata =
  589. PIX_EVENT_METADATA_ON_CONTEXT |
  590. PIXEncodeStringIsAnsi<STR>() |
  591. PIXEncodeIndexColor(color);
  592. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  593. threadInfo->destination = destination;
  594. }
  595. template<typename STR, typename... ARGS>
  596. void PIXSetMarkerOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT8 color, STR formatString, ARGS... args)
  597. {
  598. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  599. UINT64* limit = threadInfo->biasedLimit;
  600. if (limit == nullptr)
  601. {
  602. eventDestination = nullptr;
  603. return;
  604. }
  605. UINT64* destination = threadInfo->destination;
  606. if (destination < limit)
  607. {
  608. limit += PIXEventsSafeFastCopySpaceQwords;
  609. UINT64 time = PIXGetTimestampCounter();
  610. eventDestination = destination++;
  611. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  612. *destination = PIXEventsBlockEndMarker;
  613. eventSize = PIXGetEventSize(destination, threadInfo->destination);
  614. const UINT8 eventMetadata =
  615. PIX_EVENT_METADATA_ON_CONTEXT |
  616. PIXEncodeStringIsAnsi<STR>() |
  617. PIXEncodeIndexColor(color);
  618. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata);
  619. threadInfo->destination = destination;
  620. }
  621. else
  622. {
  623. PIXSetMarkerOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...);
  624. }
  625. }
  626. template<typename CONTEXT, typename STR, typename... ARGS>
  627. void PIXSetMarker(CONTEXT* context, UINT8 color, STR formatString, ARGS... args)
  628. {
  629. UINT64* destination = nullptr;
  630. UINT8 eventSize = 0u;
  631. #ifdef PIX_CONTEXT_EMIT_CPU_EVENTS
  632. PIXSetMarkerOnContextCpu(destination, eventSize, context, color, formatString, args...);
  633. #endif
  634. #ifdef PIX_USE_GPU_MARKERS_V2
  635. if (destination != nullptr)
  636. {
  637. PIXInsertTimingMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast<void*>(destination), eventSize * sizeof(UINT64));
  638. }
  639. else
  640. #endif
  641. {
  642. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  643. #ifdef PIX_USE_GPU_MARKERS_V2
  644. destination = buffer;
  645. UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords;
  646. UINT64* eventDestination = destination++;
  647. PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...);
  648. *destination = 0ull;
  649. eventSize = static_cast<const UINT8>(destination - buffer);
  650. const UINT8 eventMetadata =
  651. PIX_EVENT_METADATA_ON_CONTEXT |
  652. PIXEncodeStringIsAnsi<STR>() |
  653. PIXEncodeIndexColor(color);
  654. *eventDestination = PIXEncodeEventInfo(0, PIXEvent_SetMarker, eventSize, eventMetadata);
  655. PIXInsertGPUMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  656. #else
  657. destination = PixEventsLegacy::EncodeSetMarkerForContext(buffer, color, formatString, args...);
  658. PIXSetGPUMarkerOnContext(context, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  659. #endif
  660. }
  661. }
  662. __declspec(noinline) inline void PIXEndEventAllocate(PIXEventsThreadInfo* threadInfo)
  663. {
  664. UINT64 time = PIXEventsReplaceBlock(threadInfo, true);
  665. if (!time)
  666. return;
  667. UINT64* destination = threadInfo->destination;
  668. UINT64* limit = threadInfo->biasedLimit;
  669. if (destination >= limit)
  670. return;
  671. limit += PIXEventsSafeFastCopySpaceQwords;
  672. const UINT8 eventSize = 1;
  673. const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE;
  674. *destination++ = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata);
  675. *destination = PIXEventsBlockEndMarker;
  676. threadInfo->destination = destination;
  677. }
  678. inline void PIXEndEvent()
  679. {
  680. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  681. UINT64* limit = threadInfo->biasedLimit;
  682. if (limit != nullptr)
  683. {
  684. UINT64* destination = threadInfo->destination;
  685. if (destination < limit)
  686. {
  687. limit += PIXEventsSafeFastCopySpaceQwords;
  688. UINT64 time = PIXGetTimestampCounter();
  689. const UINT8 eventSize = 1;
  690. const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE;
  691. *destination++ = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata);
  692. *destination = PIXEventsBlockEndMarker;
  693. threadInfo->destination = destination;
  694. }
  695. else
  696. {
  697. PIXEndEventAllocate(threadInfo);
  698. }
  699. }
  700. }
  701. __declspec(noinline) inline UINT64* PIXEndEventOnContextCpuAllocate(PIXEventsThreadInfo* threadInfo, void* context)
  702. {
  703. UINT64 time = PIXEventsReplaceBlock(threadInfo, true);
  704. if (!time)
  705. return nullptr;
  706. UINT64* destination = threadInfo->destination;
  707. UINT64* limit = threadInfo->biasedLimit;
  708. if (destination >= limit)
  709. return nullptr;
  710. limit += PIXEventsSafeFastCopySpaceQwords;
  711. UINT64* eventDestination = destination++;
  712. #ifdef PIX_XBOX
  713. UNREFERENCED_PARAMETER(context);
  714. #else
  715. PIXCopyEventArgument(destination, limit, context);
  716. #endif
  717. * destination = PIXEventsBlockEndMarker;
  718. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  719. const UINT8 eventMetadata = PIX_EVENT_METADATA_ON_CONTEXT;
  720. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata);
  721. threadInfo->destination = destination;
  722. return eventDestination;
  723. }
  724. inline UINT64* PIXEndEventOnContextCpu(void* context)
  725. {
  726. PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo();
  727. UINT64* limit = threadInfo->biasedLimit;
  728. if (limit != nullptr)
  729. {
  730. UINT64* destination = threadInfo->destination;
  731. if (destination < limit)
  732. {
  733. limit += PIXEventsSafeFastCopySpaceQwords;
  734. UINT64 time = PIXGetTimestampCounter();
  735. UINT64* eventDestination = destination++;
  736. #ifndef PIX_XBOX
  737. PIXCopyEventArgument(destination, limit, context);
  738. #endif
  739. * destination = PIXEventsBlockEndMarker;
  740. const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination);
  741. const UINT8 eventMetadata = PIX_EVENT_METADATA_ON_CONTEXT;
  742. *eventDestination = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata);
  743. threadInfo->destination = destination;
  744. return eventDestination;
  745. }
  746. else
  747. {
  748. return PIXEndEventOnContextCpuAllocate(threadInfo, context);
  749. }
  750. }
  751. return nullptr;
  752. }
  753. template<typename CONTEXT>
  754. void PIXEndEvent(CONTEXT* context)
  755. {
  756. UINT64* destination = nullptr;
  757. #ifdef PIX_CONTEXT_EMIT_CPU_EVENTS
  758. destination = PIXEndEventOnContextCpu(context);
  759. #endif
  760. #ifdef PIX_USE_GPU_MARKERS_V2
  761. if (destination != nullptr)
  762. {
  763. PIXInsertTimingMarkerOnContextForEndEvent(context, PIXEvent_EndEvent);
  764. }
  765. else
  766. #endif
  767. {
  768. #ifdef PIX_USE_GPU_MARKERS_V2
  769. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  770. destination = buffer;
  771. UINT64* eventDestination = destination++;
  772. const UINT8 eventSize = static_cast<const UINT8>(destination - buffer);
  773. const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE;
  774. *eventDestination = PIXEncodeEventInfo(0, PIXEvent_EndEvent, eventSize, eventMetadata);
  775. PIXInsertGPUMarkerOnContextForEndEvent(context, PIXEvent_EndEvent, static_cast<void*>(buffer), static_cast<UINT>(reinterpret_cast<BYTE*>(destination) - reinterpret_cast<BYTE*>(buffer)));
  776. #else
  777. PIXEndGPUEventOnContext(context);
  778. #endif
  779. }
  780. }
  781. }
  782. #if defined(USE_PIX)
  783. template<typename... ARGS>
  784. void PIXBeginEvent(UINT64 color, PCWSTR formatString, ARGS... args)
  785. {
  786. PIXEventsDetail::PIXBeginEvent(color, formatString, args...);
  787. }
  788. template<typename... ARGS>
  789. void PIXBeginEvent(UINT64 color, PCSTR formatString, ARGS... args)
  790. {
  791. PIXEventsDetail::PIXBeginEvent(color, formatString, args...);
  792. }
  793. template<typename... ARGS>
  794. void PIXBeginEvent(UINT32 color, PCWSTR formatString, ARGS... args)
  795. {
  796. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  797. }
  798. template<typename... ARGS>
  799. void PIXBeginEvent(UINT32 color, PCSTR formatString, ARGS... args)
  800. {
  801. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  802. }
  803. template<typename... ARGS>
  804. void PIXBeginEvent(INT32 color, PCWSTR formatString, ARGS... args)
  805. {
  806. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  807. }
  808. template<typename... ARGS>
  809. void PIXBeginEvent(INT32 color, PCSTR formatString, ARGS... args)
  810. {
  811. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  812. }
  813. template<typename... ARGS>
  814. void PIXBeginEvent(DWORD color, PCWSTR formatString, ARGS... args)
  815. {
  816. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  817. }
  818. template<typename... ARGS>
  819. void PIXBeginEvent(DWORD color, PCSTR formatString, ARGS... args)
  820. {
  821. PIXEventsDetail::PIXBeginEvent(static_cast<UINT64>(color), formatString, args...);
  822. }
  823. template<typename... ARGS>
  824. void PIXBeginEvent(UINT8 color, PCWSTR formatString, ARGS... args)
  825. {
  826. PIXEventsDetail::PIXBeginEvent(color, formatString, args...);
  827. }
  828. template<typename... ARGS>
  829. void PIXBeginEvent(UINT8 color, PCSTR formatString, ARGS... args)
  830. {
  831. PIXEventsDetail::PIXBeginEvent(color, formatString, args...);
  832. }
  833. template<typename... ARGS>
  834. void PIXSetMarker(UINT64 color, PCWSTR formatString, ARGS... args)
  835. {
  836. PIXEventsDetail::PIXSetMarker(color, formatString, args...);
  837. }
  838. template<typename... ARGS>
  839. void PIXSetMarker(UINT64 color, PCSTR formatString, ARGS... args)
  840. {
  841. PIXEventsDetail::PIXSetMarker(color, formatString, args...);
  842. }
  843. template<typename... ARGS>
  844. void PIXSetMarker(UINT32 color, PCWSTR formatString, ARGS... args)
  845. {
  846. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  847. }
  848. template<typename... ARGS>
  849. void PIXSetMarker(UINT32 color, PCSTR formatString, ARGS... args)
  850. {
  851. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  852. }
  853. template<typename... ARGS>
  854. void PIXSetMarker(INT32 color, PCWSTR formatString, ARGS... args)
  855. {
  856. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  857. }
  858. template<typename... ARGS>
  859. void PIXSetMarker(INT32 color, PCSTR formatString, ARGS... args)
  860. {
  861. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  862. }
  863. template<typename... ARGS>
  864. void PIXSetMarker(DWORD color, PCWSTR formatString, ARGS... args)
  865. {
  866. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  867. }
  868. template<typename... ARGS>
  869. void PIXSetMarker(DWORD color, PCSTR formatString, ARGS... args)
  870. {
  871. PIXEventsDetail::PIXSetMarker(static_cast<UINT64>(color), formatString, args...);
  872. }
  873. template<typename... ARGS>
  874. void PIXSetMarker(UINT8 color, PCWSTR formatString, ARGS... args)
  875. {
  876. PIXEventsDetail::PIXSetMarker(color, formatString, args...);
  877. }
  878. template<typename... ARGS>
  879. void PIXSetMarker(UINT8 color, PCSTR formatString, ARGS... args)
  880. {
  881. PIXEventsDetail::PIXSetMarker(color, formatString, args...);
  882. }
  883. template<typename CONTEXT, typename... ARGS>
  884. void PIXBeginEvent(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  885. {
  886. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  887. }
  888. template<typename CONTEXT, typename... ARGS>
  889. void PIXBeginEvent(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  890. {
  891. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  892. }
  893. template<typename CONTEXT, typename... ARGS>
  894. void PIXBeginEvent(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  895. {
  896. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  897. }
  898. template<typename CONTEXT, typename... ARGS>
  899. void PIXBeginEvent(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  900. {
  901. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  902. }
  903. template<typename CONTEXT, typename... ARGS>
  904. void PIXBeginEvent(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  905. {
  906. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  907. }
  908. template<typename CONTEXT, typename... ARGS>
  909. void PIXBeginEvent(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  910. {
  911. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  912. }
  913. template<typename CONTEXT, typename... ARGS>
  914. void PIXBeginEvent(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  915. {
  916. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  917. }
  918. template<typename CONTEXT, typename... ARGS>
  919. void PIXBeginEvent(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  920. {
  921. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  922. }
  923. template<typename CONTEXT, typename... ARGS>
  924. void PIXBeginEvent(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  925. {
  926. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  927. }
  928. template<typename CONTEXT, typename... ARGS>
  929. void PIXBeginEvent(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  930. {
  931. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  932. }
  933. template<typename CONTEXT, typename... ARGS>
  934. void PIXSetMarker(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  935. {
  936. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  937. }
  938. template<typename CONTEXT, typename... ARGS>
  939. void PIXSetMarker(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  940. {
  941. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  942. }
  943. template<typename CONTEXT, typename... ARGS>
  944. void PIXSetMarker(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  945. {
  946. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  947. }
  948. template<typename CONTEXT, typename... ARGS>
  949. void PIXSetMarker(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  950. {
  951. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  952. }
  953. template<typename CONTEXT, typename... ARGS>
  954. void PIXSetMarker(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  955. {
  956. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  957. }
  958. template<typename CONTEXT, typename... ARGS>
  959. void PIXSetMarker(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  960. {
  961. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  962. }
  963. template<typename CONTEXT, typename... ARGS>
  964. void PIXSetMarker(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  965. {
  966. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  967. }
  968. template<typename CONTEXT, typename... ARGS>
  969. void PIXSetMarker(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  970. {
  971. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  972. }
  973. template<typename CONTEXT, typename... ARGS>
  974. void PIXSetMarker(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  975. {
  976. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  977. }
  978. template<typename CONTEXT, typename... ARGS>
  979. void PIXSetMarker(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  980. {
  981. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  982. }
  983. inline void PIXEndEvent()
  984. {
  985. PIXEventsDetail::PIXEndEvent();
  986. }
  987. template<typename CONTEXT>
  988. void PIXEndEvent(CONTEXT* context)
  989. {
  990. PIXEventsDetail::PIXEndEvent(context);
  991. }
  992. #else // USE_PIX_RETAIL
  993. inline void PIXBeginEvent(UINT64, _In_ PCSTR, ...) {}
  994. inline void PIXBeginEvent(UINT64, _In_ PCWSTR, ...) {}
  995. inline void PIXBeginEvent(void*, UINT64, _In_ PCSTR, ...) {}
  996. inline void PIXBeginEvent(void*, UINT64, _In_ PCWSTR, ...) {}
  997. inline void PIXEndEvent() {}
  998. inline void PIXEndEvent(void*) {}
  999. inline void PIXSetMarker(UINT64, _In_ PCSTR, ...) {}
  1000. inline void PIXSetMarker(UINT64, _In_ PCWSTR, ...) {}
  1001. inline void PIXSetMarker(void*, UINT64, _In_ PCSTR, ...) {}
  1002. inline void PIXSetMarker(void*, UINT64, _In_ PCWSTR, ...) {}
  1003. #endif // USE_PIX
  1004. template<typename CONTEXT, typename... ARGS>
  1005. void PIXBeginRetailEvent(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  1006. {
  1007. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  1008. }
  1009. template<typename CONTEXT, typename... ARGS>
  1010. void PIXBeginRetailEvent(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  1011. {
  1012. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  1013. }
  1014. template<typename CONTEXT, typename... ARGS>
  1015. void PIXBeginRetailEvent(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  1016. {
  1017. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1018. }
  1019. template<typename CONTEXT, typename... ARGS>
  1020. void PIXBeginRetailEvent(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  1021. {
  1022. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1023. }
  1024. template<typename CONTEXT, typename... ARGS>
  1025. void PIXBeginRetailEvent(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  1026. {
  1027. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1028. }
  1029. template<typename CONTEXT, typename... ARGS>
  1030. void PIXBeginRetailEvent(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  1031. {
  1032. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1033. }
  1034. template<typename CONTEXT, typename... ARGS>
  1035. void PIXBeginRetailEvent(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  1036. {
  1037. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1038. }
  1039. template<typename CONTEXT, typename... ARGS>
  1040. void PIXBeginRetailEvent(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  1041. {
  1042. PIXEventsDetail::PIXBeginEvent(context, static_cast<UINT64>(color), formatString, args...);
  1043. }
  1044. template<typename CONTEXT, typename... ARGS>
  1045. void PIXBeginRetailEvent(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  1046. {
  1047. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  1048. }
  1049. template<typename CONTEXT, typename... ARGS>
  1050. void PIXBeginRetailEvent(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  1051. {
  1052. PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...);
  1053. }
  1054. template<typename CONTEXT, typename... ARGS>
  1055. void PIXSetRetailMarker(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  1056. {
  1057. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  1058. }
  1059. template<typename CONTEXT, typename... ARGS>
  1060. void PIXSetRetailMarker(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  1061. {
  1062. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  1063. }
  1064. template<typename CONTEXT, typename... ARGS>
  1065. void PIXSetRetailMarker(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  1066. {
  1067. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1068. }
  1069. template<typename CONTEXT, typename... ARGS>
  1070. void PIXSetRetailMarker(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  1071. {
  1072. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1073. }
  1074. template<typename CONTEXT, typename... ARGS>
  1075. void PIXSetRetailMarker(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  1076. {
  1077. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1078. }
  1079. template<typename CONTEXT, typename... ARGS>
  1080. void PIXSetRetailMarker(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  1081. {
  1082. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1083. }
  1084. template<typename CONTEXT, typename... ARGS>
  1085. void PIXSetRetailMarker(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  1086. {
  1087. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1088. }
  1089. template<typename CONTEXT, typename... ARGS>
  1090. void PIXSetRetailMarker(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  1091. {
  1092. PIXEventsDetail::PIXSetMarker(context, static_cast<UINT64>(color), formatString, args...);
  1093. }
  1094. template<typename CONTEXT, typename... ARGS>
  1095. void PIXSetRetailMarker(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  1096. {
  1097. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  1098. }
  1099. template<typename CONTEXT, typename... ARGS>
  1100. void PIXSetRetailMarker(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  1101. {
  1102. PIXEventsDetail::PIXSetMarker(context, color, formatString, args...);
  1103. }
  1104. template<typename CONTEXT>
  1105. void PIXEndRetailEvent(CONTEXT* context)
  1106. {
  1107. PIXEventsDetail::PIXEndEvent(context);
  1108. }
  1109. template<typename CONTEXT>
  1110. class PIXScopedEventObject
  1111. {
  1112. CONTEXT* m_context;
  1113. public:
  1114. template<typename... ARGS>
  1115. PIXScopedEventObject(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  1116. : m_context(context)
  1117. {
  1118. PIXBeginEvent(m_context, color, formatString, args...);
  1119. }
  1120. template<typename... ARGS>
  1121. PIXScopedEventObject(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  1122. : m_context(context)
  1123. {
  1124. PIXBeginEvent(m_context, color, formatString, args...);
  1125. }
  1126. template<typename... ARGS>
  1127. PIXScopedEventObject(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  1128. : m_context(context)
  1129. {
  1130. PIXBeginEvent(m_context, color, formatString, args...);
  1131. }
  1132. template<typename... ARGS>
  1133. PIXScopedEventObject(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  1134. : m_context(context)
  1135. {
  1136. PIXBeginEvent(m_context, color, formatString, args...);
  1137. }
  1138. template<typename... ARGS>
  1139. PIXScopedEventObject(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  1140. : m_context(context)
  1141. {
  1142. PIXBeginEvent(m_context, color, formatString, args...);
  1143. }
  1144. template<typename... ARGS>
  1145. PIXScopedEventObject(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  1146. : m_context(context)
  1147. {
  1148. PIXBeginEvent(m_context, color, formatString, args...);
  1149. }
  1150. template<typename... ARGS>
  1151. PIXScopedEventObject(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  1152. : m_context(context)
  1153. {
  1154. PIXBeginEvent(m_context, color, formatString, args...);
  1155. }
  1156. template<typename... ARGS>
  1157. PIXScopedEventObject(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  1158. : m_context(context)
  1159. {
  1160. PIXBeginEvent(m_context, color, formatString, args...);
  1161. }
  1162. template<typename... ARGS>
  1163. PIXScopedEventObject(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  1164. : m_context(context)
  1165. {
  1166. PIXBeginEvent(m_context, color, formatString, args...);
  1167. }
  1168. template<typename... ARGS>
  1169. PIXScopedEventObject(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  1170. : m_context(context)
  1171. {
  1172. PIXBeginEvent(m_context, color, formatString, args...);
  1173. }
  1174. ~PIXScopedEventObject()
  1175. {
  1176. PIXEndEvent(m_context);
  1177. }
  1178. };
  1179. template<typename CONTEXT>
  1180. class PIXScopedRetailEventObject
  1181. {
  1182. CONTEXT* m_context;
  1183. public:
  1184. template<typename... ARGS>
  1185. PIXScopedRetailEventObject(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args)
  1186. : m_context(context)
  1187. {
  1188. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1189. }
  1190. template<typename... ARGS>
  1191. PIXScopedRetailEventObject(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args)
  1192. : m_context(context)
  1193. {
  1194. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1195. }
  1196. template<typename... ARGS>
  1197. PIXScopedRetailEventObject(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args)
  1198. : m_context(context)
  1199. {
  1200. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1201. }
  1202. template<typename... ARGS>
  1203. PIXScopedRetailEventObject(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args)
  1204. : m_context(context)
  1205. {
  1206. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1207. }
  1208. template<typename... ARGS>
  1209. PIXScopedRetailEventObject(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args)
  1210. : m_context(context)
  1211. {
  1212. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1213. }
  1214. template<typename... ARGS>
  1215. PIXScopedRetailEventObject(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args)
  1216. : m_context(context)
  1217. {
  1218. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1219. }
  1220. template<typename... ARGS>
  1221. PIXScopedRetailEventObject(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args)
  1222. : m_context(context)
  1223. {
  1224. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1225. }
  1226. template<typename... ARGS>
  1227. PIXScopedRetailEventObject(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args)
  1228. : m_context(context)
  1229. {
  1230. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1231. }
  1232. template<typename... ARGS>
  1233. PIXScopedRetailEventObject(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args)
  1234. : m_context(context)
  1235. {
  1236. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1237. }
  1238. template<typename... ARGS>
  1239. PIXScopedRetailEventObject(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args)
  1240. : m_context(context)
  1241. {
  1242. PIXBeginRetailEvent(m_context, color, formatString, args...);
  1243. }
  1244. ~PIXScopedRetailEventObject()
  1245. {
  1246. PIXEndRetailEvent(m_context);
  1247. }
  1248. };
  1249. template<>
  1250. class PIXScopedEventObject<void>
  1251. {
  1252. public:
  1253. template<typename... ARGS>
  1254. PIXScopedEventObject(UINT64 color, PCWSTR formatString, ARGS... args)
  1255. {
  1256. PIXBeginEvent(color, formatString, args...);
  1257. }
  1258. template<typename... ARGS>
  1259. PIXScopedEventObject(UINT64 color, PCSTR formatString, ARGS... args)
  1260. {
  1261. PIXBeginEvent(color, formatString, args...);
  1262. }
  1263. template<typename... ARGS>
  1264. PIXScopedEventObject(UINT32 color, PCWSTR formatString, ARGS... args)
  1265. {
  1266. PIXBeginEvent(color, formatString, args...);
  1267. }
  1268. template<typename... ARGS>
  1269. PIXScopedEventObject(UINT32 color, PCSTR formatString, ARGS... args)
  1270. {
  1271. PIXBeginEvent(color, formatString, args...);
  1272. }
  1273. template<typename... ARGS>
  1274. PIXScopedEventObject(INT32 color, PCWSTR formatString, ARGS... args)
  1275. {
  1276. PIXBeginEvent(color, formatString, args...);
  1277. }
  1278. template<typename... ARGS>
  1279. PIXScopedEventObject(INT32 color, PCSTR formatString, ARGS... args)
  1280. {
  1281. PIXBeginEvent(color, formatString, args...);
  1282. }
  1283. template<typename... ARGS>
  1284. PIXScopedEventObject(DWORD color, PCWSTR formatString, ARGS... args)
  1285. {
  1286. PIXBeginEvent(color, formatString, args...);
  1287. }
  1288. template<typename... ARGS>
  1289. PIXScopedEventObject(DWORD color, PCSTR formatString, ARGS... args)
  1290. {
  1291. PIXBeginEvent(color, formatString, args...);
  1292. }
  1293. template<typename... ARGS>
  1294. PIXScopedEventObject(UINT8 color, PCWSTR formatString, ARGS... args)
  1295. {
  1296. PIXBeginEvent(color, formatString, args...);
  1297. }
  1298. template<typename... ARGS>
  1299. PIXScopedEventObject(UINT8 color, PCSTR formatString, ARGS... args)
  1300. {
  1301. PIXBeginEvent(color, formatString, args...);
  1302. }
  1303. ~PIXScopedEventObject()
  1304. {
  1305. PIXEndEvent();
  1306. }
  1307. };
  1308. #define PIXConcatenate(a, b) a ## b
  1309. #define PIXGetScopedEventVariableName(a, b) PIXConcatenate(a, b)
  1310. #define PIXScopedEvent(context, ...) PIXScopedEventObject<PIXInferScopedEventType<decltype(context)>::Type> PIXGetScopedEventVariableName(pixEvent, __LINE__)(context, __VA_ARGS__)
  1311. #ifdef PIX3__DEFINED_CONSTEXPR
  1312. #undef constexpr
  1313. #undef PIX3__DEFINED_CONSTEXPR
  1314. #endif
  1315. #endif // _PIXEvents_H__