Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional support for Tracy #1865

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(CheckSymbolExists)
include(CheckLibraryExists)
include(CMakeDependentOption)
include(CheckIPOSupported)
include(cmake/FetchDependencies.cmake)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")

Expand Down
50 changes: 50 additions & 0 deletions cmake/FetchDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
include(FetchContent)

macro(define_git_dependency_vars name default_url default_tag)
string(TOUPPER ${name} VAR_NAME)
string(MAKE_C_IDENTIFIER ${VAR_NAME} VAR_NAME)

if (NOT ${VAR_NAME}_REPOSITORY_URL)
set(
"${VAR_NAME}_REPOSITORY_URL"
"${default_url}"
CACHE STRING
"${name} repository URL. Set this to use a fork."
FORCE
)
endif ()

if (NOT ${VAR_NAME}_REPOSITORY_TAG)
set(
"${VAR_NAME}_REPOSITORY_TAG"
"${default_tag}"
CACHE STRING
"${name} repository commit hash or tag. Set this when using a new version or a custom branch."
FORCE
)
endif ()
endmacro()

function(fetch_dependency name default_url default_tag)
define_git_dependency_vars(${name} ${default_url} ${default_tag})

message(STATUS "Using ${name}: ${${VAR_NAME}_REPOSITORY_URL} (ref ${${VAR_NAME}_REPOSITORY_TAG})")

FetchContent_Declare(
${name}
GIT_REPOSITORY "${${VAR_NAME}_REPOSITORY_URL}"
GIT_TAG "${${VAR_NAME}_REPOSITORY_TAG}"
)

FetchContent_GetProperties(${name})
endfunction()

option(TRACY_ENABLE "Build with Tracy support." OFF)

if (TRACY_ENABLE)
fetch_dependency(tracy "https://github.com/wolfpld/tracy.git" "v0.10")
FetchContent_MakeAvailable(tracy)
set(BUILD_SHARED_LIBS OFF)
set(TRACY_STATIC ON)
set(TRACY_ON_DEMAND ON)
endif()
5 changes: 5 additions & 0 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ARMJIT.h"
#include "Platform.h"
#include "GPU.h"
#include "Tracy.h"

#ifdef JIT_ENABLED
#include "ARMJIT.h"
Expand Down Expand Up @@ -114,6 +115,7 @@ ARM::ARM(u32 num)
: GdbStub(this, Platform::GetConfigInt(num ? Platform::GdbPortARM7 : Platform::GdbPortARM9))
#endif
{
ZoneScopedN(TracyFunction);
// well uh
Num = num;

Expand All @@ -135,6 +137,7 @@ ARM::~ARM()

ARMv5::ARMv5() : ARM(0)
{
ZoneScopedN(TracyFunction);
#ifndef JIT_ENABLED
DTCM = new u8[DTCMPhysicalSize];
#endif
Expand Down Expand Up @@ -258,6 +261,7 @@ void ARMv4::Reset()

void ARM::DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
file->Section((char*)(Num ? "ARM7" : "ARM9"));

file->Var32((u32*)&Cycles);
Expand Down Expand Up @@ -318,6 +322,7 @@ void ARM::DoSavestate(Savestate* file)

void ARMv5::DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
ARM::DoSavestate(file);
CP15DoSavestate(file);
}
Expand Down
2 changes: 2 additions & 0 deletions src/ARMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "Wifi.h"
#include "NDSCart.h"
#include "Platform.h"
#include "Tracy.h"

using Platform::Log;
using Platform::LogLevel;
Expand Down Expand Up @@ -1179,6 +1180,7 @@ template void CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u3

void ResetBlockCache()
{
ZoneScopedN(TracyFunction);
Log(LogLevel::Debug, "Resetting JIT block cache...\n");

// could be replace through a function which only resets
Expand Down
2 changes: 2 additions & 0 deletions src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Wifi.h"
#include "NDSCart.h"
#include "SPU.h"
#include "Tracy.h"

#include <stdlib.h>

Expand Down Expand Up @@ -877,6 +878,7 @@ void DeInit()

void Reset()
{
ZoneScopedN(TracyFunction);
for (int region = 0; region < memregions_Count; region++)
{
for (int i = 0; i < Mappings[region].Length; i++)
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ if (ENABLE_JIT)
endif()
endif()

if (TRACY_ENABLE)
target_link_libraries(core PUBLIC TracyClient)
target_include_directories(core SYSTEM PUBLIC TracyClient)
target_compile_definitions(core PUBLIC HAVE_TRACY TRACY_ENABLE TRACY_ENABLED)
endif()

if (WIN32)
target_link_libraries(core PRIVATE ole32 comctl32 wsock32 ws2_32)
elseif(NOT APPLE)
Expand Down
6 changes: 6 additions & 0 deletions src/CP15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DSi.h"
#include "ARM.h"
#include "Platform.h"
#include "Tracy.h"

#ifdef JIT_ENABLED
#include "ARMJIT.h"
Expand Down Expand Up @@ -75,6 +76,7 @@ void ARMv5::CP15Reset()

void ARMv5::CP15DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
file->Section("CP15");

file->Var32(&CP15Control);
Expand Down Expand Up @@ -105,6 +107,7 @@ void ARMv5::CP15DoSavestate(Savestate* file)

void ARMv5::UpdateDTCMSetting()
{
ZoneScopedN(TracyFunction);
u32 newDTCMBase;
u32 newDTCMMask;
u32 newDTCMSize;
Expand Down Expand Up @@ -135,6 +138,7 @@ void ARMv5::UpdateDTCMSetting()

void ARMv5::UpdateITCMSetting()
{
ZoneScopedN(TracyFunction);
if (CP15Control & (1<<18))
{
ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
Expand Down Expand Up @@ -260,6 +264,7 @@ void ARMv5::UpdatePURegion(u32 n)

void ARMv5::UpdatePURegions(bool update_all)
{
ZoneScopedN(TracyFunction);
if (!(CP15Control & (1<<0)))
{
// PU disabled
Expand Down Expand Up @@ -295,6 +300,7 @@ void ARMv5::UpdatePURegions(bool update_all)

void ARMv5::UpdateRegionTimings(u32 addrstart, u32 addrend)
{
ZoneScopedN(TracyFunction);
for (u32 i = addrstart; i < addrend; i++)
{
u8 pu = PU_Map[i];
Expand Down
2 changes: 2 additions & 0 deletions src/DMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GPU.h"
#include "DMA_Timings.h"
#include "Platform.h"
#include "Tracy.h"

using Platform::Log;
using Platform::LogLevel;
Expand Down Expand Up @@ -82,6 +83,7 @@ void DMA::Reset()

void DMA::DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
char magic[5] = "DMAx";
magic[3] = '0' + Num + (CPU*4);
file->Section(magic);
Expand Down
11 changes: 11 additions & 0 deletions src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#endif

#include "GPU2D_Soft.h"
#include "Tracy.h"

using Platform::Log;
using Platform::LogLevel;
Expand Down Expand Up @@ -184,6 +185,7 @@ void DeInit()

void ResetVRAMCache()
{
ZoneScopedN(TracyFunction);
for (int i = 0; i < 9; i++)
VRAMDirty[i] = NonStupidBitField<128*1024/VRAMDirtyGranularity>();

Expand Down Expand Up @@ -212,6 +214,7 @@ void ResetVRAMCache()

void Reset()
{
ZoneScopedN(TracyFunction);
VCount = 0;
NextVCount = -1;
TotalScanlines = 0;
Expand Down Expand Up @@ -315,6 +318,7 @@ void Stop()

void DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
file->Section("GPUG");

file->Var16(&VCount);
Expand Down Expand Up @@ -1030,6 +1034,7 @@ void DisplayFIFO(u32 x)

void StartFrame()
{
ZoneScopedN(TracyFunction);
// only run the display FIFO if needed:
// * if it is used for display or capture
// * if we have display FIFO DMA
Expand All @@ -1041,6 +1046,8 @@ void StartFrame()

void StartHBlank(u32 line)
{
ZoneScopedN(TracyFunction);
ZoneValue(line);
DispStat[0] |= (1<<1);
DispStat[1] |= (1<<1);

Expand Down Expand Up @@ -1084,6 +1091,8 @@ void StartHBlank(u32 line)

void FinishFrame(u32 lines)
{
ZoneScopedN(TracyFunction);
ZoneValue(lines);
FrontBuffer = FrontBuffer ? 0 : 1;
AssignFramebuffers();

Expand All @@ -1098,6 +1107,8 @@ void FinishFrame(u32 lines)

void StartScanline(u32 line)
{
ZoneScopedN(TracyFunction);
ZoneValue(line);
if (line == 0)
VCount = 0;
else if (NextVCount != 0xFFFFFFFF)
Expand Down
2 changes: 2 additions & 0 deletions src/GPU2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string.h>
#include "NDS.h"
#include "GPU.h"
#include "Tracy.h"

using Platform::Log;
using Platform::LogLevel;
Expand Down Expand Up @@ -142,6 +143,7 @@ void Unit::Reset()

void Unit::DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
file->Section((char*)(Num ? "GP2B" : "GP2A"));

file->Var32(&DispCnt);
Expand Down
12 changes: 12 additions & 0 deletions src/GPU3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GPU.h"
#include "FIFO.h"
#include "Platform.h"
#include "Tracy.h"

using Platform::Log;
using Platform::LogLevel;
Expand Down Expand Up @@ -310,6 +311,7 @@ void ResetRenderingState()

void Reset()
{
ZoneScopedN(TracyFunction);
CmdFIFO.Clear();
CmdPIPE.Clear();

Expand Down Expand Up @@ -391,6 +393,7 @@ void Reset()

void DoSavestate(Savestate* file)
{
ZoneScopedN(TracyFunction);
file->Section("GP3D");

CmdFIFO.DoSavestate(file);
Expand Down Expand Up @@ -811,6 +814,7 @@ void AddCycles(s32 num)

void NextVertexSlot()
{
ZoneScopedN(TracyFunction);
s32 num = (9 - VertexSlotCounter) + 1;

for (;;)
Expand Down Expand Up @@ -854,6 +858,7 @@ void NextVertexSlot()

void StallPolygonPipeline(s32 delay, s32 nonstalldelay)
{
ZoneScopedN(TracyFunction);
if (PolygonPipeline > 0)
{
CycleCount += PolygonPipeline + delay;
Expand All @@ -880,6 +885,7 @@ void StallPolygonPipeline(s32 delay, s32 nonstalldelay)
template<int comp, s32 plane, bool attribs>
void ClipSegment(Vertex* outbuf, Vertex* vin, Vertex* vout)
{
ZoneScopedN(TracyFunction);
s64 factor_num = vin->Position[3] - (plane*vin->Position[comp]);
s32 factor_den = factor_num - (vout->Position[3] - (plane*vout->Position[comp]));

Expand Down Expand Up @@ -909,6 +915,7 @@ void ClipSegment(Vertex* outbuf, Vertex* vin, Vertex* vout)
template<int comp, bool attribs>
int ClipAgainstPlane(Vertex* vertices, int nverts, int clipstart)
{
ZoneScopedN(TracyFunction);
Vertex temp[10];
int prev, next;
int c = clipstart;
Expand Down Expand Up @@ -990,6 +997,7 @@ int ClipAgainstPlane(Vertex* vertices, int nverts, int clipstart)
template<bool attribs>
int ClipPolygon(Vertex* vertices, int nverts, int clipstart)
{
ZoneScopedN(TracyFunction);
// clip.
// for each vertex:
// if it's outside, check if the previous and next vertices are inside
Expand Down Expand Up @@ -1022,6 +1030,7 @@ bool ClipCoordsEqual(Vertex* a, Vertex* b)

void SubmitPolygon()
{
ZoneScopedN(TracyFunction);
Vertex clippedvertices[10];
Vertex* reusedvertices[2];
int clipstart = 0;
Expand Down Expand Up @@ -1834,6 +1843,7 @@ inline void VertexPipelineCmdDelayed4()

void ExecuteCommand()
{
ZoneScopedN(TracyFunction);
CmdFIFOEntry entry = CmdFIFORead();

//printf("FIFO: processing %02X %08X. Levels: FIFO=%d, PIPE=%d\n", entry.Command, entry.Param, CmdFIFO->Level(), CmdPIPE->Level());
Expand Down Expand Up @@ -2452,6 +2462,7 @@ void FinishWork(s32 cycles)

void Run()
{
ZoneScopedN(TracyFunction);
if (!GeometryEnabled || FlushRequest ||
(CmdPIPE.IsEmpty() && !(GXStat & (1<<27))))
{
Expand Down Expand Up @@ -2529,6 +2540,7 @@ bool YSort(Polygon* a, Polygon* b)

void VBlank()
{
ZoneScopedN(TracyFunction);
if (GeometryEnabled)
{
if (RenderingEnabled)
Expand Down
Loading
Loading