PIXEvents.h 55 KB

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