3#include <litefx/string.hpp>
4#include <litefx/math.hpp>
11using namespace Microsoft::WRL;
16#define D3D12_EVENT_METADATA 0x02
18#define EVENT_TIMESTAMP_WRITE_MASK 0x00000FFFFFFFFFFF
19#define EVENT_TYPE_WRITE_MASK 0x00000000000003FF
20#define EVENT_TIMESTAMP_BIT_SHIFT 20
21#define EVENT_TYPE_BIT_SHIFT 10
22#define EVENT_TYPE_END_EVENT 0x00
23#define EVENT_TYPE_BEGIN_EVENT_VARARGS 0x01
24#define EVENT_TYPE_BEGIN_EVENT_NOARGS 0x02
26consteval UInt64 EncodeEventInfo(UInt64 timestamp, UInt64 eventType)
28 return ((timestamp & EVENT_TIMESTAMP_WRITE_MASK) << EVENT_TIMESTAMP_BIT_SHIFT) | ((eventType & EVENT_TYPE_WRITE_MASK) << EVENT_TYPE_BIT_SHIFT);
31#define EVENT_STRING_ALIGNMENT_WRITE_MASK 0x000000000000000F
32#define EVENT_STRING_ALIGNMENT_BIT_SHIFT 60
33#define EVENT_STRING_COPY_CHUNK_SIZE_WRITE_MASK 0x000000000000001F
34#define EVENT_STRING_COPY_CHUNK_SIZE_BIT_SHIFT 55
35#define EVENT_STRING_IS_ANSI_WRITE_MASK 0x0000000000000001
36#define EVENT_STRING_IS_ANSI_BIT_SHIFT 54
37#define EVENT_STRING_IS_SHORTCUT_WRITE_MASK 0x0000000000000001
38#define EVENT_STRING_IS_SHORTCUT_BIT_SHIFT 53
40consteval UInt64 EncodeStringInfo(UInt64 alignment, UInt64 copyChunkSize, BOOL isANSI, BOOL isShortcut)
42 return ((alignment & EVENT_STRING_ALIGNMENT_WRITE_MASK) << EVENT_STRING_ALIGNMENT_BIT_SHIFT) | ((copyChunkSize & EVENT_STRING_COPY_CHUNK_SIZE_WRITE_MASK) << EVENT_STRING_COPY_CHUNK_SIZE_BIT_SHIFT) |
43 ((
static_cast<UInt64>(isANSI) & EVENT_STRING_IS_ANSI_WRITE_MASK) << EVENT_STRING_IS_ANSI_BIT_SHIFT) | ((
static_cast<UInt64>(isShortcut) & EVENT_STRING_IS_SHORTCUT_WRITE_MASK) << EVENT_STRING_IS_SHORTCUT_BIT_SHIFT);
46static void CopyEventName(
const String str, UInt64*& buffer, UInt64* end)
48 *buffer++ = ::EncodeStringInfo(0, 8, FALSE, FALSE);
49 auto argument = str.c_str();
61 c =
static_cast<UInt16>(argument[1]);
70 c =
static_cast<UInt16>(argument[2]);
79 c =
static_cast<UInt16>(argument[3]);
93template <
typename... TArgs>
94static void inline BeginEvent(ID3D12CommandQueue* queue, UInt64 color, StringView format, TArgs... args)
96 std::array<UInt64, 64> buffer {};
97 buffer[0] = ::EncodeEventInfo(0, EVENT_TYPE_BEGIN_EVENT_NOARGS);
99 UInt64* destination = &buffer[2];
100 UInt64* limit = destination + 62;
104 ::CopyEventName(str, destination, limit);
107 queue->BeginEvent(D3D12_EVENT_METADATA,
static_cast<void*
>(buffer.data()),
static_cast<UInt32>(
reinterpret_cast<Byte*
>(destination) -
reinterpret_cast<Byte*
>(buffer.data())));
110template <
typename... TArgs>
111static void inline BeginEvent(
const ComPtr<ID3D12CommandQueue>& queue, UInt64 color, StringView format, TArgs... args)
113 ::BeginEvent(queue.Get(), color, format, args...);
116template <
typename... TArgs>
117static void inline BeginEvent(ID3D12CommandQueue* queue, StringView format, TArgs... args)
119 ::BeginEvent(queue, 0xDBDBDBFF, format, args...);
122template <
typename... TArgs>
123static void inline BeginEvent(
const ComPtr<ID3D12CommandQueue>& queue, StringView format, TArgs... args)
125 ::BeginEvent(queue.Get(), 0xDBDBDBFF, format, args...);
128static void inline EndEvent(ID3D12CommandQueue* queue)
133static void inline EndEvent(
const ComPtr<ID3D12CommandQueue>& queue)
138#undef D3D12_EVENT_METADATA
139#undef EVENT_TIMESTAMP_WRITE_MASK
140#undef EVENT_TYPE_WRITE_MASK
141#undef EVENT_TIMESTAMP_BIT_SHIFT
142#undef EVENT_TYPE_WRITE_BIT_SHIFT
143#undef EVENT_TYPE_END_EVENT
144#undef EVENT_TYPE_BEGIN_EVENT_VARARGS
145#undef EVENT_TYPE_BEGIN_EVENT_NOARGS
146#undef EVENT_STRING_ALIGNMENT_WRITE_MASK
147#undef EVENT_STRING_ALIGNMENT_BIT_SHIFT
148#undef EVENT_STRING_COPY_CHUNK_SIZE_WRITE_MASK
149#undef EVENT_STRING_COPY_CHUNK_SIZE_BIT_SHIFT
150#undef EVENT_STRING_IS_ANSI_WRITE_MASK
151#undef EVENT_STRING_IS_ANSI_BIT_SHIFT
152#undef EVENT_STRING_IS_SHORTCUT_WRITE_MASK
153#undef EVENT_STRING_IS_SHORTCUT_BIT_SHIFT
157template <
typename... TArgs>
158static void inline BeginEvent(ID3D12CommandQueue* , UInt64 , StringView , TArgs... )
162template <
typename... TArgs>
163static void inline BeginEvent(
const ComPtr<ID3D12CommandQueue>& , UInt64 , StringView , TArgs... )
167template <
typename... TArgs>
168static void inline BeginEvent(ID3D12CommandQueue* , StringView , TArgs... )
172template <
typename... TArgs>
173static void inline BeginEvent(
const ComPtr<ID3D12CommandQueue>& , StringView format, TArgs... )
177static void inline EndEvent(ID3D12CommandQueue* )
181static void inline EndEvent(
const ComPtr<ID3D12CommandQueue>& )
uint32_t UInt32
Definition: math.hpp:37
uint16_t UInt16
Definition: math.hpp:35
uint64_t UInt64
Definition: math.hpp:39
uint8_t Byte
Definition: math.hpp:33
std::string String
Definition: string.hpp:19
auto format(LiteFX::Platform t, FormatContext &ctx) const
Definition: app_formatters.hpp:8