12 #ifndef _PIXEventsCommon_H_ 13 #define _PIXEventsCommon_H_ 15 #if defined(_AMD64_) || defined(_X86_) 16 #include <emmintrin.h> 17 #endif // _AMD64_ || _X86_ 19 extern "C" UINT64 WINAPI PIXEventsReplaceBlock(
bool getEarliestTime);
23 PIXEvent_EndEvent = 0x000,
24 PIXEvent_BeginEvent_VarArgs = 0x001,
25 PIXEvent_BeginEvent_NoArgs = 0x002,
26 PIXEvent_SetMarker_VarArgs = 0x007,
27 PIXEvent_SetMarker_NoArgs = 0x008,
29 PIXEvent_EndEvent_OnContext = 0x010,
30 PIXEvent_BeginEvent_OnContext_VarArgs = 0x011,
31 PIXEvent_BeginEvent_OnContext_NoArgs = 0x012,
32 PIXEvent_SetMarker_OnContext_VarArgs = 0x017,
33 PIXEvent_SetMarker_OnContext_NoArgs = 0x018,
36 static const UINT64 PIXEventsReservedRecordSpaceQwords = 64;
44 static const UINT64 PIXEventsReservedTailSpaceQwords = 2;
45 static const UINT64 PIXEventsSafeFastCopySpaceQwords = PIXEventsReservedRecordSpaceQwords - PIXEventsReservedTailSpaceQwords;
46 static const UINT64 PIXEventsGraphicsRecordSpaceQwords = 64;
49 static const UINT64 PIXEventsBlockEndMarker = 0x00000000000FFF80;
52 static const UINT64 PIXEventsTypeReadMask = 0x00000000000FFC00;
53 static const UINT64 PIXEventsTypeWriteMask = 0x00000000000003FF;
54 static const UINT64 PIXEventsTypeBitShift = 10;
57 static const UINT64 PIXEventsTimestampReadMask = 0xFFFFFFFFFFF00000;
58 static const UINT64 PIXEventsTimestampWriteMask = 0x00000FFFFFFFFFFF;
59 static const UINT64 PIXEventsTimestampBitShift = 20;
61 inline UINT64 PIXEncodeEventInfo(UINT64 timestamp, PIXEventType eventType)
63 return ((timestamp & PIXEventsTimestampWriteMask) << PIXEventsTimestampBitShift) |
64 (((UINT64)eventType & PIXEventsTypeWriteMask) << PIXEventsTypeBitShift);
68 static const UINT64 PIXEventsStringAlignmentWriteMask = 0x000000000000000F;
69 static const UINT64 PIXEventsStringAlignmentReadMask = 0xF000000000000000;
70 static const UINT64 PIXEventsStringAlignmentBitShift = 60;
73 static const UINT64 PIXEventsStringCopyChunkSizeWriteMask = 0x000000000000001F;
74 static const UINT64 PIXEventsStringCopyChunkSizeReadMask = 0x0F80000000000000;
75 static const UINT64 PIXEventsStringCopyChunkSizeBitShift = 55;
78 static const UINT64 PIXEventsStringIsANSIWriteMask = 0x0000000000000001;
79 static const UINT64 PIXEventsStringIsANSIReadMask = 0x0040000000000000;
80 static const UINT64 PIXEventsStringIsANSIBitShift = 54;
83 static const UINT64 PIXEventsStringIsShortcutWriteMask = 0x0000000000000001;
84 static const UINT64 PIXEventsStringIsShortcutReadMask = 0x0020000000000000;
85 static const UINT64 PIXEventsStringIsShortcutBitShift = 53;
87 inline UINT64 PIXEncodeStringInfo(UINT64 alignment, UINT64 copyChunkSize, BOOL isANSI, BOOL isShortcut)
89 return ((alignment & PIXEventsStringAlignmentWriteMask) << PIXEventsStringAlignmentBitShift) |
90 ((copyChunkSize & PIXEventsStringCopyChunkSizeWriteMask) << PIXEventsStringCopyChunkSizeBitShift) |
91 (((UINT64)isANSI & PIXEventsStringIsANSIWriteMask) << PIXEventsStringIsANSIBitShift) |
92 (((UINT64)isShortcut & PIXEventsStringIsShortcutWriteMask) << PIXEventsStringIsShortcutBitShift);
95 template<UINT alignment,
class T>
96 inline bool PIXIsPointerAligned(T* pointer)
98 return !(((UINT64)pointer) & (alignment - 1));
102 inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_
const UINT64* limit, T argument)
104 if (destination < limit)
106 *((T*)destination) = argument;
114 inline void PIXCopyEventArgument<float>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit,
float argument)
116 if (destination < limit)
118 *((
double*)destination) = (double)(argument);
126 inline void PIXCopyEventArgument<char>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit,
char argument)
128 if (destination < limit)
130 *((INT64*)destination) = (INT64)(argument);
138 inline void PIXCopyEventArgument<unsigned char>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit,
unsigned char argument)
140 if (destination < limit)
142 *destination = (UINT64)(argument);
150 inline void PIXCopyEventArgument<bool>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit,
bool argument)
152 if (destination < limit)
154 *destination = (UINT64)(argument);
159 inline void PIXCopyEventArgumentSlowest(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_
const UINT64* limit, _In_ PCSTR argument)
161 *destination++ = PIXEncodeStringInfo(0, 8, TRUE, FALSE);
162 while (destination < limit)
164 UINT64 c = argument[0];
225 inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_
const UINT64* limit, _In_ PCSTR argument)
227 if (PIXIsPointerAligned<8>(argument))
229 *destination++ = PIXEncodeStringInfo(0, 8, TRUE, FALSE);
230 UINT64* source = (UINT64*)argument;
231 while (destination < limit)
233 UINT64 qword = *source++;
234 *destination++ = qword;
236 if (!((qword & 0xFF00000000000000) &&
237 (qword & 0xFF000000000000) &&
238 (qword & 0xFF0000000000) &&
239 (qword & 0xFF00000000) &&
240 (qword & 0xFF000000) &&
241 (qword & 0xFF0000) &&
251 PIXCopyEventArgumentSlowest(destination, limit, argument);
256 inline void PIXCopyEventArgument<PCSTR>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument)
258 if (destination < limit)
260 if (argument !=
nullptr)
262 #if defined(_AMD64_) || defined(_X86_) 263 if (PIXIsPointerAligned<16>(argument))
265 *destination++ = PIXEncodeStringInfo(0, 16, TRUE, FALSE);
266 __m128i zero = _mm_setzero_si128();
267 if (PIXIsPointerAligned<16>(destination))
269 while (destination < limit)
271 __m128i mem = _mm_load_si128((__m128i*)argument);
272 _mm_store_si128((__m128i*)destination, mem);
274 __m128i res = _mm_cmpeq_epi8(mem, zero);
276 if (_mm_movemask_epi8(res))
283 while (destination < limit)
285 __m128i mem = _mm_load_si128((__m128i*)argument);
286 _mm_storeu_si128((__m128i*)destination, mem);
288 __m128i res = _mm_cmpeq_epi8(mem, zero);
290 if (_mm_movemask_epi8(res))
297 #endif // _AMD64_ || _X86_ 299 PIXCopyEventArgumentSlow(destination, limit, argument);
304 *destination++ = 0ull;
310 inline void PIXCopyEventArgument<PSTR>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PSTR argument)
312 PIXCopyEventArgument(destination, limit, (PCSTR)argument);
315 inline void PIXCopyEventArgumentSlowest(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_
const UINT64* limit, _In_ PCWSTR argument)
317 *destination++ = PIXEncodeStringInfo(0, 8, FALSE, FALSE);
318 while (destination < limit)
320 UINT64 c = argument[0];
353 inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_
const UINT64* limit, _In_ PCWSTR argument)
355 if (PIXIsPointerAligned<8>(argument))
357 *destination++ = PIXEncodeStringInfo(0, 8, FALSE, FALSE);
358 UINT64* source = (UINT64*)argument;
359 while (destination < limit)
361 UINT64 qword = *source++;
362 *destination++ = qword;
365 if (!((qword & 0xFFFF000000000000) &&
366 (qword & 0xFFFF00000000) &&
367 (qword & 0xFFFF0000) &&
376 PIXCopyEventArgumentSlowest(destination, limit, argument);
381 inline void PIXCopyEventArgument<PCWSTR>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument)
383 if (destination < limit)
385 if (argument !=
nullptr)
387 #if defined(_AMD64_) || defined(_X86_) 388 if (PIXIsPointerAligned<16>(argument))
390 *destination++ = PIXEncodeStringInfo(0, 16, FALSE, FALSE);
391 __m128i zero = _mm_setzero_si128();
392 if (PIXIsPointerAligned<16>(destination))
394 while (destination < limit)
396 __m128i mem = _mm_load_si128((__m128i*)argument);
397 _mm_store_si128((__m128i*)destination, mem);
399 __m128i res = _mm_cmpeq_epi16(mem, zero);
401 if (_mm_movemask_epi8(res))
408 while (destination < limit)
410 __m128i mem = _mm_load_si128((__m128i*)argument);
411 _mm_storeu_si128((__m128i*)destination, mem);
413 __m128i res = _mm_cmpeq_epi16(mem, zero);
415 if (_mm_movemask_epi8(res))
422 #endif // _AMD64_ || _X86_ 424 PIXCopyEventArgumentSlow(destination, limit, argument);
429 *destination++ = 0ull;
435 inline void PIXCopyEventArgument<PWSTR>(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PWSTR argument)
437 PIXCopyEventArgument(destination, limit, (PCWSTR)argument);
440 #if defined(__d3d12_x_h__) || defined(__d3d12_h__) 442 inline void PIXSetMarkerOnContext(_In_ ID3D12GraphicsCommandList* commandList, _In_reads_bytes_(size)
void* data, UINT size)
444 commandList->SetMarker(D3D12_EVENT_METADATA, data, size);
447 inline void PIXSetMarkerOnContext(_In_ ID3D12CommandQueue* commandQueue, _In_reads_bytes_(size)
void* data, UINT size)
449 commandQueue->SetMarker(D3D12_EVENT_METADATA, data, size);
452 inline void PIXBeginEventOnContext(_In_ ID3D12GraphicsCommandList* commandList, _In_reads_bytes_(size)
void* data, UINT size)
454 commandList->BeginEvent(D3D12_EVENT_METADATA, data, size);
457 inline void PIXBeginEventOnContext(_In_ ID3D12CommandQueue* commandQueue, _In_reads_bytes_(size)
void* data, UINT size)
459 commandQueue->BeginEvent(D3D12_EVENT_METADATA, data, size);
461 inline void PIXEndEventOnContext(_In_ ID3D12GraphicsCommandList* commandList)
463 commandList->EndEvent();
466 inline void PIXEndEventOnContext(_In_ ID3D12CommandQueue* commandQueue)
468 commandQueue->EndEvent();
471 #endif //__d3d12_x_h__ 485 #endif //_PIXEventsCommon_H_ Definition: PIXEventsCommon.h:473