Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/debug.h
ShadPKG / common / debug.h
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6#ifdef _MSC_VER
7#define BREAKPOINT __debugbreak
8#elif defined(__GNUC__)
9#define BREAKPOINT __builtin_trap
10#else
11#error What the fuck is this compiler
12#endif
13 
14#ifdef ENABLE_TRACY
15#include <tracy/Tracy.hpp>
16#endif
17 
18static inline bool IsProfilerConnected() {
19#if TRACY_ENABLE
20 return tracy::GetProfiler().IsConnected();
21#else
22 return false;
23#endif
24}
25 
26#define TRACY_GPU_ENABLED 0
27 
28#define CUSTOM_LOCK(type, varname) \
29 tracy::LockableCtx varname { \
30 []() -> const tracy::SourceLocationData* { \
31 static constexpr tracy::SourceLocationData srcloc{nullptr, #type " " #varname, \
32 TracyFile, TracyLine, 0}; \
33 return &srcloc; \
34 }() \
35 }
36 
37#define TRACK_ALLOC(ptr, size, pool) TracyAllocN(std::bit_cast<void*>(ptr), (size), (pool))
38#define TRACK_FREE(ptr, pool) TracyFreeN(std::bit_cast<void*>(ptr), (pool))
39 
40enum MarkersPalette : int {
41 EmulatorMarkerColor = 0x264653,
42 RendererMarkerColor = 0x2a9d8f,
43 HleMarkerColor = 0xe9c46a,
44 GpuMarkerColor = 0xf4a261,
45 Reserved1 = 0xe76f51,
46};
47 
48#define EMULATOR_TRACE ZoneScopedC(EmulatorMarkerColor)
49#define RENDERER_TRACE ZoneScopedC(RendererMarkerColor)
50#define HLE_TRACE ZoneScopedC(HleMarkerColor)
51 
52#define TRACE_HINT(str) ZoneText(str.data(), str.size())
53 
54#define TRACE_WARN(msg) \
55 [](const auto& msg) { TracyMessageC(msg.c_str(), msg.size(), tracy::Color::DarkOrange); }(msg);
56#define TRACE_ERROR(msg) \
57 [](const auto& msg) { TracyMessageC(msg.c_str(), msg.size(), tracy::Color::Red); }(msg)
58#define TRACE_CRIT(msg) \
59 [](const auto& msg) { TracyMessageC(msg.c_str(), msg.size(), tracy::Color::HotPink); }(msg)
60 
61#define GPU_SCOPE_LOCATION(name, color) \
62 tracy::SourceLocationData{name, TracyFunction, TracyFile, (uint32_t)TracyLine, color};
63 
64#define MUTEX_LOCATION(name) \
65 tracy::SourceLocationData{nullptr, name, TracyFile, (uint32_t)TracyLine, 0};
66 
67#define FRAME_END FrameMark
68 
69#ifdef TRACY_FIBERS
70#define FIBER_ENTER(name) TracyFiberEnter(name)
71#define FIBER_EXIT TracyFiberLeave
72#else
73#define FIBER_ENTER(name)
74#define FIBER_EXIT
75#endif
76