TracyVulkan.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. #ifndef __TRACYVULKAN_HPP__
  2. #define __TRACYVULKAN_HPP__
  3. #if !defined TRACY_ENABLE
  4. #define TracyVkContext(x,y,z,w) nullptr
  5. #define TracyVkContextCalibrated(x,y,z,w,a,b) nullptr
  6. #define TracyVkDestroy(x)
  7. #define TracyVkContextName(c,x,y)
  8. #define TracyVkNamedZone(c,x,y,z,w)
  9. #define TracyVkNamedZoneC(c,x,y,z,w,a)
  10. #define TracyVkZone(c,x,y)
  11. #define TracyVkZoneC(c,x,y,z)
  12. #define TracyVkZoneTransient(c,x,y,z,w)
  13. #define TracyVkCollect(c,x)
  14. #define TracyVkNamedZoneS(c,x,y,z,w,a)
  15. #define TracyVkNamedZoneCS(c,x,y,z,w,v,a)
  16. #define TracyVkZoneS(c,x,y,z)
  17. #define TracyVkZoneCS(c,x,y,z,w)
  18. #define TracyVkZoneTransientS(c,x,y,z,w,a)
  19. namespace tracy
  20. {
  21. class VkCtxScope {};
  22. }
  23. using TracyVkCtx = void*;
  24. #else
  25. #include <assert.h>
  26. #include <stdlib.h>
  27. #include <vulkan/vulkan.h>
  28. #include "Tracy.hpp"
  29. #include "client/TracyProfiler.hpp"
  30. #include "client/TracyCallstack.hpp"
  31. namespace tracy
  32. {
  33. class VkCtx
  34. {
  35. friend class VkCtxScope;
  36. enum { QueryCount = 64 * 1024 };
  37. public:
  38. VkCtx( VkPhysicalDevice physdev, VkDevice device, VkQueue queue, VkCommandBuffer cmdbuf, PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, PFN_vkGetCalibratedTimestampsEXT _vkGetCalibratedTimestampsEXT )
  39. : m_device( device )
  40. , m_timeDomain( VK_TIME_DOMAIN_DEVICE_EXT )
  41. , m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) )
  42. , m_head( 0 )
  43. , m_tail( 0 )
  44. , m_oldCnt( 0 )
  45. , m_queryCount( QueryCount )
  46. , m_vkGetCalibratedTimestampsEXT( _vkGetCalibratedTimestampsEXT )
  47. {
  48. assert( m_context != 255 );
  49. if( _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT && _vkGetCalibratedTimestampsEXT )
  50. {
  51. uint32_t num;
  52. _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT( physdev, &num, nullptr );
  53. if( num > 4 ) num = 4;
  54. VkTimeDomainEXT data[4];
  55. _vkGetPhysicalDeviceCalibrateableTimeDomainsEXT( physdev, &num, data );
  56. for( uint32_t i=0; i<num; i++ )
  57. {
  58. // TODO VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
  59. if( data[i] == VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT )
  60. {
  61. m_timeDomain = data[i];
  62. break;
  63. }
  64. }
  65. }
  66. VkPhysicalDeviceProperties prop;
  67. vkGetPhysicalDeviceProperties( physdev, &prop );
  68. const float period = prop.limits.timestampPeriod;
  69. VkQueryPoolCreateInfo poolInfo = {};
  70. poolInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
  71. poolInfo.queryCount = m_queryCount;
  72. poolInfo.queryType = VK_QUERY_TYPE_TIMESTAMP;
  73. while( vkCreateQueryPool( device, &poolInfo, nullptr, &m_query ) != VK_SUCCESS )
  74. {
  75. m_queryCount /= 2;
  76. poolInfo.queryCount = m_queryCount;
  77. }
  78. VkCommandBufferBeginInfo beginInfo = {};
  79. beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
  80. beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
  81. VkSubmitInfo submitInfo = {};
  82. submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
  83. submitInfo.commandBufferCount = 1;
  84. submitInfo.pCommandBuffers = &cmdbuf;
  85. vkBeginCommandBuffer( cmdbuf, &beginInfo );
  86. vkCmdResetQueryPool( cmdbuf, m_query, 0, m_queryCount );
  87. vkEndCommandBuffer( cmdbuf );
  88. vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
  89. vkQueueWaitIdle( queue );
  90. int64_t tcpu, tgpu;
  91. if( m_timeDomain == VK_TIME_DOMAIN_DEVICE_EXT )
  92. {
  93. vkBeginCommandBuffer( cmdbuf, &beginInfo );
  94. vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, m_query, 0 );
  95. vkEndCommandBuffer( cmdbuf );
  96. vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
  97. vkQueueWaitIdle( queue );
  98. tcpu = Profiler::GetTime();
  99. vkGetQueryPoolResults( device, m_query, 0, 1, sizeof( tgpu ), &tgpu, sizeof( tgpu ), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT );
  100. vkBeginCommandBuffer( cmdbuf, &beginInfo );
  101. vkCmdResetQueryPool( cmdbuf, m_query, 0, 1 );
  102. vkEndCommandBuffer( cmdbuf );
  103. vkQueueSubmit( queue, 1, &submitInfo, VK_NULL_HANDLE );
  104. vkQueueWaitIdle( queue );
  105. }
  106. else
  107. {
  108. enum { NumProbes = 32 };
  109. VkCalibratedTimestampInfoEXT spec[2] = {
  110. { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, VK_TIME_DOMAIN_DEVICE_EXT },
  111. { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, m_timeDomain },
  112. };
  113. uint64_t ts[2];
  114. uint64_t deviation[NumProbes];
  115. for( int i=0; i<NumProbes; i++ )
  116. {
  117. _vkGetCalibratedTimestampsEXT( device, 2, spec, ts, deviation+i );
  118. }
  119. uint64_t minDeviation = deviation[0];
  120. for( int i=1; i<NumProbes; i++ )
  121. {
  122. if( minDeviation > deviation[i] )
  123. {
  124. minDeviation = deviation[i];
  125. }
  126. }
  127. m_deviation = minDeviation * 3 / 2;
  128. m_qpcToNs = int64_t( 1000000000. / GetFrequencyQpc() );
  129. Calibrate( device, m_prevCalibration, tgpu );
  130. tcpu = Profiler::GetTime();
  131. }
  132. uint8_t flags = 0;
  133. if( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT ) flags |= GpuContextCalibration;
  134. auto item = Profiler::QueueSerial();
  135. MemWrite( &item->hdr.type, QueueType::GpuNewContext );
  136. MemWrite( &item->gpuNewContext.cpuTime, tcpu );
  137. MemWrite( &item->gpuNewContext.gpuTime, tgpu );
  138. memset( &item->gpuNewContext.thread, 0, sizeof( item->gpuNewContext.thread ) );
  139. MemWrite( &item->gpuNewContext.period, period );
  140. MemWrite( &item->gpuNewContext.context, m_context );
  141. MemWrite( &item->gpuNewContext.flags, flags );
  142. MemWrite( &item->gpuNewContext.type, GpuContextType::Vulkan );
  143. #ifdef TRACY_ON_DEMAND
  144. GetProfiler().DeferItem( *item );
  145. #endif
  146. Profiler::QueueSerialFinish();
  147. m_res = (int64_t*)tracy_malloc( sizeof( int64_t ) * m_queryCount );
  148. }
  149. ~VkCtx()
  150. {
  151. tracy_free( m_res );
  152. vkDestroyQueryPool( m_device, m_query, nullptr );
  153. }
  154. void Name( const char* name, uint16_t len )
  155. {
  156. auto ptr = (char*)tracy_malloc( len );
  157. memcpy( ptr, name, len );
  158. auto item = Profiler::QueueSerial();
  159. MemWrite( &item->hdr.type, QueueType::GpuContextName );
  160. MemWrite( &item->gpuContextNameFat.context, m_context );
  161. MemWrite( &item->gpuContextNameFat.ptr, (uint64_t)ptr );
  162. MemWrite( &item->gpuContextNameFat.size, len );
  163. #ifdef TRACY_ON_DEMAND
  164. GetProfiler().DeferItem( *item );
  165. #endif
  166. Profiler::QueueSerialFinish();
  167. }
  168. void Collect( VkCommandBuffer cmdbuf )
  169. {
  170. ZoneScopedC( Color::Red4 );
  171. if( m_tail == m_head ) return;
  172. #ifdef TRACY_ON_DEMAND
  173. if( !GetProfiler().IsConnected() )
  174. {
  175. vkCmdResetQueryPool( cmdbuf, m_query, 0, m_queryCount );
  176. m_head = m_tail = 0;
  177. int64_t tgpu;
  178. if( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT ) Calibrate( m_device, m_prevCalibration, tgpu );
  179. return;
  180. }
  181. #endif
  182. unsigned int cnt;
  183. if( m_oldCnt != 0 )
  184. {
  185. cnt = m_oldCnt;
  186. m_oldCnt = 0;
  187. }
  188. else
  189. {
  190. cnt = m_head < m_tail ? m_queryCount - m_tail : m_head - m_tail;
  191. }
  192. if( vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( int64_t ) * m_queryCount, m_res, sizeof( int64_t ), VK_QUERY_RESULT_64_BIT ) == VK_NOT_READY )
  193. {
  194. m_oldCnt = cnt;
  195. return;
  196. }
  197. for( unsigned int idx=0; idx<cnt; idx++ )
  198. {
  199. auto item = Profiler::QueueSerial();
  200. MemWrite( &item->hdr.type, QueueType::GpuTime );
  201. MemWrite( &item->gpuTime.gpuTime, m_res[idx] );
  202. MemWrite( &item->gpuTime.queryId, uint16_t( m_tail + idx ) );
  203. MemWrite( &item->gpuTime.context, m_context );
  204. Profiler::QueueSerialFinish();
  205. }
  206. if( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT )
  207. {
  208. int64_t tgpu, tcpu;
  209. Calibrate( m_device, tcpu, tgpu );
  210. const auto refCpu = Profiler::GetTime();
  211. const auto delta = tcpu - m_prevCalibration;
  212. if( delta > 0 )
  213. {
  214. m_prevCalibration = tcpu;
  215. auto item = Profiler::QueueSerial();
  216. MemWrite( &item->hdr.type, QueueType::GpuCalibration );
  217. MemWrite( &item->gpuCalibration.gpuTime, tgpu );
  218. MemWrite( &item->gpuCalibration.cpuTime, refCpu );
  219. MemWrite( &item->gpuCalibration.cpuDelta, delta );
  220. MemWrite( &item->gpuCalibration.context, m_context );
  221. Profiler::QueueSerialFinish();
  222. }
  223. }
  224. vkCmdResetQueryPool( cmdbuf, m_query, m_tail, cnt );
  225. m_tail += cnt;
  226. if( m_tail == m_queryCount ) m_tail = 0;
  227. }
  228. private:
  229. tracy_force_inline unsigned int NextQueryId()
  230. {
  231. const auto id = m_head;
  232. m_head = ( m_head + 1 ) % m_queryCount;
  233. assert( m_head != m_tail );
  234. return id;
  235. }
  236. tracy_force_inline uint8_t GetId() const
  237. {
  238. return m_context;
  239. }
  240. tracy_force_inline void Calibrate( VkDevice device, int64_t& tCpu, int64_t& tGpu )
  241. {
  242. assert( m_timeDomain != VK_TIME_DOMAIN_DEVICE_EXT );
  243. VkCalibratedTimestampInfoEXT spec[2] = {
  244. { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, VK_TIME_DOMAIN_DEVICE_EXT },
  245. { VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, nullptr, m_timeDomain },
  246. };
  247. uint64_t ts[2];
  248. uint64_t deviation;
  249. do
  250. {
  251. m_vkGetCalibratedTimestampsEXT( device, 2, spec, ts, &deviation );
  252. }
  253. while( deviation > m_deviation );
  254. #if defined _WIN32 || defined __CYGWIN__
  255. tGpu = ts[0];
  256. tCpu = ts[1] * m_qpcToNs;
  257. #else
  258. assert( false );
  259. #endif
  260. }
  261. VkDevice m_device;
  262. VkQueryPool m_query;
  263. VkTimeDomainEXT m_timeDomain;
  264. uint64_t m_deviation;
  265. int64_t m_qpcToNs;
  266. int64_t m_prevCalibration;
  267. uint8_t m_context;
  268. unsigned int m_head;
  269. unsigned int m_tail;
  270. unsigned int m_oldCnt;
  271. unsigned int m_queryCount;
  272. int64_t* m_res;
  273. PFN_vkGetCalibratedTimestampsEXT m_vkGetCalibratedTimestampsEXT;
  274. };
  275. class VkCtxScope
  276. {
  277. public:
  278. tracy_force_inline VkCtxScope( VkCtx* ctx, const SourceLocationData* srcloc, VkCommandBuffer cmdbuf, bool is_active )
  279. #ifdef TRACY_ON_DEMAND
  280. : m_active( is_active && GetProfiler().IsConnected() )
  281. #else
  282. : m_active( is_active )
  283. #endif
  284. {
  285. if( !m_active ) return;
  286. m_cmdbuf = cmdbuf;
  287. m_ctx = ctx;
  288. const auto queryId = ctx->NextQueryId();
  289. vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->m_query, queryId );
  290. auto item = Profiler::QueueSerial();
  291. MemWrite( &item->hdr.type, QueueType::GpuZoneBeginSerial );
  292. MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
  293. MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
  294. MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() );
  295. MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
  296. MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
  297. Profiler::QueueSerialFinish();
  298. }
  299. tracy_force_inline VkCtxScope( VkCtx* ctx, const SourceLocationData* srcloc, VkCommandBuffer cmdbuf, int depth, bool is_active )
  300. #ifdef TRACY_ON_DEMAND
  301. : m_active( is_active && GetProfiler().IsConnected() )
  302. #else
  303. : m_active( is_active )
  304. #endif
  305. {
  306. if( !m_active ) return;
  307. m_cmdbuf = cmdbuf;
  308. m_ctx = ctx;
  309. const auto queryId = ctx->NextQueryId();
  310. vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->m_query, queryId );
  311. auto item = Profiler::QueueSerialCallstack( Callstack( depth ) );
  312. MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstackSerial );
  313. MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
  314. MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
  315. MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() );
  316. MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
  317. MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
  318. Profiler::QueueSerialFinish();
  319. }
  320. tracy_force_inline VkCtxScope( VkCtx* ctx, uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, VkCommandBuffer cmdbuf, bool is_active )
  321. #ifdef TRACY_ON_DEMAND
  322. : m_active( is_active && GetProfiler().IsConnected() )
  323. #else
  324. : m_active( is_active )
  325. #endif
  326. {
  327. if( !m_active ) return;
  328. m_cmdbuf = cmdbuf;
  329. m_ctx = ctx;
  330. const auto queryId = ctx->NextQueryId();
  331. vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->m_query, queryId );
  332. const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
  333. auto item = Profiler::QueueSerial();
  334. MemWrite( &item->hdr.type, QueueType::GpuZoneBeginAllocSrcLocSerial );
  335. MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
  336. MemWrite( &item->gpuZoneBegin.srcloc, srcloc );
  337. MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() );
  338. MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
  339. MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
  340. Profiler::QueueSerialFinish();
  341. }
  342. tracy_force_inline VkCtxScope( VkCtx* ctx, uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, VkCommandBuffer cmdbuf, int depth, bool is_active )
  343. #ifdef TRACY_ON_DEMAND
  344. : m_active( is_active && GetProfiler().IsConnected() )
  345. #else
  346. : m_active( is_active )
  347. #endif
  348. {
  349. if( !m_active ) return;
  350. m_cmdbuf = cmdbuf;
  351. m_ctx = ctx;
  352. const auto queryId = ctx->NextQueryId();
  353. vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->m_query, queryId );
  354. const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
  355. auto item = Profiler::QueueSerialCallstack( Callstack( depth ) );
  356. MemWrite( &item->hdr.type, QueueType::GpuZoneBeginAllocSrcLocCallstackSerial );
  357. MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
  358. MemWrite( &item->gpuZoneBegin.srcloc, srcloc );
  359. MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() );
  360. MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
  361. MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
  362. Profiler::QueueSerialFinish();
  363. }
  364. tracy_force_inline ~VkCtxScope()
  365. {
  366. if( !m_active ) return;
  367. const auto queryId = m_ctx->NextQueryId();
  368. vkCmdWriteTimestamp( m_cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, m_ctx->m_query, queryId );
  369. auto item = Profiler::QueueSerial();
  370. MemWrite( &item->hdr.type, QueueType::GpuZoneEndSerial );
  371. MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() );
  372. MemWrite( &item->gpuZoneEnd.thread, GetThreadHandle() );
  373. MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
  374. MemWrite( &item->gpuZoneEnd.context, m_ctx->GetId() );
  375. Profiler::QueueSerialFinish();
  376. }
  377. private:
  378. const bool m_active;
  379. VkCommandBuffer m_cmdbuf;
  380. VkCtx* m_ctx;
  381. };
  382. static inline VkCtx* CreateVkContext( VkPhysicalDevice physdev, VkDevice device, VkQueue queue, VkCommandBuffer cmdbuf, PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT gpdctd, PFN_vkGetCalibratedTimestampsEXT gct )
  383. {
  384. InitRPMallocThread();
  385. auto ctx = (VkCtx*)tracy_malloc( sizeof( VkCtx ) );
  386. new(ctx) VkCtx( physdev, device, queue, cmdbuf, gpdctd, gct );
  387. return ctx;
  388. }
  389. static inline void DestroyVkContext( VkCtx* ctx )
  390. {
  391. ctx->~VkCtx();
  392. tracy_free( ctx );
  393. }
  394. }
  395. using TracyVkCtx = tracy::VkCtx*;
  396. #define TracyVkContext( physdev, device, queue, cmdbuf ) tracy::CreateVkContext( physdev, device, queue, cmdbuf, nullptr, nullptr );
  397. #define TracyVkContextCalibrated( physdev, device, queue, cmdbuf, gpdctd, gct ) tracy::CreateVkContext( physdev, device, queue, cmdbuf, gpdctd, gct );
  398. #define TracyVkDestroy( ctx ) tracy::DestroyVkContext( ctx );
  399. #define TracyVkContextName( ctx, name, size ) ctx->Name( name, size );
  400. #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
  401. # define TracyVkNamedZone( ctx, varname, cmdbuf, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, TRACY_CALLSTACK, active );
  402. # define TracyVkNamedZoneC( ctx, varname, cmdbuf, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, TRACY_CALLSTACK, active );
  403. # define TracyVkZone( ctx, cmdbuf, name ) TracyVkNamedZoneS( ctx, ___tracy_gpu_zone, cmdbuf, name, TRACY_CALLSTACK, true )
  404. # define TracyVkZoneC( ctx, cmdbuf, name, color ) TracyVkNamedZoneCS( ctx, ___tracy_gpu_zone, cmdbuf, name, color, TRACY_CALLSTACK, true )
  405. # define TracyVkZoneTransient( ctx, varname, cmdbuf, name, active ) TracyVkZoneTransientS( ctx, varname, cmdbuf, name, TRACY_CALLSTACK, active )
  406. #else
  407. # define TracyVkNamedZone( ctx, varname, cmdbuf, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, active );
  408. # define TracyVkNamedZoneC( ctx, varname, cmdbuf, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, active );
  409. # define TracyVkZone( ctx, cmdbuf, name ) TracyVkNamedZone( ctx, ___tracy_gpu_zone, cmdbuf, name, true )
  410. # define TracyVkZoneC( ctx, cmdbuf, name, color ) TracyVkNamedZoneC( ctx, ___tracy_gpu_zone, cmdbuf, name, color, true )
  411. # define TracyVkZoneTransient( ctx, varname, cmdbuf, name, active ) tracy::VkCtxScope varname( ctx, __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), cmdbuf, active );
  412. #endif
  413. #define TracyVkCollect( ctx, cmdbuf ) ctx->Collect( cmdbuf );
  414. #ifdef TRACY_HAS_CALLSTACK
  415. # define TracyVkNamedZoneS( ctx, varname, cmdbuf, name, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, depth, active );
  416. # define TracyVkNamedZoneCS( ctx, varname, cmdbuf, name, color, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::VkCtxScope varname( ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), cmdbuf, depth, active );
  417. # define TracyVkZoneS( ctx, cmdbuf, name, depth ) TracyVkNamedZoneS( ctx, ___tracy_gpu_zone, cmdbuf, name, depth, true )
  418. # define TracyVkZoneCS( ctx, cmdbuf, name, color, depth ) TracyVkNamedZoneCS( ctx, ___tracy_gpu_zone, cmdbuf, name, color, depth, true )
  419. # define TracyVkZoneTransientS( ctx, varname, cmdbuf, name, depth, active ) tracy::VkCtxScope varname( ctx, __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), cmdbuf, depth, active );
  420. #else
  421. # define TracyVkNamedZoneS( ctx, varname, cmdbuf, name, depth, active ) TracyVkNamedZone( ctx, varname, cmdbuf, name, active )
  422. # define TracyVkNamedZoneCS( ctx, varname, cmdbuf, name, color, depth, active ) TracyVkNamedZoneC( ctx, varname, cmdbuf, name, color, active )
  423. # define TracyVkZoneS( ctx, cmdbuf, name, depth ) TracyVkZone( ctx, cmdbuf, name )
  424. # define TracyVkZoneCS( ctx, cmdbuf, name, color, depth ) TracyVkZoneC( ctx, cmdbuf, name, color )
  425. # define TracyVkZoneTransientS( ctx, varname, cmdbuf, name, depth, active ) TracyVkZoneTransient( ctx, varname, cmdbuf, name, active )
  426. #endif
  427. #endif
  428. #endif