mirror of
https://github.com/slendidev/lunar.git
synced 2026-01-31 00:38:59 +02:00
190
subprojects/tracy/profiler/CMakeLists.txt
Normal file
190
subprojects/tracy/profiler/CMakeLists.txt
Normal file
@@ -0,0 +1,190 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(NO_FILESELECTOR "Disable the file selector" OFF)
|
||||
option(GTK_FILESELECTOR "Use the GTK file selector on Linux instead of the xdg-portal one" OFF)
|
||||
option(LEGACY "Instead of Wayland, use the legacy X11 backend on Linux" OFF)
|
||||
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)" OFF)
|
||||
option(NO_STATISTICS "Disable calculation of statistics" OFF)
|
||||
option(SELF_PROFILE "Enable self-profiling" OFF)
|
||||
option(NO_PARALLEL_STL "Disable parallel STL" OFF)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/version.cmake)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
project(
|
||||
tracy-profiler
|
||||
LANGUAGES C CXX
|
||||
VERSION ${TRACY_VERSION_STRING}
|
||||
)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/config.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/vendor.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/server.cmake)
|
||||
|
||||
set(SERVER_FILES
|
||||
TracyAchievementData.cpp
|
||||
TracyAchievements.cpp
|
||||
TracyBadVersion.cpp
|
||||
TracyColor.cpp
|
||||
TracyEventDebug.cpp
|
||||
TracyFileselector.cpp
|
||||
TracyFilesystem.cpp
|
||||
TracyImGui.cpp
|
||||
TracyMicroArchitecture.cpp
|
||||
TracyMouse.cpp
|
||||
TracyProtoHistory.cpp
|
||||
TracySourceContents.cpp
|
||||
TracySourceTokenizer.cpp
|
||||
TracySourceView.cpp
|
||||
TracyStorage.cpp
|
||||
TracyTexture.cpp
|
||||
TracyTimelineController.cpp
|
||||
TracyTimelineItem.cpp
|
||||
TracyTimelineItemCpuData.cpp
|
||||
TracyTimelineItemGpu.cpp
|
||||
TracyTimelineItemPlot.cpp
|
||||
TracyTimelineItemThread.cpp
|
||||
TracyUserData.cpp
|
||||
TracyUtility.cpp
|
||||
TracyView.cpp
|
||||
TracyView_Annotations.cpp
|
||||
TracyView_Callstack.cpp
|
||||
TracyView_Compare.cpp
|
||||
TracyView_ConnectionState.cpp
|
||||
TracyView_ContextSwitch.cpp
|
||||
TracyView_CpuData.cpp
|
||||
TracyView_FindZone.cpp
|
||||
TracyView_FrameOverview.cpp
|
||||
TracyView_FrameTimeline.cpp
|
||||
TracyView_FrameTree.cpp
|
||||
TracyView_GpuTimeline.cpp
|
||||
TracyView_Locks.cpp
|
||||
TracyView_Memory.cpp
|
||||
TracyView_Messages.cpp
|
||||
TracyView_Navigation.cpp
|
||||
TracyView_NotificationArea.cpp
|
||||
TracyView_Options.cpp
|
||||
TracyView_Playback.cpp
|
||||
TracyView_Plots.cpp
|
||||
TracyView_Ranges.cpp
|
||||
TracyView_Samples.cpp
|
||||
TracyView_Statistics.cpp
|
||||
TracyView_Timeline.cpp
|
||||
TracyView_TraceInfo.cpp
|
||||
TracyView_Utility.cpp
|
||||
TracyView_ZoneInfo.cpp
|
||||
TracyView_ZoneTimeline.cpp
|
||||
TracyWeb.cpp
|
||||
)
|
||||
|
||||
list(TRANSFORM SERVER_FILES PREPEND "src/profiler/")
|
||||
|
||||
set(PROFILER_FILES
|
||||
src/imgui/imgui_impl_opengl3.cpp
|
||||
src/ConnectionHistory.cpp
|
||||
src/Filters.cpp
|
||||
src/Fonts.cpp
|
||||
src/HttpRequest.cpp
|
||||
src/ImGuiContext.cpp
|
||||
src/ini.c
|
||||
src/IsElevated.cpp
|
||||
src/main.cpp
|
||||
src/ResolvService.cpp
|
||||
src/RunQueue.cpp
|
||||
src/WindowPosition.cpp
|
||||
src/winmain.cpp
|
||||
src/winmainArchDiscovery.cpp
|
||||
)
|
||||
|
||||
set(INCLUDES "")
|
||||
set(LIBS "")
|
||||
|
||||
if(USE_WAYLAND)
|
||||
pkg_check_modules(WAYLAND REQUIRED egl wayland-egl wayland-cursor xkbcommon)
|
||||
set(INCLUDES "${INCLUDES};${CMAKE_CURRENT_BINARY_DIR}")
|
||||
set(LIBS "${LIBS};${WAYLAND_LIBRARIES}")
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
src/BackendWayland.cpp
|
||||
)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/FindWaylandScanner.cmake)
|
||||
|
||||
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
|
||||
pkg_get_variable(WAYLAND_PROTOCOLS_PKGDATADIR wayland-protocols pkgdatadir)
|
||||
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml
|
||||
BASENAME xdg-shell
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/xdg-activation/xdg-activation-v1.xml
|
||||
BASENAME xdg-activation
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
|
||||
BASENAME xdg-decoration
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/fractional-scale/fractional-scale-v1.xml
|
||||
BASENAME fractional-scale
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml
|
||||
BASENAME viewporter
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/staging/cursor-shape/cursor-shape-v1.xml
|
||||
BASENAME cursor-shape
|
||||
)
|
||||
ecm_add_wayland_client_protocol(PROFILER_FILES
|
||||
PROTOCOL ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/tablet/tablet-unstable-v2.xml
|
||||
BASENAME tablet
|
||||
)
|
||||
else()
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
src/BackendGlfw.cpp
|
||||
src/imgui/imgui_impl_glfw.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(${INCLUDES})
|
||||
link_libraries(${LIBS})
|
||||
|
||||
if(SELF_PROFILE)
|
||||
add_definitions(-DTRACY_ENABLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -fno-omit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -fno-omit-frame-pointer")
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
../public/TracyClient.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(PROFILER_FILES ${PROFILER_FILES}
|
||||
win32/Tracy.manifest
|
||||
win32/Tracy.rc
|
||||
)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${PROFILER_FILES} ${COMMON_FILES} ${SERVER_FILES})
|
||||
set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} ${PROFILER_FILES} ${COMMON_FILES} ${SERVER_FILES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyNfd)
|
||||
if (NOT USE_WAYLAND)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyGlfw3)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_FLAGS "-sUSE_FREETYPE=1 -pthread -DIMGUI_IMPL_OPENGL_ES2")
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS "-sASSERTIONS=0 -sUSE_GLFW=3 -sINITIAL_MEMORY=384mb -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=4gb -sWASM_BIGINT=1 -sPTHREAD_POOL_SIZE=4 -sEXPORTED_FUNCTIONS=_main,_nativeResize,_nativeOpenFile -sEXPORTED_RUNTIME_METHODS=ccall -sENVIRONMENT=web,worker --preload-file embed.tracy")
|
||||
|
||||
file(DOWNLOAD https://share.nereid.pl/i/embed.tracy ${CMAKE_CURRENT_BINARY_DIR}/embed.tracy EXPECTED_MD5 ca0fa4f01e7b8ca5581daa16b16c768d)
|
||||
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/index.html DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wasm/httpd.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
34
subprojects/tracy/profiler/src/Backend.hpp
Normal file
34
subprojects/tracy/profiler/src/Backend.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __BACKEND_HPP__
|
||||
#define __BACKEND_HPP__
|
||||
|
||||
#include <functional>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "WindowPosition.hpp"
|
||||
|
||||
class RunQueue;
|
||||
|
||||
class Backend
|
||||
{
|
||||
public:
|
||||
Backend( const char* title, const std::function<void()>& redraw, const std::function<void(float)>& scaleChanged, const std::function<int(void)>& isBusy, RunQueue* mainThreadTasks );
|
||||
~Backend();
|
||||
|
||||
void Show();
|
||||
void Run();
|
||||
void Attention();
|
||||
|
||||
void NewFrame( int& w, int& h );
|
||||
void EndFrame();
|
||||
|
||||
void SetIcon( uint8_t* data, int w, int h );
|
||||
void SetTitle( const char* title );
|
||||
|
||||
float GetDpiScale();
|
||||
|
||||
private:
|
||||
WindowPosition m_winPos;
|
||||
int m_w, m_h;
|
||||
};
|
||||
|
||||
#endif
|
||||
230
subprojects/tracy/profiler/src/BackendGlfw.cpp
Normal file
230
subprojects/tracy/profiler/src/BackendGlfw.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
#include "imgui/imgui_impl_glfw.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#ifdef __EMSCRIPTEN__
|
||||
# include <GLES2/gl2.h>
|
||||
# include <emscripten/html5.h>
|
||||
#else
|
||||
# include "imgui/imgui_impl_opengl3_loader.h"
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <thread>
|
||||
|
||||
#include "profiler/TracyConfig.hpp"
|
||||
#include "profiler/TracyImGui.hpp"
|
||||
|
||||
#include "Backend.hpp"
|
||||
#include "RunQueue.hpp"
|
||||
|
||||
|
||||
static GLFWwindow* s_window;
|
||||
static std::function<void()> s_redraw;
|
||||
static RunQueue* s_mainThreadTasks;
|
||||
static WindowPosition* s_winPos;
|
||||
static bool s_iconified;
|
||||
|
||||
extern tracy::Config s_config;
|
||||
|
||||
|
||||
static void glfw_error_callback( int error, const char* description )
|
||||
{
|
||||
fprintf(stderr, "Error %d: %s\n", error, description);
|
||||
}
|
||||
|
||||
static void glfw_window_pos_callback( GLFWwindow* window, int x, int y )
|
||||
{
|
||||
if( !glfwGetWindowAttrib( window, GLFW_MAXIMIZED ) )
|
||||
{
|
||||
s_winPos->x = x;
|
||||
s_winPos->y = y;
|
||||
}
|
||||
}
|
||||
|
||||
static void glfw_window_size_callback( GLFWwindow* window, int w, int h )
|
||||
{
|
||||
if( !glfwGetWindowAttrib( window, GLFW_MAXIMIZED ) )
|
||||
{
|
||||
s_winPos->w = w;
|
||||
s_winPos->h = h;
|
||||
}
|
||||
tracy::s_wasActive = true;
|
||||
}
|
||||
|
||||
static void glfw_window_maximize_callback( GLFWwindow*, int maximized )
|
||||
{
|
||||
s_winPos->maximize = maximized;
|
||||
}
|
||||
|
||||
static void glfw_window_iconify_callback( GLFWwindow*, int iconified )
|
||||
{
|
||||
s_iconified = iconified != 0;
|
||||
}
|
||||
|
||||
|
||||
Backend::Backend( const char* title, const std::function<void()>& redraw, const std::function<void(float)>& scaleChanged, const std::function<int(void)>& isBusy, RunQueue* mainThreadTasks )
|
||||
{
|
||||
glfwSetErrorCallback( glfw_error_callback );
|
||||
if( !glfwInit() ) exit( 1 );
|
||||
#ifdef DISPLAY_SERVER_WAYLAND
|
||||
glfwWindowHint( GLFW_ALPHA_BITS, 0 );
|
||||
#else
|
||||
glfwWindowHint( GLFW_VISIBLE, 0 );
|
||||
#endif
|
||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
|
||||
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 2 );
|
||||
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
# if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4 )
|
||||
glfwWindowHint( GLFW_WIN32_KEYBOARD_MENU, 1 );
|
||||
# endif
|
||||
#endif
|
||||
s_window = glfwCreateWindow( m_winPos.w, m_winPos.h, title, NULL, NULL );
|
||||
if( !s_window ) exit( 1 );
|
||||
|
||||
glfwSetWindowPos( s_window, m_winPos.x, m_winPos.y );
|
||||
#if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 2 )
|
||||
if( m_winPos.maximize ) glfwMaximizeWindow( s_window );
|
||||
#endif
|
||||
|
||||
glfwMakeContextCurrent( s_window );
|
||||
glfwSwapInterval( 1 ); // Enable vsync
|
||||
glfwSetWindowRefreshCallback( s_window, []( GLFWwindow* ) { tracy::s_wasActive = true; s_redraw(); } );
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL( s_window, true );
|
||||
#ifdef __EMSCRIPTEN__
|
||||
ImGui_ImplOpenGL3_Init( "#version 100" );
|
||||
#else
|
||||
ImGui_ImplOpenGL3_Init( "#version 150" );
|
||||
#endif
|
||||
|
||||
s_redraw = redraw;
|
||||
s_mainThreadTasks = mainThreadTasks;
|
||||
s_winPos = &m_winPos;
|
||||
s_iconified = false;
|
||||
|
||||
glfwSetWindowPosCallback( s_window, glfw_window_pos_callback );
|
||||
glfwSetWindowSizeCallback( s_window, glfw_window_size_callback );
|
||||
#if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
glfwSetWindowMaximizeCallback( s_window, glfw_window_maximize_callback );
|
||||
#endif
|
||||
glfwSetWindowIconifyCallback( s_window, glfw_window_iconify_callback );
|
||||
}
|
||||
|
||||
Backend::~Backend()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
|
||||
glfwDestroyWindow( s_window );
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void Backend::Show()
|
||||
{
|
||||
glfwShowWindow( s_window );
|
||||
}
|
||||
|
||||
void Backend::Run()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop( []() {
|
||||
glfwPollEvents();
|
||||
s_redraw();
|
||||
s_mainThreadTasks->Run();
|
||||
}, 0, 1 );
|
||||
#else
|
||||
while( !glfwWindowShouldClose( s_window ) )
|
||||
{
|
||||
if( s_iconified )
|
||||
{
|
||||
glfwWaitEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
glfwPollEvents();
|
||||
s_redraw();
|
||||
if( s_config.focusLostLimit && !glfwGetWindowAttrib( s_window, GLFW_FOCUSED ) ) std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
||||
s_mainThreadTasks->Run();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::Attention()
|
||||
{
|
||||
#if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
if( !glfwGetWindowAttrib( s_window, GLFW_FOCUSED ) )
|
||||
{
|
||||
glfwRequestWindowAttention( s_window );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::NewFrame( int& w, int& h )
|
||||
{
|
||||
glfwGetFramebufferSize( s_window, &w, &h );
|
||||
m_w = w;
|
||||
m_h = h;
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
}
|
||||
|
||||
void Backend::EndFrame()
|
||||
{
|
||||
const ImVec4 clear_color = ImColor( 20, 20, 17 );
|
||||
|
||||
ImGui::Render();
|
||||
glViewport( 0, 0, m_w, m_h );
|
||||
glClearColor( clear_color.x, clear_color.y, clear_color.z, clear_color.w );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() );
|
||||
|
||||
glfwSwapBuffers( s_window );
|
||||
}
|
||||
|
||||
void Backend::SetIcon( uint8_t* data, int w, int h )
|
||||
{
|
||||
GLFWimage icon;
|
||||
icon.width = w;
|
||||
icon.height = h;
|
||||
icon.pixels = data;
|
||||
glfwSetWindowIcon( s_window, 1, &icon );
|
||||
}
|
||||
|
||||
void Backend::SetTitle( const char* title )
|
||||
{
|
||||
glfwSetWindowTitle( s_window, title );
|
||||
}
|
||||
|
||||
float Backend::GetDpiScale()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return EM_ASM_DOUBLE( { return window.devicePixelRatio; } );
|
||||
#elif GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 )
|
||||
auto monitor = glfwGetWindowMonitor( s_window );
|
||||
if( !monitor ) monitor = glfwGetPrimaryMonitor();
|
||||
if( monitor )
|
||||
{
|
||||
float x, y;
|
||||
glfwGetMonitorContentScale( monitor, &x, &y );
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
extern "C" int nativeResize( int width, int height )
|
||||
{
|
||||
glfwSetWindowSize( s_window, width, height );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
1041
subprojects/tracy/profiler/src/BackendWayland.cpp
Normal file
1041
subprojects/tracy/profiler/src/BackendWayland.cpp
Normal file
File diff suppressed because it is too large
Load Diff
88
subprojects/tracy/profiler/src/ConnectionHistory.cpp
Normal file
88
subprojects/tracy/profiler/src/ConnectionHistory.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ConnectionHistory.hpp"
|
||||
|
||||
#include "../../server/tracy_pdqsort.h"
|
||||
#include "profiler/TracyStorage.hpp"
|
||||
|
||||
|
||||
ConnectionHistory::ConnectionHistory()
|
||||
: m_fn( tracy::GetSavePath( "connection.history" ) )
|
||||
{
|
||||
FILE* f = fopen( m_fn.c_str(), "rb" );
|
||||
if( !f ) return;
|
||||
|
||||
uint64_t sz;
|
||||
if( fread( &sz, 1, sizeof( sz ), f ) != sizeof( sz ) ) goto err;
|
||||
for( uint64_t i=0; i<sz; i++ )
|
||||
{
|
||||
uint64_t ssz, cnt;
|
||||
if( fread( &ssz, 1, sizeof( ssz ), f ) != sizeof( ssz ) ) goto err;
|
||||
if( ssz >= 1024 ) goto err;
|
||||
char tmp[1024];
|
||||
if( fread( tmp, 1, ssz, f ) != ssz ) goto err;
|
||||
if( fread( &cnt, 1, sizeof( cnt ), f ) != sizeof( cnt ) ) goto err;
|
||||
m_connHistMap.emplace( std::string( tmp, tmp+ssz ), cnt );
|
||||
}
|
||||
fclose( f );
|
||||
|
||||
Rebuild();
|
||||
return;
|
||||
|
||||
err:
|
||||
fclose( f );
|
||||
m_connHistMap.clear();
|
||||
}
|
||||
|
||||
ConnectionHistory::~ConnectionHistory()
|
||||
{
|
||||
FILE* f = fopen( m_fn.c_str(), "wb" );
|
||||
if( !f ) return;
|
||||
|
||||
uint64_t sz = uint64_t( m_connHistMap.size() );
|
||||
fwrite( &sz, 1, sizeof( uint64_t ), f );
|
||||
for( auto& v : m_connHistMap )
|
||||
{
|
||||
sz = uint64_t( v.first.size() );
|
||||
fwrite( &sz, 1, sizeof( uint64_t ), f );
|
||||
fwrite( v.first.c_str(), 1, sz, f );
|
||||
fwrite( &v.second, 1, sizeof( v.second ), f );
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
void ConnectionHistory::Rebuild()
|
||||
{
|
||||
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> vec;
|
||||
vec.reserve( m_connHistMap.size() );
|
||||
for( auto it = m_connHistMap.begin(); it != m_connHistMap.end(); ++it )
|
||||
{
|
||||
vec.emplace_back( it );
|
||||
}
|
||||
tracy::pdqsort_branchless( vec.begin(), vec.end(), []( const auto& lhs, const auto& rhs ) { return lhs->second > rhs->second; } );
|
||||
std::swap( m_connHistVec, vec );
|
||||
}
|
||||
|
||||
void ConnectionHistory::Count( const char* name )
|
||||
{
|
||||
std::string addr( name );
|
||||
auto it = m_connHistMap.find( addr );
|
||||
if( it != m_connHistMap.end() )
|
||||
{
|
||||
it->second++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_connHistMap.emplace( std::move( addr ), 1 );
|
||||
}
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
void ConnectionHistory::Erase( size_t idx )
|
||||
{
|
||||
assert( idx < m_connHistVec.size() );
|
||||
m_connHistMap.erase( m_connHistVec[idx] );
|
||||
Rebuild();
|
||||
}
|
||||
32
subprojects/tracy/profiler/src/ConnectionHistory.hpp
Normal file
32
subprojects/tracy/profiler/src/ConnectionHistory.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef __CONNECTIONHISTORY_HPP__
|
||||
#define __CONNECTIONHISTORY_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class ConnectionHistory
|
||||
{
|
||||
public:
|
||||
ConnectionHistory();
|
||||
~ConnectionHistory();
|
||||
|
||||
const std::string& Name( size_t idx ) const { return m_connHistVec[idx]->first; }
|
||||
|
||||
void Count( const char* name );
|
||||
void Erase( size_t idx );
|
||||
|
||||
bool empty() const { return m_connHistVec.empty(); }
|
||||
size_t size() const { return m_connHistVec.size(); }
|
||||
|
||||
private:
|
||||
void Rebuild();
|
||||
|
||||
std::string m_fn;
|
||||
|
||||
std::unordered_map<std::string, uint64_t> m_connHistMap;
|
||||
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> m_connHistVec;
|
||||
};
|
||||
|
||||
#endif
|
||||
87
subprojects/tracy/profiler/src/Filters.cpp
Normal file
87
subprojects/tracy/profiler/src/Filters.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Filters.hpp"
|
||||
|
||||
#include "profiler/TracyStorage.hpp"
|
||||
|
||||
|
||||
Filters::Filters()
|
||||
: m_fn( tracy::GetSavePath( "client.filters" ) )
|
||||
{
|
||||
FILE* f = fopen( m_fn.c_str(), "rb" );
|
||||
if( !f ) return;
|
||||
|
||||
uint8_t sz;
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
fread( m_addrFilter.InputBuf, 1, sz, f );
|
||||
m_addrFilter.Build();
|
||||
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
fread( m_portFilter.InputBuf, 1, sz, f );
|
||||
m_portFilter.Build();
|
||||
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
fread( m_progFilter.InputBuf, 1, sz, f );
|
||||
m_progFilter.Build();
|
||||
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
Filters::~Filters()
|
||||
{
|
||||
FILE* f = fopen( m_fn.c_str(), "wb" );
|
||||
if( !f ) return;
|
||||
|
||||
uint8_t sz = (uint8_t)strlen( m_addrFilter.InputBuf );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
fwrite( m_addrFilter.InputBuf, 1, sz, f );
|
||||
|
||||
sz = (uint8_t)strlen( m_portFilter.InputBuf );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
fwrite( m_portFilter.InputBuf, 1, sz, f );
|
||||
|
||||
sz = (uint8_t)strlen( m_progFilter.InputBuf );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
fwrite( m_progFilter.InputBuf, 1, sz, f );
|
||||
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
void Filters::Clear()
|
||||
{
|
||||
m_addrFilter.Clear();
|
||||
m_portFilter.Clear();
|
||||
m_progFilter.Clear();
|
||||
}
|
||||
|
||||
void Filters::Draw( float w )
|
||||
{
|
||||
m_addrFilter.Draw( "Address filter", w );
|
||||
m_portFilter.Draw( "Port filter", w );
|
||||
m_progFilter.Draw( "Program filter", w );
|
||||
}
|
||||
|
||||
bool Filters::IsActive() const
|
||||
{
|
||||
return m_addrFilter.IsActive() || m_portFilter.IsActive() || m_progFilter.IsActive();
|
||||
}
|
||||
|
||||
bool Filters::FailAddr( const char* addr )
|
||||
{
|
||||
return m_addrFilter.IsActive() && !m_addrFilter.PassFilter( addr );
|
||||
}
|
||||
|
||||
bool Filters::FailPort( uint16_t port )
|
||||
{
|
||||
if( !m_portFilter.IsActive() ) return false;
|
||||
char buf[32];
|
||||
sprintf( buf, "%" PRIu16, port );
|
||||
return !m_portFilter.PassFilter( buf );
|
||||
}
|
||||
|
||||
bool Filters::FailProg( const char* prog )
|
||||
{
|
||||
return m_progFilter.IsActive() && !m_progFilter.PassFilter( prog );
|
||||
}
|
||||
28
subprojects/tracy/profiler/src/Filters.hpp
Normal file
28
subprojects/tracy/profiler/src/Filters.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef __FILTERS_HPP__
|
||||
#define __FILTERS_HPP__
|
||||
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
|
||||
class Filters
|
||||
{
|
||||
public:
|
||||
Filters();
|
||||
~Filters();
|
||||
|
||||
void Clear();
|
||||
void Draw( float w );
|
||||
|
||||
bool IsActive() const;
|
||||
|
||||
bool FailAddr( const char* addr );
|
||||
bool FailPort( uint16_t port );
|
||||
bool FailProg( const char* prog );
|
||||
|
||||
private:
|
||||
std::string m_fn;
|
||||
|
||||
ImGuiTextFilter m_addrFilter, m_portFilter, m_progFilter;
|
||||
};
|
||||
|
||||
#endif
|
||||
59
subprojects/tracy/profiler/src/Fonts.cpp
Normal file
59
subprojects/tracy/profiler/src/Fonts.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <imgui.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "Fonts.hpp"
|
||||
#include "misc/freetype/imgui_freetype.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
#include "profiler/IconsFontAwesome6.h"
|
||||
|
||||
#include "font/DroidSans.hpp"
|
||||
#include "font/FiraCodeRetina.hpp"
|
||||
#include "font/FontAwesomeSolid.hpp"
|
||||
|
||||
ImFont* s_bigFont;
|
||||
ImFont* s_smallFont;
|
||||
ImFont* s_fixedWidth;
|
||||
|
||||
void LoadFonts( float scale )
|
||||
{
|
||||
static const ImWchar rangesBasic[] = {
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x03BC, 0x03BC, // micro
|
||||
0x03C3, 0x03C3, // small sigma
|
||||
0x2013, 0x2013, // en dash
|
||||
0x2026, 0x2026, // ellipsis
|
||||
0x2264, 0x2264, // less-than or equal to
|
||||
0,
|
||||
};
|
||||
static const ImWchar rangesIcons[] = {
|
||||
ICON_MIN_FA, ICON_MAX_FA,
|
||||
0
|
||||
};
|
||||
static const ImWchar rangesFixed[] = {
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x2026, 0x2026, // ellipsis
|
||||
0
|
||||
};
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImFontConfig configBasic;
|
||||
configBasic.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
ImFontConfig configMerge;
|
||||
configMerge.MergeMode = true;
|
||||
configMerge.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
ImFontConfig configFixed;
|
||||
configFixed.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
configFixed.GlyphExtraSpacing.x = -1;
|
||||
|
||||
io.Fonts->Clear();
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 15.0f * scale ), &configBasic, rangesBasic );
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 14.0f * scale ), &configMerge, rangesIcons );
|
||||
s_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configFixed, rangesFixed );
|
||||
s_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic );
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 20.0f * scale ), &configMerge, rangesIcons );
|
||||
s_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic );
|
||||
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
}
|
||||
12
subprojects/tracy/profiler/src/Fonts.hpp
Normal file
12
subprojects/tracy/profiler/src/Fonts.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __FONTS_HPP__
|
||||
#define __FONTS_HPP__
|
||||
|
||||
struct ImFont;
|
||||
|
||||
extern ImFont* s_bigFont;
|
||||
extern ImFont* s_smallFont;
|
||||
extern ImFont* s_fixedWidth;
|
||||
|
||||
void LoadFonts( float scale );
|
||||
|
||||
#endif
|
||||
122
subprojects/tracy/profiler/src/HttpRequest.cpp
Normal file
122
subprojects/tracy/profiler/src/HttpRequest.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../public/common/TracySocket.hpp"
|
||||
#include "../public/common/TracyVersion.hpp"
|
||||
#include "HttpRequest.hpp"
|
||||
|
||||
#if defined _WIN32
|
||||
# include <windows.h>
|
||||
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
||||
#elif defined __linux__
|
||||
# include <sys/utsname.h>
|
||||
#elif defined __APPLE__
|
||||
# include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
static constexpr char CRLF[2] = { '\r', '\n' };
|
||||
|
||||
static const char* GetOsInfo()
|
||||
{
|
||||
static char buf[1024];
|
||||
#if defined _WIN32
|
||||
t_RtlGetVersion RtlGetVersion = (t_RtlGetVersion)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlGetVersion" );
|
||||
if( !RtlGetVersion )
|
||||
{
|
||||
# ifdef __MINGW32__
|
||||
sprintf( buf, "Windows (MingW)" );
|
||||
# else
|
||||
sprintf( buf, "Windows" );
|
||||
# endif
|
||||
}
|
||||
else
|
||||
{
|
||||
RTL_OSVERSIONINFOW ver = { sizeof( RTL_OSVERSIONINFOW ) };
|
||||
RtlGetVersion( &ver );
|
||||
|
||||
# ifdef __MINGW32__
|
||||
sprintf( buf, "Windows %i.%i.%i (MingW)", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber );
|
||||
# else
|
||||
sprintf( buf, "Windows %i.%i.%i", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber );
|
||||
# endif
|
||||
}
|
||||
#elif defined __linux__
|
||||
struct utsname utsName;
|
||||
uname( &utsName );
|
||||
# if defined __ANDROID__
|
||||
sprintf( buf, "Linux %s (Android)", utsName.release );
|
||||
# else
|
||||
sprintf( buf, "Linux %s", utsName.release );
|
||||
# endif
|
||||
#elif defined __APPLE__
|
||||
# if TARGET_OS_IPHONE == 1
|
||||
sprintf( buf, "Darwin (iOS)" );
|
||||
# elif TARGET_OS_MAC == 1
|
||||
sprintf( buf, "Darwin (OSX)" );
|
||||
# else
|
||||
sprintf( buf, "Darwin (unknown)" );
|
||||
# endif
|
||||
#elif defined __DragonFly__
|
||||
sprintf( buf, "BSD (DragonFly)" );
|
||||
#elif defined __FreeBSD__
|
||||
sprintf( buf, "BSD (FreeBSD)" );
|
||||
#elif defined __NetBSD__
|
||||
sprintf( buf, "BSD (NetBSD)" );
|
||||
#elif defined __OpenBSD__
|
||||
sprintf( buf, "BSD (OpenBSD)" );
|
||||
#elif defined __QNX__
|
||||
sprintf( buf, "QNX" );
|
||||
#else
|
||||
sprintf( buf, "unknown" );
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
void HttpRequest( const char* server, const char* resource, int port, const std::function<void(int, char*)>& cb )
|
||||
{
|
||||
tracy::Socket sock;
|
||||
if( !sock.ConnectBlocking( server, port ) ) return;
|
||||
char request[4096];
|
||||
const auto len = sprintf( request, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Tracy Profiler %i.%i.%i (%s)\r\nConnection: close\r\nCache-Control: no-cache, no-store, must-revalidate\r\n\r\n", resource, server, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, GetOsInfo() );
|
||||
sock.Send( request, len );
|
||||
char response[4096];
|
||||
const auto sz = sock.ReadUpTo( response, 4096 );
|
||||
if( sz < 13 ) return;
|
||||
if( memcmp( response, "HTTP/1.1 200", 12 ) != 0 ) return;
|
||||
auto hdr = response + 13;
|
||||
int contentLength = 0;
|
||||
for(;;)
|
||||
{
|
||||
while( memcmp( hdr, CRLF, 2 ) != 0 ) hdr++;
|
||||
hdr += 2;
|
||||
if( memcmp( hdr, "Content-Length: ", 16 ) == 0 )
|
||||
{
|
||||
hdr += 16;
|
||||
contentLength = atoi( hdr );
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert( contentLength != 0 );
|
||||
for(;;)
|
||||
{
|
||||
while( memcmp( hdr, CRLF, 2 ) != 0 ) hdr++;
|
||||
hdr += 2;
|
||||
if( memcmp( hdr, CRLF, 2 ) == 0 )
|
||||
{
|
||||
hdr += 2;
|
||||
break;
|
||||
}
|
||||
hdr += 2;
|
||||
}
|
||||
|
||||
const auto hdrSize = hdr - response;
|
||||
const auto partSize = sz - hdrSize;
|
||||
char* data = new char[contentLength];
|
||||
memcpy( data, hdr, partSize );
|
||||
auto remaining = contentLength - partSize;
|
||||
if( remaining > 0 ) sock.Read( data + partSize, remaining, 15 );
|
||||
|
||||
cb( contentLength, data );
|
||||
}
|
||||
8
subprojects/tracy/profiler/src/HttpRequest.hpp
Normal file
8
subprojects/tracy/profiler/src/HttpRequest.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __HTTPREQUEST_HPP__
|
||||
#define __HTTPREQUEST_HPP__
|
||||
|
||||
#include <functional>
|
||||
|
||||
void HttpRequest( const char* server, const char* resource, int port, const std::function<void(int, char*)>& cb );
|
||||
|
||||
#endif
|
||||
19
subprojects/tracy/profiler/src/ImGuiContext.cpp
Normal file
19
subprojects/tracy/profiler/src/ImGuiContext.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <imgui.h>
|
||||
#include "profiler/TracyStorage.hpp"
|
||||
#include "ImGuiContext.hpp"
|
||||
|
||||
ImGuiTracyContext::ImGuiTracyContext()
|
||||
: m_iniFilename( tracy::GetSavePath( "imgui.ini" ) )
|
||||
{
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.IniFilename = m_iniFilename.c_str();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigInputTextCursorBlink = false;
|
||||
}
|
||||
|
||||
ImGuiTracyContext::~ImGuiTracyContext()
|
||||
{
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
16
subprojects/tracy/profiler/src/ImGuiContext.hpp
Normal file
16
subprojects/tracy/profiler/src/ImGuiContext.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef __IMGUICONTEXT_HPP__
|
||||
#define __IMGUICONTEXT_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
class ImGuiTracyContext
|
||||
{
|
||||
public:
|
||||
ImGuiTracyContext();
|
||||
~ImGuiTracyContext();
|
||||
|
||||
private:
|
||||
std::string m_iniFilename;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
subprojects/tracy/profiler/src/IsElevated.cpp
Normal file
41
subprojects/tracy/profiler/src/IsElevated.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "IsElevated.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
bool IsElevated()
|
||||
{
|
||||
HANDLE token;
|
||||
if( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ) == 0 ) return false;
|
||||
|
||||
TOKEN_ELEVATION te;
|
||||
DWORD sz;
|
||||
if( GetTokenInformation( token, TokenElevation, &te, sizeof( te ), &sz ) == 0 )
|
||||
{
|
||||
CloseHandle( token );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = te.TokenIsElevated;
|
||||
CloseHandle( token );
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined __EMSCRIPTEN__
|
||||
|
||||
bool IsElevated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
bool IsElevated()
|
||||
{
|
||||
return getuid() == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
6
subprojects/tracy/profiler/src/IsElevated.hpp
Normal file
6
subprojects/tracy/profiler/src/IsElevated.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef __ISELEVATED_HPP__
|
||||
#define __ISELEVATED_HPP__
|
||||
|
||||
bool IsElevated();
|
||||
|
||||
#endif
|
||||
59
subprojects/tracy/profiler/src/ResolvService.cpp
Normal file
59
subprojects/tracy/profiler/src/ResolvService.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifdef _WIN32
|
||||
# include <ws2tcpip.h>
|
||||
#else
|
||||
# ifdef __FreeBSD__
|
||||
# include <netinet/in.h>
|
||||
# endif
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "ResolvService.hpp"
|
||||
|
||||
ResolvService::ResolvService( uint16_t port )
|
||||
: m_exit( false )
|
||||
, m_port( port )
|
||||
, m_thread( [this] { Worker(); } )
|
||||
{
|
||||
}
|
||||
|
||||
ResolvService::~ResolvService()
|
||||
{
|
||||
m_exit.store( true, std::memory_order_relaxed );
|
||||
m_cv.notify_one();
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
void ResolvService::Query( uint32_t ip, const std::function<void(std::string&&)>& callback )
|
||||
{
|
||||
std::lock_guard<std::mutex> lock( m_lock );
|
||||
m_queue.emplace_back( QueueItem { ip, callback } );
|
||||
m_cv.notify_one();
|
||||
}
|
||||
|
||||
void ResolvService::Worker()
|
||||
{
|
||||
struct sockaddr_in addr = {};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( m_port );
|
||||
|
||||
char buf[128];
|
||||
|
||||
for(;;)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock( m_lock );
|
||||
m_cv.wait( lock, [this] { return !m_queue.empty() || m_exit.load( std::memory_order_relaxed ); } );
|
||||
if( m_exit.load( std::memory_order_relaxed ) ) return;
|
||||
auto query = m_queue.back();
|
||||
m_queue.pop_back();
|
||||
lock.unlock();
|
||||
|
||||
addr.sin_addr.s_addr = query.ip;
|
||||
if( getnameinfo( (const struct sockaddr*)&addr, sizeof( sockaddr_in ), buf, 128, nullptr, 0, NI_NOFQDN ) != 0 )
|
||||
{
|
||||
inet_ntop( AF_INET, &query.ip, buf, 17 );
|
||||
}
|
||||
query.callback( buf );
|
||||
}
|
||||
}
|
||||
38
subprojects/tracy/profiler/src/ResolvService.hpp
Normal file
38
subprojects/tracy/profiler/src/ResolvService.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef __RESOLVSERVICE_HPP__
|
||||
#define __RESOLVSERVICE_HPP__
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class ResolvService
|
||||
{
|
||||
struct QueueItem
|
||||
{
|
||||
uint32_t ip;
|
||||
std::function<void(std::string&&)> callback;
|
||||
};
|
||||
|
||||
public:
|
||||
ResolvService( uint16_t port );
|
||||
~ResolvService();
|
||||
|
||||
void Query( uint32_t ip, const std::function<void(std::string&&)>& callback );
|
||||
|
||||
private:
|
||||
void Worker();
|
||||
|
||||
std::atomic<bool> m_exit;
|
||||
std::mutex m_lock;
|
||||
std::condition_variable m_cv;
|
||||
std::vector<QueueItem> m_queue;
|
||||
uint16_t m_port;
|
||||
std::thread m_thread;
|
||||
};
|
||||
|
||||
#endif
|
||||
31
subprojects/tracy/profiler/src/RunQueue.cpp
Normal file
31
subprojects/tracy/profiler/src/RunQueue.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "RunQueue.hpp"
|
||||
|
||||
RunQueue::RunQueue()
|
||||
: m_mainThread( std::this_thread::get_id() )
|
||||
{
|
||||
}
|
||||
|
||||
void RunQueue::Queue( const std::function<void()>& cb, bool forceDelay )
|
||||
{
|
||||
if( !forceDelay && std::this_thread::get_id() == m_mainThread )
|
||||
{
|
||||
cb();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> lock( m_lock );
|
||||
m_queue.emplace_back( cb );
|
||||
}
|
||||
}
|
||||
|
||||
void RunQueue::Run()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock( m_lock );
|
||||
if( !m_queue.empty() )
|
||||
{
|
||||
std::vector<std::function<void()>> tmp;
|
||||
std::swap( tmp, m_queue );
|
||||
lock.unlock();
|
||||
for( auto& cb : tmp ) cb();
|
||||
}
|
||||
}
|
||||
23
subprojects/tracy/profiler/src/RunQueue.hpp
Normal file
23
subprojects/tracy/profiler/src/RunQueue.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __RUNQUEUE_HPP__
|
||||
#define __RUNQUEUE_HPP__
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class RunQueue
|
||||
{
|
||||
public:
|
||||
RunQueue();
|
||||
|
||||
void Queue( const std::function<void()>& cb, bool forceDelay = false );
|
||||
void Run();
|
||||
|
||||
private:
|
||||
std::vector<std::function<void()>> m_queue;
|
||||
std::mutex m_lock;
|
||||
std::thread::id m_mainThread;
|
||||
};
|
||||
|
||||
#endif
|
||||
48
subprojects/tracy/profiler/src/WindowPosition.cpp
Normal file
48
subprojects/tracy/profiler/src/WindowPosition.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "WindowPosition.hpp"
|
||||
|
||||
#include "profiler/TracyStorage.hpp"
|
||||
|
||||
|
||||
WindowPosition::WindowPosition()
|
||||
: m_fn( tracy::GetSavePath( "window.position" ) )
|
||||
{
|
||||
Defaults();
|
||||
|
||||
FILE* f = fopen( m_fn.c_str(), "rb" );
|
||||
if( f )
|
||||
{
|
||||
uint32_t data[5];
|
||||
if( fread( data, 1, sizeof( data ), f ) == sizeof( data ) )
|
||||
{
|
||||
x = data[0];
|
||||
y = data[1];
|
||||
w = data[2];
|
||||
h = data[3];
|
||||
maximize = data[4];
|
||||
}
|
||||
fclose( f );
|
||||
|
||||
if( w <= 0 || h <= 0 ) Defaults();
|
||||
}
|
||||
}
|
||||
|
||||
WindowPosition::~WindowPosition()
|
||||
{
|
||||
FILE* f = fopen( m_fn.c_str(), "wb" );
|
||||
if( !f ) return;
|
||||
uint32_t data[5] = { uint32_t( x ), uint32_t( y ), uint32_t( w ), uint32_t( h ), uint32_t( maximize ) };
|
||||
fwrite( data, 1, sizeof( data ), f );
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
void WindowPosition::Defaults()
|
||||
{
|
||||
x = 200;
|
||||
y = 200;
|
||||
w = 1650;
|
||||
h = 960;
|
||||
maximize = 0;
|
||||
}
|
||||
20
subprojects/tracy/profiler/src/WindowPosition.hpp
Normal file
20
subprojects/tracy/profiler/src/WindowPosition.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef __WINDOWPOSITION_HPP__
|
||||
#define __WINDOWPOSITION_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
class WindowPosition
|
||||
{
|
||||
public:
|
||||
WindowPosition();
|
||||
~WindowPosition();
|
||||
|
||||
int x, y, w, h, maximize;
|
||||
|
||||
private:
|
||||
void Defaults();
|
||||
|
||||
std::string m_fn;
|
||||
};
|
||||
|
||||
#endif
|
||||
2821
subprojects/tracy/profiler/src/font/DroidSans.hpp
Normal file
2821
subprojects/tracy/profiler/src/font/DroidSans.hpp
Normal file
File diff suppressed because it is too large
Load Diff
3995
subprojects/tracy/profiler/src/font/FiraCodeRetina.hpp
Normal file
3995
subprojects/tracy/profiler/src/font/FiraCodeRetina.hpp
Normal file
File diff suppressed because it is too large
Load Diff
12368
subprojects/tracy/profiler/src/font/FontAwesomeSolid.hpp
Normal file
12368
subprojects/tracy/profiler/src/font/FontAwesomeSolid.hpp
Normal file
File diff suppressed because it is too large
Load Diff
25
subprojects/tracy/profiler/src/icon.hpp
Normal file
25
subprojects/tracy/profiler/src/icon.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// File: 'icon.png' (854 bytes)
|
||||
// Exported using binary_to_compressed_c.cpp
|
||||
static const unsigned int Icon_size = 854;
|
||||
static const unsigned int Icon_data[856/4] =
|
||||
{
|
||||
0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x00010000, 0x00010000, 0x00000308, 0x58ac6b00, 0x00000054, 0x59487009, 0x0a000073, 0x0a000000,
|
||||
0x82430100, 0x00003ccc, 0x42730300, 0x08085449, 0x4fe1db08, 0x000000e0, 0x544c50b4, 0x00000045, 0x00000000, 0x00000000, 0xffe4d600, 0xb9f1d1bd,
|
||||
0xc8b0efcf, 0xe8c5adea, 0x9de7c4ab, 0xb191dfb9, 0xcda27ed8, 0x72c99e77, 0x9a72c79a, 0xbc8b5fc6, 0x56bc8b5e, 0x713cb684, 0xa67039a7, 0x35a66e37,
|
||||
0x6b34a46d, 0xa36b33a3, 0x009d642a, 0x6126d66e, 0xcc69009b, 0x00cb6800, 0x6300c364, 0xbc6000c1, 0x19ba6000, 0x5b009458, 0xab5800b1, 0x00a95700,
|
||||
0x5300a655, 0x8e4f0ea0, 0x008e4f0d, 0x5100a052, 0x9d51009e, 0x00994e00, 0x4d00974d, 0x944c0096, 0x00914b00, 0x4700914a, 0x8a47008b, 0x00894700,
|
||||
0x45008946, 0x14121186, 0x01110f0e, 0x00000101, 0x56a20400, 0x0000006f, 0x4e527404, 0x521b0053, 0xb06c3055, 0x020000a6, 0x41444929, 0xedda7854,
|
||||
0x2c95c5db, 0xc1441449, 0x66666a62, 0xf5fd6666, 0xe7ce5a9a, 0xc4dce8c8, 0xd822bb2b, 0x24378fd6, 0x3db35249, 0x027f3561, 0x584d7d68, 0x0000002d,
|
||||
0x00000000, 0x005f8000, 0xf7023f3e, 0xdef00099, 0xdffbdc09, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x0587f400, 0xe011afd6, 0x0ec0adf0, 0x700004eb, 0xb7585fbb, 0x6e5c0335, 0x3e65d616, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0xac2d3c78, 0x0c013ac7, 0xd9e75b23, 0xf3b37c5d, 0x01b2b6ec, 0x9beded6a, 0xbf8f3f15, 0xce3db801, 0xc00436ee, 0x277666c9, 0x000001a5,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xa39b8000, 0x078a6eec, 0xe8008c30, 0xb30ee6f5, 0x4af5eb9b, 0xf3371807, 0xa74cdd96,
|
||||
0xeae00313, 0x40aba32c, 0x199bdb00, 0x0009976d, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0e000000, 0x883a32f6, 0x01186001,
|
||||
0x568d1dd0, 0x195a3236, 0x0021ba8d, 0x5fe61dc6, 0xbc00a35f, 0x25ec543c, 0x66e5c018, 0x05cb2ec5, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0xbb153bd7, 0x1860040e, 0xbb3d3001, 0x85b15ab0, 0x0038e9d9, 0x2adea6e3, 0x00e9d536, 0xbbb00608, 0xe16edc99, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x53f3c000, 0x9186cf72, 0xc5830070, 0xe4b5a5c5, 0x07171696, 0xadc600c1, 0xdeb725bf,
|
||||
0x1e200719, 0x524efdc0, 0xee0161f7, 0x03ba9336, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x11000000, 0x92ef5e00, 0xc48c357a,
|
||||
0x4e5f9804, 0x804cbe6e, 0x00000202, 0x00000000, 0x00000000, 0x00000000, 0x0000043f, 0x00000000, 0x00000000, 0xe047e7c0, 0xe200133e, 0x00000007,
|
||||
0x00000000, 0xcd43f000, 0x6cd584f6, 0x24927c4c, 0x8a1907fd, 0xabe6918e, 0x00003480, 0x45490000, 0x42ae444e, 0x00008260,
|
||||
};
|
||||
|
||||
1369
subprojects/tracy/profiler/src/imgui/imgui_impl_glfw.cpp
Normal file
1369
subprojects/tracy/profiler/src/imgui/imgui_impl_glfw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
62
subprojects/tracy/profiler/src/imgui/imgui_impl_glfw.h
Normal file
62
subprojects/tracy/profiler/src/imgui/imgui_impl_glfw.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// dear imgui: Platform Backend for GLFW
|
||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||
// Issues:
|
||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
struct GLFWwindow;
|
||||
struct GLFWmonitor;
|
||||
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
// Emscripten related initialization phase methods
|
||||
#ifdef __EMSCRIPTEN__
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector);
|
||||
#endif
|
||||
|
||||
// GLFW callbacks install
|
||||
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
|
||||
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
||||
|
||||
// GFLW callbacks options:
|
||||
// - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user)
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows);
|
||||
|
||||
// GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks)
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
996
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3.cpp
Normal file
996
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3.cpp
Normal file
@@ -0,0 +1,996 @@
|
||||
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
|
||||
// - Desktop GL: 2.x 3.x 4.x
|
||||
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
||||
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||
|
||||
// About WebGL/ES:
|
||||
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
||||
// - This is done automatically on iOS, Android and Emscripten targets.
|
||||
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||
// 2024-05-07: OpenGL: Update loader for Linux to support EGL/GLVND. (#7562)
|
||||
// 2024-04-16: OpenGL: Detect ES3 contexts on desktop based on version string, to e.g. avoid calling glPolygonMode() on them. (#7447)
|
||||
// 2024-01-09: OpenGL: Update GL3W based imgui_impl_opengl3_loader.h to load "libGL.so" and variants, fixing regression on distros missing a symlink.
|
||||
// 2023-11-08: OpenGL: Update GL3W based imgui_impl_opengl3_loader.h to load "libGL.so" instead of "libGL.so.1", accommodating for NetBSD systems having only "libGL.so.3" available. (#6983)
|
||||
// 2023-10-05: OpenGL: Rename symbols in our internal loader so that LTO compilation with another copy of gl3w is possible. (#6875, #6668, #4445)
|
||||
// 2023-06-20: OpenGL: Fixed erroneous use glGetIntegerv(GL_CONTEXT_PROFILE_MASK) on contexts lower than 3.2. (#6539, #6333)
|
||||
// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375)
|
||||
// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333)
|
||||
// 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224)
|
||||
// 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530)
|
||||
// 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224)
|
||||
// 2022-11-09: OpenGL: Reverted use of glBufferSubData(), too many corruptions issues + old issues seemingly can't be reproed with Intel drivers nowadays (revert 2021-12-15 and 2022-05-23 changes).
|
||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||
// 2022-09-27: OpenGL: Added ability to '#define IMGUI_IMPL_OPENGL_DEBUG'.
|
||||
// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127).
|
||||
// 2022-05-13: OpenGL: Fixed state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states.
|
||||
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
|
||||
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
|
||||
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
|
||||
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
|
||||
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
|
||||
// 2021-05-24: OpenGL: Access GL_CLIP_ORIGIN when "GL_ARB_clip_control" extension is detected, inside of just OpenGL 4.5 version.
|
||||
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
||||
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
|
||||
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
|
||||
// 2021-01-03: OpenGL: Backup, setup and restore GL_STENCIL_TEST state.
|
||||
// 2020-10-23: OpenGL: Backup, setup and restore GL_PRIMITIVE_RESTART state.
|
||||
// 2020-10-15: OpenGL: Use glGetString(GL_VERSION) instead of glGetIntegerv(GL_MAJOR_VERSION, ...) when the later returns zero (e.g. Desktop GL 2.x)
|
||||
// 2020-09-17: OpenGL: Fix to avoid compiling/calling glBindSampler() on ES or pre 3.3 context which have the defines set by a loader.
|
||||
// 2020-07-10: OpenGL: Added support for glad2 OpenGL loader.
|
||||
// 2020-05-08: OpenGL: Made default GLSL version 150 (instead of 130) on OSX.
|
||||
// 2020-04-21: OpenGL: Fixed handling of glClipControl(GL_UPPER_LEFT) by inverting projection matrix.
|
||||
// 2020-04-12: OpenGL: Fixed context version check mistakenly testing for 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset.
|
||||
// 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader.
|
||||
// 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader.
|
||||
// 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders.
|
||||
// 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility.
|
||||
// 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call.
|
||||
// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
||||
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
||||
// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
|
||||
// 2019-03-15: OpenGL: Added a GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
|
||||
// 2019-03-03: OpenGL: Fix support for ES 2.0 (WebGL 1.0).
|
||||
// 2019-02-20: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN even if defined by the headers/loader.
|
||||
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
||||
// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
|
||||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
||||
// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT) / GL_CLIP_ORIGIN.
|
||||
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
|
||||
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
|
||||
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
|
||||
// 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
|
||||
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
|
||||
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
||||
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
|
||||
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a nullptr pointer.
|
||||
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
|
||||
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
|
||||
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
|
||||
// 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
|
||||
// 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
|
||||
// 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
|
||||
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
|
||||
// 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
|
||||
|
||||
//----------------------------------------
|
||||
// OpenGL GLSL GLSL
|
||||
// version version string
|
||||
//----------------------------------------
|
||||
// 2.0 110 "#version 110"
|
||||
// 2.1 120 "#version 120"
|
||||
// 3.0 130 "#version 130"
|
||||
// 3.1 140 "#version 140"
|
||||
// 3.2 150 "#version 150"
|
||||
// 3.3 330 "#version 330 core"
|
||||
// 4.0 400 "#version 400 core"
|
||||
// 4.1 410 "#version 410 core"
|
||||
// 4.2 420 "#version 410 core"
|
||||
// 4.3 430 "#version 430 core"
|
||||
// ES 2.0 100 "#version 100" = WebGL 1.0
|
||||
// ES 3.0 300 "#version 300 es" = WebGL 2.0
|
||||
//----------------------------------------
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "imgui.h"
|
||||
#ifndef IMGUI_DISABLE
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h> // intptr_t
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
// Clang/GCC warnings with -Weverything
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||
#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used
|
||||
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
|
||||
#pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
|
||||
#endif
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||||
#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
|
||||
#endif
|
||||
|
||||
// GL includes
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||
#include <OpenGLES/ES2/gl.h> // Use GL ES 2
|
||||
#else
|
||||
#include <GLES2/gl2.h> // Use GL ES 2
|
||||
#endif
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#endif
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
||||
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
|
||||
#else
|
||||
#include <GLES3/gl3.h> // Use GL ES 3
|
||||
#endif
|
||||
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
||||
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
|
||||
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
|
||||
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
|
||||
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
|
||||
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
|
||||
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
|
||||
#define IMGL3W_IMPL
|
||||
#include "imgui_impl_opengl3_loader.h"
|
||||
#endif
|
||||
|
||||
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
|
||||
#ifndef IMGUI_IMPL_OPENGL_ES2
|
||||
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
#define glBindVertexArray glBindVertexArrayOES
|
||||
#define glGenVertexArrays glGenVertexArraysOES
|
||||
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
|
||||
#endif
|
||||
|
||||
// Desktop GL 2.0+ has extension and glPolygonMode() which GL ES and WebGL don't have..
|
||||
// A desktop ES context can technically compile fine with our loader, so we also perform a runtime checks
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
#define IMGUI_IMPL_OPENGL_HAS_EXTENSIONS // has glGetIntegerv(GL_NUM_EXTENSIONS)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE // may have glPolygonMode()
|
||||
#endif
|
||||
|
||||
// Desktop GL 2.1+ and GL ES 3.0+ have glBindBuffer() with GL_PIXEL_UNPACK_BUFFER target.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.1+ has GL_PRIMITIVE_RESTART state
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_1)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_2)
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
#endif
|
||||
|
||||
// Desktop GL 3.3+ and GL ES 3.0+ have glBindSampler()
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && (defined(IMGUI_IMPL_OPENGL_ES3) || defined(GL_VERSION_3_3))
|
||||
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
#endif
|
||||
|
||||
// [Debugging]
|
||||
//#define IMGUI_IMPL_OPENGL_DEBUG
|
||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||
#include <stdio.h>
|
||||
#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check
|
||||
#else
|
||||
#define GL_CALL(_CALL) _CALL // Call without error check
|
||||
#endif
|
||||
|
||||
// OpenGL Data
|
||||
struct ImGui_ImplOpenGL3_Data
|
||||
{
|
||||
GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
|
||||
char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
|
||||
bool GlProfileIsES2;
|
||||
bool GlProfileIsES3;
|
||||
bool GlProfileIsCompat;
|
||||
GLint GlProfileMask;
|
||||
GLuint FontTexture;
|
||||
GLuint ShaderHandle;
|
||||
GLint AttribLocationTex; // Uniforms location
|
||||
GLint AttribLocationProjMtx;
|
||||
GLuint AttribLocationVtxPos; // Vertex attributes location
|
||||
GLuint AttribLocationVtxUV;
|
||||
GLuint AttribLocationVtxColor;
|
||||
unsigned int VboHandle, ElementsHandle;
|
||||
GLsizeiptr VertexBufferSize;
|
||||
GLsizeiptr IndexBufferSize;
|
||||
bool HasPolygonMode;
|
||||
bool HasClipOrigin;
|
||||
bool UseBufferSubData;
|
||||
|
||||
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
|
||||
{
|
||||
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
||||
}
|
||||
|
||||
// Forward Declarations
|
||||
static void ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
static void ImGui_ImplOpenGL3_ShutdownPlatformInterface();
|
||||
|
||||
// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
struct ImGui_ImplOpenGL3_VtxAttribState
|
||||
{
|
||||
GLint Enabled, Size, Type, Normalized, Stride;
|
||||
GLvoid* Ptr;
|
||||
|
||||
void GetState(GLint index)
|
||||
{
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
|
||||
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
|
||||
glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
|
||||
}
|
||||
void SetState(GLint index)
|
||||
{
|
||||
glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
|
||||
if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// Functions
|
||||
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IMGUI_CHECKVERSION();
|
||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||
|
||||
// Initialize our loader
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
if (imgl3wInit() != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
|
||||
io.BackendRendererUserData = (void*)bd;
|
||||
io.BackendRendererName = "imgui_impl_opengl3";
|
||||
|
||||
// Query for GL version (e.g. 320 for GL 3.2)
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
// GLES 2
|
||||
bd->GlVersion = 200;
|
||||
bd->GlProfileIsES2 = true;
|
||||
#else
|
||||
// Desktop or GLES 3
|
||||
const char* gl_version_str = (const char*)glGetString(GL_VERSION);
|
||||
GLint major = 0;
|
||||
GLint minor = 0;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
||||
if (major == 0 && minor == 0)
|
||||
sscanf(gl_version_str, "%d.%d", &major, &minor); // Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
|
||||
#if defined(GL_CONTEXT_PROFILE_MASK)
|
||||
if (bd->GlVersion >= 320)
|
||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask);
|
||||
bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
|
||||
#endif
|
||||
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
bd->GlProfileIsES3 = true;
|
||||
#else
|
||||
if (strncmp(gl_version_str, "OpenGL ES 3", 11) == 0)
|
||||
bd->GlProfileIsES3 = true;
|
||||
#endif
|
||||
|
||||
bd->UseBufferSubData = false;
|
||||
/*
|
||||
// Query vendor to enable glBufferSubData kludge
|
||||
#ifdef _WIN32
|
||||
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
|
||||
if (strncmp(vendor, "Intel", 5) == 0)
|
||||
bd->UseBufferSubData = true;
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_DEBUG
|
||||
printf("GlVersion = %d, \"%s\"\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2 = %d, GlProfileIsES3 = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, gl_version_str, bd->GlProfileIsCompat, bd->GlProfileMask, bd->GlProfileIsES2, bd->GlProfileIsES3, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
if (bd->GlVersion >= 320)
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||
#endif
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
||||
|
||||
// Store GLSL version string so we can refer to it later in case we recreate shaders.
|
||||
// Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure.
|
||||
if (glsl_version == nullptr)
|
||||
{
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
glsl_version = "#version 100";
|
||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
glsl_version = "#version 300 es";
|
||||
#elif defined(__APPLE__)
|
||||
glsl_version = "#version 150";
|
||||
#else
|
||||
glsl_version = "#version 130";
|
||||
#endif
|
||||
}
|
||||
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
|
||||
strcpy(bd->GlslVersionString, glsl_version);
|
||||
strcat(bd->GlslVersionString, "\n");
|
||||
|
||||
// Make an arbitrary GL call (we don't actually need the result)
|
||||
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
|
||||
GLint current_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
||||
|
||||
// Detect extensions we support
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
bd->HasPolygonMode = (!bd->GlProfileIsES2 && !bd->GlProfileIsES3);
|
||||
#endif
|
||||
bd->HasClipOrigin = (bd->GlVersion >= 450);
|
||||
#ifdef IMGUI_IMPL_OPENGL_HAS_EXTENSIONS
|
||||
GLint num_extensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
|
||||
for (GLint i = 0; i < num_extensions; i++)
|
||||
{
|
||||
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
|
||||
bd->HasClipOrigin = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_Shutdown()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui_ImplOpenGL3_ShutdownPlatformInterface();
|
||||
ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||
io.BackendRendererName = nullptr;
|
||||
io.BackendRendererUserData = nullptr;
|
||||
io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports);
|
||||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_NewFrame()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL3_Init()?");
|
||||
|
||||
if (!bd->ShaderHandle)
|
||||
ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
if (bd->GlVersion >= 310)
|
||||
glDisable(GL_PRIMITIVE_RESTART);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
if (bd->HasPolygonMode)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
#endif
|
||||
|
||||
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
|
||||
#if defined(GL_CLIP_ORIGIN)
|
||||
bool clip_origin_lower_left = true;
|
||||
if (bd->HasClipOrigin)
|
||||
{
|
||||
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)¤t_clip_origin);
|
||||
if (current_clip_origin == GL_UPPER_LEFT)
|
||||
clip_origin_lower_left = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup viewport, orthographic projection matrix
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
||||
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
|
||||
float L = draw_data->DisplayPos.x;
|
||||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||
float T = draw_data->DisplayPos.y;
|
||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||
#if defined(GL_CLIP_ORIGIN)
|
||||
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
|
||||
#endif
|
||||
const float ortho_projection[4][4] =
|
||||
{
|
||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
|
||||
};
|
||||
glUseProgram(bd->ShaderHandle);
|
||||
glUniform1i(bd->AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
|
||||
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise.
|
||||
#endif
|
||||
|
||||
(void)vertex_array_object;
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(vertex_array_object);
|
||||
#endif
|
||||
|
||||
// Bind vertex/index buffers and setup attributes for ImDrawVert
|
||||
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle));
|
||||
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxPos));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxUV));
|
||||
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxColor));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, pos)));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, uv)));
|
||||
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)offsetof(ImDrawVert, col)));
|
||||
}
|
||||
|
||||
// OpenGL3 Render function.
|
||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
|
||||
// This is in order to be able to run within an OpenGL engine that doesn't do so.
|
||||
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
||||
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
||||
if (fb_width <= 0 || fb_height <= 0)
|
||||
return;
|
||||
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Backup GL state
|
||||
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
|
||||
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
GLuint last_sampler; if (bd->GlVersion >= 330 || bd->GlProfileIsES3) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
|
||||
#endif
|
||||
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
// This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
|
||||
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_pos; last_vtx_attrib_state_pos.GetState(bd->AttribLocationVtxPos);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_uv; last_vtx_attrib_state_uv.GetState(bd->AttribLocationVtxUV);
|
||||
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_color; last_vtx_attrib_state_color.GetState(bd->AttribLocationVtxColor);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
GLint last_polygon_mode[2]; if (bd->HasPolygonMode) { glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); }
|
||||
#endif
|
||||
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
|
||||
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
|
||||
GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
|
||||
GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
|
||||
GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
|
||||
GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
|
||||
GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
|
||||
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
|
||||
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
||||
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
GLboolean last_enable_primitive_restart = (bd->GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
|
||||
#endif
|
||||
|
||||
// Setup desired GL state
|
||||
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
|
||||
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
|
||||
GLuint vertex_array_object = 0;
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
|
||||
#endif
|
||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
||||
|
||||
// Will project scissor/clipping rectangles into framebuffer space
|
||||
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||||
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
||||
|
||||
// Render command lists
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
|
||||
// Upload vertex/index buffers
|
||||
// - OpenGL drivers are in a very sorry state nowadays....
|
||||
// During 2021 we attempted to switch from glBufferData() to orphaning+glBufferSubData() following reports
|
||||
// of leaks on Intel GPU when using multi-viewports on Windows.
|
||||
// - After this we kept hearing of various display corruptions issues. We started disabling on non-Intel GPU, but issues still got reported on Intel.
|
||||
// - We are now back to using exclusively glBufferData(). So bd->UseBufferSubData IS ALWAYS FALSE in this code.
|
||||
// We are keeping the old code path for a while in case people finding new issues may want to test the bd->UseBufferSubData path.
|
||||
// - See https://github.com/ocornut/imgui/issues/4468 and please report any corruption issues.
|
||||
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
|
||||
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
|
||||
if (bd->UseBufferSubData)
|
||||
{
|
||||
if (bd->VertexBufferSize < vtx_buffer_size)
|
||||
{
|
||||
bd->VertexBufferSize = vtx_buffer_size;
|
||||
GL_CALL(glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||
}
|
||||
if (bd->IndexBufferSize < idx_buffer_size)
|
||||
{
|
||||
bd->IndexBufferSize = idx_buffer_size;
|
||||
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, nullptr, GL_STREAM_DRAW));
|
||||
}
|
||||
GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data));
|
||||
GL_CALL(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data));
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CALL(glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW));
|
||||
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW));
|
||||
}
|
||||
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback != nullptr)
|
||||
{
|
||||
// User callback, registered via ImDrawList::AddCallback()
|
||||
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
||||
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
|
||||
else
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Project scissor/clipping rectangles into framebuffer space
|
||||
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||
continue;
|
||||
|
||||
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
|
||||
GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
|
||||
|
||||
// Bind texture, Draw
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
|
||||
if (bd->GlVersion >= 320)
|
||||
GL_CALL(glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset));
|
||||
else
|
||||
#endif
|
||||
GL_CALL(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the temporary VAO
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GL_CALL(glDeleteVertexArrays(1, &vertex_array_object));
|
||||
#endif
|
||||
|
||||
// Restore modified GL state
|
||||
// This "glIsProgram()" check is required because if the program is "pending deletion" at the time of binding backup, it will have been deleted by now and will cause an OpenGL error. See #6220.
|
||||
if (last_program == 0 || glIsProgram(last_program)) glUseProgram(last_program);
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
|
||||
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
|
||||
glBindSampler(0, last_sampler);
|
||||
#endif
|
||||
glActiveTexture(last_active_texture);
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(last_vertex_array_object);
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
|
||||
last_vtx_attrib_state_pos.SetState(bd->AttribLocationVtxPos);
|
||||
last_vtx_attrib_state_uv.SetState(bd->AttribLocationVtxUV);
|
||||
last_vtx_attrib_state_color.SetState(bd->AttribLocationVtxColor);
|
||||
#endif
|
||||
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
|
||||
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
|
||||
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
|
||||
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
|
||||
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
|
||||
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
|
||||
#endif
|
||||
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons
|
||||
if (bd->HasPolygonMode) { if (bd->GlVersion <= 310 || bd->GlProfileIsCompat) { glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); } else { glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); } }
|
||||
#endif // IMGUI_IMPL_OPENGL_MAY_HAVE_POLYGON_MODE
|
||||
|
||||
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
||||
(void)bd; // Not all compilation paths use this
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateFontsTexture()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Build texture atlas
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
||||
|
||||
// Upload texture to graphics system
|
||||
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
||||
GLint last_texture;
|
||||
GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
|
||||
GL_CALL(glGenTextures(1, &bd->FontTexture));
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, bd->FontTexture));
|
||||
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
|
||||
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
|
||||
#endif
|
||||
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
||||
|
||||
// Restore state
|
||||
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyFontsTexture()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
if (bd->FontTexture)
|
||||
{
|
||||
glDeleteTextures(1, &bd->FontTexture);
|
||||
io.Fonts->SetTexID(0);
|
||||
bd->FontTexture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
|
||||
static bool CheckShader(GLuint handle, const char* desc)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
|
||||
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s! With GLSL: %s\n", desc, bd->GlslVersionString);
|
||||
if (log_length > 1)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetShaderInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
|
||||
static bool CheckProgram(GLuint handle, const char* desc)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
GLint status = 0, log_length = 0;
|
||||
glGetProgramiv(handle, GL_LINK_STATUS, &status);
|
||||
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if ((GLboolean)status == GL_FALSE)
|
||||
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! With GLSL %s\n", desc, bd->GlslVersionString);
|
||||
if (log_length > 1)
|
||||
{
|
||||
ImVector<char> buf;
|
||||
buf.resize((int)(log_length + 1));
|
||||
glGetProgramInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
|
||||
fprintf(stderr, "%s\n", buf.begin());
|
||||
}
|
||||
return (GLboolean)status == GL_TRUE;
|
||||
}
|
||||
|
||||
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
|
||||
// Backup GL state
|
||||
GLint last_texture, last_array_buffer;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
GLint last_pixel_unpack_buffer = 0;
|
||||
if (bd->GlVersion >= 210) { glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &last_pixel_unpack_buffer); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); }
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
GLint last_vertex_array;
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||
#endif
|
||||
|
||||
// Parse GLSL version string
|
||||
int glsl_version = 130;
|
||||
sscanf(bd->GlslVersionString, "#version %d", &glsl_version);
|
||||
|
||||
const GLchar* vertex_shader_glsl_120 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"attribute vec2 Position;\n"
|
||||
"attribute vec2 UV;\n"
|
||||
"attribute vec4 Color;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_130 =
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"in vec2 Position;\n"
|
||||
"in vec2 UV;\n"
|
||||
"in vec4 Color;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_300_es =
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* vertex_shader_glsl_410_core =
|
||||
"layout (location = 0) in vec2 Position;\n"
|
||||
"layout (location = 1) in vec2 UV;\n"
|
||||
"layout (location = 2) in vec4 Color;\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_120 =
|
||||
"#ifdef GL_ES\n"
|
||||
" precision mediump float;\n"
|
||||
"#endif\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"varying vec2 Frag_UV;\n"
|
||||
"varying vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_130 =
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_300_es =
|
||||
"precision mediump float;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader_glsl_410_core =
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"layout (location = 0) out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
// Select shaders matching our GLSL versions
|
||||
const GLchar* vertex_shader = nullptr;
|
||||
const GLchar* fragment_shader = nullptr;
|
||||
if (glsl_version < 130)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_120;
|
||||
fragment_shader = fragment_shader_glsl_120;
|
||||
}
|
||||
else if (glsl_version >= 410)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_410_core;
|
||||
fragment_shader = fragment_shader_glsl_410_core;
|
||||
}
|
||||
else if (glsl_version == 300)
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_300_es;
|
||||
fragment_shader = fragment_shader_glsl_300_es;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertex_shader = vertex_shader_glsl_130;
|
||||
fragment_shader = fragment_shader_glsl_130;
|
||||
}
|
||||
|
||||
// Create shaders
|
||||
const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader };
|
||||
GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vert_handle, 2, vertex_shader_with_version, nullptr);
|
||||
glCompileShader(vert_handle);
|
||||
CheckShader(vert_handle, "vertex shader");
|
||||
|
||||
const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader };
|
||||
GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(frag_handle, 2, fragment_shader_with_version, nullptr);
|
||||
glCompileShader(frag_handle);
|
||||
CheckShader(frag_handle, "fragment shader");
|
||||
|
||||
// Link
|
||||
bd->ShaderHandle = glCreateProgram();
|
||||
glAttachShader(bd->ShaderHandle, vert_handle);
|
||||
glAttachShader(bd->ShaderHandle, frag_handle);
|
||||
glLinkProgram(bd->ShaderHandle);
|
||||
CheckProgram(bd->ShaderHandle, "shader program");
|
||||
|
||||
glDetachShader(bd->ShaderHandle, vert_handle);
|
||||
glDetachShader(bd->ShaderHandle, frag_handle);
|
||||
glDeleteShader(vert_handle);
|
||||
glDeleteShader(frag_handle);
|
||||
|
||||
bd->AttribLocationTex = glGetUniformLocation(bd->ShaderHandle, "Texture");
|
||||
bd->AttribLocationProjMtx = glGetUniformLocation(bd->ShaderHandle, "ProjMtx");
|
||||
bd->AttribLocationVtxPos = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Position");
|
||||
bd->AttribLocationVtxUV = (GLuint)glGetAttribLocation(bd->ShaderHandle, "UV");
|
||||
bd->AttribLocationVtxColor = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Color");
|
||||
|
||||
// Create buffers
|
||||
glGenBuffers(1, &bd->VboHandle);
|
||||
glGenBuffers(1, &bd->ElementsHandle);
|
||||
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
|
||||
// Restore modified GL state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_BUFFER_PIXEL_UNPACK
|
||||
if (bd->GlVersion >= 210) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, last_pixel_unpack_buffer); }
|
||||
#endif
|
||||
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
|
||||
glBindVertexArray(last_vertex_array);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
||||
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
|
||||
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
|
||||
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
|
||||
ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
||||
// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
|
||||
// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void ImGui_ImplOpenGL3_RenderWindow(ImGuiViewport* viewport, void*)
|
||||
{
|
||||
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
||||
{
|
||||
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
ImGui_ImplOpenGL3_RenderDrawData(viewport->DrawData);
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_InitPlatformInterface()
|
||||
{
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
platform_io.Renderer_RenderWindow = ImGui_ImplOpenGL3_RenderWindow;
|
||||
}
|
||||
|
||||
static void ImGui_ImplOpenGL3_ShutdownPlatformInterface()
|
||||
{
|
||||
ImGui::DestroyPlatformWindows();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
67
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3.h
Normal file
67
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
|
||||
// - Desktop GL: 2.x 3.x 4.x
|
||||
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
||||
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||
|
||||
// About WebGL/ES:
|
||||
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
||||
// - This is done automatically on iOS, Android and Emscripten targets.
|
||||
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// About GLSL version:
|
||||
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
|
||||
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
||||
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
// Backend API
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
||||
|
||||
// (Optional) Called by Init/NewFrame/Shutdown
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||
|
||||
// Configuration flags to add in your imconfig file:
|
||||
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
|
||||
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android)
|
||||
|
||||
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
||||
&& !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
|
||||
// Try to detect GLES on matching platforms
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
||||
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
||||
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
|
||||
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||
#else
|
||||
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
922
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3_loader.h
Normal file
922
subprojects/tracy/profiler/src/imgui/imgui_impl_opengl3_loader.h
Normal file
@@ -0,0 +1,922 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// About imgui_impl_opengl3_loader.h:
|
||||
//
|
||||
// We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
|
||||
// which proved to be endless problems for users.
|
||||
// Our loader is custom-generated, based on gl3w but automatically filtered to only include
|
||||
// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
|
||||
// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
|
||||
//
|
||||
// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
|
||||
// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCUDING 'imgui_impl_opengl3_loader.h'
|
||||
// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
|
||||
// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
|
||||
// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
|
||||
// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
|
||||
// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
|
||||
//
|
||||
// Regenerate with:
|
||||
// python3 gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
||||
//
|
||||
// More info:
|
||||
// https://github.com/dearimgui/gl3w_stripped
|
||||
// https://github.com/ocornut/imgui/issues/4445
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* This file was generated with gl3w_gen.py, part of imgl3w
|
||||
* (hosted at https://github.com/dearimgui/gl3w_stripped)
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __gl3w_h_
|
||||
#define __gl3w_h_
|
||||
|
||||
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
||||
#ifndef __khrplatform_h_
|
||||
typedef float khronos_float_t;
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
typedef signed __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
|
||||
#include <stdint.h>
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#else
|
||||
typedef signed long long khronos_int64_t;
|
||||
typedef unsigned long long khronos_uint64_t;
|
||||
#endif
|
||||
#endif // __khrplatform_h_
|
||||
|
||||
#ifndef __gl_glcorearb_h_
|
||||
#define __gl_glcorearb_h_ 1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
** Copyright 2013-2020 The Khronos Group Inc.
|
||||
** SPDX-License-Identifier: MIT
|
||||
**
|
||||
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
||||
** API Registry. The current version of the Registry, generator scripts
|
||||
** used to make the header, and the header can be found at
|
||||
** https://github.com/KhronosGroup/OpenGL-Registry
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY
|
||||
#endif
|
||||
#ifndef APIENTRYP
|
||||
#define APIENTRYP APIENTRY *
|
||||
#endif
|
||||
#ifndef GLAPI
|
||||
#define GLAPI extern
|
||||
#endif
|
||||
/* glcorearb.h is for use with OpenGL core profile implementations.
|
||||
** It should should be placed in the same directory as gl.h and
|
||||
** included as <GL/glcorearb.h>.
|
||||
**
|
||||
** glcorearb.h includes only APIs in the latest OpenGL core profile
|
||||
** implementation together with APIs in newer ARB extensions which
|
||||
** can be supported by the core profile. It does not, and never will
|
||||
** include functionality removed from the core profile, such as
|
||||
** fixed-function vertex and fragment processing.
|
||||
**
|
||||
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
|
||||
** <GL/glext.h> in the same source file.
|
||||
*/
|
||||
/* Generated C header for:
|
||||
* API: gl
|
||||
* Profile: core
|
||||
* Versions considered: .*
|
||||
* Versions emitted: .*
|
||||
* Default extensions included: glcore
|
||||
* Additional extensions included: _nomatch_^
|
||||
* Extensions removed: _nomatch_^
|
||||
*/
|
||||
#ifndef GL_VERSION_1_0
|
||||
typedef void GLvoid;
|
||||
typedef unsigned int GLenum;
|
||||
|
||||
typedef khronos_float_t GLfloat;
|
||||
typedef int GLint;
|
||||
typedef int GLsizei;
|
||||
typedef unsigned int GLbitfield;
|
||||
typedef double GLdouble;
|
||||
typedef unsigned int GLuint;
|
||||
typedef unsigned char GLboolean;
|
||||
typedef khronos_uint8_t GLubyte;
|
||||
#define GL_COLOR_BUFFER_BIT 0x00004000
|
||||
#define GL_FALSE 0
|
||||
#define GL_TRUE 1
|
||||
#define GL_TRIANGLES 0x0004
|
||||
#define GL_ONE 1
|
||||
#define GL_SRC_ALPHA 0x0302
|
||||
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||
#define GL_FRONT 0x0404
|
||||
#define GL_BACK 0x0405
|
||||
#define GL_FRONT_AND_BACK 0x0408
|
||||
#define GL_POLYGON_MODE 0x0B40
|
||||
#define GL_CULL_FACE 0x0B44
|
||||
#define GL_DEPTH_TEST 0x0B71
|
||||
#define GL_STENCIL_TEST 0x0B90
|
||||
#define GL_VIEWPORT 0x0BA2
|
||||
#define GL_BLEND 0x0BE2
|
||||
#define GL_SCISSOR_BOX 0x0C10
|
||||
#define GL_SCISSOR_TEST 0x0C11
|
||||
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||
#define GL_PACK_ALIGNMENT 0x0D05
|
||||
#define GL_TEXTURE_2D 0x0DE1
|
||||
#define GL_UNSIGNED_BYTE 0x1401
|
||||
#define GL_UNSIGNED_SHORT 0x1403
|
||||
#define GL_UNSIGNED_INT 0x1405
|
||||
#define GL_FLOAT 0x1406
|
||||
#define GL_RGBA 0x1908
|
||||
#define GL_FILL 0x1B02
|
||||
#define GL_VENDOR 0x1F00
|
||||
#define GL_RENDERER 0x1F01
|
||||
#define GL_VERSION 0x1F02
|
||||
#define GL_EXTENSIONS 0x1F03
|
||||
#define GL_LINEAR 0x2601
|
||||
#define GL_LINEAR_MIPMAP_LINEAR 0x2703
|
||||
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||
#define GL_TEXTURE_WRAP_S 0x2802
|
||||
#define GL_TEXTURE_WRAP_T 0x2803
|
||||
#define GL_REPEAT 0x2901
|
||||
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
||||
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
|
||||
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
||||
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
|
||||
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
|
||||
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||
GLAPI void APIENTRY glClear (GLbitfield mask);
|
||||
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
GLAPI void APIENTRY glDisable (GLenum cap);
|
||||
GLAPI void APIENTRY glEnable (GLenum cap);
|
||||
GLAPI void APIENTRY glFlush (void);
|
||||
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
|
||||
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||
GLAPI GLenum APIENTRY glGetError (void);
|
||||
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
|
||||
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
|
||||
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
|
||||
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_0 */
|
||||
#ifndef GL_VERSION_1_1
|
||||
typedef khronos_float_t GLclampf;
|
||||
typedef double GLclampd;
|
||||
#define GL_TEXTURE_BINDING_2D 0x8069
|
||||
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
|
||||
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
|
||||
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
|
||||
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_1 */
|
||||
#ifndef GL_VERSION_1_2
|
||||
#define GL_CLAMP_TO_EDGE 0x812F
|
||||
#endif /* GL_VERSION_1_2 */
|
||||
#ifndef GL_VERSION_1_3
|
||||
#define GL_TEXTURE0 0x84C0
|
||||
#define GL_ACTIVE_TEXTURE 0x84E0
|
||||
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
||||
typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
||||
GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_3 */
|
||||
#ifndef GL_VERSION_1_4
|
||||
#define GL_BLEND_DST_RGB 0x80C8
|
||||
#define GL_BLEND_SRC_RGB 0x80C9
|
||||
#define GL_BLEND_DST_ALPHA 0x80CA
|
||||
#define GL_BLEND_SRC_ALPHA 0x80CB
|
||||
#define GL_FUNC_ADD 0x8006
|
||||
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||
GLAPI void APIENTRY glBlendEquation (GLenum mode);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_4 */
|
||||
#ifndef GL_VERSION_1_5
|
||||
typedef khronos_ssize_t GLsizeiptr;
|
||||
typedef khronos_intptr_t GLintptr;
|
||||
#define GL_ARRAY_BUFFER 0x8892
|
||||
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
|
||||
#define GL_ARRAY_BUFFER_BINDING 0x8894
|
||||
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
||||
#define GL_STREAM_DRAW 0x88E0
|
||||
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
|
||||
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
||||
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
||||
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
|
||||
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
|
||||
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
|
||||
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_5 */
|
||||
#ifndef GL_VERSION_2_0
|
||||
typedef char GLchar;
|
||||
typedef khronos_int16_t GLshort;
|
||||
typedef khronos_int8_t GLbyte;
|
||||
typedef khronos_uint16_t GLushort;
|
||||
#define GL_BLEND_EQUATION_RGB 0x8009
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
||||
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
||||
#define GL_FRAGMENT_SHADER 0x8B30
|
||||
#define GL_VERTEX_SHADER 0x8B31
|
||||
#define GL_COMPILE_STATUS 0x8B81
|
||||
#define GL_LINK_STATUS 0x8B82
|
||||
#define GL_INFO_LOG_LENGTH 0x8B84
|
||||
#define GL_CURRENT_PROGRAM 0x8B8D
|
||||
#define GL_UPPER_LEFT 0x8CA2
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
|
||||
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
|
||||
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
|
||||
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
|
||||
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
||||
typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||
typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
|
||||
typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
|
||||
GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
|
||||
GLAPI void APIENTRY glCompileShader (GLuint shader);
|
||||
GLAPI GLuint APIENTRY glCreateProgram (void);
|
||||
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
|
||||
GLAPI void APIENTRY glDeleteProgram (GLuint program);
|
||||
GLAPI void APIENTRY glDeleteShader (GLuint shader);
|
||||
GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
|
||||
GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
|
||||
GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
|
||||
GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
|
||||
GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
|
||||
GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
|
||||
GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
|
||||
GLAPI void APIENTRY glLinkProgram (GLuint program);
|
||||
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||
GLAPI void APIENTRY glUseProgram (GLuint program);
|
||||
GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
|
||||
GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||
GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||
#endif
|
||||
#endif /* GL_VERSION_2_0 */
|
||||
#ifndef GL_VERSION_2_1
|
||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
||||
#endif /* GL_VERSION_2_1 */
|
||||
#ifndef GL_VERSION_3_0
|
||||
typedef khronos_uint16_t GLhalf;
|
||||
#define GL_MAJOR_VERSION 0x821B
|
||||
#define GL_MINOR_VERSION 0x821C
|
||||
#define GL_NUM_EXTENSIONS 0x821D
|
||||
#define GL_FRAMEBUFFER_SRGB 0x8DB9
|
||||
#define GL_VERTEX_ARRAY_BINDING 0x85B5
|
||||
typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
|
||||
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
|
||||
typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
|
||||
typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
|
||||
typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
|
||||
GLAPI void APIENTRY glBindVertexArray (GLuint array);
|
||||
GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
|
||||
GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_0 */
|
||||
#ifndef GL_VERSION_3_1
|
||||
#define GL_VERSION_3_1 1
|
||||
#define GL_PRIMITIVE_RESTART 0x8F9D
|
||||
#endif /* GL_VERSION_3_1 */
|
||||
#ifndef GL_VERSION_3_2
|
||||
#define GL_VERSION_3_2 1
|
||||
typedef struct __GLsync *GLsync;
|
||||
typedef khronos_uint64_t GLuint64;
|
||||
typedef khronos_int64_t GLint64;
|
||||
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
|
||||
#define GL_CONTEXT_PROFILE_MASK 0x9126
|
||||
typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_2 */
|
||||
#ifndef GL_VERSION_3_3
|
||||
#define GL_VERSION_3_3 1
|
||||
#define GL_SAMPLER_BINDING 0x8919
|
||||
typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_3 */
|
||||
#ifndef GL_VERSION_4_1
|
||||
typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
|
||||
typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
|
||||
#endif /* GL_VERSION_4_1 */
|
||||
#ifndef GL_VERSION_4_3
|
||||
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||
#endif /* GL_VERSION_4_3 */
|
||||
#ifndef GL_VERSION_4_5
|
||||
#define GL_CLIP_ORIGIN 0x935C
|
||||
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
|
||||
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
|
||||
#endif /* GL_VERSION_4_5 */
|
||||
#ifndef GL_ARB_bindless_texture
|
||||
typedef khronos_uint64_t GLuint64EXT;
|
||||
#endif /* GL_ARB_bindless_texture */
|
||||
#ifndef GL_ARB_cl_event
|
||||
struct _cl_context;
|
||||
struct _cl_event;
|
||||
#endif /* GL_ARB_cl_event */
|
||||
#ifndef GL_ARB_clip_control
|
||||
#define GL_ARB_clip_control 1
|
||||
#endif /* GL_ARB_clip_control */
|
||||
#ifndef GL_ARB_debug_output
|
||||
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||
#endif /* GL_ARB_debug_output */
|
||||
#ifndef GL_EXT_EGL_image_storage
|
||||
typedef void *GLeglImageOES;
|
||||
#endif /* GL_EXT_EGL_image_storage */
|
||||
#ifndef GL_EXT_direct_state_access
|
||||
typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
|
||||
typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
|
||||
typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
|
||||
#endif /* GL_EXT_direct_state_access */
|
||||
#ifndef GL_NV_draw_vulkan_image
|
||||
typedef void (APIENTRY *GLVULKANPROCNV)(void);
|
||||
#endif /* GL_NV_draw_vulkan_image */
|
||||
#ifndef GL_NV_gpu_shader5
|
||||
typedef khronos_int64_t GLint64EXT;
|
||||
#endif /* GL_NV_gpu_shader5 */
|
||||
#ifndef GL_NV_vertex_buffer_unified_memory
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
|
||||
#endif /* GL_NV_vertex_buffer_unified_memory */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GL3W_API
|
||||
#define GL3W_API
|
||||
#endif
|
||||
|
||||
#ifndef __gl_h_
|
||||
#define __gl_h_
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GL3W_OK 0
|
||||
#define GL3W_ERROR_INIT -1
|
||||
#define GL3W_ERROR_LIBRARY_OPEN -2
|
||||
#define GL3W_ERROR_OPENGL_VERSION -3
|
||||
|
||||
typedef void (*GL3WglProc)(void);
|
||||
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
|
||||
|
||||
/* gl3w api */
|
||||
GL3W_API int imgl3wInit(void);
|
||||
GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
|
||||
GL3W_API int imgl3wIsSupported(int major, int minor);
|
||||
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
|
||||
|
||||
/* gl3w internal state */
|
||||
union ImGL3WProcs {
|
||||
GL3WglProc ptr[60];
|
||||
struct {
|
||||
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||
PFNGLATTACHSHADERPROC AttachShader;
|
||||
PFNGLBINDBUFFERPROC BindBuffer;
|
||||
PFNGLBINDSAMPLERPROC BindSampler;
|
||||
PFNGLBINDTEXTUREPROC BindTexture;
|
||||
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
||||
PFNGLBLENDEQUATIONPROC BlendEquation;
|
||||
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
||||
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||
PFNGLBUFFERDATAPROC BufferData;
|
||||
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
||||
PFNGLCLEARPROC Clear;
|
||||
PFNGLCLEARCOLORPROC ClearColor;
|
||||
PFNGLCOMPILESHADERPROC CompileShader;
|
||||
PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D;
|
||||
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||
PFNGLCREATESHADERPROC CreateShader;
|
||||
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||
PFNGLDELETESHADERPROC DeleteShader;
|
||||
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||
PFNGLDETACHSHADERPROC DetachShader;
|
||||
PFNGLDISABLEPROC Disable;
|
||||
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||
PFNGLDRAWELEMENTSPROC DrawElements;
|
||||
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
||||
PFNGLENABLEPROC Enable;
|
||||
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||
PFNGLFLUSHPROC Flush;
|
||||
PFNGLGENBUFFERSPROC GenBuffers;
|
||||
PFNGLGENTEXTURESPROC GenTextures;
|
||||
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
||||
PFNGLGETERRORPROC GetError;
|
||||
PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
||||
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
||||
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||
PFNGLGETSTRINGPROC GetString;
|
||||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
||||
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
||||
PFNGLISENABLEDPROC IsEnabled;
|
||||
PFNGLISPROGRAMPROC IsProgram;
|
||||
PFNGLLINKPROGRAMPROC LinkProgram;
|
||||
PFNGLPIXELSTOREIPROC PixelStorei;
|
||||
PFNGLPOLYGONMODEPROC PolygonMode;
|
||||
PFNGLREADPIXELSPROC ReadPixels;
|
||||
PFNGLSCISSORPROC Scissor;
|
||||
PFNGLSHADERSOURCEPROC ShaderSource;
|
||||
PFNGLTEXIMAGE2DPROC TexImage2D;
|
||||
PFNGLTEXPARAMETERIPROC TexParameteri;
|
||||
PFNGLUNIFORM1IPROC Uniform1i;
|
||||
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||
PFNGLUSEPROGRAMPROC UseProgram;
|
||||
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
|
||||
PFNGLVIEWPORTPROC Viewport;
|
||||
} gl;
|
||||
};
|
||||
|
||||
GL3W_API extern union ImGL3WProcs imgl3wProcs;
|
||||
|
||||
/* OpenGL functions */
|
||||
#define glActiveTexture imgl3wProcs.gl.ActiveTexture
|
||||
#define glAttachShader imgl3wProcs.gl.AttachShader
|
||||
#define glBindBuffer imgl3wProcs.gl.BindBuffer
|
||||
#define glBindSampler imgl3wProcs.gl.BindSampler
|
||||
#define glBindTexture imgl3wProcs.gl.BindTexture
|
||||
#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
|
||||
#define glBlendEquation imgl3wProcs.gl.BlendEquation
|
||||
#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
|
||||
#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
|
||||
#define glBufferData imgl3wProcs.gl.BufferData
|
||||
#define glBufferSubData imgl3wProcs.gl.BufferSubData
|
||||
#define glClear imgl3wProcs.gl.Clear
|
||||
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||
#define glCompressedTexImage2D imgl3wProcs.gl.CompressedTexImage2D
|
||||
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||
#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
|
||||
#define glDeleteShader imgl3wProcs.gl.DeleteShader
|
||||
#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
|
||||
#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
|
||||
#define glDetachShader imgl3wProcs.gl.DetachShader
|
||||
#define glDisable imgl3wProcs.gl.Disable
|
||||
#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
|
||||
#define glDrawElements imgl3wProcs.gl.DrawElements
|
||||
#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
|
||||
#define glEnable imgl3wProcs.gl.Enable
|
||||
#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
|
||||
#define glFlush imgl3wProcs.gl.Flush
|
||||
#define glGenBuffers imgl3wProcs.gl.GenBuffers
|
||||
#define glGenTextures imgl3wProcs.gl.GenTextures
|
||||
#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
|
||||
#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
|
||||
#define glGetError imgl3wProcs.gl.GetError
|
||||
#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
|
||||
#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
|
||||
#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
|
||||
#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
|
||||
#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
|
||||
#define glGetString imgl3wProcs.gl.GetString
|
||||
#define glGetStringi imgl3wProcs.gl.GetStringi
|
||||
#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
|
||||
#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
|
||||
#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
|
||||
#define glIsEnabled imgl3wProcs.gl.IsEnabled
|
||||
#define glIsProgram imgl3wProcs.gl.IsProgram
|
||||
#define glLinkProgram imgl3wProcs.gl.LinkProgram
|
||||
#define glPixelStorei imgl3wProcs.gl.PixelStorei
|
||||
#define glPolygonMode imgl3wProcs.gl.PolygonMode
|
||||
#define glReadPixels imgl3wProcs.gl.ReadPixels
|
||||
#define glScissor imgl3wProcs.gl.Scissor
|
||||
#define glShaderSource imgl3wProcs.gl.ShaderSource
|
||||
#define glTexImage2D imgl3wProcs.gl.TexImage2D
|
||||
#define glTexParameteri imgl3wProcs.gl.TexParameteri
|
||||
#define glUniform1i imgl3wProcs.gl.Uniform1i
|
||||
#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
|
||||
#define glUseProgram imgl3wProcs.gl.UseProgram
|
||||
#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
|
||||
#define glViewport imgl3wProcs.gl.Viewport
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef IMGL3W_IMPL
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define GL3W_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
static HMODULE libgl;
|
||||
typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
|
||||
static GL3WglGetProcAddr wgl_get_proc_address;
|
||||
|
||||
static int open_libgl(void)
|
||||
{
|
||||
libgl = LoadLibraryA("opengl32.dll");
|
||||
if (!libgl)
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void close_libgl(void) { FreeLibrary(libgl); }
|
||||
static GL3WglProc get_proc(const char *proc)
|
||||
{
|
||||
GL3WglProc res;
|
||||
res = (GL3WglProc)wgl_get_proc_address(proc);
|
||||
if (!res)
|
||||
res = (GL3WglProc)GetProcAddress(libgl, proc);
|
||||
return res;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void *libgl;
|
||||
static int open_libgl(void)
|
||||
{
|
||||
libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void close_libgl(void) { dlclose(libgl); }
|
||||
|
||||
static GL3WglProc get_proc(const char *proc)
|
||||
{
|
||||
GL3WglProc res;
|
||||
*(void **)(&res) = dlsym(libgl, proc);
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void* libgl; // OpenGL library
|
||||
static void* libglx; // GLX library
|
||||
static void* libegl; // EGL library
|
||||
static GL3WGetProcAddressProc gl_get_proc_address;
|
||||
|
||||
static void close_libgl(void)
|
||||
{
|
||||
if (libgl) {
|
||||
dlclose(libgl);
|
||||
libgl = NULL;
|
||||
}
|
||||
if (libegl) {
|
||||
dlclose(libegl);
|
||||
libegl = NULL;
|
||||
}
|
||||
if (libglx) {
|
||||
dlclose(libglx);
|
||||
libglx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int is_library_loaded(const char* name, void** lib)
|
||||
{
|
||||
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
||||
return *lib != NULL;
|
||||
}
|
||||
|
||||
static int open_libs(void)
|
||||
{
|
||||
// On Linux we have two APIs to get process addresses: EGL and GLX.
|
||||
// EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
|
||||
|
||||
libgl = NULL;
|
||||
libegl = NULL;
|
||||
libglx = NULL;
|
||||
|
||||
// First check what's already loaded, the windowing library might have
|
||||
// already loaded either EGL or GLX and we want to use the same one.
|
||||
|
||||
if (is_library_loaded("libEGL.so.1", &libegl) ||
|
||||
is_library_loaded("libGLX.so.0", &libglx)) {
|
||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (libgl)
|
||||
return GL3W_OK;
|
||||
else
|
||||
close_libgl();
|
||||
}
|
||||
|
||||
if (is_library_loaded("libGL.so", &libgl))
|
||||
return GL3W_OK;
|
||||
if (is_library_loaded("libGL.so.1", &libgl))
|
||||
return GL3W_OK;
|
||||
if (is_library_loaded("libGL.so.3", &libgl))
|
||||
return GL3W_OK;
|
||||
|
||||
// Neither is already loaded, so we have to load one. Try EGL first
|
||||
// because it is supported under both X11 and Wayland.
|
||||
|
||||
// Load OpenGL + EGL
|
||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||
libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (libgl && libegl)
|
||||
return GL3W_OK;
|
||||
else
|
||||
close_libgl();
|
||||
|
||||
// Fall back to legacy libGL, which includes GLX
|
||||
// While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
|
||||
libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
|
||||
|
||||
if (libgl)
|
||||
return GL3W_OK;
|
||||
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
}
|
||||
|
||||
static int open_libgl(void)
|
||||
{
|
||||
int res = open_libs();
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (libegl)
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
|
||||
else if (libglx)
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
|
||||
else
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
||||
|
||||
if (!gl_get_proc_address) {
|
||||
close_libgl();
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
}
|
||||
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static GL3WglProc get_proc(const char* proc)
|
||||
{
|
||||
GL3WglProc res = NULL;
|
||||
|
||||
// Before EGL version 1.5, eglGetProcAddress doesn't support querying core
|
||||
// functions and may return a dummy function if we try, so try to load the
|
||||
// function from the GL library directly first.
|
||||
if (libegl)
|
||||
*(void**)(&res) = dlsym(libgl, proc);
|
||||
|
||||
if (!res)
|
||||
res = gl_get_proc_address(proc);
|
||||
|
||||
if (!libegl && !res)
|
||||
*(void**)(&res) = dlsym(libgl, proc);
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct { int major, minor; } version;
|
||||
|
||||
static int parse_version(void)
|
||||
{
|
||||
if (!glGetIntegerv)
|
||||
return GL3W_ERROR_INIT;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
|
||||
if (version.major == 0 && version.minor == 0)
|
||||
{
|
||||
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||
if (const char* gl_version = (const char*)glGetString(GL_VERSION))
|
||||
sscanf(gl_version, "%d.%d", &version.major, &version.minor);
|
||||
}
|
||||
if (version.major < 2)
|
||||
return GL3W_ERROR_OPENGL_VERSION;
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void load_procs(GL3WGetProcAddressProc proc);
|
||||
|
||||
int imgl3wInit(void)
|
||||
{
|
||||
int res = open_libgl();
|
||||
if (res)
|
||||
return res;
|
||||
atexit(close_libgl);
|
||||
return imgl3wInit2(get_proc);
|
||||
}
|
||||
|
||||
int imgl3wInit2(GL3WGetProcAddressProc proc)
|
||||
{
|
||||
load_procs(proc);
|
||||
return parse_version();
|
||||
}
|
||||
|
||||
int imgl3wIsSupported(int major, int minor)
|
||||
{
|
||||
if (major < 2)
|
||||
return 0;
|
||||
if (version.major == major)
|
||||
return version.minor >= minor;
|
||||
return version.major >= major;
|
||||
}
|
||||
|
||||
GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
|
||||
|
||||
static const char *proc_names[] = {
|
||||
"glActiveTexture",
|
||||
"glAttachShader",
|
||||
"glBindBuffer",
|
||||
"glBindSampler",
|
||||
"glBindTexture",
|
||||
"glBindVertexArray",
|
||||
"glBlendEquation",
|
||||
"glBlendEquationSeparate",
|
||||
"glBlendFuncSeparate",
|
||||
"glBufferData",
|
||||
"glBufferSubData",
|
||||
"glClear",
|
||||
"glClearColor",
|
||||
"glCompileShader",
|
||||
"glCompressedTexImage2D",
|
||||
"glCreateProgram",
|
||||
"glCreateShader",
|
||||
"glDeleteBuffers",
|
||||
"glDeleteProgram",
|
||||
"glDeleteShader",
|
||||
"glDeleteTextures",
|
||||
"glDeleteVertexArrays",
|
||||
"glDetachShader",
|
||||
"glDisable",
|
||||
"glDisableVertexAttribArray",
|
||||
"glDrawElements",
|
||||
"glDrawElementsBaseVertex",
|
||||
"glEnable",
|
||||
"glEnableVertexAttribArray",
|
||||
"glFlush",
|
||||
"glGenBuffers",
|
||||
"glGenTextures",
|
||||
"glGenVertexArrays",
|
||||
"glGetAttribLocation",
|
||||
"glGetError",
|
||||
"glGetIntegerv",
|
||||
"glGetProgramInfoLog",
|
||||
"glGetProgramiv",
|
||||
"glGetShaderInfoLog",
|
||||
"glGetShaderiv",
|
||||
"glGetString",
|
||||
"glGetStringi",
|
||||
"glGetUniformLocation",
|
||||
"glGetVertexAttribPointerv",
|
||||
"glGetVertexAttribiv",
|
||||
"glIsEnabled",
|
||||
"glIsProgram",
|
||||
"glLinkProgram",
|
||||
"glPixelStorei",
|
||||
"glPolygonMode",
|
||||
"glReadPixels",
|
||||
"glScissor",
|
||||
"glShaderSource",
|
||||
"glTexImage2D",
|
||||
"glTexParameteri",
|
||||
"glUniform1i",
|
||||
"glUniformMatrix4fv",
|
||||
"glUseProgram",
|
||||
"glVertexAttribPointer",
|
||||
"glViewport",
|
||||
};
|
||||
|
||||
GL3W_API union ImGL3WProcs imgl3wProcs;
|
||||
|
||||
static void load_procs(GL3WGetProcAddressProc proc)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
274
subprojects/tracy/profiler/src/ini.c
Normal file
274
subprojects/tracy/profiler/src/ini.c
Normal file
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* Copyright (c) 2016 rxi
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "ini.h"
|
||||
|
||||
struct ini_t {
|
||||
char *data;
|
||||
char *end;
|
||||
};
|
||||
|
||||
|
||||
/* Case insensitive string compare */
|
||||
static int strcmpci(const char *a, const char *b) {
|
||||
for (;;) {
|
||||
int d = tolower(*a) - tolower(*b);
|
||||
if (d != 0 || !*a) {
|
||||
return d;
|
||||
}
|
||||
a++, b++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the next string in the split data */
|
||||
static char* next(ini_t *ini, char *p) {
|
||||
p += strlen(p);
|
||||
while (p < ini->end && *p == '\0') {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void trim_back(ini_t *ini, char *p) {
|
||||
while (p >= ini->data && (*p == ' ' || *p == '\t' || *p == '\r')) {
|
||||
*p-- = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static char* discard_line(ini_t *ini, char *p) {
|
||||
while (p < ini->end && *p != '\n') {
|
||||
*p++ = '\0';
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static char *unescape_quoted_value(ini_t *ini, char *p) {
|
||||
/* Use `q` as write-head and `p` as read-head, `p` is always ahead of `q`
|
||||
* as escape sequences are always larger than their resultant data */
|
||||
char *q = p;
|
||||
p++;
|
||||
while (p < ini->end && *p != '"' && *p != '\r' && *p != '\n') {
|
||||
if (*p == '\\') {
|
||||
/* Handle escaped char */
|
||||
p++;
|
||||
switch (*p) {
|
||||
default : *q = *p; break;
|
||||
case 'r' : *q = '\r'; break;
|
||||
case 'n' : *q = '\n'; break;
|
||||
case 't' : *q = '\t'; break;
|
||||
case '\r' :
|
||||
case '\n' :
|
||||
case '\0' : goto end;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Handle normal char */
|
||||
*q = *p;
|
||||
}
|
||||
q++, p++;
|
||||
}
|
||||
end:
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
/* Splits data in place into strings containing section-headers, keys and
|
||||
* values using one or more '\0' as a delimiter. Unescapes quoted values */
|
||||
static void split_data(ini_t *ini) {
|
||||
char *value_start, *line_start;
|
||||
char *p = ini->data;
|
||||
|
||||
while (p < ini->end) {
|
||||
switch (*p) {
|
||||
case '\r':
|
||||
case '\n':
|
||||
case '\t':
|
||||
case ' ':
|
||||
*p = '\0';
|
||||
/* Fall through */
|
||||
|
||||
case '\0':
|
||||
p++;
|
||||
break;
|
||||
|
||||
case '[':
|
||||
p += strcspn(p, "]\n");
|
||||
*p = '\0';
|
||||
break;
|
||||
|
||||
case ';':
|
||||
p = discard_line(ini, p);
|
||||
break;
|
||||
|
||||
default:
|
||||
line_start = p;
|
||||
p += strcspn(p, "=\n");
|
||||
|
||||
/* Is line missing a '='? */
|
||||
if (*p != '=') {
|
||||
p = discard_line(ini, line_start);
|
||||
break;
|
||||
}
|
||||
trim_back(ini, p - 1);
|
||||
|
||||
/* Replace '=' and whitespace after it with '\0' */
|
||||
do {
|
||||
*p++ = '\0';
|
||||
} while (*p == ' ' || *p == '\r' || *p == '\t');
|
||||
|
||||
/* Is a value after '=' missing? */
|
||||
if (*p == '\n' || *p == '\0') {
|
||||
p = discard_line(ini, line_start);
|
||||
break;
|
||||
}
|
||||
|
||||
if (*p == '"') {
|
||||
/* Handle quoted string value */
|
||||
value_start = p;
|
||||
p = unescape_quoted_value(ini, p);
|
||||
|
||||
/* Was the string empty? */
|
||||
if (p == value_start) {
|
||||
p = discard_line(ini, line_start);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Discard the rest of the line after the string value */
|
||||
p = discard_line(ini, p);
|
||||
|
||||
} else {
|
||||
/* Handle normal value */
|
||||
p += strcspn(p, "\n");
|
||||
trim_back(ini, p - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ini_t* ini_load(const char *filename) {
|
||||
ini_t *ini = NULL;
|
||||
FILE *fp = NULL;
|
||||
int n, sz;
|
||||
|
||||
/* Init ini struct */
|
||||
ini = malloc(sizeof(*ini));
|
||||
if (!ini) {
|
||||
goto fail;
|
||||
}
|
||||
memset(ini, 0, sizeof(*ini));
|
||||
|
||||
/* Open file */
|
||||
fp = fopen(filename, "rb");
|
||||
if (!fp) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Get file size */
|
||||
fseek(fp, 0, SEEK_END);
|
||||
sz = ftell(fp);
|
||||
rewind(fp);
|
||||
|
||||
/* Load file content into memory, null terminate, init end var */
|
||||
ini->data = malloc(sz + 1);
|
||||
ini->data[sz] = '\0';
|
||||
ini->end = ini->data + sz;
|
||||
n = fread(ini->data, 1, sz, fp);
|
||||
if (n != sz) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Prepare data */
|
||||
split_data(ini);
|
||||
|
||||
/* Clean up and return */
|
||||
fclose(fp);
|
||||
return ini;
|
||||
|
||||
fail:
|
||||
if (fp) fclose(fp);
|
||||
if (ini) ini_free(ini);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ini_free(ini_t *ini) {
|
||||
free(ini->data);
|
||||
free(ini);
|
||||
}
|
||||
|
||||
|
||||
const char* ini_get(ini_t *ini, const char *section, const char *key) {
|
||||
char *current_section = "";
|
||||
char *val;
|
||||
char *p = ini->data;
|
||||
|
||||
if (*p == '\0') {
|
||||
p = next(ini, p);
|
||||
}
|
||||
|
||||
while (p < ini->end) {
|
||||
if (*p == '[') {
|
||||
/* Handle section */
|
||||
current_section = p + 1;
|
||||
|
||||
} else {
|
||||
/* Handle key */
|
||||
val = next(ini, p);
|
||||
if (!section || !strcmpci(section, current_section)) {
|
||||
if (!strcmpci(p, key)) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
p = val;
|
||||
}
|
||||
|
||||
p = next(ini, p);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int ini_sget(
|
||||
ini_t *ini, const char *section, const char *key,
|
||||
const char *scanfmt, void *dst
|
||||
) {
|
||||
const char *val = ini_get(ini, section, key);
|
||||
if (!val) {
|
||||
return 0;
|
||||
}
|
||||
if (scanfmt) {
|
||||
sscanf(val, scanfmt, dst);
|
||||
} else {
|
||||
*((const char**) dst) = val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
28
subprojects/tracy/profiler/src/ini.h
Normal file
28
subprojects/tracy/profiler/src/ini.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2016 rxi
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MIT license. See `ini.c` for details.
|
||||
*/
|
||||
|
||||
#ifndef INI_H
|
||||
#define INI_H
|
||||
|
||||
#define INI_VERSION "0.1.1"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ini_t ini_t;
|
||||
|
||||
ini_t* ini_load(const char *filename);
|
||||
void ini_free(ini_t *ini);
|
||||
const char* ini_get(ini_t *ini, const char *section, const char *key);
|
||||
int ini_sget(ini_t *ini, const char *section, const char *key, const char *scanfmt, void *dst);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1524
subprojects/tracy/profiler/src/main.cpp
Normal file
1524
subprojects/tracy/profiler/src/main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1400
subprojects/tracy/profiler/src/profiler/IconsFontAwesome6.h
Normal file
1400
subprojects/tracy/profiler/src/profiler/IconsFontAwesome6.h
Normal file
File diff suppressed because it is too large
Load Diff
202
subprojects/tracy/profiler/src/profiler/TracyAchievementData.cpp
Normal file
202
subprojects/tracy/profiler/src/profiler/TracyAchievementData.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "TracyAchievements.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracySourceContents.hpp"
|
||||
#include "TracyWeb.hpp"
|
||||
|
||||
namespace tracy::data
|
||||
{
|
||||
|
||||
AchievementItem ai_samplingIntro = { "samplingIntro", "Sampling program execution", [](const ctx& c){
|
||||
ImGui::TextWrapped( "Sampling program execution is a great way to find out where the hot spots are in your program. It can be used to find out which functions take the most time, or which lines of code are executed the most often." );
|
||||
ImGui::TextWrapped( "While instrumentation requires changes to your code, sampling does not. However, because of the way it works, the results are coarser and it's not possible to know when functions are called or when they return." );
|
||||
ImGui::TextWrapped( "Sampling is automatic on Linux. On Windows, you must run the profiled application as an administrator for it to work." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Depending on your system configuration, some additional steps may be required. Please refer to the user manual for more information." );
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
} };
|
||||
|
||||
AchievementItem* ac_samplingItems[] = { &ai_samplingIntro, nullptr };
|
||||
AchievementCategory ac_sampling = { "sampling", "Sampling", ac_samplingItems };
|
||||
|
||||
|
||||
AchievementItem ai_100million = { "100million", "It's over 100 million!", [](const ctx& c){
|
||||
ImGui::TextWrapped( "Tracy can handle a lot of data. How about 100 million zones in a single trace? Add a lot of zones to your program and see how it handles it!" );
|
||||
ImGui::TextWrapped( "Capturing a long-running profile trace is easy. Need to profile an hour of your program execution? You can do it." );
|
||||
ImGui::TextWrapped( "Note that it doesn't make much sense to instrument every little function you might have. The cost of the instrumentation itself will be higher than the cost of the function in such a case." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Keep in mind that the more zones you have, the more memory and CPU time the profiler will use. Be careful not to run out of memory." );
|
||||
ImGui::TextWrapped( "To capture 100 million zones, you will need approximately 4 GB of RAM." );
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
} };
|
||||
|
||||
AchievementItem ai_instrumentationStatistics = { "instrumentationStatistics", "Show me the stats!", [](const ctx&){
|
||||
ImGui::TextWrapped( "Once you have instrumented your application, you can view the statistics for each zone in the timeline. This allows you to see how much time is spent in each zone and how many times it is called." );
|
||||
ImGui::TextWrapped( "To view the statistics, click on the \"" ICON_FA_ARROW_UP_WIDE_SHORT " Statistics\" button on the top bar. This will open a new window with a list of all zones in the trace." );
|
||||
} };
|
||||
|
||||
AchievementItem ai_findZone = { "findZone", "Find some zones", [](const ctx&){
|
||||
ImGui::TextWrapped( "You can search for zones in the trace by opening the search window with the \"" ICON_FA_MAGNIFYING_GLASS " Find zone\" button on the top bar. It will ask you for the zone name, which in most cases will be the function name in the code." );
|
||||
ImGui::TextWrapped( "The search may find more than one zone with the same name. A list of all the zones found is displayed, and you can select any of them." );
|
||||
ImGui::TextWrapped( "Alternatively, you can open the Statistics window and click an entry there. This will open the Find zone window as if you had searched for that zone." );
|
||||
ImGui::TextWrapped( "When a zone is selected, a number of statistics are displayed to help you understand the performance of your application. In addition, a histogram of the zone execution times is displayed to make it easier for you to determine the performance of the profiled code. Be sure to select a zone with a large number of calls to make the histogram look interesting!" );
|
||||
ImGui::TextWrapped( "Note that you can draw a range on the histogram to limit the number of entries displayed in the zone list below. This list allows you to examine each zone individually. There are also a number of zone groupings that you can select. Each group can be selected and the time associated with the selected group will be highlighted on the histogram." );
|
||||
} };
|
||||
|
||||
AchievementItem* ac_instrumentationIntroItems[] = {
|
||||
&ai_100million,
|
||||
&ai_instrumentationStatistics,
|
||||
&ai_findZone,
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_instrumentationIntro = { "instrumentationIntro", "Instrumentating your application", [](const ctx& c){
|
||||
constexpr const char* src = R"(#include "Tracy.hpp"
|
||||
|
||||
void SomeFunction()
|
||||
{
|
||||
ZoneScoped;
|
||||
// Your code here
|
||||
}
|
||||
)";
|
||||
|
||||
static SourceContents sc;
|
||||
sc.Parse( src );
|
||||
|
||||
ImGui::TextWrapped( "Instrumentation is a powerful feature that allows you to see the exact runtime of each call to the selected set of functions. The downside is that it takes a bit of manual work to get it set up." );
|
||||
ImGui::TextWrapped( "To get started, open a source file and include the Tracy.hpp header. This will give you access to a variety of macros provided by Tracy. Next, add the ZoneScoped macro to the beginning of one of your functions, like this:" );
|
||||
ImGui::PushFont( c.fixed );
|
||||
PrintSource( sc.get() );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextWrapped( "Now, when you profile your application, you will see a new zone appear on the timeline for each call to the function. This allows you to see how much time is spent in each call and how many times the function is called." );
|
||||
ImGui::PushFont( c.small );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextWrapped( "Note: The ZoneScoped macro is just one of the many macros provided by Tracy. See the documentation for more information." );
|
||||
ImGui::TextWrapped( "The above description applies to C++ code, but things are done similarly in other programming languages. Refer to the documentation for your language for more information." );
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
}, ac_instrumentationIntroItems };
|
||||
|
||||
AchievementItem ai_frameImages = { "frameImages", "A picture is worth a thousand words", [](const ctx&){
|
||||
ImGui::TextWrapped( "Tracy allows you to add context to each frame, by attaching a screenshot. You can do this with the FrameImage macro." );
|
||||
ImGui::TextWrapped( "You will have to do the screen capture and resizing yourself, which can be a bit complicated. The manual provides a sample code that shows how to do this in a performant way." );
|
||||
ImGui::TextWrapped( "The frame images are displayed in the context of a frame, for example, when you hover over the frame in the timeline or in the frame graph at the top of the screen." );
|
||||
ImGui::TextWrapped( "You can even view a recording of what your application was doing by clicking the " ICON_FA_SCREWDRIVER_WRENCH " icon and then selecting the \"" ICON_FA_PLAY " Playback\" option. Try it out!" );
|
||||
ImGui::TextWrapped( "The FrameImage macro is a great way to see what happened in your application at a particular time. Maybe you have a performance problem that only occurs when a certain object is on the screen?" );
|
||||
} };
|
||||
|
||||
AchievementItem* ac_instrumentFramesItems[] = {
|
||||
&ai_frameImages,
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_instrumentFrames = { "instrumentFrames", "Instrumenting frames", [](const ctx& c){
|
||||
constexpr const char* src = R"(#include "Tracy.hpp"
|
||||
|
||||
void Render()
|
||||
{
|
||||
// Render the frame
|
||||
SwapBuffers();
|
||||
FrameMark;
|
||||
}
|
||||
)";
|
||||
|
||||
static SourceContents sc;
|
||||
sc.Parse( src );
|
||||
|
||||
ImGui::TextWrapped( "In addition to instrumenting functions, you can also instrument frames. This allows you to see how much time is spent in each frame of your application." );
|
||||
ImGui::TextWrapped( "To instrument frames, you need to add the FrameMark macro at the beginning of each frame. This can be done in the main loop of your application, or in a separate function that is called at the beginning of each frame." );
|
||||
ImGui::PushFont( c.fixed );
|
||||
PrintSource( sc.get() );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextWrapped( "When you profile your application, you will see a new frame appear on the timeline each time the FrameMark macro is called. This allows you to see how much time is spent in each frame and how many frames are rendered per second." );
|
||||
ImGui::TextWrapped( "The FrameMark macro is a great way to see at a glance how your application is performing over time. Maybe there are some performance problems that only appear after a few minutes of running the application? A frame graph is drawn at the top of the profiler window where you can see the timing of all frames." );
|
||||
ImGui::TextWrapped( "Note that some applications do not have a frame-based structure, and in such cases, frame instrumentation may not be useful. That's ok." );
|
||||
}, ac_instrumentFramesItems };
|
||||
|
||||
AchievementItem* ac_instrumentationItems[] = { &ai_instrumentationIntro, &ai_instrumentFrames, nullptr };
|
||||
AchievementCategory ac_instrumentation = { "instrumentation", "Instrumentation", ac_instrumentationItems };
|
||||
|
||||
|
||||
AchievementItem ai_loadTrace = { "loadTrace", "Load a trace", [](const ctx&){
|
||||
ImGui::TextWrapped( "You can open a previously saved trace file (or one received from a friend) with the \"" ICON_FA_FOLDER_OPEN " Open saved trace\" button on the welcome screen." );
|
||||
} };
|
||||
|
||||
AchievementItem ai_saveTrace = { "saveTrace", "Save a trace", [](const ctx&){
|
||||
ImGui::TextWrapped( "Now that you have traced your application (or are in the process of doing so), you can save it to disk for future reference. You can do this by clicking on the " ICON_FA_WIFI " icon in the top left corner of the screen and then clicking on the \"" ICON_FA_FLOPPY_DISK " Save trace\" button." );
|
||||
ImGui::TextWrapped( "Keeping old traces on hand can be beneficial, as you can compare the performance of your optimizations with what you had before." );
|
||||
ImGui::TextWrapped( "You can also share the trace with your friends or co-workers by sending them the trace file." );
|
||||
ImGui::Spacing();
|
||||
tracy::TextColoredUnformatted( 0xFF44FFFF, ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( "Warning" );
|
||||
ImGui::SameLine();
|
||||
tracy::TextColoredUnformatted( 0xFF44FFFF, ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::TextWrapped( "Trace files can contain sensitive information about your application, such as program code, or even the contents of source files. Be careful when sharing them with others." );
|
||||
} };
|
||||
|
||||
AchievementItem* ac_connectToServerItems[] = {
|
||||
&ai_saveTrace,
|
||||
&ai_loadTrace,
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem* ac_connectToServerUnlock[] = {
|
||||
&ai_instrumentationIntro,
|
||||
&ai_samplingIntro,
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_connectToServer = { "connectToClient", "First profiling session", [](const ctx&){
|
||||
ImGui::TextWrapped( "Let's start our adventure by instrumenting your application and connecting it to the profiler. Here's a quick refresher:" );
|
||||
ImGui::TextWrapped( " 1. Integrate Tracy Profiler into your application. This can be done using CMake, Meson, or simply by adding the source files to your project." );
|
||||
ImGui::TextWrapped( " 2. Make sure that TracyClient.cpp (or the Tracy library) is included in your build." );
|
||||
ImGui::TextWrapped( " 3. Define TRACY_ENABLE in your build configuration, for the whole application. Do not do it in a single source file because it won't work." );
|
||||
ImGui::TextWrapped( " 4. Start your application, and \"" ICON_FA_WIFI " Connect\" to it with the profiler." );
|
||||
ImGui::TextWrapped( "Please refer to the user manual for more details." );
|
||||
if( ImGui::SmallButton( "Download the user manual" ) )
|
||||
{
|
||||
tracy::OpenWebpage( "https://github.com/wolfpld/tracy/releases" );
|
||||
}
|
||||
}, ac_connectToServerItems, ac_connectToServerUnlock };
|
||||
|
||||
AchievementItem ai_globalSettings = { "globalSettings", "Global settings", [](const ctx&){
|
||||
ImGui::TextWrapped( "Tracy has a variety of settings that can be adjusted to suit your needs. These settings can be found by clicking on the " ICON_FA_WRENCH " icon on the welcome screen. This will open the about window, where you can expand the \"" ICON_FA_TOOLBOX " Global settings\" menu." );
|
||||
ImGui::TextWrapped( "The settings are saved between sessions, so you only need to set them once." );
|
||||
} };
|
||||
|
||||
AchievementItem* ac_achievementsIntroItems[] = {
|
||||
&ai_connectToServer,
|
||||
&ai_globalSettings,
|
||||
nullptr
|
||||
};
|
||||
|
||||
AchievementItem ai_achievementsIntro = { "achievementsIntro", "Click here to discover achievements!", [](const ctx&){
|
||||
ImGui::TextWrapped( "Clicking on the " ICON_FA_STAR " button opens the Achievements List. Here you can see the tasks to be completed along with a short description of what needs to be done." );
|
||||
ImGui::TextWrapped( "As you complete each Achievement, new Achievements will appear, so be sure to keep checking the list for new ones!" );
|
||||
ImGui::TextWrapped( "To make the new things easier to spot, the Achievements List will show a marker next to them. The achievements " ICON_FA_STAR " button will glow yellow when there are new things to see." );
|
||||
ImGui::TextUnformatted( "New tasks:" );
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( 0xFF4488FF, ICON_FA_CIRCLE_EXCLAMATION );
|
||||
ImGui::TextUnformatted( "Completed tasks:" );
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( 0xFF44FF44, ICON_FA_CIRCLE_CHECK );
|
||||
ImGui::TextWrapped( "Good luck!" );
|
||||
}, ac_achievementsIntroItems, nullptr, true, 1 };
|
||||
|
||||
AchievementItem* ac_firstStepsItems[] = { &ai_achievementsIntro, nullptr };
|
||||
AchievementCategory ac_firstSteps = { "firstSteps", "First steps", ac_firstStepsItems, 1 };
|
||||
|
||||
|
||||
AchievementCategory* AchievementCategories[] = {
|
||||
&ac_firstSteps,
|
||||
&ac_instrumentation,
|
||||
&ac_sampling,
|
||||
nullptr
|
||||
};
|
||||
|
||||
}
|
||||
225
subprojects/tracy/profiler/src/profiler/TracyAchievements.cpp
Normal file
225
subprojects/tracy/profiler/src/profiler/TracyAchievements.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../ini.h"
|
||||
|
||||
#include "TracyAchievements.hpp"
|
||||
#include "TracyStorage.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
namespace data { extern AchievementCategory* AchievementCategories[]; }
|
||||
|
||||
AchievementsMgr::AchievementsMgr()
|
||||
{
|
||||
auto cat = data::AchievementCategories;
|
||||
while( *cat )
|
||||
{
|
||||
FillMap( (*cat)->items, *cat );
|
||||
cat++;
|
||||
}
|
||||
|
||||
const auto fn = tracy::GetSavePath( "achievements.ini" );
|
||||
auto ini = ini_load( fn );
|
||||
if( !ini ) return;
|
||||
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
uint64_t unlockTime, doneTime;
|
||||
int hideCompleted, hideNew;
|
||||
|
||||
if( ini_sget( ini, v.first, "unlockTime", "%" PRIu64, &unlockTime ) &&
|
||||
ini_sget( ini, v.first, "doneTime", "%" PRIu64, &doneTime ) &&
|
||||
ini_sget( ini, v.first, "hideCompleted", "%d", &hideCompleted ) &&
|
||||
ini_sget( ini, v.first, "hideNew", "%d", &hideNew ) )
|
||||
{
|
||||
auto& it = v.second.item;
|
||||
it->unlockTime = unlockTime;
|
||||
it->doneTime = doneTime;
|
||||
it->hideCompleted = hideCompleted != 0;
|
||||
it->hideNew = hideNew != 0;
|
||||
}
|
||||
}
|
||||
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
auto& it = v.second.item;
|
||||
if( it->doneTime > 0 )
|
||||
{
|
||||
auto c = it->items;
|
||||
if( c )
|
||||
{
|
||||
while( *c )
|
||||
{
|
||||
if( (*c)->unlockTime == 0 ) (*c)->unlockTime = it->doneTime;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c = it->unlocks;
|
||||
if( c )
|
||||
{
|
||||
while( *c )
|
||||
{
|
||||
if( (*c)->unlockTime == 0 ) (*c)->unlockTime = it->doneTime;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
if( v.second.category->unlockTime == 0 && v.second.item->unlockTime > 0 )
|
||||
{
|
||||
v.second.category->unlockTime = v.second.item->unlockTime;
|
||||
}
|
||||
}
|
||||
|
||||
auto c = data::AchievementCategories;
|
||||
while( *c )
|
||||
{
|
||||
if( (*c)->unlockTime > 0 )
|
||||
{
|
||||
auto items = (*c)->items;
|
||||
while( *items )
|
||||
{
|
||||
if( (*items)->unlockTime == 0 ) (*items)->unlockTime = (*c)->unlockTime;
|
||||
items++;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
ini_free( ini );
|
||||
}
|
||||
|
||||
AchievementsMgr::~AchievementsMgr()
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
void AchievementsMgr::Achieve( const char* id )
|
||||
{
|
||||
auto it = m_map.find( id );
|
||||
assert( it != m_map.end() );
|
||||
auto& a = *it->second.item;
|
||||
|
||||
if( a.unlockTime == 0 ) return;
|
||||
if( a.doneTime > 0 ) return;
|
||||
|
||||
const auto t = uint64_t( time( nullptr ) );
|
||||
|
||||
a.doneTime = uint64_t( t );
|
||||
m_queue.push_back( &a );
|
||||
|
||||
auto c = a.items;
|
||||
if( c )
|
||||
{
|
||||
while( *c ) (*c++)->unlockTime = t;
|
||||
}
|
||||
c = a.unlocks;
|
||||
if( c )
|
||||
{
|
||||
while( *c )
|
||||
{
|
||||
(*c)->unlockTime = t;
|
||||
auto cit = m_map.find( (*c)->id );
|
||||
if( cit->second.category->unlockTime == 0 ) cit->second.category->unlockTime = t;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
data::AchievementCategory** AchievementsMgr::GetCategories() const
|
||||
{
|
||||
return data::AchievementCategories;
|
||||
}
|
||||
|
||||
data::AchievementCategory* AchievementsMgr::GetCategoryForAchievement( const char* id ) const
|
||||
{
|
||||
auto it = m_map.find( id );
|
||||
assert( it != m_map.end() );
|
||||
return it->second.category;
|
||||
}
|
||||
|
||||
data::AchievementItem* AchievementsMgr::GetNextQueue()
|
||||
{
|
||||
if( m_queue.empty() ) return nullptr;
|
||||
return m_queue.front();
|
||||
}
|
||||
|
||||
void AchievementsMgr::PopQueue()
|
||||
{
|
||||
assert( !m_queue.empty() );
|
||||
m_queue.erase( m_queue.begin() );
|
||||
}
|
||||
|
||||
bool AchievementsMgr::NeedsAttention() const
|
||||
{
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
auto& it = v.second.item;
|
||||
if( it->unlockTime > 0 && !it->hideNew ) return true;
|
||||
if( it->doneTime > 0 && !it->hideCompleted ) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AchievementsMgr::CategoryNeedsAttention( const char* id ) const
|
||||
{
|
||||
auto c = data::AchievementCategories;
|
||||
while( *c )
|
||||
{
|
||||
if( strcmp( (*c)->id, id ) == 0 )
|
||||
{
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
if( v.second.category == (*c) )
|
||||
{
|
||||
auto& it = v.second.item;
|
||||
if( it->unlockTime > 0 && !it->hideNew ) return true;
|
||||
if( it->doneTime > 0 && !it->hideCompleted ) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
assert( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
void AchievementsMgr::FillMap( data::AchievementItem** items, data::AchievementCategory* category )
|
||||
{
|
||||
while( *items )
|
||||
{
|
||||
m_map.emplace( (*items)->id, AchievementPair { *items, category } );
|
||||
if( (*items)->items) FillMap( (*items)->items, category );
|
||||
items++;
|
||||
}
|
||||
}
|
||||
|
||||
void AchievementsMgr::Save()
|
||||
{
|
||||
const auto fn = tracy::GetSavePath( "achievements.ini" );
|
||||
FILE* f = fopen( fn, "wb" );
|
||||
if( !f ) return;
|
||||
|
||||
for( auto& v : m_map )
|
||||
{
|
||||
auto& it = v.second.item;
|
||||
fprintf( f, "[%s]\n", it->id );
|
||||
fprintf( f, "unlockTime=%" PRIu64 "\n", it->unlockTime );
|
||||
fprintf( f, "doneTime=%" PRIu64 "\n", it->doneTime );
|
||||
fprintf( f, "hideCompleted=%d\n", it->hideCompleted ? 1 : 0 );
|
||||
fprintf( f, "hideNew=%d\n\n", it->hideNew ? 1 : 0 );
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef __TRACYACHIEVEMENTS_HPP__
|
||||
#define __TRACYACHIEVEMENTS_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "TracyCharUtil.hpp"
|
||||
#include "tracy_robin_hood.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
namespace data
|
||||
{
|
||||
|
||||
struct ctx
|
||||
{
|
||||
ImFont* big;
|
||||
ImFont* small;
|
||||
ImFont* fixed;
|
||||
};
|
||||
|
||||
struct AchievementItem
|
||||
{
|
||||
const char* id;
|
||||
const char* name;
|
||||
void(*description)(const ctx&);
|
||||
AchievementItem** items;
|
||||
AchievementItem** unlocks;
|
||||
bool keepOpen;
|
||||
uint64_t unlockTime;
|
||||
uint64_t doneTime;
|
||||
bool hideCompleted;
|
||||
bool hideNew;
|
||||
};
|
||||
|
||||
struct AchievementCategory
|
||||
{
|
||||
const char* id;
|
||||
const char* name;
|
||||
AchievementItem** items;
|
||||
uint64_t unlockTime;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class AchievementsMgr
|
||||
{
|
||||
struct AchievementPair
|
||||
{
|
||||
data::AchievementItem* item;
|
||||
data::AchievementCategory* category;
|
||||
};
|
||||
|
||||
public:
|
||||
AchievementsMgr();
|
||||
~AchievementsMgr();
|
||||
|
||||
void Achieve( const char* id );
|
||||
data::AchievementCategory** GetCategories() const;
|
||||
data::AchievementCategory* GetCategoryForAchievement( const char* id ) const;
|
||||
|
||||
data::AchievementItem* GetNextQueue();
|
||||
void PopQueue();
|
||||
|
||||
bool NeedsAttention() const;
|
||||
bool CategoryNeedsAttention( const char* id ) const;
|
||||
|
||||
private:
|
||||
void FillMap( data::AchievementItem** items, data::AchievementCategory* category );
|
||||
void Save();
|
||||
|
||||
std::vector<data::AchievementItem*> m_queue;
|
||||
tracy::unordered_flat_map<const char*, AchievementPair, charutil::Hasher, charutil::Comparator> m_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
124
subprojects/tracy/profiler/src/profiler/TracyBadVersion.cpp
Normal file
124
subprojects/tracy/profiler/src/profiler/TracyBadVersion.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "TracyBadVersion.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyWeb.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
void BadVersionImpl( BadVersionState& badVer, ImFont* big )
|
||||
{
|
||||
assert( badVer.state != BadVersionState::Ok );
|
||||
|
||||
switch( badVer.state )
|
||||
{
|
||||
case BadVersionState::BadFile:
|
||||
ImGui::OpenPopup( "Bad file" );
|
||||
break;
|
||||
case BadVersionState::ReadError:
|
||||
ImGui::OpenPopup( "File read error" );
|
||||
break;
|
||||
case BadVersionState::UnsupportedVersion:
|
||||
ImGui::OpenPopup( "Unsupported file version" );
|
||||
break;
|
||||
case BadVersionState::LegacyVersion:
|
||||
ImGui::OpenPopup( "Legacy file version" );
|
||||
break;
|
||||
case BadVersionState::LoadFailure:
|
||||
ImGui::OpenPopup( "Trace load failure" );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Bad file", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open is not a Tracy dump." );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "Oops" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "File read error", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open cannot be mapped to memory." );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "OK" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Unsupported file version", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
TextCentered( ICON_FA_CLOUD_ARROW_DOWN );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "The file you are trying to open is unsupported.\nYou should update to Tracy %i.%i.%i or newer and try again.", badVer.version >> 16, ( badVer.version >> 8 ) & 0xFF, badVer.version & 0xFF );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( ICON_FA_DOWNLOAD " Download update" ) )
|
||||
{
|
||||
tracy::OpenWebpage( "https://github.com/wolfpld/tracy/releases" );
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( "Maybe later" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Legacy file version", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
TextCentered( ICON_FA_GHOST );
|
||||
ImGui::PopFont();
|
||||
ImGui::Text( "You are trying to open a file which was created by legacy version %i.%i.%i.\nUse the update utility from an older version of the profiler to convert the file to a supported version.", badVer.version >> 16, ( badVer.version >> 8 ) & 0xFF, badVer.version & 0xFF );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "Maybe I don't need it" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Trace load failure", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( big );
|
||||
TextCentered( ICON_FA_BOMB );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextUnformatted( "The file you are trying to open is corrupted." );
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted( badVer.msg.c_str() );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "OK" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
badVer.state = BadVersionState::Ok;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
39
subprojects/tracy/profiler/src/profiler/TracyBadVersion.hpp
Normal file
39
subprojects/tracy/profiler/src/profiler/TracyBadVersion.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __TRACYBADVERSION_HPP__
|
||||
#define __TRACYBADVERSION_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
struct ImFont;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct BadVersionState
|
||||
{
|
||||
enum State
|
||||
{
|
||||
Ok,
|
||||
BadFile,
|
||||
ReadError,
|
||||
UnsupportedVersion,
|
||||
LegacyVersion,
|
||||
LoadFailure
|
||||
};
|
||||
|
||||
State state = Ok;
|
||||
int version = 0;
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void BadVersionImpl( BadVersionState& badVer, ImFont* big );
|
||||
}
|
||||
|
||||
tracy_force_inline void BadVersion( BadVersionState& badVer, ImFont* big ) { if( badVer.state != BadVersionState::Ok ) detail::BadVersionImpl( badVer, big ); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
50
subprojects/tracy/profiler/src/profiler/TracyBuzzAnim.hpp
Normal file
50
subprojects/tracy/profiler/src/profiler/TracyBuzzAnim.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef __TRACYBUZZANIM_HPP__
|
||||
#define __TRACYBUZZANIM_HPP__
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class BuzzAnim
|
||||
{
|
||||
public:
|
||||
bool Match( const T& comp ) const
|
||||
{
|
||||
return active && comp == id;
|
||||
}
|
||||
|
||||
float Time() const
|
||||
{
|
||||
assert( active );
|
||||
return time;
|
||||
}
|
||||
|
||||
void Enable( const T& val, float len )
|
||||
{
|
||||
active = true;
|
||||
time = len;
|
||||
id = val;
|
||||
}
|
||||
|
||||
bool Update( float dt )
|
||||
{
|
||||
if( active )
|
||||
{
|
||||
time -= dt;
|
||||
if( time <= 0 ) active = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool active = false;
|
||||
float time;
|
||||
T id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
36
subprojects/tracy/profiler/src/profiler/TracyColor.cpp
Normal file
36
subprojects/tracy/profiler/src/profiler/TracyColor.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "TracyColor.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
uint32_t GetHsvColor( uint64_t hue, int value )
|
||||
{
|
||||
const uint8_t h = ( hue * 11400714819323198485ull ) & 0xFF;
|
||||
const uint8_t s = 108;
|
||||
const uint8_t v = std::max( 96, 170 - value * 8 );
|
||||
|
||||
const uint8_t reg = h / 43;
|
||||
const uint8_t rem = ( h - ( reg * 43 ) ) * 6;
|
||||
|
||||
const uint8_t p = ( v * ( 255 - s ) ) >> 8;
|
||||
const uint8_t q = ( v * ( 255 - ( ( s * rem ) >> 8 ) ) ) >> 8;
|
||||
const uint8_t t = ( v * ( 255 - ( ( s * ( 255 - rem ) ) >> 8 ) ) ) >> 8;
|
||||
|
||||
uint8_t r, g, b;
|
||||
|
||||
switch( reg )
|
||||
{
|
||||
case 0: r = v; g = t; b = p; break;
|
||||
case 1: r = q; g = v; b = p; break;
|
||||
case 2: r = p; g = v; b = t; break;
|
||||
case 3: r = p; g = q; b = v; break;
|
||||
case 4: r = t; g = p; b = v; break;
|
||||
default: r = v; g = p; b = q; break;
|
||||
}
|
||||
|
||||
return 0xFF000000 | ( r << 16 ) | ( g << 8 ) | b;
|
||||
}
|
||||
|
||||
}
|
||||
41
subprojects/tracy/profiler/src/profiler/TracyColor.hpp
Normal file
41
subprojects/tracy/profiler/src/profiler/TracyColor.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef __TRACYCOLOR_HPP__
|
||||
#define __TRACYCOLOR_HPP__
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
uint32_t GetHsvColor( uint64_t hue, int value );
|
||||
|
||||
template<int V = 25>
|
||||
static tracy_force_inline uint32_t HighlightColor( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
( std::min<int>( 0xFF, ( ( ( color & 0x00FF0000 ) >> 16 ) + V ) ) << 16 ) |
|
||||
( std::min<int>( 0xFF, ( ( ( color & 0x0000FF00 ) >> 8 ) + V ) ) << 8 ) |
|
||||
( std::min<int>( 0xFF, ( ( ( color & 0x000000FF ) ) + V ) ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColor( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
( ( ( ( color & 0x00FF0000 ) >> 16 ) * 2 / 3 ) << 16 ) |
|
||||
( ( ( ( color & 0x0000FF00 ) >> 8 ) * 2 / 3 ) << 8 ) |
|
||||
( ( ( ( color & 0x000000FF ) ) * 2 / 3 ) );
|
||||
}
|
||||
|
||||
static tracy_force_inline uint32_t DarkenColorMore( uint32_t color )
|
||||
{
|
||||
return 0xFF000000 |
|
||||
( ( ( ( color & 0x00FF0000 ) >> 16 ) * 1 / 4 ) << 16 ) |
|
||||
( ( ( ( color & 0x0000FF00 ) >> 8 ) * 1 / 4 ) << 8 ) |
|
||||
( ( ( ( color & 0x000000FF ) ) * 1 / 4 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
25
subprojects/tracy/profiler/src/profiler/TracyConfig.hpp
Normal file
25
subprojects/tracy/profiler/src/profiler/TracyConfig.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __TRACYCONFIG_HPP__
|
||||
#define __TRACYCONFIG_HPP__
|
||||
|
||||
#include "TracyUtility.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct Config
|
||||
{
|
||||
bool threadedRendering = true;
|
||||
bool focusLostLimit = true;
|
||||
int targetFps = 60;
|
||||
bool memoryLimit = false;
|
||||
int memoryLimitPercent = 80;
|
||||
bool achievements = false;
|
||||
bool achievementsAsked = false;
|
||||
int dynamicColors = 1;
|
||||
bool forceColors = false;
|
||||
int shortenName = (int)ShortenName::NoSpaceAndNormalize;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
48
subprojects/tracy/profiler/src/profiler/TracyDecayValue.hpp
Normal file
48
subprojects/tracy/profiler/src/profiler/TracyDecayValue.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef __TRACYDECAYVALUE_HPP__
|
||||
#define __TRACYDECAYVALUE_HPP__
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class DecayValue
|
||||
{
|
||||
public:
|
||||
DecayValue( const T& init, bool active = false )
|
||||
: m_value( init )
|
||||
, m_active( active )
|
||||
{
|
||||
}
|
||||
|
||||
tracy_force_inline operator const T& () const { return m_value; }
|
||||
tracy_force_inline T operator->() const { return m_value; }
|
||||
|
||||
tracy_force_inline DecayValue& operator=( const T& value )
|
||||
{
|
||||
m_value = value;
|
||||
m_active = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tracy_force_inline void Decay( const T& value )
|
||||
{
|
||||
if( m_active )
|
||||
{
|
||||
m_active = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T m_value;
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
361
subprojects/tracy/profiler/src/profiler/TracyEventDebug.cpp
Normal file
361
subprojects/tracy/profiler/src/profiler/TracyEventDebug.cpp
Normal file
@@ -0,0 +1,361 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "TracyEventDebug.hpp"
|
||||
#include "../public/common/TracyQueue.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
void EventDebug( const QueueItem& ev )
|
||||
{
|
||||
static FILE* f = fopen( "eventdebug.txt", "wb" );
|
||||
switch( ev.hdr.type )
|
||||
{
|
||||
case QueueType::ZoneText:
|
||||
fprintf( f, "ev %i (ZoneText)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneName:
|
||||
fprintf( f, "ev %i (ZoneName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::Message:
|
||||
fprintf( f, "ev %i (Message)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageColor:
|
||||
fprintf( f, "ev %i (MessageColor)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageCallstack:
|
||||
fprintf( f, "ev %i (MessageCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageColorCallstack:
|
||||
fprintf( f, "ev %i (MessageColorCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageAppInfo:
|
||||
fprintf( f, "ev %i (MessageAppInfo)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneBeginAllocSrcLoc:
|
||||
fprintf( f, "ev %i (ZoneBeginAllocSrcLoc)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneBeginAllocSrcLocCallstack:
|
||||
fprintf( f, "ev %i (ZoneBeginAllocSrcLocCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackSerial:
|
||||
fprintf( f, "ev %i (CallstackSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::Callstack:
|
||||
fprintf( f, "ev %i (Callstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackAlloc:
|
||||
fprintf( f, "ev %i (CallstackAlloc)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackSample:
|
||||
fprintf( f, "ev %i (CallstackSample)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackSampleContextSwitch:
|
||||
fprintf( f, "ev %i (CallstackSampleContextSwitch)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameImage:
|
||||
fprintf( f, "ev %i (FrameImage)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneBegin:
|
||||
fprintf( f, "ev %i (ZoneBegin)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.zoneBeginLean.time );
|
||||
break;
|
||||
case QueueType::ZoneBeginCallstack:
|
||||
fprintf( f, "ev %i (ZoneBeginCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneEnd:
|
||||
fprintf( f, "ev %i (ZoneEnd)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.zoneEnd.time );
|
||||
break;
|
||||
case QueueType::LockWait:
|
||||
fprintf( f, "ev %i (LockWait)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockObtain:
|
||||
fprintf( f, "ev %i (LockObtain)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockRelease:
|
||||
fprintf( f, "ev %i (LockRelease)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockSharedWait:
|
||||
fprintf( f, "ev %i (LockSharedWait)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockSharedObtain:
|
||||
fprintf( f, "ev %i (LockSharedObtain)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockSharedRelease:
|
||||
fprintf( f, "ev %i (LockSharedRelease)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockName:
|
||||
fprintf( f, "ev %i (LockName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemAlloc:
|
||||
fprintf( f, "ev %i (MemAlloc)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemAllocNamed:
|
||||
fprintf( f, "ev %i (MemAllocNamed)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemFree:
|
||||
fprintf( f, "ev %i (MemFree)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemFreeNamed:
|
||||
fprintf( f, "ev %i (MemFreeNamed)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemAllocCallstack:
|
||||
fprintf( f, "ev %i (MemAllocCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemAllocCallstackNamed:
|
||||
fprintf( f, "ev %i (MemAllocCallstackNamed)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemFreeCallstack:
|
||||
fprintf( f, "ev %i (MemFreeCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemFreeCallstackNamed:
|
||||
fprintf( f, "ev %i (MemFreeCallstackNamed)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBegin:
|
||||
fprintf( f, "ev %i (GpuZoneBegin)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginCallstack:
|
||||
fprintf( f, "ev %i (GpuZoneBeginCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginAllocSrcLoc:
|
||||
fprintf( f, "ev %i (GpuZoneBeginAllocSrcLoc)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginAllocSrcLocCallstack:
|
||||
fprintf( f, "ev %i (GpuZoneBeginAllocSrcLocCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneEnd:
|
||||
fprintf( f, "ev %i (GpuZoneEnd)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginSerial:
|
||||
fprintf( f, "ev %i (GpuZoneBeginSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginCallstackSerial:
|
||||
fprintf( f, "ev %i (GpuZoneBeginCallstackSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginAllocSrcLocSerial:
|
||||
fprintf( f, "ev %i (GpuZoneBeginAllocSrcLocSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneBeginAllocSrcLocCallstackSerial:
|
||||
fprintf( f, "ev %i (GpuZoneBeginAllocSrcLocCallstackSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuZoneEndSerial:
|
||||
fprintf( f, "ev %i (GpuZoneEndSerial)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::PlotDataInt:
|
||||
fprintf( f, "ev %i (PlotDataInt)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::PlotDataFloat:
|
||||
fprintf( f, "ev %i (PlotDataFloat)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::PlotDataDouble:
|
||||
fprintf( f, "ev %i (PlotDataDouble)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ContextSwitch:
|
||||
fprintf( f, "ev %i (ContextSwitch)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.contextSwitch.time );
|
||||
fprintf( f, "\tthread = %" PRIu32 " -> %" PRIu32 "\n", ev.contextSwitch.oldThread, ev.contextSwitch.newThread );
|
||||
fprintf( f, "\tcpu = %" PRIu8 ", reason = %" PRIu8 ", state = %" PRIu8 "\n", ev.contextSwitch.cpu, ev.contextSwitch.reason, ev.contextSwitch.state );
|
||||
break;
|
||||
case QueueType::ThreadWakeup:
|
||||
fprintf( f, "ev %i (ThreadWakeup)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuTime:
|
||||
fprintf( f, "ev %i (GpuTime)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuContextName:
|
||||
fprintf( f, "ev %i (GpuContextName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackFrameSize:
|
||||
fprintf( f, "ev %i (CallstackFrameSize)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SymbolInformation:
|
||||
fprintf( f, "ev %i (SymbolInformation)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FiberEnter:
|
||||
fprintf( f, "ev %i (FiberEnter)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.fiberEnter.time );
|
||||
fprintf( f, "\tfiber = %" PRIu64 "\n", ev.fiberEnter.fiber );
|
||||
fprintf( f, "\tthread = %" PRIu32 "\n", ev.fiberEnter.thread );
|
||||
break;
|
||||
case QueueType::FiberLeave:
|
||||
fprintf( f, "ev %i (FiberLeave)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.fiberLeave.time );
|
||||
fprintf( f, "\tthread = %" PRIu32 "\n", ev.fiberLeave.thread );
|
||||
break;
|
||||
case QueueType::Terminate:
|
||||
fprintf( f, "ev %i (Terminate)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::KeepAlive:
|
||||
fprintf( f, "ev %i (KeepAlive)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ThreadContext:
|
||||
fprintf( f, "ev %i (ThreadContext)\n", ev.hdr.idx );
|
||||
fprintf( f, "\tthread = %" PRIu32 "\n", ev.threadCtx.thread );
|
||||
break;
|
||||
case QueueType::GpuCalibration:
|
||||
fprintf( f, "ev %i (GpuCalibration)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuTimeSync:
|
||||
fprintf( f, "ev %i (GpuTimeSync)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::Crash:
|
||||
fprintf( f, "ev %i (Crash)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CrashReport:
|
||||
fprintf( f, "ev %i (CrashReport)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneValidation:
|
||||
fprintf( f, "ev %i (ZoneValidation)\n", ev.hdr.idx );
|
||||
fprintf( f, "\tid = %" PRIu32 "\n", ev.zoneValidation.id );
|
||||
break;
|
||||
case QueueType::ZoneColor:
|
||||
fprintf( f, "ev %i (ZoneColor)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ZoneValue:
|
||||
fprintf( f, "ev %i (ZoneValue)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameMarkMsg:
|
||||
fprintf( f, "ev %i (FrameMarkMsg)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameMarkMsgStart:
|
||||
fprintf( f, "ev %i (FrameMarkMsgStart)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameMarkMsgEnd:
|
||||
fprintf( f, "ev %i (FrameMarkMsgEnd)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SourceLocation:
|
||||
fprintf( f, "ev %i (SourceLocation)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockAnnounce:
|
||||
fprintf( f, "ev %i (LockAnnounce)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockTerminate:
|
||||
fprintf( f, "ev %i (LockTerminate)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::LockMark:
|
||||
fprintf( f, "ev %i (LockMark)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageLiteral:
|
||||
fprintf( f, "ev %i (MessageLiteral)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageLiteralColor:
|
||||
fprintf( f, "ev %i (MessageLiteralColor)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageLiteralCallstack:
|
||||
fprintf( f, "ev %i (MessageLiteralCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MessageLiteralColorCallstack:
|
||||
fprintf( f, "ev %i (MessageLiteralColorCallstack)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::GpuNewContext:
|
||||
fprintf( f, "ev %i (GpuNewContext)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackFrame:
|
||||
fprintf( f, "ev %i (CallstackFrame)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SysTimeReport:
|
||||
fprintf( f, "ev %i (SysTimeReport)\n", ev.hdr.idx );
|
||||
fprintf( f, "\ttime = %" PRIi64 "\n", ev.sysTime.time );
|
||||
fprintf( f, "\tsysTime = %f\n", ev.sysTime.sysTime );
|
||||
break;
|
||||
case QueueType::TidToPid:
|
||||
fprintf( f, "ev %i (TidToPid)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleCpuCycle:
|
||||
fprintf( f, "ev %i (HwSampleCpuCycle)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleInstructionRetired:
|
||||
fprintf( f, "ev %i (HwSampleInstructionRetired)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleCacheReference:
|
||||
fprintf( f, "ev %i (HwSampleCacheReference)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleCacheMiss:
|
||||
fprintf( f, "ev %i (HwSampleCacheMiss)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleBranchRetired:
|
||||
fprintf( f, "ev %i (HwSampleBranchRetired)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::HwSampleBranchMiss:
|
||||
fprintf( f, "ev %i (HwSampleBranchMiss)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::PlotConfig:
|
||||
fprintf( f, "ev %i (PlotConfig)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ParamSetup:
|
||||
fprintf( f, "ev %i (ParamSetup)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::AckServerQueryNoop:
|
||||
fprintf( f, "ev %i (AckServerQueryNoop)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::AckSourceCodeNotAvailable:
|
||||
fprintf( f, "ev %i (AckSourceCodeNotAvailable)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::AckSymbolCodeNotAvailable:
|
||||
fprintf( f, "ev %i (AckSymbolCodeNotAvailable)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CpuTopology:
|
||||
fprintf( f, "ev %i (CpuTopology)\n", ev.hdr.idx );
|
||||
fprintf( f, "\tpackage = %" PRIu32 "\n", ev.cpuTopology.package );
|
||||
fprintf( f, "\tcore = %" PRIu32 "\n", ev.cpuTopology.core );
|
||||
fprintf( f, "\tthread = %" PRIu32 "\n", ev.cpuTopology.thread );
|
||||
break;
|
||||
case QueueType::SingleStringData:
|
||||
fprintf( f, "ev %i (SingleStringData)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SecondStringData:
|
||||
fprintf( f, "ev %i (SecondStringData)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::MemNamePayload:
|
||||
fprintf( f, "ev %i (MemNamePayload)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::StringData:
|
||||
fprintf( f, "ev %i (StringData)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ThreadName:
|
||||
fprintf( f, "ev %i (ThreadName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::PlotName:
|
||||
fprintf( f, "ev %i (PlotName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SourceLocationPayload:
|
||||
fprintf( f, "ev %i (SourceLocationPayload)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackPayload:
|
||||
fprintf( f, "ev %i (CallstackPayload)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::CallstackAllocPayload:
|
||||
fprintf( f, "ev %i (CallstackAllocPayload)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameName:
|
||||
fprintf( f, "ev %i (FrameName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FrameImageData:
|
||||
fprintf( f, "ev %i (FrameImageData)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ExternalName:
|
||||
fprintf( f, "ev %i (ExternalName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::ExternalThreadName:
|
||||
fprintf( f, "ev %i (ExternalThreadName)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SymbolCode:
|
||||
fprintf( f, "ev %i (SymbolCode)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::SourceCode:
|
||||
fprintf( f, "ev %i (SourceCode)\n", ev.hdr.idx );
|
||||
break;
|
||||
case QueueType::FiberName:
|
||||
fprintf( f, "ev %i (FiberName)\n", ev.hdr.idx );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
fflush( f );
|
||||
}
|
||||
|
||||
}
|
||||
10
subprojects/tracy/profiler/src/profiler/TracyEventDebug.hpp
Normal file
10
subprojects/tracy/profiler/src/profiler/TracyEventDebug.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __TRACYEVENTDEBUG_HPP__
|
||||
#define __TRACYEVENTDEBUG_HPP__
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
struct QueueItem;
|
||||
void EventDebug( const QueueItem& ev );
|
||||
}
|
||||
|
||||
#endif
|
||||
126
subprojects/tracy/profiler/src/profiler/TracyFileselector.cpp
Normal file
126
subprojects/tracy/profiler/src/profiler/TracyFileselector.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "TracyFileselector.hpp"
|
||||
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
# ifdef __EMSCRIPTEN__
|
||||
# include <emscripten.h>
|
||||
# else
|
||||
# include "../nfd/nfd.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace tracy::Fileselector
|
||||
{
|
||||
|
||||
static bool s_hasFailed = false;
|
||||
|
||||
void Init()
|
||||
{
|
||||
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
|
||||
NFD_Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
|
||||
NFD_Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool HasFailed()
|
||||
{
|
||||
if( s_hasFailed )
|
||||
{
|
||||
s_hasFailed = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
static std::function<void(const char*)> s_openFileCallback;
|
||||
|
||||
extern "C" int nativeOpenFile()
|
||||
{
|
||||
s_openFileCallback( "upload.tracy" );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool OpenFileImpl( const char* ext, const char* desc, const std::function<void(const char*)>& callback )
|
||||
{
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
# ifdef __EMSCRIPTEN__
|
||||
s_openFileCallback = callback;
|
||||
EM_ASM( {
|
||||
var input = document.createElement( 'input' );
|
||||
input.type = 'file';
|
||||
input.accept = UTF8ToString( $0 );
|
||||
input.onchange = (e) => {
|
||||
var file = e.target.files[0];
|
||||
var reader = new FileReader();
|
||||
reader.readAsArrayBuffer( file );
|
||||
reader.onload = () => {
|
||||
var buf = reader.result;
|
||||
var view = new Uint8Array( buf );
|
||||
FS.createDataFile( '/', 'upload.tracy', view, true, true );
|
||||
Module.ccall( 'nativeOpenFile', 'number', [], [] );
|
||||
FS.unlink( '/upload.tracy' );
|
||||
};
|
||||
};
|
||||
input.click();
|
||||
}, ext );
|
||||
return true;
|
||||
# else
|
||||
nfdu8filteritem_t filter = { desc, ext };
|
||||
nfdu8char_t* fn;
|
||||
const auto res = NFD_OpenDialogU8( &fn, &filter, 1, nullptr );
|
||||
if( res == NFD_OKAY )
|
||||
{
|
||||
callback( (const char*)fn );
|
||||
NFD_FreePathU8( fn );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res != NFD_ERROR;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool SaveFileImpl( const char* ext, const char* desc, const std::function<void(const char*)>& callback )
|
||||
{
|
||||
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
|
||||
nfdu8filteritem_t filter = { desc, ext };
|
||||
nfdu8char_t* fn;
|
||||
const auto res = NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr );
|
||||
if( res == NFD_OKAY )
|
||||
{
|
||||
callback( (const char*)fn );
|
||||
NFD_FreePathU8( fn );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res != NFD_ERROR;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenFile( const char* ext, const char* desc, const std::function<void(const char*)>& callback )
|
||||
{
|
||||
if( !OpenFileImpl( ext, desc, callback ) ) s_hasFailed = true;
|
||||
}
|
||||
|
||||
void SaveFile( const char* ext, const char* desc, const std::function<void(const char*)>& callback )
|
||||
{
|
||||
if( !SaveFileImpl( ext, desc, callback ) ) s_hasFailed = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef __TRACYFILESELECTOR_HPP__
|
||||
#define __TRACYFILESELECTOR_HPP__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace tracy::Fileselector
|
||||
{
|
||||
|
||||
void Init();
|
||||
void Shutdown();
|
||||
bool HasFailed();
|
||||
|
||||
void OpenFile( const char* ext, const char* desc, const std::function<void(const char*)>& callback );
|
||||
void SaveFile( const char* ext, const char* desc, const std::function<void(const char*)>& callback );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
19
subprojects/tracy/profiler/src/profiler/TracyFilesystem.cpp
Normal file
19
subprojects/tracy/profiler/src/profiler/TracyFilesystem.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "TracyFilesystem.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view, const Worker& worker )
|
||||
{
|
||||
if( worker.GetSourceFileFromCache( fn ).data != nullptr ) return true;
|
||||
struct stat buf;
|
||||
if( stat( view.SourceSubstitution( fn ), &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0 )
|
||||
{
|
||||
if(!view.ValidateSourceAge()) return true;
|
||||
return (uint64_t)buf.st_mtime < olderThan;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
23
subprojects/tracy/profiler/src/profiler/TracyFilesystem.hpp
Normal file
23
subprojects/tracy/profiler/src/profiler/TracyFilesystem.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __TRACYFILESYSTEM_HPP__
|
||||
#define __TRACYFILESYSTEM_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class View;
|
||||
class Worker;
|
||||
|
||||
static inline bool FileExists( const char* fn )
|
||||
{
|
||||
struct stat buf;
|
||||
return stat( fn, &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0;
|
||||
}
|
||||
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view, const Worker& worker );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
130
subprojects/tracy/profiler/src/profiler/TracyImGui.cpp
Normal file
130
subprojects/tracy/profiler/src/profiler/TracyImGui.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
|
||||
extern void* zigzagTex;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
bool s_wasActive = false;
|
||||
|
||||
bool WasActive()
|
||||
{
|
||||
if( s_wasActive )
|
||||
{
|
||||
s_wasActive = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color )
|
||||
{
|
||||
const auto v = ( end - start ) / ( h * 2 );
|
||||
draw->AddImage( zigzagTex, wpos + ImVec2( start, -h ), wpos + ImVec2( end, h ), ImVec2( 0, 0 ), ImVec2( v, 1 ), color );
|
||||
}
|
||||
|
||||
void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted )
|
||||
{
|
||||
assert( x1 >= x0 );
|
||||
assert( y1 >= y0 );
|
||||
assert( sw > 0 );
|
||||
|
||||
const auto ww = ImGui::GetItemRectSize().x;
|
||||
if( x0 > ww || x1 < 0 ) return;
|
||||
|
||||
if( x1 - x0 > ww )
|
||||
{
|
||||
x0 = std::max<double>( 0, x0 );
|
||||
x1 = std::min<double>( ww, x1 );
|
||||
}
|
||||
|
||||
x0 += wpos.x;
|
||||
x1 += wpos.x;
|
||||
|
||||
ImGui::PushClipRect( ImVec2( x0, y0 ), ImVec2( x1, y1 ), true );
|
||||
|
||||
const auto rw = x1 - x0;
|
||||
const auto rh = y1 - y0;
|
||||
const auto cnt = int( ( rh + rw + sw*2 ) / ( sw*2 ) );
|
||||
auto v0 = ImVec2( x0, y0 - rw );
|
||||
|
||||
if ( fix_stripes_in_screen_space )
|
||||
{
|
||||
const auto window_height = double( ImGui::GetWindowHeight() );
|
||||
const auto flipped_v0y = window_height - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right
|
||||
|
||||
const auto manhattan_distance = x0 + flipped_v0y;
|
||||
const auto in_multiples_of_2_times_sw = int( manhattan_distance / ( sw*2 ) );
|
||||
|
||||
const auto floored_manhatten_distance = double( in_multiples_of_2_times_sw*sw*2 ); //floor in terms of 2 * stripe width
|
||||
|
||||
const auto corrected_flipped_v0y = ( floored_manhatten_distance - x0 ); //the corrected (floored) y respects the position of the stripes
|
||||
v0.y = window_height - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space
|
||||
}
|
||||
|
||||
for( int i=0; i<cnt; i++ )
|
||||
{
|
||||
draw->PathLineTo( v0 + ImVec2( 0, i*sw*2 ) );
|
||||
draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw ) );
|
||||
draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw + sw ) );
|
||||
draw->PathLineTo( v0 + ImVec2( 0, i*sw*2 + sw ) );
|
||||
draw->PathFillConvex( color );
|
||||
}
|
||||
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
|
||||
void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty )
|
||||
{
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto ty15 = round( ty * 1.5f );
|
||||
const auto mintxt = TimeToString( tmin );
|
||||
const auto maxtxt = TimeToString( tmax );
|
||||
const auto maxsz = ImGui::CalcTextSize( maxtxt ).x;
|
||||
DrawLine( draw, dpos, dpos + ImVec2( 0, ty15 ), 0x66FFFFFF );
|
||||
DrawLine( draw, dpos + ImVec2( w-1, 0 ), dpos + ImVec2( w-1, ty15 ), 0x66FFFFFF );
|
||||
draw->AddText( wpos + ImVec2( 0, ty15 ), 0x66FFFFFF, mintxt );
|
||||
draw->AddText( wpos + ImVec2( w-1-maxsz, ty15 ), 0x66FFFFFF, maxtxt );
|
||||
|
||||
char range[64];
|
||||
sprintf( range, ICON_FA_LEFT_LONG " %s " ICON_FA_RIGHT_LONG, TimeToString( tmax - tmin ) );
|
||||
|
||||
const auto rsz = ImGui::CalcTextSize( range ).x;
|
||||
draw->AddText( wpos + ImVec2( round( (w-1-rsz) * 0.5 ), ty15 ), 0x66FFFFFF, range );
|
||||
}
|
||||
|
||||
void PrintSource( const std::vector<Tokenizer::Line>& lines )
|
||||
{
|
||||
for( auto& line: lines )
|
||||
{
|
||||
auto ptr = line.begin;
|
||||
auto it = line.tokens.begin();
|
||||
while( ptr < line.end )
|
||||
{
|
||||
if( it == line.tokens.end() )
|
||||
{
|
||||
ImGui::TextUnformatted( ptr, line.end );
|
||||
ImGui::SameLine( 0, 0 );
|
||||
break;
|
||||
}
|
||||
if( ptr < it->begin )
|
||||
{
|
||||
ImGui::TextUnformatted( ptr, it->begin );
|
||||
ImGui::SameLine( 0, 0 );
|
||||
}
|
||||
auto color = SyntaxColors[(int)it->color];
|
||||
TextColoredUnformatted( color, it->begin, it->end );
|
||||
ImGui::SameLine( 0, 0 );
|
||||
ptr = it->end;
|
||||
++it;
|
||||
}
|
||||
ImGui::ItemSize( ImVec2( 0, 0 ), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
271
subprojects/tracy/profiler/src/profiler/TracyImGui.hpp
Normal file
271
subprojects/tracy/profiler/src/profiler/TracyImGui.hpp
Normal file
@@ -0,0 +1,271 @@
|
||||
#ifndef __TRACYIMGUI_HPP__
|
||||
#define __TRACYIMGUI_HPP__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( disable: 4244 ) // conversion from don't care to whatever, possible loss of data
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "TracySourceTokenizer.hpp"
|
||||
|
||||
#if !IMGUI_DEFINE_MATH_OPERATORS
|
||||
static inline ImVec2 operator+( const ImVec2& l, const ImVec2& r ) { return ImVec2( l.x + r.x, l.y + r.y ); }
|
||||
static inline ImVec2 operator-( const ImVec2& l, const ImVec2& r ) { return ImVec2( l.x - r.x, l.y - r.y ); }
|
||||
#endif
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
extern bool s_wasActive;
|
||||
bool WasActive();
|
||||
|
||||
|
||||
void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color );
|
||||
void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted );
|
||||
void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty );
|
||||
void PrintSource( const std::vector<Tokenizer::Line>& lines );
|
||||
|
||||
|
||||
static constexpr const uint32_t SyntaxColors[] = {
|
||||
0xFFB2B2B2, // default
|
||||
0xFF51AD72, // comment
|
||||
0xFF1E5EB7, // preprocessor
|
||||
0xFFFFA3A3, // string
|
||||
0xFFFFD1A3, // char literal
|
||||
0xFF87E8FF, // keyword
|
||||
0xFFE899CE, // number
|
||||
0xFFE5E5E5, // punctuation
|
||||
0xFFBF75C6, // type
|
||||
0xFFE2AF35, // special
|
||||
};
|
||||
|
||||
static constexpr const uint32_t AsmOpTypeColors[] = {
|
||||
0xFFE2AF35, // None
|
||||
0xFF358FE2, // Jump
|
||||
0xFF358FE2, // Branch
|
||||
0xFF35E2AF, // Call
|
||||
0xFF35E2AF, // Ret
|
||||
0xFF22FFFF, // Privileged
|
||||
};
|
||||
|
||||
static constexpr const uint32_t AsmSyntaxColors[] = {
|
||||
0xFFFFD1A3, // label
|
||||
0xFFE5E5E5, // default ('[', '+', '*', ',')
|
||||
0xFF51AD72, // dword/xmmword 'ptr'
|
||||
0xFFBF75C6, // register
|
||||
0xFFE899CE, // literal
|
||||
};
|
||||
|
||||
|
||||
[[maybe_unused]] static inline float GetScale()
|
||||
{
|
||||
return ImGui::GetTextLineHeight() / 15.f;
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void ImageCentered( ImTextureID user_texture_id, const ImVec2& size )
|
||||
{
|
||||
ImGui::SetCursorPosX( ( ImGui::GetWindowWidth() - size.x ) * 0.5f );
|
||||
ImGui::Image( user_texture_id, size );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void TextCentered( const char* text )
|
||||
{
|
||||
const auto tw = ImGui::CalcTextSize( text ).x;
|
||||
ImGui::SetCursorPosX( ( ImGui::GetWindowWidth() - tw ) * 0.5f );
|
||||
ImGui::TextUnformatted( text );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void TextColoredUnformatted( uint32_t col, const char* text, const char* end = nullptr )
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, col );
|
||||
ImGui::TextUnformatted( text, end );
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void TextColoredUnformatted( const ImVec4& col, const char* text, const char* end = nullptr )
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, col );
|
||||
ImGui::TextUnformatted( text, end );
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void TextDisabledUnformatted( const char* begin, const char* end = nullptr )
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::TextUnformatted( begin, end );
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void TextFocused( const char* label, const char* value )
|
||||
{
|
||||
TextDisabledUnformatted( label );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( value );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void DrawWaitingDots( double time )
|
||||
{
|
||||
s_wasActive = true;
|
||||
ImGui::TextUnformatted( "" );
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto wpos = ImGui::GetWindowPos();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
const auto h = ImGui::GetCursorPosY() - ty * 0.5f;
|
||||
const auto w = ImGui::GetWindowWidth();
|
||||
draw->AddCircleFilled( wpos + ImVec2( w * 0.5f - ty, h ), ty * ( 0.15f + 0.2f * ( pow( cos( time * 3.5f + 0.3f ), 16.f ) ) ), 0xFFBBBBBB, 12 );
|
||||
draw->AddCircleFilled( wpos + ImVec2( w * 0.5f , h ), ty * ( 0.15f + 0.2f * ( pow( cos( time * 3.5f ), 16.f ) ) ), 0xFFBBBBBB, 12 );
|
||||
draw->AddCircleFilled( wpos + ImVec2( w * 0.5f + ty, h ), ty * ( 0.15f + 0.2f * ( pow( cos( time * 3.5f - 0.3f ), 16.f ) ) ), 0xFFBBBBBB, 12 );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline bool SmallCheckbox( const char* label, bool* var )
|
||||
{
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
auto ret = ImGui::Checkbox( label, var );
|
||||
ImGui::PopStyleVar();
|
||||
return ret;
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void SmallColorBox( uint32_t color )
|
||||
{
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
ImGui::ColorButton( "c1", ImVec4( (color & 0xFF) / 255.f, ((color>>8) & 0xFF ) / 255.f, ((color>>16) & 0xFF ) / 255.f, 1.f ), ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop );
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline bool ButtonDisablable( const char* label, bool disabled )
|
||||
{
|
||||
if( disabled )
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button( label );
|
||||
ImGui::EndDisabled();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImGui::Button( label );
|
||||
}
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline bool SmallButtonDisablable( const char* label, bool disabled )
|
||||
{
|
||||
if( disabled )
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::SmallButton( label );
|
||||
ImGui::EndDisabled();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImGui::SmallButton( label );
|
||||
}
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void DrawTextContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color, const char* text )
|
||||
{
|
||||
const auto scale = round( GetScale() );
|
||||
draw->AddText( pos + ImVec2( scale, scale ), 0xAA000000, text );
|
||||
draw->AddText( pos, color, text );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static inline void DrawTextSuperContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color, const char* text )
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
const auto s1 = round( scale );
|
||||
const auto s2 = round( scale * 1.5f );
|
||||
draw->AddText( pos + ImVec2( 0, s2 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( 0, -s2 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( s2, 0 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( -s2, 0 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( s1, s1 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( -s1, s1 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( -s1, -s1 ), 0xAA000000, text );
|
||||
draw->AddText( pos + ImVec2( s1, -s1 ), 0xAA000000, text );
|
||||
draw->AddText( pos, color, text );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static void SetButtonHighlightColor()
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Button, (ImVec4)ImColor::HSV( 0.35f, 0.6f, 0.6f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV( 0.35f, 0.8f, 0.8f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV( 0.35f, 0.7f, 0.7f ) );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static void ToggleButton( const char* label, bool& toggle )
|
||||
{
|
||||
const auto active = toggle;
|
||||
if( active ) SetButtonHighlightColor();
|
||||
if( ImGui::Button( label ) ) toggle = !toggle;
|
||||
if( active ) ImGui::PopStyleColor( 3 );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static void SmallToggleButton( const char* label, bool& toggle )
|
||||
{
|
||||
const auto active = toggle;
|
||||
if( active ) SetButtonHighlightColor();
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
if( ImGui::Button( label ) ) toggle = !toggle;
|
||||
ImGui::PopStyleVar( 1 );
|
||||
if( active ) ImGui::PopStyleColor( 3 );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static bool ClipboardButton( int id = 0 )
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Border, ImVec4( 0.43f, 0.43f, 0.50f, 0.25f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_Button, ImVec4( 0.26f, 0.59f, 0.98f, 0.20f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, ImVec4( 0.26f, 0.59f, 0.98f, 0.5f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_ButtonActive, ImVec4( 0.06f, 0.53f, 0.98f, 0.5f ) );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
|
||||
ImGui::PushID( id );
|
||||
const auto res = ImGui::SmallButton( ICON_FA_CLIPBOARD );
|
||||
ImGui::PopID();
|
||||
ImGui::PopStyleColor( 5 );
|
||||
return res;
|
||||
}
|
||||
|
||||
[[maybe_unused]] static tracy_force_inline void DrawLine( ImDrawList* draw, const ImVec2& v1, const ImVec2& v2, uint32_t col, float thickness = 1.0f )
|
||||
{
|
||||
const ImVec2 data[2] = { v1, v2 };
|
||||
draw->AddPolyline( data, 2, col, 0, thickness );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static tracy_force_inline void DrawLine( ImDrawList* draw, const ImVec2& v1, const ImVec2& v2, const ImVec2& v3, uint32_t col, float thickness = 1.0f )
|
||||
{
|
||||
const ImVec2 data[3] = { v1, v2, v3 };
|
||||
draw->AddPolyline( data, 3, col, 0, thickness );
|
||||
}
|
||||
|
||||
[[maybe_unused]] static tracy_force_inline void TooltipIfHovered( const char* text )
|
||||
{
|
||||
if( !ImGui::IsItemHovered() ) return;
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted( text );
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
[[maybe_unused]] void tracy_force_inline DrawHelpMarker( const char* desc )
|
||||
{
|
||||
TextDisabledUnformatted( "(?)" );
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos( 450.0f * ty / 15.f );
|
||||
ImGui::TextUnformatted( desc );
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
28
subprojects/tracy/profiler/src/profiler/TracyLockHelpers.hpp
Normal file
28
subprojects/tracy/profiler/src/profiler/TracyLockHelpers.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef __TRACYLOCKHELPERS_HPP__
|
||||
#define __TRACYLOCKHELPERS_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static tracy_force_inline uint64_t GetThreadBit( uint8_t thread )
|
||||
{
|
||||
return uint64_t( 1 ) << thread;
|
||||
}
|
||||
|
||||
static tracy_force_inline bool IsThreadWaiting( uint64_t bitlist, uint64_t threadBit )
|
||||
{
|
||||
return ( bitlist & threadBit ) != 0;
|
||||
}
|
||||
|
||||
static tracy_force_inline bool AreOtherWaiting( uint64_t bitlist, uint64_t threadBit )
|
||||
{
|
||||
return ( bitlist & ~threadBit ) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
181051
subprojects/tracy/profiler/src/profiler/TracyMicroArchitecture.cpp
Normal file
181051
subprojects/tracy/profiler/src/profiler/TracyMicroArchitecture.cpp
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,46 @@
|
||||
#include <stdint.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct AsmDesc
|
||||
{
|
||||
uint8_t type;
|
||||
uint16_t width;
|
||||
};
|
||||
|
||||
struct AsmVar
|
||||
{
|
||||
int descNum;
|
||||
AsmDesc desc[5];
|
||||
int isaSet;
|
||||
float tp;
|
||||
int port, uops, minlat, maxlat;
|
||||
bool minbound, maxbound;
|
||||
};
|
||||
|
||||
struct AsmOp
|
||||
{
|
||||
int id;
|
||||
int descId;
|
||||
int numVariants;
|
||||
const AsmVar*const* variant;
|
||||
};
|
||||
|
||||
struct MicroArchitecture
|
||||
{
|
||||
int numOps;
|
||||
const AsmOp*const* ops;
|
||||
};
|
||||
|
||||
extern const char* MicroArchitectureList[];
|
||||
extern const char* PortList[];
|
||||
extern const char* OpsList[];
|
||||
extern const char* OpDescList[];
|
||||
extern const char* IsaList[];
|
||||
extern const MicroArchitecture* const MicroArchitectureData[];
|
||||
|
||||
extern int OpsNum;
|
||||
extern int MicroArchitectureNum;
|
||||
|
||||
};
|
||||
90
subprojects/tracy/profiler/src/profiler/TracyMouse.cpp
Normal file
90
subprojects/tracy/profiler/src/profiler/TracyMouse.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "TracyMouse.hpp"
|
||||
|
||||
#include "imgui_internal.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static constexpr int MouseButtons = IM_ARRAYSIZE( ImGuiContext::IO.MouseDown );
|
||||
static constexpr float MouseDragThreshold = 2;
|
||||
|
||||
struct Mouse
|
||||
{
|
||||
bool mouseDown[MouseButtons];
|
||||
bool mouseClicked[MouseButtons];
|
||||
bool mouseReleased[MouseButtons];
|
||||
bool mouseDragging[MouseButtons];
|
||||
ImVec2 mouseDragDelta[MouseButtons];
|
||||
bool mousePotentialClickRelease[MouseButtons];
|
||||
};
|
||||
|
||||
static Mouse s_mouse = {};
|
||||
|
||||
void MouseFrame()
|
||||
{
|
||||
for( int i=0; i<MouseButtons; i++ )
|
||||
{
|
||||
s_mouse.mouseDown[i] = ImGui::IsMouseDown( i );
|
||||
s_mouse.mouseClicked[i] = ImGui::IsMouseClicked( i );
|
||||
s_mouse.mouseReleased[i] = ImGui::IsMouseReleased( i );
|
||||
s_mouse.mouseDragging[i] = ImGui::IsMouseDragging( i, 0 );
|
||||
s_mouse.mouseDragDelta[i] = ImGui::GetMouseDragDelta( i, 0 );
|
||||
|
||||
if( s_mouse.mouseDragging[i] )
|
||||
{
|
||||
if( s_mouse.mouseClicked[i] || s_mouse.mousePotentialClickRelease[i] )
|
||||
{
|
||||
if( std::abs( s_mouse.mouseDragDelta[i].x ) < MouseDragThreshold && std::abs( s_mouse.mouseDragDelta[i].y ) < MouseDragThreshold )
|
||||
{
|
||||
s_mouse.mouseDragging[i] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_mouse.mousePotentialClickRelease[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( !s_mouse.mouseDown[i] && !s_mouse.mouseReleased[i] )
|
||||
{
|
||||
s_mouse.mousePotentialClickRelease[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsMouseDown( ImGuiMouseButton button )
|
||||
{
|
||||
return s_mouse.mouseDown[button];
|
||||
}
|
||||
|
||||
bool IsMouseClicked( ImGuiMouseButton button )
|
||||
{
|
||||
return s_mouse.mouseClicked[button];
|
||||
}
|
||||
|
||||
bool IsMouseDragging( ImGuiMouseButton button )
|
||||
{
|
||||
return s_mouse.mouseDragging[button];
|
||||
}
|
||||
|
||||
ImVec2 GetMouseDragDelta( ImGuiMouseButton button )
|
||||
{
|
||||
return s_mouse.mouseDragDelta[button];
|
||||
}
|
||||
|
||||
void ConsumeMouseEvents( ImGuiMouseButton button )
|
||||
{
|
||||
s_mouse.mouseDown[button] = false;
|
||||
s_mouse.mouseClicked[button] = false;
|
||||
s_mouse.mouseDragging[button] = false;
|
||||
}
|
||||
|
||||
bool IsMouseClickReleased( ImGuiMouseButton button )
|
||||
{
|
||||
if( s_mouse.mouseReleased[button] && s_mouse.mousePotentialClickRelease[button] ) return true;
|
||||
if( s_mouse.mouseClicked[button] ) s_mouse.mousePotentialClickRelease[button] = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
21
subprojects/tracy/profiler/src/profiler/TracyMouse.hpp
Normal file
21
subprojects/tracy/profiler/src/profiler/TracyMouse.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __TRACYMOUSE_HPP__
|
||||
#define __TRACYMOUSE_HPP__
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
void MouseFrame();
|
||||
|
||||
bool IsMouseDown( ImGuiMouseButton button );
|
||||
bool IsMouseClicked( ImGuiMouseButton button );
|
||||
bool IsMouseDragging( ImGuiMouseButton button );
|
||||
ImVec2 GetMouseDragDelta( ImGuiMouseButton button );
|
||||
|
||||
void ConsumeMouseEvents( ImGuiMouseButton button );
|
||||
bool IsMouseClickReleased( ImGuiMouseButton button );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "TracyFileHeader.hpp"
|
||||
#include "TracyProtoHistory.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr ProtocolHistory_t ProtocolHistoryArr[] = {
|
||||
{ 66, FileVersion( 0, 11, 0 ) },
|
||||
{ 64, FileVersion( 0, 10, 0 ) },
|
||||
{ 63, FileVersion( 0, 9, 0 ), FileVersion( 0, 9, 1 ) },
|
||||
{ 57, FileVersion( 0, 8, 2 ) },
|
||||
{ 56, FileVersion( 0, 8, 1 ) },
|
||||
{ 55, FileVersion( 0, 8, 0 ) },
|
||||
{ 46, FileVersion( 0, 7, 6 ), FileVersion( 0, 7, 8 ) },
|
||||
{ 44, FileVersion( 0, 7, 5 ) },
|
||||
{ 42, FileVersion( 0, 7, 3 ), FileVersion( 0, 7, 4 ) },
|
||||
{ 40, FileVersion( 0, 7, 1 ), FileVersion( 0, 7, 2 ) },
|
||||
{ 35, FileVersion( 0, 7, 0 ) },
|
||||
{ 25, FileVersion( 0, 6, 2 ), FileVersion( 0, 6, 3 ) },
|
||||
{ 24, FileVersion( 0, 6, 1 ) },
|
||||
{ 23, FileVersion( 0, 6, 0 ) },
|
||||
{ 14, FileVersion( 0, 5, 0 ) },
|
||||
{ 1, FileVersion( 0, 4, 1 ) },
|
||||
{}
|
||||
};
|
||||
|
||||
const ProtocolHistory_t* ProtocolHistory = ProtocolHistoryArr;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef __TRACYPROTOHISTORY_HPP__
|
||||
#define __TRACYPROTOHISTORY_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct ProtocolHistory_t
|
||||
{
|
||||
uint32_t protocol;
|
||||
uint32_t minVer;
|
||||
uint32_t maxVer;
|
||||
};
|
||||
|
||||
extern const ProtocolHistory_t* ProtocolHistory;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
105
subprojects/tracy/profiler/src/profiler/TracySourceContents.cpp
Normal file
105
subprojects/tracy/profiler/src/profiler/TracySourceContents.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "TracySourceContents.hpp"
|
||||
#include "TracyView.hpp"
|
||||
#include "TracyWorker.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
SourceContents::SourceContents()
|
||||
: m_file( nullptr )
|
||||
, m_fileStringIdx( 0 )
|
||||
, m_data( nullptr )
|
||||
, m_dataBuf( nullptr )
|
||||
, m_dataSize( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
SourceContents::~SourceContents()
|
||||
{
|
||||
delete[] m_dataBuf;
|
||||
}
|
||||
|
||||
void SourceContents::Parse( const char* fileName, const Worker& worker, const View& view )
|
||||
{
|
||||
if( m_file == fileName ) return;
|
||||
|
||||
m_file = fileName;
|
||||
m_fileStringIdx = worker.FindStringIdx( fileName );
|
||||
m_lines.clear();
|
||||
if( fileName )
|
||||
{
|
||||
uint32_t sz;
|
||||
const auto srcCache = worker.GetSourceFileFromCache( fileName );
|
||||
if( srcCache.data != nullptr )
|
||||
{
|
||||
m_data = srcCache.data;
|
||||
m_dataSize = srcCache.len;
|
||||
sz = srcCache.len;
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE* f = fopen( view.SourceSubstitution( fileName ), "rb" );
|
||||
if( f )
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
sz = ftell( f );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
if( sz > m_dataSize )
|
||||
{
|
||||
delete[] m_dataBuf;
|
||||
m_dataBuf = new char[sz];
|
||||
m_dataSize = sz;
|
||||
}
|
||||
fread( m_dataBuf, 1, sz, f );
|
||||
m_data = m_dataBuf;
|
||||
fclose( f );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if( m_file ) Tokenize( m_data, sz );
|
||||
}
|
||||
}
|
||||
|
||||
void SourceContents::Parse( const char* source )
|
||||
{
|
||||
if( source == m_data ) return;
|
||||
|
||||
const size_t len = strlen( source );
|
||||
|
||||
m_file = nullptr;
|
||||
m_fileStringIdx = 0;
|
||||
m_data = source;
|
||||
m_dataBuf = nullptr;
|
||||
m_dataSize = len;
|
||||
Tokenize( source, len );
|
||||
}
|
||||
|
||||
void SourceContents::Tokenize( const char* txt, size_t sz )
|
||||
{
|
||||
Tokenizer tokenizer;
|
||||
for(;;)
|
||||
{
|
||||
auto end = txt;
|
||||
while( *end != '\n' && *end != '\r' && end - m_data < sz ) end++;
|
||||
m_lines.emplace_back( Tokenizer::Line { txt, end, tokenizer.Tokenize( txt, end ) } );
|
||||
if( end - m_data == sz ) break;
|
||||
if( *end == '\n' )
|
||||
{
|
||||
end++;
|
||||
if( end - m_data < sz && *end == '\r' ) end++;
|
||||
}
|
||||
else if( *end == '\r' )
|
||||
{
|
||||
end++;
|
||||
if( end - m_data < sz && *end == '\n' ) end++;
|
||||
}
|
||||
if( end - m_data == sz ) break;
|
||||
txt = end;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef __TRACYSOURCECONTENTS_HPP__
|
||||
#define __TRACYSOURCECONTENTS_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <vector>
|
||||
|
||||
#include "TracySourceTokenizer.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class View;
|
||||
class Worker;
|
||||
|
||||
class SourceContents
|
||||
{
|
||||
public:
|
||||
SourceContents();
|
||||
~SourceContents();
|
||||
|
||||
void Parse( const char* fileName, const Worker& worker, const View& view );
|
||||
void Parse( const char* source );
|
||||
|
||||
const std::vector<Tokenizer::Line>& get() const { return m_lines; }
|
||||
bool empty() const { return m_lines.empty(); }
|
||||
|
||||
const char* filename() const { return m_file; }
|
||||
uint32_t idx() const { return m_fileStringIdx; }
|
||||
bool is_cached() const { return m_data != m_dataBuf; }
|
||||
const char* data() const { return m_data; }
|
||||
size_t data_size() const { return m_dataSize; }
|
||||
|
||||
private:
|
||||
void Tokenize( const char* txt, size_t sz );
|
||||
|
||||
const char* m_file;
|
||||
uint32_t m_fileStringIdx;
|
||||
|
||||
const char* m_data;
|
||||
char* m_dataBuf;
|
||||
size_t m_dataSize;
|
||||
|
||||
std::vector<Tokenizer::Line> m_lines;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
421
subprojects/tracy/profiler/src/profiler/TracySourceTokenizer.cpp
Normal file
421
subprojects/tracy/profiler/src/profiler/TracySourceTokenizer.cpp
Normal file
@@ -0,0 +1,421 @@
|
||||
#include "tracy_robin_hood.h"
|
||||
#include "TracyCharUtil.hpp"
|
||||
#include "TracySourceTokenizer.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
namespace {
|
||||
static unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> GetKeywords()
|
||||
{
|
||||
unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> ret;
|
||||
for( auto& v : {
|
||||
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept",
|
||||
"bitand", "bitor", "break", "case", "catch", "class", "compl", "concept", "const", "consteval",
|
||||
"constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype",
|
||||
"default", "delete", "do", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "for",
|
||||
"friend", "if", "inline", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "operator",
|
||||
"or", "or_eq", "private", "protected", "public", "reflexpr", "register", "reinterpret_cast",
|
||||
"return", "requires", "sizeof", "static", "static_assert", "static_cast", "struct", "switch",
|
||||
"synchronized", "template", "thread_local", "throw", "try", "typedef", "typeid", "typename",
|
||||
"union", "using", "virtual", "volatile", "while", "xor", "xor_eq", "override", "final", "import",
|
||||
"module", "transaction_safe", "transaction_safe_dynamic" } )
|
||||
{
|
||||
ret.insert( v );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> GetTypes()
|
||||
{
|
||||
unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> ret;
|
||||
for( auto& v : {
|
||||
"bool", "char", "char8_t", "char16_t", "char32_t", "double", "float", "int", "long", "short", "signed",
|
||||
"unsigned", "void", "wchar_t", "size_t", "int8_t", "int16_t", "int32_t", "int64_t", "int_fast8_t",
|
||||
"int_fast16_t", "int_fast32_t", "int_fast64_t", "int_least8_t", "int_least16_t", "int_least32_t",
|
||||
"int_least64_t", "intmax_t", "intptr_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "uint_fast8_t",
|
||||
"uint_fast16_t", "uint_fast32_t", "uint_fast64_t", "uint_least8_t", "uint_least16_t", "uint_least32_t",
|
||||
"uint_least64_t", "uintmax_t", "uintptr_t", "type_info", "bad_typeid", "bad_cast", "type_index",
|
||||
"clock_t", "time_t", "tm", "timespec", "ptrdiff_t", "nullptr_t", "max_align_t", "auto",
|
||||
|
||||
"__m64", "__m128", "__m128i", "__m128d", "__m256", "__m256i", "__m256d", "__m512", "__m512i",
|
||||
"__m512d", "__mmask8", "__mmask16", "__mmask32", "__mmask64",
|
||||
|
||||
"int8x8_t", "int16x4_t", "int32x2_t", "int64x1_t", "uint8x8_t", "uint16x4_t", "uint32x2_t",
|
||||
"uint64x1_t", "float32x2_t", "poly8x8_t", "poly16x4_t", "int8x16_t", "int16x8_t", "int32x4_t",
|
||||
"int64x2_t", "uint8x16_t", "uint16x8_t", "uint32x4_t", "uint64x2_t", "float32x4_t", "poly8x16_t",
|
||||
"poly16x8_t",
|
||||
|
||||
"int8x8x2_t", "int16x4x2_t", "int32x2x2_t", "int64x1x2_t", "uint8x8x2_t", "uint16x4x2_t",
|
||||
"uint32x2x2_t", "uint64x1x2_t", "float32x2x2_t", "poly8x8x2_t", "poly16x4x2_t", "int8x16x2_t",
|
||||
"int16x8x2_t", "int32x4x2_t", "int64x2x2_t", "uint8x16x2_t", "uint16x8x2_t", "uint32x4x2_t",
|
||||
"uint64x2x2_t", "float32x4x2_t", "poly8x16x2_t", "poly16x8x2_t",
|
||||
|
||||
"int8x8x3_t", "int16x4x3_t", "int32x2x3_t", "int64x1x3_t", "uint8x8x3_t", "uint16x4x3_t",
|
||||
"uint32x2x3_t", "uint64x1x3_t", "float32x2x3_t", "poly8x8x3_t", "poly16x4x3_t", "int8x16x3_t",
|
||||
"int16x8x3_t", "int32x4x3_t", "int64x2x3_t", "uint8x16x3_t", "uint16x8x3_t", "uint32x4x3_t",
|
||||
"uint64x2x3_t", "float32x4x3_t", "poly8x16x3_t", "poly16x8x3_t",
|
||||
|
||||
"int8x8x4_t", "int16x4x4_t", "int32x2x4_t", "int64x1x4_t", "uint8x8x4_t", "uint16x4x4_t",
|
||||
"uint32x2x4_t", "uint64x1x4_t", "float32x2x4_t", "poly8x8x4_t", "poly16x4x4_t", "int8x16x4_t",
|
||||
"int16x8x4_t", "int32x4x4_t", "int64x2x4_t", "uint8x16x4_t", "uint16x8x4_t", "uint32x4x4_t",
|
||||
"uint64x2x4_t", "float32x4x4_t", "poly8x16x4_t", "poly16x8x4_t" } )
|
||||
{
|
||||
ret.insert( v );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> GetSpecial()
|
||||
{
|
||||
unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> ret;
|
||||
for( auto& v : { "this", "nullptr", "true", "false", "goto", "NULL" } )
|
||||
{
|
||||
ret.insert( v );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> GetAsmRegs()
|
||||
{
|
||||
unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> ret;
|
||||
for( auto& v : {
|
||||
// x64
|
||||
"ah", "al", "ax", "bh", "bl", "bp", "bpl", "bx", "ch", "cl", "cs", "cx", "dh", "di", "dil", "dl", "ds", "dx",
|
||||
"eax", "ebp", "ebx", "ecx", "edi", "edx", "flags", "eip", "eiz", "es", "esi", "esp", "fpsw", "fs", "gs", "ip",
|
||||
"rax", "rbp", "rbx", "rcx", "rdi", "rdx", "rip", "riz", "rsi", "rsp", "si", "sil", "sp", "spl", "ss", "cr0",
|
||||
"cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
|
||||
"dr0", "dr1", "dr2", "dr3", "dr4", "dr5", "dr6", "dr7", "dr8", "dr9", "dr10", "dr11", "dr12", "dr13", "dr14",
|
||||
"dr15", "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7",
|
||||
"mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
||||
"st(0)", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4",
|
||||
"xmm5", "xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", "xmm16", "xmm17",
|
||||
"xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "xmm24", "xmm25", "xmm26", "xmm27", "xmm28", "xmm29",
|
||||
"xmm30", "xmm31", "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7", "ymm8", "ymm9", "ymm10",
|
||||
"ymm11", "ymm12", "ymm13", "ymm14", "ymm15", "ymm16", "ymm17", "ymm18", "ymm19", "ymm20", "ymm21", "ymm22",
|
||||
"ymm23", "ymm24", "ymm25", "ymm26", "ymm27", "ymm28", "ymm29", "ymm30", "ymm31", "zmm0", "zmm1", "zmm2",
|
||||
"zmm3", "zmm4", "zmm5", "zmm6", "zmm7", "zmm8", "zmm9", "zmm10", "zmm11", "zmm12", "zmm13", "zmm14", "zmm15",
|
||||
"zmm16", "zmm17", "zmm18", "zmm19", "zmm20", "zmm21", "zmm22", "zmm23", "zmm24", "zmm25", "zmm26", "zmm27",
|
||||
"zmm28", "zmm29", "zmm30", "zmm31", "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b", "r8d", "r9d",
|
||||
"r10d", "r11d", "r12d", "r13d", "r14d", "r15d", "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
|
||||
// ARM
|
||||
"apsr", "apsr_nzcv", "cpsr", "fpexc", "fpinst", "fpscr", "fpscr_nzcv", "fpsid", "itstate", "lr", "pc", "sp",
|
||||
"spsr", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
|
||||
"d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
|
||||
"fpinst2", "mvfr0", "mvfr1", "mvfr2", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11",
|
||||
"q12", "q13", "q14", "q15", "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12",
|
||||
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16",
|
||||
"s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", "w0",
|
||||
"w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11", "w12", "w13", "w14", "w15", "w16", "w17",
|
||||
"w18", "w19", "w20", "w21", "w22", "w23", "w24", "w25", "w26", "w27", "w28", "w29", "w30", "x0", "x1", "x2",
|
||||
"x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19",
|
||||
"x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29", "x30", "v0", "v1", "v2", "v3", "v4",
|
||||
"v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20",
|
||||
"v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "xzr", "wzr", "b0", "b1", "b2", "b3",
|
||||
"b4", "b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15", "b16", "b17", "b18", "b19",
|
||||
"b20", "b21", "b22", "b23", "b24", "b25", "b26", "b27", "b28", "b29", "b30", "h0", "h1", "h2", "h3", "h4",
|
||||
"h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15", "h16", "h17", "h18", "h19", "h20",
|
||||
"h21", "h22", "h23", "h24", "h25", "h26", "h27", "h28", "h29", "h30" } )
|
||||
{
|
||||
ret.insert( v );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> GetAsmSizeDirectives()
|
||||
{
|
||||
unordered_flat_set<const char*, charutil::Hasher, charutil::Comparator> ret;
|
||||
for( auto& v : { "byte", "word", "dword", "qword", "xmmword", "ymmword", "zmmword" } )
|
||||
{
|
||||
ret.insert( v );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Tokenizer::Tokenizer()
|
||||
: m_isInComment( false )
|
||||
, m_isInPreprocessor( false )
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<Tokenizer::Token> Tokenizer::Tokenize( const char* begin, const char* end )
|
||||
{
|
||||
std::vector<Token> ret;
|
||||
if( m_isInPreprocessor )
|
||||
{
|
||||
if( begin == end )
|
||||
{
|
||||
m_isInPreprocessor = false;
|
||||
return ret;
|
||||
}
|
||||
if( *(end-1) != '\\' ) m_isInPreprocessor = false;
|
||||
ret.emplace_back( Token { begin, end, TokenColor::Preprocessor } );
|
||||
return ret;
|
||||
}
|
||||
const bool first = !m_isInComment;
|
||||
while( begin != end )
|
||||
{
|
||||
if( m_isInComment )
|
||||
{
|
||||
const auto pos = begin;
|
||||
for(;;)
|
||||
{
|
||||
while( begin != end && *begin != '*' ) begin++;
|
||||
begin++;
|
||||
if( begin < end )
|
||||
{
|
||||
if( *begin == '/' )
|
||||
{
|
||||
begin++;
|
||||
ret.emplace_back( Token { pos, begin, TokenColor::Comment } );
|
||||
m_isInComment = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.emplace_back( Token { pos, end, TokenColor::Comment } );
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while( begin != end && isspace( (uint8_t)*begin ) ) begin++;
|
||||
if( first && begin < end && *begin == '#' )
|
||||
{
|
||||
if( *(end-1) == '\\' ) m_isInPreprocessor = true;
|
||||
ret.emplace_back( Token { begin, end, TokenColor::Preprocessor } );
|
||||
return ret;
|
||||
}
|
||||
const auto pos = begin;
|
||||
const auto col = IdentifyToken( begin, end );
|
||||
ret.emplace_back( Token { pos, begin, col } );
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool TokenizeNumber( const char*& begin, const char* end )
|
||||
{
|
||||
const bool startNum = *begin >= '0' && *begin <= '9';
|
||||
if( *begin != '+' && *begin != '-' && !startNum ) return false;
|
||||
begin++;
|
||||
bool hasNum = startNum;
|
||||
while( begin < end && ( ( *begin >= '0' && *begin <= '9' ) || *begin == '\'' ) )
|
||||
{
|
||||
hasNum = true;
|
||||
begin++;
|
||||
}
|
||||
if( !hasNum ) return false;
|
||||
bool isFloat = false, isBinary = false;
|
||||
if( begin < end )
|
||||
{
|
||||
if( *begin == '.' )
|
||||
{
|
||||
isFloat = true;
|
||||
begin++;
|
||||
while( begin < end && ( ( *begin >= '0' && *begin <= '9' ) || *begin == '\'' ) ) begin++;
|
||||
}
|
||||
else if( *begin == 'x' || *begin == 'X' )
|
||||
{
|
||||
// hexadecimal
|
||||
begin++;
|
||||
while( begin < end && ( ( *begin >= '0' && *begin <= '9' ) || ( *begin >= 'a' && *begin <= 'f' ) || ( *begin >= 'A' && *begin <= 'F' ) || *begin == '\'' ) ) begin++;
|
||||
}
|
||||
else if( *begin == 'b' || *begin == 'B' )
|
||||
{
|
||||
isBinary = true;
|
||||
begin++;
|
||||
while( begin < end && ( ( *begin == '0' || *begin == '1' ) || *begin == '\'' ) ) begin++;
|
||||
}
|
||||
}
|
||||
if( !isBinary )
|
||||
{
|
||||
if( begin < end && ( *begin == 'e' || *begin == 'E' || *begin == 'p' || *begin == 'P' ) )
|
||||
{
|
||||
isFloat = true;
|
||||
begin++;
|
||||
if( begin < end && ( *begin == '+' || *begin == '-' ) ) begin++;
|
||||
bool hasDigits = false;
|
||||
while( begin < end && ( ( *begin >= '0' && *begin <= '9' ) || ( *begin >= 'a' && *begin <= 'f' ) || ( *begin >= 'A' && *begin <= 'F' ) || *begin == '\'' ) )
|
||||
{
|
||||
hasDigits = true;
|
||||
begin++;
|
||||
}
|
||||
if( !hasDigits ) return false;
|
||||
}
|
||||
if( begin < end && ( *begin == 'f' || *begin == 'F' || *begin == 'l' || *begin == 'L' ) ) begin++;
|
||||
}
|
||||
if( !isFloat )
|
||||
{
|
||||
while( begin < end && ( *begin == 'u' || *begin == 'U' || *begin == 'l' || *begin == 'L' ) ) begin++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Tokenizer::TokenColor Tokenizer::IdentifyToken( const char*& begin, const char* end )
|
||||
{
|
||||
static const auto s_keywords = GetKeywords();
|
||||
static const auto s_types = GetTypes();
|
||||
static const auto s_special = GetSpecial();
|
||||
|
||||
if( *begin == '"' )
|
||||
{
|
||||
begin++;
|
||||
while( begin < end )
|
||||
{
|
||||
if( *begin == '"' )
|
||||
{
|
||||
begin++;
|
||||
break;
|
||||
}
|
||||
begin += 1 + ( *begin == '\\' && end - begin > 1 && *(begin+1) == '"' );
|
||||
}
|
||||
return TokenColor::String;
|
||||
}
|
||||
if( *begin == '\'' )
|
||||
{
|
||||
begin++;
|
||||
if( begin < end && *begin == '\\' ) begin++;
|
||||
if( begin < end ) begin++;
|
||||
if( begin < end && *begin == '\'' ) begin++;
|
||||
return TokenColor::CharacterLiteral;
|
||||
}
|
||||
if( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) || *begin == '_' )
|
||||
{
|
||||
const char* tmp = begin;
|
||||
begin++;
|
||||
while( begin < end && ( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) || ( *begin >= '0' && *begin <= '9' ) || *begin == '_' ) ) begin++;
|
||||
if( begin - tmp <= 24 )
|
||||
{
|
||||
char buf[25];
|
||||
memcpy( buf, tmp, begin-tmp );
|
||||
buf[begin-tmp] = '\0';
|
||||
if( s_keywords.find( buf ) != s_keywords.end() ) return TokenColor::Keyword;
|
||||
if( s_types.find( buf ) != s_types.end() ) return TokenColor::Type;
|
||||
if( s_special.find( buf ) != s_special.end() ) return TokenColor::Special;
|
||||
}
|
||||
return TokenColor::Default;
|
||||
}
|
||||
const char* tmp = begin;
|
||||
if( TokenizeNumber( begin, end ) ) return TokenColor::Number;
|
||||
begin = tmp;
|
||||
if( *begin == '/' && end - begin > 1 )
|
||||
{
|
||||
if( *(begin+1) == '/' )
|
||||
{
|
||||
begin = end;
|
||||
return TokenColor::Comment;
|
||||
}
|
||||
if( *(begin+1) == '*' )
|
||||
{
|
||||
begin += 2;
|
||||
for(;;)
|
||||
{
|
||||
while( begin < end && *begin != '*' ) begin++;
|
||||
if( begin == end )
|
||||
{
|
||||
m_isInComment = true;
|
||||
return TokenColor::Comment;
|
||||
}
|
||||
begin++;
|
||||
if( begin < end && *begin == '/' )
|
||||
{
|
||||
begin++;
|
||||
return TokenColor::Comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while( begin < end )
|
||||
{
|
||||
switch( *begin )
|
||||
{
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
case '!':
|
||||
case '%':
|
||||
case '^':
|
||||
case '&':
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
case '-':
|
||||
case '+':
|
||||
case '=':
|
||||
case '~':
|
||||
case '|':
|
||||
case '<':
|
||||
case '>':
|
||||
case '?':
|
||||
case ':':
|
||||
case '/':
|
||||
case ';':
|
||||
case ',':
|
||||
case '.':
|
||||
begin++;
|
||||
break;
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
if( begin != tmp ) return TokenColor::Punctuation;
|
||||
begin = end;
|
||||
return TokenColor::Default;
|
||||
}
|
||||
|
||||
std::vector<Tokenizer::AsmToken> Tokenizer::TokenizeAsm( const char* begin, const char* end )
|
||||
{
|
||||
std::vector<AsmToken> ret;
|
||||
while( begin != end )
|
||||
{
|
||||
while( begin != end && isspace( (uint8_t)*begin ) ) begin++;
|
||||
const auto pos = begin;
|
||||
const auto col = IdentifyAsmToken( begin, end );
|
||||
ret.emplace_back( AsmToken { pos, begin, col } );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tokenizer::AsmTokenColor Tokenizer::IdentifyAsmToken( const char*& begin, const char* end )
|
||||
{
|
||||
static const auto s_regs = GetAsmRegs();
|
||||
static const auto s_sizes = GetAsmSizeDirectives();
|
||||
|
||||
while( begin < end && *begin == ' ' ) begin++;
|
||||
if( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) )
|
||||
{
|
||||
const char* tmp = begin;
|
||||
begin++;
|
||||
while( begin < end && ( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) || ( *begin >= '0' && *begin <= '9' ) || *begin == '_' ) ) begin++;
|
||||
if( begin - tmp <= 10 )
|
||||
{
|
||||
char buf[11];
|
||||
memcpy( buf, tmp, begin-tmp );
|
||||
buf[begin-tmp] = '\0';
|
||||
if( s_regs.find( buf ) != s_regs.end() ) return AsmTokenColor::Register;
|
||||
if( s_sizes.find( buf ) != s_sizes.end() )
|
||||
{
|
||||
if( end - begin >= 4 && memcmp( begin, " ptr", 4 ) == 0 )
|
||||
{
|
||||
begin += 4;
|
||||
return AsmTokenColor::SizeDirective;
|
||||
}
|
||||
}
|
||||
}
|
||||
return AsmTokenColor::Default;
|
||||
}
|
||||
else if( *begin >= '0' && *begin <= '9' )
|
||||
{
|
||||
while( begin < end && ( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) || ( *begin >= '0' && *begin <= '9' ) || *begin == '_' ) ) begin++;
|
||||
return AsmTokenColor::Literal;
|
||||
}
|
||||
else
|
||||
{
|
||||
while( begin < end && !( ( *begin >= 'a' && *begin <= 'z' ) || ( *begin >= 'A' && *begin <= 'Z' ) || ( *begin >= '0' && *begin <= '9' ) || *begin == '_' ) ) begin++;
|
||||
return AsmTokenColor::Default;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef __TRACYSOURCETOKENIZER_HPP__
|
||||
#define __TRACYSOURCETOKENIZER_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class Tokenizer
|
||||
{
|
||||
public:
|
||||
enum class TokenColor : uint8_t
|
||||
{
|
||||
Default,
|
||||
Comment,
|
||||
Preprocessor,
|
||||
String,
|
||||
CharacterLiteral,
|
||||
Keyword,
|
||||
Number,
|
||||
Punctuation,
|
||||
Type,
|
||||
Special
|
||||
};
|
||||
|
||||
struct Token
|
||||
{
|
||||
const char* begin;
|
||||
const char* end;
|
||||
TokenColor color;
|
||||
};
|
||||
|
||||
struct Line
|
||||
{
|
||||
const char* begin;
|
||||
const char* end;
|
||||
std::vector<Token> tokens;
|
||||
};
|
||||
|
||||
enum class AsmTokenColor : uint8_t
|
||||
{
|
||||
Label, // no-op, padding
|
||||
Default, // '+', '[', '*', etc
|
||||
SizeDirective, // byte, word, dword, etc
|
||||
Register, // rax, rip, etc
|
||||
Literal, // 0x04, etc
|
||||
};
|
||||
|
||||
struct AsmToken
|
||||
{
|
||||
const char* begin;
|
||||
const char* end;
|
||||
AsmTokenColor color;
|
||||
};
|
||||
|
||||
Tokenizer();
|
||||
|
||||
std::vector<Token> Tokenize( const char* begin, const char* end );
|
||||
std::vector<AsmToken> TokenizeAsm( const char* begin, const char* end );
|
||||
|
||||
private:
|
||||
TokenColor IdentifyToken( const char*& begin, const char* end );
|
||||
AsmTokenColor IdentifyAsmToken( const char*& begin, const char* end );
|
||||
|
||||
bool m_isInComment;
|
||||
bool m_isInPreprocessor;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
5745
subprojects/tracy/profiler/src/profiler/TracySourceView.cpp
Normal file
5745
subprojects/tracy/profiler/src/profiler/TracySourceView.cpp
Normal file
File diff suppressed because it is too large
Load Diff
305
subprojects/tracy/profiler/src/profiler/TracySourceView.hpp
Normal file
305
subprojects/tracy/profiler/src/profiler/TracySourceView.hpp
Normal file
@@ -0,0 +1,305 @@
|
||||
#ifndef __TRACYSOURCEVIEW_HPP__
|
||||
#define __TRACYSOURCEVIEW_HPP__
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "tracy_robin_hood.h"
|
||||
#include "TracyCharUtil.hpp"
|
||||
#include "TracyDecayValue.hpp"
|
||||
#include "TracySourceContents.hpp"
|
||||
#include "TracySourceTokenizer.hpp"
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
#include "../public/common/TracyProtocol.hpp"
|
||||
|
||||
struct ImFont;
|
||||
struct ImVec2;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class View;
|
||||
class Worker;
|
||||
struct CallstackFrameData;
|
||||
|
||||
class SourceView
|
||||
{
|
||||
public:
|
||||
enum class RegsX86 : uint8_t
|
||||
{
|
||||
invalid, flags,
|
||||
rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15,
|
||||
mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7,
|
||||
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9,
|
||||
xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm16, xmm17, xmm18, xmm19,
|
||||
xmm20, xmm21, xmm22, xmm23, xmm24, xmm25, xmm26, xmm27, xmm28, xmm29,
|
||||
xmm30, xmm31, k0, k1, k2, k3, k4, k5, k6, k7,
|
||||
NUMBER_OF_ENTRIES
|
||||
};
|
||||
|
||||
enum class CostType
|
||||
{
|
||||
SampleCount,
|
||||
Cycles,
|
||||
SlowBranches,
|
||||
SlowCache,
|
||||
Retirements,
|
||||
BranchesTaken,
|
||||
BranchMiss,
|
||||
CacheAccess,
|
||||
CacheMiss
|
||||
};
|
||||
|
||||
private:
|
||||
struct AsmOpParams
|
||||
{
|
||||
uint8_t type;
|
||||
uint16_t width;
|
||||
};
|
||||
|
||||
enum class LeaData : uint8_t
|
||||
{
|
||||
none,
|
||||
b,
|
||||
bd,
|
||||
bi,
|
||||
bid,
|
||||
d,
|
||||
i,
|
||||
id,
|
||||
r,
|
||||
rd
|
||||
};
|
||||
|
||||
enum { ReadBit = 0x100 };
|
||||
enum { WriteBit = 0x200 };
|
||||
enum { ReuseBit = 0x400 };
|
||||
enum { RegMask = 0x0FF };
|
||||
enum { FlagMask = 0xF00 };
|
||||
|
||||
enum class OpType : uint8_t
|
||||
{
|
||||
None,
|
||||
Jump,
|
||||
Branch,
|
||||
Call,
|
||||
Ret,
|
||||
Privileged
|
||||
};
|
||||
|
||||
struct AsmLine
|
||||
{
|
||||
uint64_t addr;
|
||||
uint64_t jumpAddr;
|
||||
std::string mnemonic;
|
||||
std::string operands;
|
||||
uint8_t len;
|
||||
LeaData leaData;
|
||||
OpType opType;
|
||||
bool jumpConditional;
|
||||
std::vector<AsmOpParams> params;
|
||||
std::vector<Tokenizer::AsmToken> opTokens;
|
||||
union
|
||||
{
|
||||
RegsX86 readX86[12];
|
||||
};
|
||||
union
|
||||
{
|
||||
RegsX86 writeX86[20];
|
||||
};
|
||||
uint16_t regData[20];
|
||||
};
|
||||
|
||||
enum { AsmLineSize = sizeof( AsmLine ) };
|
||||
|
||||
struct JumpData
|
||||
{
|
||||
uint64_t min;
|
||||
uint64_t max;
|
||||
size_t level;
|
||||
std::vector<uint64_t> source;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DisplaySource,
|
||||
DisplayAsm,
|
||||
DisplayMixed
|
||||
};
|
||||
|
||||
struct AddrStat
|
||||
{
|
||||
uint64_t local;
|
||||
uint64_t ext;
|
||||
|
||||
AddrStat& operator+=( const AddrStat& other )
|
||||
{
|
||||
local += other.local;
|
||||
ext += other.ext;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct AddrStatData
|
||||
{
|
||||
AddrStat ipTotalSrc = {};
|
||||
AddrStat ipTotalAsm = {};
|
||||
AddrStat ipMaxSrc = {};
|
||||
AddrStat ipMaxAsm = {};
|
||||
AddrStat hwMaxSrc = {};
|
||||
AddrStat hwMaxAsm = {};
|
||||
unordered_flat_map<uint64_t, AddrStat> ipCountSrc, ipCountAsm;
|
||||
unordered_flat_map<uint64_t, AddrStat> hwCountSrc, hwCountAsm;
|
||||
};
|
||||
|
||||
struct History
|
||||
{
|
||||
const char* fileName;
|
||||
int64_t line;
|
||||
uint64_t baseAddr;
|
||||
uint64_t symAddr;
|
||||
};
|
||||
|
||||
public:
|
||||
SourceView();
|
||||
|
||||
void UpdateFont( ImFont* fixed, ImFont* small, ImFont* big ) { m_font = fixed; m_smallFont = small; m_bigFont = big; }
|
||||
void SetCpuId( uint32_t cpuid );
|
||||
|
||||
void OpenSource( const char* fileName, int line, const View& view, const Worker& worker );
|
||||
void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view, bool updateHistory = true );
|
||||
void Render( Worker& worker, View& view );
|
||||
|
||||
void CalcInlineStats( bool val ) { m_calcInlineStats = val; }
|
||||
bool IsSymbolView() const { return !m_asm.empty(); }
|
||||
|
||||
private:
|
||||
void ParseSource( const char* fileName, const Worker& worker, const View& view );
|
||||
bool Disassemble( uint64_t symAddr, const Worker& worker );
|
||||
|
||||
void SelectViewMode();
|
||||
|
||||
void RenderSimpleSourceView();
|
||||
void RenderSymbolView( Worker& worker, View& view );
|
||||
|
||||
void RenderSymbolSourceView( const AddrStatData& as, Worker& worker, const View& view, bool hasInlines );
|
||||
uint64_t RenderSymbolAsmView( const AddrStatData& as, Worker& worker, View& view );
|
||||
|
||||
void RenderLine( const Tokenizer::Line& line, int lineNum, const AddrStat& ipcnt, const AddrStatData& as, Worker* worker, const View* view );
|
||||
void RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStatData& as, Worker& worker, uint64_t& jumpOut, int maxAddrLen, int maxAddrLenRel, View& view );
|
||||
void RenderHwLinePart( size_t cycles, size_t retired, size_t branchRetired, size_t branchMiss, size_t cacheRef, size_t cacheMiss, size_t branchRel, size_t branchRelMax, size_t cacheRel, size_t cacheRelMax, const ImVec2& ts );
|
||||
|
||||
void SelectLine( uint32_t line, const Worker* worker, bool updateAsmLine = true, uint64_t targetAddr = 0, bool changeAsmLine = true );
|
||||
void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool updateAsmLine = true, uint64_t targetAddr = 0, bool changeAsmLine = true );
|
||||
void SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker& worker );
|
||||
|
||||
void GatherIpHwStats( AddrStatData& as, Worker& worker, const View& view, CostType cost );
|
||||
void GatherIpStats( uint64_t baseAddr, AddrStatData& as, const Worker& worker, bool limitView, const View& view );
|
||||
void GatherAdditionalIpStats( uint64_t baseAddr, AddrStatData& as, const Worker& worker, bool limitView, const View& view );
|
||||
void GatherChildStats( uint64_t baseAddr, unordered_flat_map<uint64_t, uint32_t>& vec, Worker& worker, bool limitView, const View& view );
|
||||
|
||||
uint32_t CountAsmIpStats( uint64_t baseAddr, const Worker& worker, bool limitView, const View& view );
|
||||
void CountHwStats( AddrStatData& as, Worker& worker, const View& view );
|
||||
|
||||
void SelectMicroArchitecture( const char* moniker );
|
||||
|
||||
void ResetAsm();
|
||||
void FollowRead( size_t line, RegsX86 reg, size_t limit );
|
||||
void FollowWrite( size_t line, RegsX86 reg, size_t limit );
|
||||
void CheckRead( size_t line, RegsX86 reg, size_t limit );
|
||||
void CheckWrite( size_t line, RegsX86 reg, size_t limit );
|
||||
|
||||
bool IsInContext( const Worker& worker, uint64_t addr ) const;
|
||||
const std::vector<uint64_t>* GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line, const Worker& worker );
|
||||
|
||||
tracy_force_inline float CalcJumpSeparation( float scale );
|
||||
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
void Save( const Worker& worker, size_t start = 0, size_t stop = std::numeric_limits<size_t>::max() );
|
||||
#endif
|
||||
|
||||
tracy_force_inline void SetFont();
|
||||
tracy_force_inline void UnsetFont();
|
||||
|
||||
ImFont* m_font;
|
||||
ImFont* m_smallFont;
|
||||
ImFont* m_bigFont;
|
||||
uint64_t m_symAddr;
|
||||
uint64_t m_baseAddr;
|
||||
uint64_t m_targetAddr;
|
||||
int m_targetLine;
|
||||
int m_selectedLine;
|
||||
int m_asmSelected;
|
||||
DecayValue<int> m_hoveredLine;
|
||||
DecayValue<uint32_t> m_hoveredSource;
|
||||
int m_displayMode;
|
||||
uint32_t m_codeLen;
|
||||
int32_t m_disasmFail;
|
||||
DecayValue<uint64_t> m_highlightAddr;
|
||||
int m_asmCountBase;
|
||||
bool m_asmRelative;
|
||||
bool m_asmBytes;
|
||||
bool m_asmShowSourceLocation;
|
||||
bool m_calcInlineStats;
|
||||
uint8_t m_maxAsmBytes;
|
||||
uint64_t m_jumpPopupAddr;
|
||||
const CallstackFrameData* m_localCallstackPopup;
|
||||
bool m_hwSamples, m_hwSamplesRelative;
|
||||
bool m_childCalls;
|
||||
bool m_childCallList;
|
||||
bool m_propagateInlines;
|
||||
CostType m_cost;
|
||||
|
||||
SourceContents m_source;
|
||||
SourceContents m_sourceTooltip;
|
||||
std::vector<AsmLine> m_asm;
|
||||
|
||||
unordered_flat_map<uint64_t, uint32_t> m_locMap;
|
||||
unordered_flat_map<uint64_t, JumpData> m_jumpTable;
|
||||
unordered_flat_set<uint64_t> m_jumpOut;
|
||||
size_t m_maxJumpLevel;
|
||||
bool m_showJumps;
|
||||
|
||||
unordered_flat_map<uint64_t, std::vector<uint64_t>> m_locationAddress;
|
||||
bool m_locAddrIsProp;
|
||||
|
||||
unordered_flat_map<uint32_t, uint32_t> m_sourceFiles;
|
||||
unordered_flat_set<uint64_t> m_selectedAddresses;
|
||||
unordered_flat_set<uint64_t> m_selectedAddressesHover;
|
||||
|
||||
uint32_t m_maxLine;
|
||||
int m_maxMnemonicLen;
|
||||
int m_maxOperandLen;
|
||||
|
||||
unordered_flat_map<const char*, int, charutil::Hasher, charutil::Comparator> m_microArchOpMap;
|
||||
CpuArchitecture m_cpuArch;
|
||||
int m_selMicroArch;
|
||||
int m_idxMicroArch, m_profileMicroArch;
|
||||
|
||||
unordered_flat_set<uint32_t> m_asmSampleSelect;
|
||||
unordered_flat_set<uint32_t> m_srcSampleSelect;
|
||||
int32_t m_asmGroupSelect = -1;
|
||||
int32_t m_srcGroupSelect = -1;
|
||||
|
||||
float m_srcWidth;
|
||||
float m_asmWidth;
|
||||
float m_jumpOffset;
|
||||
|
||||
Tokenizer m_tokenizer;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t file = 0;
|
||||
uint32_t line = 0;
|
||||
size_t sel;
|
||||
std::vector<uint64_t> target;
|
||||
} m_asmTarget;
|
||||
|
||||
std::vector<History> m_history;
|
||||
size_t m_historyCursor = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
211
subprojects/tracy/profiler/src/profiler/TracyStorage.cpp
Normal file
211
subprojects/tracy/profiler/src/profiler/TracyStorage.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
#ifdef __MINGW32__
|
||||
# define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <direct.h>
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <dirent.h>
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "TracyStorage.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static bool CreateDirStruct( const std::string& path )
|
||||
{
|
||||
struct stat buf;
|
||||
if( stat( path.c_str(), &buf ) == 0 ) return true;
|
||||
|
||||
if( errno != ENOENT )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
do
|
||||
{
|
||||
pos = path.find( '/', pos+1 );
|
||||
#ifdef _WIN32
|
||||
if( pos == 2 && path[1] == ':' ) continue; // Don't create drive name.
|
||||
if( _mkdir( path.substr( 0, pos ).c_str() ) != 0 )
|
||||
#else
|
||||
if( mkdir( path.substr( 0, pos ).c_str(), S_IRWXU ) != 0 )
|
||||
#endif
|
||||
{
|
||||
if( errno != EEXIST )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
while( pos != std::string::npos );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void GetConfigDirectory( char* buf, size_t& sz )
|
||||
{
|
||||
#ifdef _WIN32
|
||||
auto path = getenv( "APPDATA" );
|
||||
sz = strlen( path );
|
||||
memcpy( buf, path, sz );
|
||||
|
||||
for( size_t i=0; i<sz; i++ )
|
||||
{
|
||||
if( buf[i] == '\\' )
|
||||
{
|
||||
buf[i] = '/';
|
||||
}
|
||||
}
|
||||
#else
|
||||
auto path = getenv( "XDG_CONFIG_HOME" );
|
||||
if( path && *path )
|
||||
{
|
||||
sz = strlen( path );
|
||||
memcpy( buf, path, sz );
|
||||
}
|
||||
else
|
||||
{
|
||||
path = getenv( "HOME" );
|
||||
assert( path && *path );
|
||||
|
||||
sz = strlen( path );
|
||||
memcpy( buf, path, sz );
|
||||
memcpy( buf+sz, "/.config", 8 );
|
||||
sz += 8;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* GetSavePath( const char* file )
|
||||
{
|
||||
assert( file && *file );
|
||||
|
||||
enum { Pool = 8 };
|
||||
enum { MaxPath = 512 };
|
||||
static char bufpool[Pool][MaxPath];
|
||||
static int bufsel = 0;
|
||||
char* buf = bufpool[bufsel];
|
||||
bufsel = ( bufsel + 1 ) % Pool;
|
||||
|
||||
size_t sz;
|
||||
GetConfigDirectory( buf, sz );
|
||||
|
||||
memcpy( buf+sz, "/tracy/", 8 );
|
||||
sz += 7;
|
||||
|
||||
auto status = CreateDirStruct( buf );
|
||||
assert( status );
|
||||
|
||||
const auto fsz = strlen( file );
|
||||
assert( sz + fsz < MaxPath );
|
||||
memcpy( buf+sz, file, fsz+1 );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char* GetSavePath( const char* program, uint64_t time, const char* file, bool create )
|
||||
{
|
||||
assert( program && *program );
|
||||
|
||||
enum { Pool = 8 };
|
||||
enum { MaxPath = 512 };
|
||||
static char bufpool[Pool][MaxPath];
|
||||
static int bufsel = 0;
|
||||
char* buf = bufpool[bufsel];
|
||||
bufsel = ( bufsel + 1 ) % Pool;
|
||||
|
||||
size_t sz;
|
||||
GetConfigDirectory( buf, sz );
|
||||
|
||||
const auto psz = strlen( program );
|
||||
assert( psz < 512 );
|
||||
char tmp[512];
|
||||
strcpy( tmp, program );
|
||||
for( size_t i=0; i<psz; i++ )
|
||||
{
|
||||
switch( tmp[i] )
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 0x7F:
|
||||
case '<':
|
||||
case '>':
|
||||
case ':':
|
||||
case '"':
|
||||
case '/':
|
||||
case '\\':
|
||||
case '|':
|
||||
case '?':
|
||||
case '*':
|
||||
tmp[i] = '_';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 604800 = 7 days
|
||||
sz += sprintf( buf+sz, "/tracy/user/%c/%s/%" PRIu64 "/%" PRIu64 "/", tmp[0], tmp, uint64_t( time / 604800 ), time );
|
||||
|
||||
if( create )
|
||||
{
|
||||
auto status = CreateDirStruct( buf );
|
||||
assert( status );
|
||||
}
|
||||
|
||||
if( file )
|
||||
{
|
||||
const auto fsz = strlen( file );
|
||||
assert( sz + fsz < MaxPath );
|
||||
memcpy( buf+sz, file, fsz+1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[sz] = '\0';
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
||||
14
subprojects/tracy/profiler/src/profiler/TracyStorage.hpp
Normal file
14
subprojects/tracy/profiler/src/profiler/TracyStorage.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __TRACYSTORAGE_HPP__
|
||||
#define __TRACYSTORAGE_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
const char* GetSavePath( const char* file );
|
||||
const char* GetSavePath( const char* program, uint64_t time, const char* file, bool create );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
187
subprojects/tracy/profiler/src/profiler/TracyTexture.cpp
Normal file
187
subprojects/tracy/profiler/src/profiler/TracyTexture.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
# include <emscripten/html5.h>
|
||||
# include <GLES2/gl2.h>
|
||||
#else
|
||||
# include "../profiler/src/imgui/imgui_impl_opengl3_loader.h"
|
||||
#endif
|
||||
#include "TracyTexture.hpp"
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
#ifndef COMPRESSED_RGB_S3TC_DXT1_EXT
|
||||
# define COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
#endif
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static bool s_hardwareS3tc;
|
||||
|
||||
void InitTexture()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
s_hardwareS3tc = emscripten_webgl_enable_extension( emscripten_webgl_get_current_context(), "WEBGL_compressed_texture_s3tc" );
|
||||
#else
|
||||
s_hardwareS3tc = false;
|
||||
GLint num;
|
||||
glGetIntegerv( GL_NUM_EXTENSIONS, &num );
|
||||
for( GLint i=0; i<num; i++ )
|
||||
{
|
||||
auto ext = (const char*)glGetStringi( GL_EXTENSIONS, GLuint( i ) );
|
||||
if( strcmp( ext, "GL_EXT_texture_compression_s3tc" ) == 0 )
|
||||
{
|
||||
s_hardwareS3tc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void* MakeTexture( bool zigzag )
|
||||
{
|
||||
GLuint tex;
|
||||
glGenTextures( 1, &tex );
|
||||
glBindTexture( GL_TEXTURE_2D, tex );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, zigzag ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, zigzag ? GL_REPEAT : GL_CLAMP_TO_EDGE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
return (void*)(intptr_t)tex;
|
||||
}
|
||||
|
||||
void FreeTexture( void* _tex, void(*runOnMainThread)(const std::function<void()>&, bool) )
|
||||
{
|
||||
auto tex = (GLuint)(intptr_t)_tex;
|
||||
runOnMainThread( [tex] { glDeleteTextures( 1, &tex ); }, false );
|
||||
}
|
||||
|
||||
static tracy_force_inline void DecodeDxt1Part( uint64_t d, uint32_t* dst, uint32_t w )
|
||||
{
|
||||
uint8_t* in = (uint8_t*)&d;
|
||||
uint16_t c0, c1;
|
||||
uint32_t idx;
|
||||
memcpy( &c0, in, 2 );
|
||||
memcpy( &c1, in+2, 2 );
|
||||
memcpy( &idx, in+4, 4 );
|
||||
|
||||
uint8_t r0 = ( ( c0 & 0xF800 ) >> 8 ) | ( ( c0 & 0xF800 ) >> 13 );
|
||||
uint8_t g0 = ( ( c0 & 0x07E0 ) >> 3 ) | ( ( c0 & 0x07E0 ) >> 9 );
|
||||
uint8_t b0 = ( ( c0 & 0x001F ) << 3 ) | ( ( c0 & 0x001F ) >> 2 );
|
||||
|
||||
uint8_t r1 = ( ( c1 & 0xF800 ) >> 8 ) | ( ( c1 & 0xF800 ) >> 13 );
|
||||
uint8_t g1 = ( ( c1 & 0x07E0 ) >> 3 ) | ( ( c1 & 0x07E0 ) >> 9 );
|
||||
uint8_t b1 = ( ( c1 & 0x001F ) << 3 ) | ( ( c1 & 0x001F ) >> 2 );
|
||||
|
||||
uint32_t dict[4];
|
||||
|
||||
dict[0] = 0xFF000000 | ( b0 << 16 ) | ( g0 << 8 ) | r0;
|
||||
dict[1] = 0xFF000000 | ( b1 << 16 ) | ( g1 << 8 ) | r1;
|
||||
|
||||
uint32_t r, g, b;
|
||||
if( c0 > c1 )
|
||||
{
|
||||
r = (2*r0+r1)/3;
|
||||
g = (2*g0+g1)/3;
|
||||
b = (2*b0+b1)/3;
|
||||
dict[2] = 0xFF000000 | ( b << 16 ) | ( g << 8 ) | r;
|
||||
r = (2*r1+r0)/3;
|
||||
g = (2*g1+g0)/3;
|
||||
b = (2*b1+b0)/3;
|
||||
dict[3] = 0xFF000000 | ( b << 16 ) | ( g << 8 ) | r;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (int(r0)+r1)/2;
|
||||
g = (int(g0)+g1)/2;
|
||||
b = (int(b0)+b1)/2;
|
||||
dict[2] = 0xFF000000 | ( b << 16 ) | ( g << 8 ) | r;
|
||||
dict[3] = 0xFF000000;
|
||||
}
|
||||
|
||||
memcpy( dst+0, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+1, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+2, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+3, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
dst += w;
|
||||
|
||||
memcpy( dst+0, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+1, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+2, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+3, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
dst += w;
|
||||
|
||||
memcpy( dst+0, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+1, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+2, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+3, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
dst += w;
|
||||
|
||||
memcpy( dst+0, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+1, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+2, dict + (idx & 0x3), 4 );
|
||||
idx >>= 2;
|
||||
memcpy( dst+3, dict + (idx & 0x3), 4 );
|
||||
}
|
||||
|
||||
void UpdateTexture( void* _tex, const char* data, int w, int h )
|
||||
{
|
||||
auto tex = (GLuint)(intptr_t)_tex;
|
||||
glBindTexture( GL_TEXTURE_2D, tex );
|
||||
if( s_hardwareS3tc )
|
||||
{
|
||||
glCompressedTexImage2D( GL_TEXTURE_2D, 0, COMPRESSED_RGB_S3TC_DXT1_EXT, w, h, 0, w * h / 2, data );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto tmp = new uint32_t[w*h];
|
||||
auto src = (const uint64_t*)data;
|
||||
auto dst = tmp;
|
||||
for( int y=0; y<h/4; y++ )
|
||||
{
|
||||
for( int x=0; x<w/4; x++ )
|
||||
{
|
||||
uint64_t d = *src++;
|
||||
DecodeDxt1Part( d, dst, w );
|
||||
dst += 4;
|
||||
}
|
||||
dst += w*3;
|
||||
}
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp );
|
||||
delete[] tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTextureRGBA( void* _tex, void* data, int w, int h )
|
||||
{
|
||||
auto tex = (GLuint)(intptr_t)_tex;
|
||||
glBindTexture( GL_TEXTURE_2D, tex );
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
|
||||
}
|
||||
|
||||
void UpdateTextureRGBAMips( void* _tex, void** data, int* w, int* h, size_t mips )
|
||||
{
|
||||
auto tex = (GLuint)(intptr_t)_tex;
|
||||
glBindTexture( GL_TEXTURE_2D, tex );
|
||||
for( size_t i=0; i<mips; i++ )
|
||||
{
|
||||
glTexImage2D( GL_TEXTURE_2D, i, GL_RGBA, w[i], h[i], 0, GL_RGBA, GL_UNSIGNED_BYTE, data[i] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
subprojects/tracy/profiler/src/profiler/TracyTexture.hpp
Normal file
18
subprojects/tracy/profiler/src/profiler/TracyTexture.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __TRACYTEXTURE_HPP__
|
||||
#define __TRACYTEXTURE_HPP__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
void InitTexture();
|
||||
void* MakeTexture( bool zigzag = false );
|
||||
void FreeTexture( void* tex, void(*runOnMainThread)(const std::function<void()>&, bool) );
|
||||
void UpdateTexture( void* tex, const char* data, int w, int h );
|
||||
void UpdateTextureRGBA( void* tex, void* data, int w, int h );
|
||||
void UpdateTextureRGBAMips( void* tex, void** data, int* w, int* h, size_t mips );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef __TRACYTIMELINECONTEXT_HPP__
|
||||
#define __TRACYTIMELINECONTEXT_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct TimelineContext
|
||||
{
|
||||
float w, ty, sty, scale;
|
||||
float yMin, yMax;
|
||||
double pxns, nspx;
|
||||
int64_t vStart, vEnd;
|
||||
ImVec2 wpos;
|
||||
bool hover;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,177 @@
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
#include "TracyTimelineItem.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineController.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TimelineController::TimelineController( View& view, Worker& worker, bool threading )
|
||||
: m_height( 0 )
|
||||
, m_scroll( 0 )
|
||||
, m_centerItemkey( nullptr )
|
||||
, m_centerItemOffsetY( 0 )
|
||||
, m_firstFrame( true )
|
||||
, m_view( view )
|
||||
, m_worker( worker )
|
||||
#ifdef __EMSCRIPTEN__
|
||||
, m_td( 0, "Render" )
|
||||
#else
|
||||
, m_td( threading ? (size_t)std::max( 0, ( (int)std::thread::hardware_concurrency() - 2 ) / 2 ) : 0, "Render" )
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
TimelineController::~TimelineController()
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineController::FirstFrameExpired()
|
||||
{
|
||||
m_firstFrame = false;
|
||||
}
|
||||
|
||||
void TimelineController::Begin()
|
||||
{
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
void TimelineController::UpdateCenterItem()
|
||||
{
|
||||
ImVec2 mousePos = ImGui::GetMousePos();
|
||||
|
||||
m_centerItemkey = nullptr;
|
||||
m_centerItemOffsetY = 0;
|
||||
|
||||
if( m_firstFrame || !ImGui::IsMousePosValid( &mousePos ) ) return;
|
||||
|
||||
const auto timelineMousePosY = mousePos.y - ImGui::GetWindowPos().y;
|
||||
int centerY = timelineMousePosY + ImGui::GetScrollY();
|
||||
|
||||
int yBegin = 0;
|
||||
int yEnd = 0;
|
||||
for( auto& item : m_items )
|
||||
{
|
||||
m_centerItemkey = item->GetKey();
|
||||
yBegin = yEnd;
|
||||
yEnd += item->GetHeight();
|
||||
|
||||
const auto inLowerBounds = m_centerItemkey == m_items.front()->GetKey() || yBegin <= centerY;
|
||||
const auto inUpperBounds = m_centerItemkey == m_items.back()->GetKey() || centerY < yEnd;
|
||||
|
||||
if( inLowerBounds && inUpperBounds )
|
||||
{
|
||||
m_centerItemOffsetY = centerY - yBegin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<int> TimelineController::CalculateScrollPosition() const
|
||||
{
|
||||
if( !m_centerItemkey ) return std::nullopt;
|
||||
|
||||
ImVec2 mousePos = ImGui::GetMousePos();
|
||||
|
||||
if( !ImGui::IsMousePosValid( &mousePos ) ) return std::nullopt;
|
||||
|
||||
const auto timelineMousePosY = mousePos.y - ImGui::GetWindowPos().y;
|
||||
|
||||
int yBegin = 0;
|
||||
int yEnd = 0;
|
||||
for( auto& item : m_items )
|
||||
{
|
||||
yBegin = yEnd;
|
||||
yEnd += item->GetHeight();
|
||||
|
||||
if( item->GetKey() != m_centerItemkey ) continue;
|
||||
|
||||
int scrollY = yBegin + m_centerItemOffsetY - timelineMousePosY;
|
||||
|
||||
return scrollY;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool vcenter, float yMin, float yMax, ImFont* smallFont )
|
||||
{
|
||||
auto shouldUpdateCenterItem = [&] () {
|
||||
const auto imguiChangedScroll = m_scroll != ImGui::GetScrollY();
|
||||
const auto& mouseDelta = ImGui::GetIO().MouseDelta;
|
||||
const auto mouseMoved = mouseDelta.x != 0.0f || mouseDelta.y != 0.0f;
|
||||
const auto& mousePos = ImGui::GetIO().MousePos;
|
||||
const auto mouseVisible = ImGui::IsMousePosValid( &mousePos );
|
||||
return ( ( imguiChangedScroll || mouseMoved || !mouseVisible ) && !ImGui::IsMouseDown( 1 ) ) || !m_centerItemkey;
|
||||
};
|
||||
|
||||
if( !vcenter )
|
||||
{
|
||||
m_centerItemkey = nullptr;
|
||||
m_centerItemOffsetY = 0;
|
||||
}
|
||||
else if( shouldUpdateCenterItem() )
|
||||
{
|
||||
UpdateCenterItem();
|
||||
}
|
||||
|
||||
const auto& viewData = m_view.GetViewData();
|
||||
|
||||
TimelineContext ctx;
|
||||
ctx.w = ImGui::GetContentRegionAvail().x - 1;
|
||||
ctx.ty = ImGui::GetTextLineHeight();
|
||||
ImGui::PushFont( smallFont );
|
||||
ctx.sty = ImGui::GetTextLineHeight();
|
||||
ImGui::PopFont();
|
||||
ctx.scale = GetScale();
|
||||
ctx.yMin = yMin;
|
||||
ctx.yMax = yMax;
|
||||
ctx.pxns = pxns;
|
||||
ctx.nspx = 1.0 / pxns;
|
||||
ctx.vStart = viewData.zvStart;
|
||||
ctx.vEnd = viewData.zvEnd;
|
||||
ctx.wpos = wpos;
|
||||
ctx.hover = hover;
|
||||
|
||||
int yOffset = 0;
|
||||
for( auto& item : m_items )
|
||||
{
|
||||
if( item->WantPreprocess() && item->IsVisible() )
|
||||
{
|
||||
const auto yPos = wpos.y + yOffset;
|
||||
const bool visible = m_firstFrame || ( yPos < yMax && yPos + item->GetHeight() >= yMin );
|
||||
item->Preprocess( ctx, m_td, visible, yPos );
|
||||
}
|
||||
yOffset += m_firstFrame ? 0 : item->GetHeight();
|
||||
}
|
||||
m_td.Sync();
|
||||
|
||||
yOffset = 0;
|
||||
for( auto& item : m_items )
|
||||
{
|
||||
auto currentFrameItemHeight = item->GetHeight();
|
||||
item->Draw( m_firstFrame, ctx, yOffset );
|
||||
if( m_firstFrame ) currentFrameItemHeight = item->GetHeight();
|
||||
yOffset += currentFrameItemHeight;
|
||||
}
|
||||
|
||||
if( const auto scrollY = CalculateScrollPosition() )
|
||||
{
|
||||
int clampedScrollY = std::min<int>( *scrollY, std::max<int>( yOffset - ImGui::GetWindowHeight(), 0 ) );
|
||||
ImGui::SetScrollY( clampedScrollY );
|
||||
int minHeight = ImGui::GetWindowHeight() + clampedScrollY;
|
||||
yOffset = std::max( yOffset, minHeight );
|
||||
}
|
||||
|
||||
const auto scrollPos = ImGui::GetScrollY();
|
||||
if( ( scrollPos == 0 && m_scroll != 0 ) || yOffset > m_height )
|
||||
{
|
||||
m_height = yOffset;
|
||||
}
|
||||
m_scroll = scrollPos;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef __TRACYTIMELINECONTROLLER_HPP__
|
||||
#define __TRACYTIMELINECONTROLLER_HPP__
|
||||
|
||||
#include <assert.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "TracyImGui.hpp"
|
||||
#include "../server/TracyTaskDispatch.hpp"
|
||||
#include "../server/tracy_robin_hood.h"
|
||||
#include "../public/common/TracyForceInline.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TimelineItem;
|
||||
class View;
|
||||
class Worker;
|
||||
|
||||
class TimelineController
|
||||
{
|
||||
public:
|
||||
TimelineController( View& view, Worker& worker, bool threading );
|
||||
~TimelineController();
|
||||
|
||||
void FirstFrameExpired();
|
||||
void Begin();
|
||||
void End( double pxns, const ImVec2& wpos, bool hover, bool vcenter, float yMin, float yMax, ImFont* smallFont );
|
||||
|
||||
template<class T, class U>
|
||||
void AddItem( U* data )
|
||||
{
|
||||
auto it = m_itemMap.find( data );
|
||||
if( it == m_itemMap.end() ) it = m_itemMap.emplace( data, std::make_unique<T>( m_view, m_worker, data ) ).first;
|
||||
m_items.emplace_back( it->second.get() );
|
||||
}
|
||||
|
||||
float GetHeight() const { return m_height; }
|
||||
const unordered_flat_map<const void*, std::unique_ptr<TimelineItem>>& GetItemMap() const { return m_itemMap; }
|
||||
|
||||
tracy_force_inline TimelineItem& GetItem( const void* data )
|
||||
{
|
||||
auto it = m_itemMap.find( data );
|
||||
assert( it != m_itemMap.end() );
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateCenterItem();
|
||||
std::optional<int> CalculateScrollPosition() const;
|
||||
|
||||
std::vector<TimelineItem*> m_items;
|
||||
unordered_flat_map<const void*, std::unique_ptr<TimelineItem>> m_itemMap;
|
||||
|
||||
float m_height;
|
||||
float m_scroll;
|
||||
|
||||
const void* m_centerItemkey;
|
||||
int m_centerItemOffsetY;
|
||||
|
||||
bool m_firstFrame;
|
||||
|
||||
View& m_view;
|
||||
Worker& m_worker;
|
||||
|
||||
TaskDispatch m_td;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
104
subprojects/tracy/profiler/src/profiler/TracyTimelineDraw.hpp
Normal file
104
subprojects/tracy/profiler/src/profiler/TracyTimelineDraw.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef __TRACYTIMELINEDRAW_HPP__
|
||||
#define __TRACYTIMELINEDRAW_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyShortPtr.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
enum class TimelineDrawType : uint8_t
|
||||
{
|
||||
Folded,
|
||||
Zone,
|
||||
GhostFolded,
|
||||
Ghost
|
||||
};
|
||||
|
||||
struct TimelineDraw
|
||||
{
|
||||
TimelineDrawType type;
|
||||
uint16_t depth;
|
||||
short_ptr<void*> ev;
|
||||
Int48 rend;
|
||||
uint32_t num;
|
||||
};
|
||||
|
||||
|
||||
enum class ContextSwitchDrawType : uint8_t
|
||||
{
|
||||
Waiting,
|
||||
Folded,
|
||||
Running
|
||||
};
|
||||
|
||||
struct ContextSwitchDraw
|
||||
{
|
||||
ContextSwitchDrawType type;
|
||||
uint32_t idx;
|
||||
uint32_t data; // Folded: number of items -OR- Waiting: wait stack
|
||||
};
|
||||
|
||||
|
||||
struct SamplesDraw
|
||||
{
|
||||
uint32_t num;
|
||||
uint32_t idx;
|
||||
};
|
||||
|
||||
|
||||
struct MessagesDraw
|
||||
{
|
||||
short_ptr<MessageData> msg;
|
||||
bool highlight;
|
||||
uint32_t num;
|
||||
};
|
||||
|
||||
|
||||
struct CpuUsageDraw
|
||||
{
|
||||
int own;
|
||||
int other;
|
||||
};
|
||||
|
||||
|
||||
struct CpuCtxDraw
|
||||
{
|
||||
uint32_t idx;
|
||||
uint32_t num;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct LockState
|
||||
{
|
||||
enum Type : uint8_t
|
||||
{
|
||||
Nothing = 1 << 0,
|
||||
HasLock = 1 << 1, // green
|
||||
HasBlockingLock = 1 << 2, // yellow
|
||||
WaitLock = 1 << 3 // red
|
||||
};
|
||||
};
|
||||
|
||||
struct LockDrawItem
|
||||
{
|
||||
Int48 t1;
|
||||
LockState::Type state;
|
||||
uint32_t condensed;
|
||||
short_ptr<LockEventPtr> ptr, next;
|
||||
};
|
||||
|
||||
struct LockDraw
|
||||
{
|
||||
uint32_t id;
|
||||
bool forceDraw;
|
||||
uint8_t thread;
|
||||
std::vector<LockDrawItem> data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
167
subprojects/tracy/profiler/src/profiler/TracyTimelineItem.cpp
Normal file
167
subprojects/tracy/profiler/src/profiler/TracyTimelineItem.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TimelineItem::TimelineItem( View& view, Worker& worker, const void* key, bool wantPreprocess )
|
||||
: m_visible( true )
|
||||
, m_showFull( true )
|
||||
, m_height( 0 )
|
||||
, m_wantPreprocess( wantPreprocess )
|
||||
, m_key( key )
|
||||
, m_view( view )
|
||||
, m_worker( worker )
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffset )
|
||||
{
|
||||
const auto yBegin = yOffset;
|
||||
auto yEnd = yOffset;
|
||||
|
||||
if( !IsVisible() )
|
||||
{
|
||||
DrawFinished();
|
||||
if( m_height != 0 ) AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
||||
return;
|
||||
}
|
||||
if( IsEmpty() )
|
||||
{
|
||||
DrawFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto w = ctx.w;
|
||||
const auto ty = ctx.ty;
|
||||
const auto ostep = ty + 1;
|
||||
const auto& wpos = ctx.wpos;
|
||||
const auto yPos = wpos.y + yBegin;
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
|
||||
ImGui::PushID( this );
|
||||
ImGui::PushClipRect( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yBegin + m_height ), true );
|
||||
|
||||
yEnd += ostep;
|
||||
if( m_showFull )
|
||||
{
|
||||
if( !DrawContents( ctx, yEnd ) && !m_view.GetViewData().drawEmptyLabels )
|
||||
{
|
||||
DrawFinished();
|
||||
yEnd = yBegin;
|
||||
AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
||||
ImGui::PopClipRect();
|
||||
ImGui::PopID();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DrawOverlay( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yEnd ) );
|
||||
ImGui::PopClipRect();
|
||||
|
||||
float labelWidth;
|
||||
const auto hdrOffset = yBegin;
|
||||
const bool drawHeader = yPos + ty >= ctx.yMin && yPos <= ctx.yMax;
|
||||
if( drawHeader )
|
||||
{
|
||||
const auto color = HeaderColor();
|
||||
const auto colorInactive = HeaderColorInactive();
|
||||
|
||||
if( m_showFull )
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( 0, hdrOffset ), color, ICON_FA_CARET_DOWN );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( 0, hdrOffset ), colorInactive, ICON_FA_CARET_RIGHT );
|
||||
}
|
||||
const auto label = HeaderLabel();
|
||||
labelWidth = ImGui::CalcTextSize( label ).x;
|
||||
DrawTextContrast( draw, wpos + ImVec2( ty, hdrOffset ), m_showFull ? color : colorInactive, label );
|
||||
if( m_showFull )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 0, hdrOffset + ty - 1 ), dpos + ImVec2( w, hdrOffset + ty - 1 ), HeaderLineColor() );
|
||||
HeaderExtraContents( ctx, hdrOffset, labelWidth );
|
||||
}
|
||||
|
||||
if( ctx.hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) )
|
||||
{
|
||||
HeaderTooltip( label );
|
||||
|
||||
if( IsMouseClicked( 0 ) )
|
||||
{
|
||||
m_showFull = !m_showFull;
|
||||
}
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
const auto t0 = RangeBegin();
|
||||
const auto t1 = RangeEnd();
|
||||
if( t0 < t1 )
|
||||
{
|
||||
m_view.ZoomToRange( t0, t1 );
|
||||
}
|
||||
}
|
||||
if( IsMouseClicked( 1 ) )
|
||||
{
|
||||
ImGui::OpenPopup( "menuPopup" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ImGui::BeginPopup( "menuPopup" ) )
|
||||
{
|
||||
if( ImGui::MenuItem( ICON_FA_EYE_SLASH " Hide" ) )
|
||||
{
|
||||
SetVisible( false );
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
yEnd += 0.2f * ostep;
|
||||
AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
||||
DrawFinished();
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void TimelineItem::AdjustThreadHeight( bool firstFrame, int yBegin, int yEnd )
|
||||
{
|
||||
const auto speed = 4.0;
|
||||
const auto baseMove = 1.0;
|
||||
|
||||
const auto newHeight = yEnd - yBegin;
|
||||
if( firstFrame )
|
||||
{
|
||||
m_height = newHeight;
|
||||
}
|
||||
else if( m_height != newHeight )
|
||||
{
|
||||
const auto diff = newHeight - m_height;
|
||||
const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime;
|
||||
if( diff > 0 )
|
||||
{
|
||||
const auto move = preClampMove + baseMove;
|
||||
m_height = int( std::min<double>( m_height + move, newHeight ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto move = preClampMove - baseMove;
|
||||
m_height = int( std::max<double>( m_height + move, newHeight ) );
|
||||
}
|
||||
s_wasActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineItem::VisibilityCheckbox()
|
||||
{
|
||||
SmallCheckbox( HeaderLabel(), &m_visible );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef __TRACYTIMELINEITEM_HPP__
|
||||
#define __TRACYTIMELINEITEM_HPP__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct TimelineContext;
|
||||
class TaskDispatch;
|
||||
class View;
|
||||
class Worker;
|
||||
|
||||
class TimelineItem
|
||||
{
|
||||
public:
|
||||
TimelineItem( View& view, Worker& worker, const void* key, bool wantPreprocess );
|
||||
virtual ~TimelineItem() = default;
|
||||
|
||||
// draws the timeline item and also updates the next frame height value
|
||||
void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset );
|
||||
|
||||
bool WantPreprocess() const { return m_wantPreprocess; }
|
||||
virtual void Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos ) { assert( false ); }
|
||||
|
||||
void VisibilityCheckbox();
|
||||
virtual void SetVisible( bool visible ) { m_visible = visible; }
|
||||
virtual bool IsVisible() const { return m_visible; }
|
||||
|
||||
void SetShowFull( bool showFull ) { m_showFull = showFull; }
|
||||
|
||||
// returns 0 instead of the correct value for the first frame
|
||||
int GetHeight() const { return m_height; }
|
||||
|
||||
const void* GetKey() const { return m_key; }
|
||||
|
||||
protected:
|
||||
virtual uint32_t HeaderColor() const = 0;
|
||||
virtual uint32_t HeaderColorInactive() const = 0;
|
||||
virtual uint32_t HeaderLineColor() const = 0;
|
||||
virtual const char* HeaderLabel() const = 0;
|
||||
|
||||
virtual void HeaderTooltip( const char* label ) const {};
|
||||
virtual void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) {};
|
||||
|
||||
virtual int64_t RangeBegin() const = 0;
|
||||
virtual int64_t RangeEnd() const = 0;
|
||||
|
||||
virtual bool DrawContents( const TimelineContext& ctx, int& offset ) = 0;
|
||||
virtual void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) {}
|
||||
virtual void DrawFinished() {}
|
||||
|
||||
virtual bool IsEmpty() const { return false; }
|
||||
|
||||
bool m_visible;
|
||||
bool m_showFull;
|
||||
|
||||
private:
|
||||
void AdjustThreadHeight( bool firstFrame, int yBegin, int yEnd );
|
||||
|
||||
int m_height;
|
||||
bool m_wantPreprocess;
|
||||
|
||||
const void* m_key;
|
||||
|
||||
protected:
|
||||
View& m_view;
|
||||
Worker& m_worker;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,259 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineItemCpuData.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyView.hpp"
|
||||
#include "TracyWorker.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TimelineItemCpuData::TimelineItemCpuData( View& view, Worker& worker, void* key )
|
||||
: TimelineItem( view, worker, key, true )
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineItemCpuData::SetVisible( bool visible )
|
||||
{
|
||||
m_view.GetViewData().drawCpuData = visible;
|
||||
}
|
||||
|
||||
bool TimelineItemCpuData::IsVisible() const
|
||||
{
|
||||
return m_view.GetViewData().drawCpuData;
|
||||
}
|
||||
|
||||
bool TimelineItemCpuData::IsEmpty() const
|
||||
{
|
||||
return m_worker.GetCpuDataCpuCount() == 0;
|
||||
}
|
||||
|
||||
int64_t TimelineItemCpuData::RangeBegin() const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t TimelineItemCpuData::RangeEnd() const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool TimelineItemCpuData::DrawContents( const TimelineContext& ctx, int& offset )
|
||||
{
|
||||
m_view.DrawCpuData( ctx, m_cpuDraw, m_ctxDraw, offset, m_hasCpuData );
|
||||
return true;
|
||||
}
|
||||
|
||||
void TimelineItemCpuData::DrawFinished()
|
||||
{
|
||||
m_cpuDraw.clear();
|
||||
for( auto& v : m_ctxDraw ) v.clear();
|
||||
}
|
||||
|
||||
void TimelineItemCpuData::Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos )
|
||||
{
|
||||
assert( m_cpuDraw.empty() );
|
||||
for( auto& v : m_ctxDraw ) assert( v.empty() );
|
||||
|
||||
if( !visible ) return;
|
||||
|
||||
const auto yMin = ctx.yMin;
|
||||
const auto yMax = ctx.yMax;
|
||||
const auto ty = ctx.ty;
|
||||
const auto sty = ctx.sty;
|
||||
const auto ostep = ty + 1;
|
||||
const auto sstep = sty + 1;
|
||||
|
||||
bool hasCpuData = false;
|
||||
auto pos = yPos + ostep;
|
||||
|
||||
#ifdef TRACY_NO_STATISTICS
|
||||
if( m_view.GetViewData().drawCpuUsageGraph )
|
||||
#else
|
||||
if( m_view.GetViewData().drawCpuUsageGraph && m_worker.IsCpuUsageReady() )
|
||||
#endif
|
||||
{
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
auto& ctxUsage = m_worker.GetCpuUsage();
|
||||
if( !ctxUsage.empty() )
|
||||
{
|
||||
hasCpuData = true;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const auto cpuDataCount = m_worker.GetCpuDataCpuCount();
|
||||
const auto cpuData = m_worker.GetCpuData();
|
||||
for( int i=0; i<cpuDataCount; i++ )
|
||||
{
|
||||
if( !cpuData[i].cs.empty() )
|
||||
{
|
||||
hasCpuData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( hasCpuData )
|
||||
{
|
||||
const auto cpuUsageHeight = floor( 30.f * GetScale() );
|
||||
if( pos <= yMax && pos + cpuUsageHeight + 3 >= yMin )
|
||||
{
|
||||
td.Queue( [this, &ctx] {
|
||||
PreprocessCpuUsage( ctx );
|
||||
} );
|
||||
}
|
||||
pos += cpuUsageHeight + 3;
|
||||
}
|
||||
}
|
||||
m_hasCpuData = hasCpuData;
|
||||
|
||||
auto cpuData = m_worker.GetCpuData();
|
||||
const auto cpuCnt = m_worker.GetCpuDataCpuCount();
|
||||
if( m_ctxDraw.size() != cpuCnt ) m_ctxDraw.resize( cpuCnt );
|
||||
|
||||
for( int i=0; i<cpuCnt; i++ )
|
||||
{
|
||||
auto& cs = cpuData[i].cs;
|
||||
if( !cs.empty() && pos <= yMax && pos + sty >= yMin )
|
||||
{
|
||||
td.Queue( [this, &ctx, &cs, i] {
|
||||
PreprocessCpuCtxSwitches( ctx, cs, m_ctxDraw[i] );
|
||||
} );
|
||||
}
|
||||
pos += sstep;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float MinVisSize = 3;
|
||||
|
||||
void TimelineItemCpuData::PreprocessCpuCtxSwitches( const TimelineContext& ctx, const Vector<ContextSwitchCpu>& cs, std::vector<CpuCtxDraw>& out )
|
||||
{
|
||||
const auto vStart = ctx.vStart;
|
||||
const auto vEnd = ctx.vEnd;
|
||||
const auto nspx = ctx.nspx;
|
||||
|
||||
auto it = std::lower_bound( cs.begin(), cs.end(), std::max<int64_t>( 0, vStart ), [] ( const auto& l, const auto& r ) { return ( l.IsEndValid() ? l.End() : l.Start() ) < r; } );
|
||||
if( it == cs.end() ) return;
|
||||
auto eit = std::lower_bound( it, cs.end(), vEnd, [] ( const auto& l, const auto& r ) { return l.Start() < r; } );
|
||||
if( it == eit ) return;
|
||||
|
||||
const auto MinVisNs = int64_t( round( GetScale() * MinVisSize * nspx ) );
|
||||
|
||||
while( it < eit )
|
||||
{
|
||||
const auto end = it->IsEndValid() ? it->End() : it->Start();
|
||||
const auto zsz = end - it->Start();
|
||||
if( zsz < MinVisNs )
|
||||
{
|
||||
auto nextTime = end + MinVisNs;
|
||||
auto next = it + 1;
|
||||
for(;;)
|
||||
{
|
||||
next = std::lower_bound( next, eit, nextTime, [] ( const auto& l, const auto& r ) { return ( l.IsEndValid() ? l.End() : l.Start() ) < r; } );
|
||||
if( next == eit ) break;
|
||||
auto prev = next - 1;
|
||||
const auto pt = prev->IsEndValid() ? prev->End() : prev->Start();
|
||||
const auto nt = next->IsEndValid() ? next->End() : next->Start();
|
||||
if( nt - pt >= MinVisNs ) break;
|
||||
nextTime = nt + MinVisNs;
|
||||
}
|
||||
out.emplace_back( CpuCtxDraw { uint32_t( it - cs.begin() ), uint32_t( next - it ) } );
|
||||
it = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
out.emplace_back( CpuCtxDraw { uint32_t( it - cs.begin() ), 0 } );
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineItemCpuData::PreprocessCpuUsage( const TimelineContext& ctx )
|
||||
{
|
||||
const auto vStart = ctx.vStart;
|
||||
const auto nspx = ctx.nspx;
|
||||
const auto w = ctx.w;
|
||||
const auto num = size_t( w );
|
||||
|
||||
if( vStart > m_worker.GetLastTime() || int64_t( vStart + nspx * num ) < 0 ) return;
|
||||
|
||||
const auto lastTime = m_worker.GetLastTime();
|
||||
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
auto& ctxUsage = m_worker.GetCpuUsage();
|
||||
if( !ctxUsage.empty() )
|
||||
{
|
||||
auto itBegin = ctxUsage.begin();
|
||||
for( size_t i=0; i<num; i++ )
|
||||
{
|
||||
const auto time = int64_t( vStart + nspx * i );
|
||||
if( time > lastTime ) return;
|
||||
if( time < 0 )
|
||||
{
|
||||
m_cpuDraw.emplace_back( CpuUsageDraw { 0, 0 } );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto test = ( time << 16 ) | 0xFFFF;
|
||||
auto it = std::upper_bound( itBegin, ctxUsage.end(), test, [] ( const auto& l, const auto& r ) { return l < r._time_other_own; } );
|
||||
if( it == ctxUsage.end() ) return;
|
||||
if( it == ctxUsage.begin() )
|
||||
{
|
||||
m_cpuDraw.emplace_back( CpuUsageDraw { 0, 0 } );
|
||||
}
|
||||
else
|
||||
{
|
||||
--it;
|
||||
m_cpuDraw.emplace_back( CpuUsageDraw { it->Own(), it->Other() } );
|
||||
}
|
||||
itBegin = it;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_cpuDraw.resize( num );
|
||||
memset( m_cpuDraw.data(), 0, sizeof( CpuUsageDraw ) * num );
|
||||
|
||||
const auto pid = m_worker.GetPid();
|
||||
const auto cpuDataCount = m_worker.GetCpuDataCpuCount();
|
||||
const auto cpuData = m_worker.GetCpuData();
|
||||
|
||||
for( int i=0; i<cpuDataCount; i++ )
|
||||
{
|
||||
auto& cs = cpuData[i].cs;
|
||||
if( !cs.empty() )
|
||||
{
|
||||
auto itBegin = cs.begin();
|
||||
auto ptr = m_cpuDraw.data();
|
||||
for( size_t i=0; i<num; i++ )
|
||||
{
|
||||
const auto time = int64_t( vStart + nspx * i );
|
||||
if( time > lastTime ) break;
|
||||
if( time >= 0 )
|
||||
{
|
||||
auto it = std::lower_bound( itBegin, cs.end(), time, [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
|
||||
if( it == cs.end() ) break;
|
||||
if( it->IsEndValid() && it->Start() <= time )
|
||||
{
|
||||
if( m_worker.GetPidFromTid( m_worker.DecompressThreadExternal( it->Thread() ) ) == pid )
|
||||
{
|
||||
ptr->own++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr->other++;
|
||||
}
|
||||
}
|
||||
itBegin = it;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef __TRACYTIMELINEITEMCPUDATA_HPP__
|
||||
#define __TRACYTIMELINEITEMCPUDATA_HPP__
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TimelineItemCpuData final : public TimelineItem
|
||||
{
|
||||
public:
|
||||
TimelineItemCpuData( View& view, Worker& worker, void* key );
|
||||
|
||||
void SetVisible( bool visible ) override;
|
||||
bool IsVisible() const override;
|
||||
|
||||
protected:
|
||||
uint32_t HeaderColor() const override { return 0xFFDD88DD; }
|
||||
uint32_t HeaderColorInactive() const override { return 0xFF6E446E; }
|
||||
uint32_t HeaderLineColor() const override { return 0x66DD88DD; }
|
||||
const char* HeaderLabel() const override { return "CPU data"; }
|
||||
|
||||
int64_t RangeBegin() const override;
|
||||
int64_t RangeEnd() const override;
|
||||
|
||||
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
|
||||
void DrawFinished() override;
|
||||
|
||||
bool IsEmpty() const override;
|
||||
|
||||
void Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos ) override;
|
||||
|
||||
private:
|
||||
void PreprocessCpuUsage( const TimelineContext& ctx );
|
||||
void PreprocessCpuCtxSwitches( const TimelineContext& ctx, const Vector<ContextSwitchCpu>& cs, std::vector<CpuCtxDraw>& out );
|
||||
|
||||
std::vector<CpuUsageDraw> m_cpuDraw;
|
||||
std::vector<std::vector<CpuCtxDraw>> m_ctxDraw;
|
||||
|
||||
bool m_hasCpuData;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
197
subprojects/tracy/profiler/src/profiler/TracyTimelineItemGpu.cpp
Normal file
197
subprojects/tracy/profiler/src/profiler/TracyTimelineItemGpu.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPopcnt.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineItemGpu.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyView.hpp"
|
||||
#include "TracyWorker.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TimelineItemGpu::TimelineItemGpu( View& view, Worker& worker, GpuCtxData* gpu )
|
||||
: TimelineItem( view, worker, gpu, false )
|
||||
, m_gpu( gpu )
|
||||
, m_idx( view.GetNextGpuIdx() )
|
||||
{
|
||||
}
|
||||
|
||||
bool TimelineItemGpu::IsEmpty() const
|
||||
{
|
||||
return m_gpu->threadData.empty();
|
||||
}
|
||||
|
||||
const char* TimelineItemGpu::HeaderLabel() const
|
||||
{
|
||||
static char buf[4096];
|
||||
if( m_gpu->name.Active() )
|
||||
{
|
||||
sprintf( buf, "%s", m_worker.GetString( m_gpu->name ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
void TimelineItemGpu::HeaderTooltip( const char* label ) const
|
||||
{
|
||||
const bool dynamicColors = m_view.GetViewData().dynamicColors;
|
||||
const bool isMultithreaded =
|
||||
( m_gpu->type == GpuContextType::Vulkan ) ||
|
||||
( m_gpu->type == GpuContextType::OpenCL ) ||
|
||||
( m_gpu->type == GpuContextType::Direct3D12 );
|
||||
|
||||
char buf[64];
|
||||
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
|
||||
|
||||
ImGui::BeginTooltip();
|
||||
if( m_gpu->name.Active() ) TextFocused( "Name:", m_worker.GetString( m_gpu->name ) );
|
||||
ImGui::TextUnformatted( buf );
|
||||
ImGui::Separator();
|
||||
if( !isMultithreaded )
|
||||
{
|
||||
SmallColorBox( GetThreadColor( m_gpu->thread, 0, dynamicColors ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Thread:", m_worker.GetThreadName( m_gpu->thread ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_gpu->threadData.size() == 1 )
|
||||
{
|
||||
auto it = m_gpu->threadData.begin();
|
||||
auto tid = it->first;
|
||||
if( tid == 0 )
|
||||
{
|
||||
if( !it->second.timeline.empty() )
|
||||
{
|
||||
if( it->second.timeline.is_magic() )
|
||||
{
|
||||
auto& tl = *(Vector<GpuEvent>*)&it->second.timeline;
|
||||
tid = m_worker.DecompressThread( tl.begin()->Thread() );
|
||||
}
|
||||
else
|
||||
{
|
||||
tid = m_worker.DecompressThread( (*it->second.timeline.begin())->Thread() );
|
||||
}
|
||||
}
|
||||
}
|
||||
SmallColorBox( GetThreadColor( tid, 0, dynamicColors ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( tid ) );
|
||||
if( m_worker.IsThreadFiber( tid ) )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled( "Threads:" );
|
||||
ImGui::Indent();
|
||||
for( auto& td : m_gpu->threadData )
|
||||
{
|
||||
SmallColorBox( GetThreadColor( td.first, 0, dynamicColors ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( m_worker.GetThreadName( td.first ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( td.first ) );
|
||||
}
|
||||
ImGui::Unindent();
|
||||
}
|
||||
}
|
||||
const auto t0 = RangeBegin();
|
||||
if( t0 != std::numeric_limits<int64_t>::max() )
|
||||
{
|
||||
TextFocused( "Appeared at", TimeToString( t0 ) );
|
||||
}
|
||||
TextFocused( "Zone count:", RealToString( m_gpu->count ) );
|
||||
if( m_gpu->period != 1.f )
|
||||
{
|
||||
TextFocused( "Timestamp accuracy:", TimeToString( m_gpu->period ) );
|
||||
}
|
||||
if( m_gpu->overflow != 0 )
|
||||
{
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted( "GPU timer overflow has been detected." );
|
||||
TextFocused( "Timer resolution:", RealToString( 63 - TracyLzcnt( m_gpu->overflow ) ) );
|
||||
ImGui::SameLine();
|
||||
TextDisabledUnformatted( "bits" );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
void TimelineItemGpu::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
|
||||
{
|
||||
if( m_gpu->name.Active() )
|
||||
{
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
|
||||
char buf[64];
|
||||
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
|
||||
draw->AddText( ctx.wpos + ImVec2( ty * 1.5f + labelWidth, offset ), HeaderColorInactive(), buf );
|
||||
}
|
||||
}
|
||||
|
||||
int64_t TimelineItemGpu::RangeBegin() const
|
||||
{
|
||||
int64_t t = std::numeric_limits<int64_t>::max();
|
||||
for( auto& td : m_gpu->threadData )
|
||||
{
|
||||
int64_t t0;
|
||||
if( td.second.timeline.is_magic() )
|
||||
{
|
||||
t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
t0 = td.second.timeline.front()->GpuStart();
|
||||
}
|
||||
if( t0 >= 0 )
|
||||
{
|
||||
t = std::min( t, t0 );
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
int64_t TimelineItemGpu::RangeEnd() const
|
||||
{
|
||||
int64_t t = std::numeric_limits<int64_t>::min();
|
||||
for( auto& td : m_gpu->threadData )
|
||||
{
|
||||
int64_t t0;
|
||||
if( td.second.timeline.is_magic() )
|
||||
{
|
||||
t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
t0 = td.second.timeline.front()->GpuStart();
|
||||
}
|
||||
if( t0 >= 0 )
|
||||
{
|
||||
if( td.second.timeline.is_magic() )
|
||||
{
|
||||
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( ((Vector<GpuEvent>*)&td.second.timeline)->back() ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( *td.second.timeline.back() ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
bool TimelineItemGpu::DrawContents( const TimelineContext& ctx, int& offset )
|
||||
{
|
||||
return m_view.DrawGpu( ctx, *m_gpu, offset );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef __TRACYTIMELINEITEMGPU_HPP__
|
||||
#define __TRACYTIMELINEITEMGPU_HPP__
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TimelineItemGpu final : public TimelineItem
|
||||
{
|
||||
public:
|
||||
TimelineItemGpu( View& view, Worker& worker, GpuCtxData* gpu );
|
||||
|
||||
int GetIdx() const { return m_idx; }
|
||||
|
||||
protected:
|
||||
uint32_t HeaderColor() const override { return 0xFFFFAAAA; }
|
||||
uint32_t HeaderColorInactive() const override { return 0xFF886666; }
|
||||
uint32_t HeaderLineColor() const override { return 0x33FFFFFF; }
|
||||
const char* HeaderLabel() const override;
|
||||
|
||||
int64_t RangeBegin() const override;
|
||||
int64_t RangeEnd() const override;
|
||||
|
||||
void HeaderTooltip( const char* label ) const override;
|
||||
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
|
||||
|
||||
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
|
||||
|
||||
bool IsEmpty() const override;
|
||||
|
||||
private:
|
||||
GpuCtxData* m_gpu;
|
||||
int m_idx;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,238 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineItemPlot.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyView.hpp"
|
||||
#include "TracyWorker.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr int PlotHeightPx = 100;
|
||||
constexpr int MinVisSize = 3;
|
||||
|
||||
|
||||
TimelineItemPlot::TimelineItemPlot( View& view, Worker& worker, PlotData* plot )
|
||||
: TimelineItem( view, worker, plot, true )
|
||||
, m_plot( plot )
|
||||
{
|
||||
}
|
||||
|
||||
bool TimelineItemPlot::IsEmpty() const
|
||||
{
|
||||
return m_plot->data.empty();
|
||||
}
|
||||
|
||||
const char* TimelineItemPlot::HeaderLabel() const
|
||||
{
|
||||
static char tmp[1024];
|
||||
switch( m_plot->type )
|
||||
{
|
||||
case PlotType::User:
|
||||
return m_worker.GetString( m_plot->name );
|
||||
case PlotType::Memory:
|
||||
if( m_plot->name == 0 )
|
||||
{
|
||||
return ICON_FA_MEMORY " Memory usage";
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( tmp, ICON_FA_MEMORY " %s", m_worker.GetString( m_plot->name ) );
|
||||
return tmp;
|
||||
}
|
||||
case PlotType::SysTime:
|
||||
return ICON_FA_GAUGE_HIGH " CPU usage";
|
||||
case PlotType::Power:
|
||||
sprintf( tmp, ICON_FA_BOLT " %s", m_worker.GetString( m_plot->name ) );
|
||||
return tmp;
|
||||
default:
|
||||
assert( false );
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineItemPlot::HeaderTooltip( const char* label ) const
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
SmallColorBox( GetPlotColor( *m_plot, m_worker ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Plot", label );
|
||||
ImGui::Separator();
|
||||
|
||||
const auto first = RangeBegin();
|
||||
const auto last = RangeEnd();
|
||||
const auto activity = last - first;
|
||||
const auto traceLen = m_worker.GetLastTime() - m_worker.GetFirstTime();
|
||||
|
||||
TextFocused( "Appeared at", TimeToString( first ) );
|
||||
TextFocused( "Last event at", TimeToString( last ) );
|
||||
TextFocused( "Activity time:", TimeToString( activity ) );
|
||||
ImGui::SameLine();
|
||||
char buf[64];
|
||||
PrintStringPercent( buf, activity / double( traceLen ) * 100 );
|
||||
TextDisabledUnformatted( buf );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Data points:", RealToString( m_plot->data.size() ) );
|
||||
TextFocused( "Data range:", FormatPlotValue( m_plot->max - m_plot->min, m_plot->format ) );
|
||||
TextFocused( "Min value:", FormatPlotValue( m_plot->min, m_plot->format ) );
|
||||
TextFocused( "Max value:", FormatPlotValue( m_plot->max, m_plot->format ) );
|
||||
TextFocused( "Avg value:", FormatPlotValue( m_plot->sum / m_plot->data.size(), m_plot->format ) );
|
||||
TextFocused( "Data/second:", RealToString( double( m_plot->data.size() ) / activity * 1000000000ll ) );
|
||||
|
||||
const auto it = std::lower_bound( m_plot->data.begin(), m_plot->data.end(), last - 1000000000ll * 10, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
|
||||
const auto tr10 = last - it->time.Val();
|
||||
if( tr10 != 0 )
|
||||
{
|
||||
TextFocused( "D/s (10s):", RealToString( double( std::distance( it, m_plot->data.end() ) ) / tr10 * 1000000000ll ) );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
void TimelineItemPlot::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
|
||||
{
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
|
||||
char tmp[128];
|
||||
sprintf( tmp, "(y-range: %s, visible data points: %s)", FormatPlotValue( m_plot->rMax - m_plot->rMin, m_plot->format ), RealToString( m_plot->num ) );
|
||||
draw->AddText( ctx.wpos + ImVec2( ty * 1.5f + labelWidth, offset ), 0xFF226E6E, tmp );
|
||||
}
|
||||
|
||||
int64_t TimelineItemPlot::RangeBegin() const
|
||||
{
|
||||
return m_plot->data.front().time.Val();
|
||||
}
|
||||
|
||||
int64_t TimelineItemPlot::RangeEnd() const
|
||||
{
|
||||
return m_plot->data.back().time.Val();
|
||||
}
|
||||
|
||||
bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset )
|
||||
{
|
||||
return m_view.DrawPlot( ctx, *m_plot, m_draw, offset );
|
||||
}
|
||||
|
||||
void TimelineItemPlot::DrawFinished()
|
||||
{
|
||||
m_draw.clear();
|
||||
}
|
||||
|
||||
void TimelineItemPlot::Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos )
|
||||
{
|
||||
assert( m_draw.empty() );
|
||||
|
||||
if( !visible ) return;
|
||||
if( yPos > ctx.yMax ) return;
|
||||
if( m_plot->data.empty() ) return;
|
||||
const auto PlotHeight = int( round( PlotHeightPx * GetScale() ) );
|
||||
if( yPos + PlotHeight < ctx.yMin ) return;
|
||||
|
||||
td.Queue( [this, &ctx] {
|
||||
const auto vStart = ctx.vStart;
|
||||
const auto vEnd = ctx.vEnd;
|
||||
const auto nspx = ctx.nspx;
|
||||
const auto MinVisNs = int64_t( round( MinVisSize * nspx ) );
|
||||
|
||||
auto& vec = m_plot->data;
|
||||
vec.ensure_sorted();
|
||||
if( vec.front().time.Val() > vEnd || vec.back().time.Val() < vStart )
|
||||
{
|
||||
m_plot->rMin = 0;
|
||||
m_plot->rMax = 0;
|
||||
m_plot->num = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = std::lower_bound( vec.begin(), vec.end(), vStart, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
|
||||
auto end = std::lower_bound( it, vec.end(), vEnd, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
|
||||
|
||||
if( end != vec.end() ) end++;
|
||||
if( it != vec.begin() ) it--;
|
||||
|
||||
double min = it->val;
|
||||
double max = it->val;
|
||||
const auto num = end - it;
|
||||
if( num > 1000000 )
|
||||
{
|
||||
min = m_plot->min;
|
||||
max = m_plot->max;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto tmp = it;
|
||||
while( ++tmp < end )
|
||||
{
|
||||
if( tmp->val < min ) min = tmp->val;
|
||||
else if( tmp->val > max ) max = tmp->val;
|
||||
}
|
||||
}
|
||||
if( min == max )
|
||||
{
|
||||
min--;
|
||||
max++;
|
||||
}
|
||||
|
||||
m_plot->rMin = min;
|
||||
m_plot->rMax = max;
|
||||
m_plot->num = num;
|
||||
|
||||
m_draw.emplace_back( 0 );
|
||||
m_draw.emplace_back( it - vec.begin() );
|
||||
|
||||
++it;
|
||||
while( it < end )
|
||||
{
|
||||
auto next = std::upper_bound( it, end, int64_t( it->time.Val() + MinVisNs ), [] ( const auto& l, const auto& r ) { return l < r.time.Val(); } );
|
||||
assert( next > it );
|
||||
const auto rsz = uint32_t( next - it );
|
||||
if( rsz < 4 )
|
||||
{
|
||||
for( int i=0; i<rsz; i++ )
|
||||
{
|
||||
m_draw.emplace_back( 0 );
|
||||
m_draw.emplace_back( it - vec.begin() );
|
||||
++it;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sync with View::DrawPlot()!
|
||||
constexpr int NumSamples = 256;
|
||||
uint32_t samples[NumSamples];
|
||||
uint32_t cnt = 0;
|
||||
uint32_t offset = it - vec.begin();
|
||||
if( rsz < NumSamples )
|
||||
{
|
||||
for( cnt=0; cnt<rsz; cnt++ )
|
||||
{
|
||||
samples[cnt] = offset + cnt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto skip = ( rsz + NumSamples - 1 ) / NumSamples;
|
||||
const auto limit = rsz / skip;
|
||||
for( cnt=0; cnt<limit; cnt++ )
|
||||
{
|
||||
samples[cnt] = offset + cnt * skip;
|
||||
}
|
||||
if( cnt == limit ) cnt--;
|
||||
samples[cnt++] = offset + rsz - 1;
|
||||
}
|
||||
it = next;
|
||||
|
||||
pdqsort_branchless( samples, samples+cnt, [&vec] ( const auto& l, const auto& r ) { return vec[l].val < vec[r].val; } );
|
||||
|
||||
assert( rsz > 0 );
|
||||
m_draw.emplace_back( rsz );
|
||||
m_draw.emplace_back( offset );
|
||||
m_draw.emplace_back( samples[0] );
|
||||
m_draw.emplace_back( samples[cnt-1] );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef __TRACYTIMELINEITEMPLOT_HPP__
|
||||
#define __TRACYTIMELINEITEMPLOT_HPP__
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TimelineItemPlot final : public TimelineItem
|
||||
{
|
||||
public:
|
||||
TimelineItemPlot( View& view, Worker& worker, PlotData* plot );
|
||||
|
||||
protected:
|
||||
uint32_t HeaderColor() const override { return 0xFF44DDDD; }
|
||||
uint32_t HeaderColorInactive() const override { return 0xFF226E6E; }
|
||||
uint32_t HeaderLineColor() const override { return 0x8844DDDD; }
|
||||
const char* HeaderLabel() const override;
|
||||
|
||||
int64_t RangeBegin() const override;
|
||||
int64_t RangeEnd() const override;
|
||||
|
||||
void HeaderTooltip( const char* label ) const override;
|
||||
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
|
||||
|
||||
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
|
||||
void DrawFinished() override;
|
||||
|
||||
bool IsEmpty() const override;
|
||||
|
||||
void Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos ) override;
|
||||
|
||||
private:
|
||||
PlotData* m_plot;
|
||||
|
||||
std::vector<uint32_t> m_draw;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
1008
subprojects/tracy/profiler/src/profiler/TracyTimelineItemThread.cpp
Normal file
1008
subprojects/tracy/profiler/src/profiler/TracyTimelineItemThread.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
#ifndef __TRACYTIMELINEITEMTHREAD_HPP__
|
||||
#define __TRACYTIMELINEITEMTHREAD_HPP__
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TimelineItemThread final : public TimelineItem
|
||||
{
|
||||
public:
|
||||
TimelineItemThread( View& view, Worker& worker, const ThreadData* plot );
|
||||
|
||||
protected:
|
||||
uint32_t HeaderColor() const override;
|
||||
uint32_t HeaderColorInactive() const override;
|
||||
uint32_t HeaderLineColor() const override;
|
||||
const char* HeaderLabel() const override;
|
||||
|
||||
int64_t RangeBegin() const override;
|
||||
int64_t RangeEnd() const override;
|
||||
|
||||
void HeaderTooltip( const char* label ) const override;
|
||||
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
|
||||
|
||||
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
|
||||
void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) override;
|
||||
void DrawFinished() override;
|
||||
|
||||
bool IsEmpty() const override;
|
||||
|
||||
void Preprocess( const TimelineContext& ctx, TaskDispatch& td, bool visible, int yPos ) override;
|
||||
|
||||
private:
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
int PreprocessGhostLevel( const TimelineContext& ctx, const Vector<GhostZone>& vec, int depth, bool visible );
|
||||
#endif
|
||||
int PreprocessZoneLevel( const TimelineContext& ctx, const Vector<short_ptr<ZoneEvent>>& vec, int depth, bool visible );
|
||||
|
||||
template<typename Adapter, typename V>
|
||||
int PreprocessZoneLevel( const TimelineContext& ctx, const V& vec, int depth, bool visible );
|
||||
|
||||
void PreprocessContextSwitches( const TimelineContext& ctx, const ContextSwitch& ctxSwitch, bool visible );
|
||||
void PreprocessSamples( const TimelineContext& ctx, const Vector<SampleData>& vec, bool visible, int yPos );
|
||||
void PreprocessMessages( const TimelineContext& ctx, const Vector<short_ptr<MessageData>>& vec, uint64_t tid, bool visible, int yPos );
|
||||
void PreprocessLocks( const TimelineContext& ctx, const unordered_flat_map<uint32_t, LockMap*>& locks, uint32_t tid, TaskDispatch& td, bool visible );
|
||||
|
||||
const ThreadData* m_thread;
|
||||
bool m_ghost;
|
||||
|
||||
std::vector<SamplesDraw> m_samplesDraw;
|
||||
std::vector<ContextSwitchDraw> m_ctxDraw;
|
||||
std::vector<TimelineDraw> m_draw;
|
||||
std::vector<MessagesDraw> m_msgDraw;
|
||||
std::vector<std::unique_ptr<LockDraw>> m_lockDraw;
|
||||
int m_depth;
|
||||
bool m_hasCtxSwitch;
|
||||
bool m_hasSamples;
|
||||
bool m_hasMessages;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
387
subprojects/tracy/profiler/src/profiler/TracyUserData.cpp
Normal file
387
subprojects/tracy/profiler/src/profiler/TracyUserData.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
#include <assert.h>
|
||||
#include <memory>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <stdio.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../ini.h"
|
||||
|
||||
#include "TracyStorage.hpp"
|
||||
#include "TracyUserData.hpp"
|
||||
#include "TracyViewData.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr auto FileDescription = "description";
|
||||
constexpr auto FileTimeline = "timeline";
|
||||
constexpr auto FileOptions = "options";
|
||||
constexpr auto FileAnnotations = "annotations";
|
||||
constexpr auto FileSourceSubstitutions = "srcsub";
|
||||
|
||||
enum : uint32_t { VersionTimeline = 0 };
|
||||
enum : uint32_t { VersionOptions = 7 };
|
||||
enum : uint32_t { VersionAnnotations = 0 };
|
||||
enum : uint32_t { VersionSourceSubstitutions = 0 };
|
||||
|
||||
UserData::UserData()
|
||||
: m_preserveState( false )
|
||||
{
|
||||
}
|
||||
|
||||
UserData::UserData( const char* program, uint64_t time )
|
||||
: m_program( program )
|
||||
, m_time( time )
|
||||
{
|
||||
if( m_program.empty() ) m_program = "_";
|
||||
|
||||
FILE* f = OpenFile( FileDescription, false );
|
||||
if( f )
|
||||
{
|
||||
fseek( f, 0, SEEK_END );
|
||||
const auto sz = ftell( f );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
auto buf = std::unique_ptr<char[]>( new char[sz] );
|
||||
fread( buf.get(), 1, sz, f );
|
||||
fclose( f );
|
||||
m_description.assign( buf.get(), buf.get() + sz );
|
||||
}
|
||||
}
|
||||
|
||||
void UserData::Init( const char* program, uint64_t time )
|
||||
{
|
||||
assert( !Valid() );
|
||||
m_program = program;
|
||||
m_time = time;
|
||||
|
||||
if( m_program.empty() ) m_program = "_";
|
||||
}
|
||||
|
||||
bool UserData::SetDescription( const char* description )
|
||||
{
|
||||
assert( Valid() );
|
||||
|
||||
m_description = description;
|
||||
const auto sz = m_description.size();
|
||||
|
||||
FILE* f = OpenFile( FileDescription, true );
|
||||
if( !f ) return false;
|
||||
|
||||
fwrite( description, 1, sz, f );
|
||||
fclose( f );
|
||||
return true;
|
||||
}
|
||||
|
||||
void UserData::LoadState( ViewData& data )
|
||||
{
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileTimeline, false );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver;
|
||||
fread( &ver, 1, sizeof( ver ), f );
|
||||
if( ver == VersionTimeline )
|
||||
{
|
||||
fread( &data.zvStart, 1, sizeof( data.zvStart ), f );
|
||||
fread( &data.zvEnd, 1, sizeof( data.zvEnd ), f );
|
||||
//fread( &data.zvHeight, 1, sizeof( data.zvHeight ), f );
|
||||
fseek( f, sizeof( float ), SEEK_CUR );
|
||||
//fread( &data.zvScroll, 1, sizeof( data.zvScroll ), f );
|
||||
fseek( f, sizeof( float ), SEEK_CUR );
|
||||
fread( &data.frameScale, 1, sizeof( data.frameScale ), f );
|
||||
fread( &data.frameStart, 1, sizeof( data.frameStart ), f );
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
f = OpenFile( FileOptions, false );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver;
|
||||
fread( &ver, 1, sizeof( ver ), f );
|
||||
// TODO: remove in future
|
||||
if( ver == VersionOptions )
|
||||
{
|
||||
fread( &data.drawGpuZones, 1, sizeof( data.drawGpuZones ), f );
|
||||
fread( &data.drawZones, 1, sizeof( data.drawZones ), f );
|
||||
fread( &data.drawLocks, 1, sizeof( data.drawLocks ), f );
|
||||
fread( &data.drawPlots, 1, sizeof( data.drawPlots ), f );
|
||||
fread( &data.onlyContendedLocks, 1, sizeof( data.onlyContendedLocks ), f );
|
||||
fread( &data.drawEmptyLabels, 1, sizeof( data.drawEmptyLabels ), f );
|
||||
fread( &data.drawFrameTargets, 1, sizeof( data.drawFrameTargets ), f );
|
||||
fread( &data.drawContextSwitches, 1, sizeof( data.drawContextSwitches ), f );
|
||||
fread( &data.darkenContextSwitches, 1, sizeof( data.darkenContextSwitches ), f );
|
||||
fread( &data.drawCpuData, 1, sizeof( data.drawCpuData ), f );
|
||||
fread( &data.drawCpuUsageGraph, 1, sizeof( data.drawCpuUsageGraph ), f );
|
||||
fread( &data.drawSamples, 1, sizeof( data.drawSamples ), f );
|
||||
fread( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f );
|
||||
fread( &data.forceColors, 1, sizeof( data.forceColors ), f );
|
||||
fread( &data.ghostZones, 1, sizeof( data.ghostZones ), f );
|
||||
fread( &data.frameTarget, 1, sizeof( data.frameTarget ), f );
|
||||
fclose( f );
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose( f );
|
||||
const auto path = GetSavePath( m_program.c_str(), m_time, FileOptions, false );
|
||||
assert( path );
|
||||
auto ini = ini_load( path );
|
||||
if( ini )
|
||||
{
|
||||
int v;
|
||||
if( ini_sget( ini, "options", "drawGpuZones", "%d", &v ) ) data.drawGpuZones = v;
|
||||
if( ini_sget( ini, "options", "drawZones", "%d", &v ) ) data.drawZones = v;
|
||||
if( ini_sget( ini, "options", "drawLocks", "%d", &v ) ) data.drawLocks = v;
|
||||
if( ini_sget( ini, "options", "drawPlots", "%d", &v ) ) data.drawPlots = v;
|
||||
if( ini_sget( ini, "options", "onlyContendedLocks", "%d", &v ) ) data.onlyContendedLocks = v;
|
||||
if( ini_sget( ini, "options", "drawEmptyLabels", "%d", &v ) ) data.drawEmptyLabels = v;
|
||||
if( ini_sget( ini, "options", "drawFrameTargets", "%d", &v ) ) data.drawFrameTargets = v;
|
||||
if( ini_sget( ini, "options", "drawContextSwitches", "%d", &v ) ) data.drawContextSwitches = v;
|
||||
if( ini_sget( ini, "options", "darkenContextSwitches", "%d", &v ) ) data.darkenContextSwitches = v;
|
||||
if( ini_sget( ini, "options", "drawCpuData", "%d", &v ) ) data.drawCpuData = v;
|
||||
if( ini_sget( ini, "options", "drawCpuUsageGraph", "%d", &v ) ) data.drawCpuUsageGraph = v;
|
||||
if( ini_sget( ini, "options", "drawSamples", "%d", &v ) ) data.drawSamples = v;
|
||||
if( ini_sget( ini, "options", "dynamicColors", "%d", &v ) ) data.dynamicColors = v;
|
||||
if( ini_sget( ini, "options", "forceColors", "%d", &v ) ) data.forceColors = v;
|
||||
if( ini_sget( ini, "options", "ghostZones", "%d", &v ) ) data.ghostZones = v;
|
||||
if( ini_sget( ini, "options", "frameTarget", "%d", &v ) ) data.frameTarget = v;
|
||||
if( ini_sget( ini, "options", "shortenName", "%d", &v ) ) data.shortenName = (ShortenName)v;
|
||||
if( ini_sget( ini, "options", "plotHeight", "%d", &v ) ) data.plotHeight = v;
|
||||
ini_free( ini );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserData::SaveState( const ViewData& data )
|
||||
{
|
||||
if( !m_preserveState ) return;
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileTimeline, true );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver = VersionTimeline;
|
||||
fwrite( &ver, 1, sizeof( ver ), f );
|
||||
fwrite( &data.zvStart, 1, sizeof( data.zvStart ), f );
|
||||
fwrite( &data.zvEnd, 1, sizeof( data.zvEnd ), f );
|
||||
//fwrite( &data.zvHeight, 1, sizeof( data.zvHeight ), f );
|
||||
float zero = 0;
|
||||
fwrite( &zero, 1, sizeof( zero ), f );
|
||||
//fwrite( &data.zvScroll, 1, sizeof( data.zvScroll ), f );
|
||||
fwrite( &zero, 1, sizeof( zero ), f );
|
||||
fwrite( &data.frameScale, 1, sizeof( data.frameScale ), f );
|
||||
fwrite( &data.frameStart, 1, sizeof( data.frameStart ), f );
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
f = OpenFile( FileOptions, true );
|
||||
if( f )
|
||||
{
|
||||
fprintf( f, "[options]\n" );
|
||||
fprintf( f, "drawGpuZones = %d\n", data.drawGpuZones );
|
||||
fprintf( f, "drawZones = %d\n", data.drawZones );
|
||||
fprintf( f, "drawLocks = %d\n", data.drawLocks );
|
||||
fprintf( f, "drawPlots = %d\n", data.drawPlots );
|
||||
fprintf( f, "onlyContendedLocks = %d\n", data.onlyContendedLocks );
|
||||
fprintf( f, "drawEmptyLabels = %d\n", data.drawEmptyLabels );
|
||||
fprintf( f, "drawFrameTargets = %d\n", data.drawFrameTargets );
|
||||
fprintf( f, "drawContextSwitches = %d\n", data.drawContextSwitches );
|
||||
fprintf( f, "darkenContextSwitches = %d\n", data.darkenContextSwitches );
|
||||
fprintf( f, "drawCpuData = %d\n", data.drawCpuData );
|
||||
fprintf( f, "drawCpuUsageGraph = %d\n", data.drawCpuUsageGraph );
|
||||
fprintf( f, "drawSamples = %d\n", data.drawSamples );
|
||||
fprintf( f, "dynamicColors = %d\n", data.dynamicColors );
|
||||
fprintf( f, "forceColors = %d\n", data.forceColors );
|
||||
fprintf( f, "ghostZones = %d\n", data.ghostZones );
|
||||
fprintf( f, "frameTarget = %d\n", data.frameTarget );
|
||||
fprintf( f, "shortenName = %d\n", (int)data.shortenName );
|
||||
fprintf( f, "plotHeight = %d\n", data.plotHeight );
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
void UserData::StateShouldBePreserved()
|
||||
{
|
||||
m_preserveState = true;
|
||||
}
|
||||
|
||||
void UserData::LoadAnnotations( std::vector<std::unique_ptr<Annotation>>& data )
|
||||
{
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileAnnotations, false );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver;
|
||||
fread( &ver, 1, sizeof( ver ), f );
|
||||
if( ver == VersionAnnotations )
|
||||
{
|
||||
uint32_t sz;
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
for( uint32_t i=0; i<sz; i++ )
|
||||
{
|
||||
auto ann = std::make_unique<Annotation>();
|
||||
|
||||
uint32_t tsz;
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
ann->text.assign( buf, tsz );
|
||||
}
|
||||
fread( &ann->range.min, 1, sizeof( ann->range.min ), f );
|
||||
fread( &ann->range.max, 1, sizeof( ann->range.max ), f );
|
||||
fread( &ann->color, 1, sizeof( ann->color ), f );
|
||||
ann->range.active = true;
|
||||
|
||||
data.emplace_back( std::move( ann ) );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
void UserData::SaveAnnotations( const std::vector<std::unique_ptr<Annotation>>& data )
|
||||
{
|
||||
if( !m_preserveState ) return;
|
||||
if( data.empty() )
|
||||
{
|
||||
Remove( FileAnnotations );
|
||||
return;
|
||||
}
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileAnnotations, true );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver = VersionAnnotations;
|
||||
fwrite( &ver, 1, sizeof( ver ), f );
|
||||
uint32_t sz = uint32_t( data.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
for( auto& ann : data )
|
||||
{
|
||||
sz = uint32_t( ann->text.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
if( sz != 0 )
|
||||
{
|
||||
fwrite( ann->text.c_str(), 1, sz, f );
|
||||
}
|
||||
fwrite( &ann->range.min, 1, sizeof( ann->range.min ), f );
|
||||
fwrite( &ann->range.max, 1, sizeof( ann->range.max ), f );
|
||||
fwrite( &ann->color, 1, sizeof( ann->color ), f );
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
bool UserData::LoadSourceSubstitutions( std::vector<SourceRegex>& data )
|
||||
{
|
||||
assert( Valid() );
|
||||
bool regexValid = true;
|
||||
FILE* f = OpenFile( FileSourceSubstitutions, false );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver;
|
||||
fread( &ver, 1, sizeof( ver ), f );
|
||||
if( ver == VersionSourceSubstitutions )
|
||||
{
|
||||
uint32_t sz;
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
for( uint32_t i=0; i<sz; i++ )
|
||||
{
|
||||
std::string pattern, target;
|
||||
uint32_t tsz;
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
pattern.assign( buf, tsz );
|
||||
}
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
target.assign( buf, tsz );
|
||||
}
|
||||
std::regex regex;
|
||||
try
|
||||
{
|
||||
regex.assign( pattern );
|
||||
}
|
||||
catch( std::regex_error& )
|
||||
{
|
||||
regexValid = false;
|
||||
}
|
||||
data.emplace_back( SourceRegex { std::move( pattern ), std::move( target ), std::move( regex ) } );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
return regexValid;
|
||||
}
|
||||
|
||||
void UserData::SaveSourceSubstitutions( const std::vector<SourceRegex>& data )
|
||||
{
|
||||
if( !m_preserveState ) return;
|
||||
if( data.empty() )
|
||||
{
|
||||
Remove( FileSourceSubstitutions );
|
||||
return;
|
||||
}
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileSourceSubstitutions, true );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver = VersionSourceSubstitutions;
|
||||
fwrite( &ver, 1, sizeof( ver ), f );
|
||||
uint32_t sz = uint32_t( data.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
for( auto& v : data )
|
||||
{
|
||||
sz = uint32_t( v.pattern.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
if( sz != 0 )
|
||||
{
|
||||
fwrite( v.pattern.c_str(), 1, sz, f );
|
||||
}
|
||||
sz = uint32_t( v.target.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
if( sz != 0 )
|
||||
{
|
||||
fwrite( v.target.c_str(), 1, sz, f );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FILE* UserData::OpenFile( const char* filename, bool write )
|
||||
{
|
||||
const auto path = GetSavePath( m_program.c_str(), m_time, filename, write );
|
||||
if( !path ) return nullptr;
|
||||
FILE* f = fopen( path, write ? "wb" : "rb" );
|
||||
return f;
|
||||
}
|
||||
|
||||
void UserData::Remove( const char* filename )
|
||||
{
|
||||
const auto path = GetSavePath( m_program.c_str(), m_time, filename, false );
|
||||
if( !path ) return;
|
||||
unlink( path );
|
||||
}
|
||||
|
||||
const char* UserData::GetConfigLocation() const
|
||||
{
|
||||
assert( Valid() );
|
||||
return GetSavePath( m_program.c_str(), m_time, nullptr, false );
|
||||
}
|
||||
|
||||
}
|
||||
55
subprojects/tracy/profiler/src/profiler/TracyUserData.hpp
Normal file
55
subprojects/tracy/profiler/src/profiler/TracyUserData.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef __TRACYUSERDATA_HPP__
|
||||
#define __TRACYUSERDATA_HPP__
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct Annotation;
|
||||
struct SourceRegex;
|
||||
struct ViewData;
|
||||
|
||||
class UserData
|
||||
{
|
||||
public:
|
||||
UserData();
|
||||
UserData( const char* program, uint64_t time );
|
||||
|
||||
bool Valid() const { return !m_program.empty(); }
|
||||
void Init( const char* program, uint64_t time );
|
||||
|
||||
const std::string& GetDescription() const { return m_description; }
|
||||
bool SetDescription( const char* description );
|
||||
|
||||
void LoadState( ViewData& data );
|
||||
void SaveState( const ViewData& data );
|
||||
void StateShouldBePreserved();
|
||||
|
||||
void LoadAnnotations( std::vector<std::unique_ptr<Annotation>>& data );
|
||||
void SaveAnnotations( const std::vector<std::unique_ptr<Annotation>>& data );
|
||||
|
||||
bool LoadSourceSubstitutions( std::vector<SourceRegex>& data );
|
||||
void SaveSourceSubstitutions( const std::vector<SourceRegex>& data );
|
||||
|
||||
const char* GetConfigLocation() const;
|
||||
|
||||
private:
|
||||
FILE* OpenFile( const char* filename, bool write );
|
||||
void Remove( const char* filename );
|
||||
|
||||
std::string m_program;
|
||||
uint64_t m_time;
|
||||
|
||||
std::string m_description;
|
||||
|
||||
bool m_preserveState;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
190
subprojects/tracy/profiler/src/profiler/TracyUtility.cpp
Normal file
190
subprojects/tracy/profiler/src/profiler/TracyUtility.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "TracyColor.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyWorker.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
// Short list based on GetTypes() in TracySourceTokenizer.cpp
|
||||
constexpr const char* TypesList[] = {
|
||||
"bool ", "char ", "double ", "float ", "int ", "long ", "short ",
|
||||
"signed ", "unsigned ", "void ", "wchar_t ", "size_t ", "int8_t ",
|
||||
"int16_t ", "int32_t ", "int64_t ", "intptr_t ", "uint8_t ", "uint16_t ",
|
||||
"uint32_t ", "uint64_t ", "ptrdiff_t ", nullptr
|
||||
};
|
||||
|
||||
const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz )
|
||||
{
|
||||
assert( type != ShortenName::Never );
|
||||
if( name[0] == '<' || name[0] == '[' ) return name;
|
||||
if( type == ShortenName::Always ) zsz = 0;
|
||||
|
||||
static char buf[64*1024];
|
||||
char tmp[64*1024];
|
||||
|
||||
auto end = name + strlen( name );
|
||||
auto ptr = name;
|
||||
auto dst = tmp;
|
||||
int cnt = 0;
|
||||
for(;;)
|
||||
{
|
||||
auto start = ptr;
|
||||
while( ptr < end && *ptr != '<' ) ptr++;
|
||||
memcpy( dst, start, ptr - start + 1 );
|
||||
dst += ptr - start + 1;
|
||||
if( ptr == end ) break;
|
||||
cnt++;
|
||||
ptr++;
|
||||
while( cnt > 0 )
|
||||
{
|
||||
if( ptr == end ) break;
|
||||
if( *ptr == '<' ) cnt++;
|
||||
else if( *ptr == '>' ) cnt--;
|
||||
ptr++;
|
||||
}
|
||||
*dst++ = '>';
|
||||
}
|
||||
|
||||
end = dst-1;
|
||||
ptr = tmp;
|
||||
dst = buf;
|
||||
cnt = 0;
|
||||
for(;;)
|
||||
{
|
||||
auto start = ptr;
|
||||
while( ptr < end && *ptr != '(' ) ptr++;
|
||||
memcpy( dst, start, ptr - start + 1 );
|
||||
dst += ptr - start + 1;
|
||||
if( ptr == end ) break;
|
||||
cnt++;
|
||||
ptr++;
|
||||
while( cnt > 0 )
|
||||
{
|
||||
if( ptr == end ) break;
|
||||
if( *ptr == '(' ) cnt++;
|
||||
else if( *ptr == ')' ) cnt--;
|
||||
ptr++;
|
||||
}
|
||||
*dst++ = ')';
|
||||
}
|
||||
|
||||
end = dst-1;
|
||||
if( end - buf > 6 && memcmp( end-6, " const", 6 ) == 0 )
|
||||
{
|
||||
dst[-7] = '\0';
|
||||
end -= 6;
|
||||
}
|
||||
|
||||
ptr = buf;
|
||||
for(;;)
|
||||
{
|
||||
auto match = TypesList;
|
||||
while( *match )
|
||||
{
|
||||
auto m = *match;
|
||||
auto p = ptr;
|
||||
while( *m )
|
||||
{
|
||||
if( *m != *p ) break;
|
||||
m++;
|
||||
p++;
|
||||
}
|
||||
if( !*m )
|
||||
{
|
||||
ptr = p;
|
||||
break;
|
||||
}
|
||||
match++;
|
||||
}
|
||||
if( !*match ) break;
|
||||
}
|
||||
|
||||
tsz = ImGui::CalcTextSize( ptr, end );
|
||||
if( type == ShortenName::OnlyNormalize || tsz.x < zsz ) return ptr;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
auto p = ptr;
|
||||
while( p < end && *p != ':' ) p++;
|
||||
if( p == end ) return ptr;
|
||||
p++;
|
||||
while( p < end && *p == ':' ) p++;
|
||||
ptr = p;
|
||||
tsz = ImGui::CalcTextSize( ptr, end );
|
||||
if( tsz.x < zsz ) return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TooltipNormalizedName( const char* name, const char* normalized )
|
||||
{
|
||||
if( ImGui::IsItemHovered() && normalized != name && strcmp( normalized, name ) != 0 )
|
||||
{
|
||||
const auto scale = ImGui::GetTextLineHeight() / 15.f;
|
||||
if( ImGui::CalcTextSize( name ).x > 1400 * scale )
|
||||
{
|
||||
ImGui::SetNextWindowSize( ImVec2( 1400 * scale, 0 ) );
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextWrapped( "%s", name );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted( name );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GetThreadColor( uint64_t thread, int depth, bool dynamic )
|
||||
{
|
||||
if( !dynamic ) return 0xFFCC5555;
|
||||
return GetHsvColor( thread, depth );
|
||||
}
|
||||
|
||||
uint32_t GetPlotColor( const PlotData& plot, const Worker& worker )
|
||||
{
|
||||
switch( plot.type )
|
||||
{
|
||||
case PlotType::User:
|
||||
if( plot.color != 0 ) return plot.color | 0xFF000000;
|
||||
return GetHsvColor( charutil::hash( worker.GetString( plot.name ) ), -10 );
|
||||
case PlotType::Memory:
|
||||
return 0xFF2266CC;
|
||||
case PlotType::SysTime:
|
||||
return 0xFFBAB220;
|
||||
case PlotType::Power:
|
||||
return 0xFF33CC33;
|
||||
default:
|
||||
assert( false );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char* FormatPlotValue( double val, PlotValueFormatting format )
|
||||
{
|
||||
static char buf[64];
|
||||
switch( format )
|
||||
{
|
||||
case PlotValueFormatting::Number:
|
||||
return RealToString( val );
|
||||
break;
|
||||
case PlotValueFormatting::Memory:
|
||||
return MemSizeToString( val );
|
||||
break;
|
||||
case PlotValueFormatting::Percentage:
|
||||
sprintf( buf, "%.2f%%", val );
|
||||
break;
|
||||
case PlotValueFormatting::Watt:
|
||||
sprintf( buf, "%s W", RealToString( val ) );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
||||
34
subprojects/tracy/profiler/src/profiler/TracyUtility.hpp
Normal file
34
subprojects/tracy/profiler/src/profiler/TracyUtility.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __TRACYUTILITY_HPP__
|
||||
#define __TRACYUTILITY_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "../server/TracyEvent.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class Worker;
|
||||
|
||||
enum class ShortenName : uint8_t
|
||||
{
|
||||
Never,
|
||||
Always,
|
||||
OnlyNormalize,
|
||||
NoSpace,
|
||||
NoSpaceAndNormalize,
|
||||
};
|
||||
|
||||
const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, float zsz );
|
||||
void TooltipNormalizedName( const char* name, const char* normalized );
|
||||
|
||||
static inline const char* ShortenZoneName( ShortenName type, const char* name ) { ImVec2 tsz = {}; return ShortenZoneName( type, name, tsz, 0 ); }
|
||||
|
||||
uint32_t GetThreadColor( uint64_t thread, int depth, bool dynamic );
|
||||
uint32_t GetPlotColor( const PlotData& plot, const Worker& worker );
|
||||
const char* FormatPlotValue( double val, PlotValueFormatting format );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
1426
subprojects/tracy/profiler/src/profiler/TracyView.cpp
Normal file
1426
subprojects/tracy/profiler/src/profiler/TracyView.cpp
Normal file
File diff suppressed because it is too large
Load Diff
880
subprojects/tracy/profiler/src/profiler/TracyView.hpp
Normal file
880
subprojects/tracy/profiler/src/profiler/TracyView.hpp
Normal file
@@ -0,0 +1,880 @@
|
||||
#ifndef __TRACYVIEW_HPP__
|
||||
#define __TRACYVIEW_HPP__
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "TracyAchievements.hpp"
|
||||
#include "TracyBadVersion.hpp"
|
||||
#include "TracyBuzzAnim.hpp"
|
||||
#include "TracyConfig.hpp"
|
||||
#include "TracyDecayValue.hpp"
|
||||
#include "TracySourceContents.hpp"
|
||||
#include "TracyTimelineController.hpp"
|
||||
#include "TracyUserData.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyViewData.hpp"
|
||||
#include "../server/TracyFileWrite.hpp"
|
||||
#include "../server/TracyShortPtr.hpp"
|
||||
#include "../server/TracyWorker.hpp"
|
||||
#include "../server/tracy_robin_hood.h"
|
||||
#include "../server/TracyVector.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr const char* GpuContextNames[] = {
|
||||
"Invalid",
|
||||
"OpenGL",
|
||||
"Vulkan",
|
||||
"OpenCL",
|
||||
"Direct3D 12",
|
||||
"Direct3D 11"
|
||||
};
|
||||
|
||||
struct MemoryPage;
|
||||
class FileRead;
|
||||
class SourceView;
|
||||
struct TimelineContext;
|
||||
struct TimelineDraw;
|
||||
struct ContextSwitchDraw;
|
||||
struct SamplesDraw;
|
||||
struct MessagesDraw;
|
||||
struct CpuUsageDraw;
|
||||
struct CpuCtxDraw;
|
||||
struct LockDraw;
|
||||
struct PlotDraw;
|
||||
|
||||
|
||||
class View
|
||||
{
|
||||
struct Animation
|
||||
{
|
||||
bool active = false;
|
||||
int64_t start0, start1;
|
||||
int64_t end0, end1;
|
||||
double progress;
|
||||
};
|
||||
|
||||
struct Region
|
||||
{
|
||||
bool active = false;
|
||||
int64_t start;
|
||||
int64_t end;
|
||||
};
|
||||
|
||||
struct ZoneTimeData
|
||||
{
|
||||
int64_t time;
|
||||
uint64_t count;
|
||||
};
|
||||
|
||||
enum class AccumulationMode
|
||||
{
|
||||
SelfOnly,
|
||||
AllChildren,
|
||||
NonReentrantChildren
|
||||
};
|
||||
|
||||
struct StatisticsCache
|
||||
{
|
||||
RangeSlim range;
|
||||
AccumulationMode accumulationMode;
|
||||
size_t sourceCount;
|
||||
size_t count;
|
||||
int64_t total;
|
||||
uint16_t threadNum;
|
||||
};
|
||||
|
||||
public:
|
||||
struct PlotView
|
||||
{
|
||||
double min;
|
||||
double max;
|
||||
};
|
||||
|
||||
using SetTitleCallback = void(*)( const char* );
|
||||
using SetScaleCallback = void(*)( float );
|
||||
using AttentionCallback = void(*)();
|
||||
|
||||
View( void(*cbMainThread)(const std::function<void()>&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr );
|
||||
View( void(*cbMainThread)(const std::function<void()>&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr );
|
||||
~View();
|
||||
|
||||
bool Draw();
|
||||
bool WasActive() const;
|
||||
|
||||
void UpdateFont( ImFont* fixed, ImFont* small, ImFont* big ) { m_fixedFont = fixed; m_smallFont = small; m_bigFont = big; }
|
||||
|
||||
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }
|
||||
void ViewSource( const char* fileName, int line );
|
||||
void ViewSource( const char* fileName, int line, const char* functionName );
|
||||
void ViewSourceCheckKeyMod( const char* fileName, int line, const char* functionName );
|
||||
void ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr );
|
||||
bool ViewDispatch( const char* fileName, int line, uint64_t symAddr );
|
||||
|
||||
bool ReconnectRequested() const { return m_reconnectRequested; }
|
||||
std::string GetAddress() const { return m_worker.GetAddr(); }
|
||||
uint16_t GetPort() const { return m_worker.GetPort(); }
|
||||
|
||||
const char* SourceSubstitution( const char* srcFile ) const;
|
||||
bool ValidateSourceAge() const { return m_validateSourceAge; }
|
||||
|
||||
void ShowSampleParents( uint64_t symAddr, bool withInlines ) { m_sampleParents.symAddr = symAddr; m_sampleParents.sel = 0; m_sampleParents.withInlines = withInlines; }
|
||||
|
||||
ViewData& GetViewData() { return m_vd; }
|
||||
const ViewData& GetViewData() const { return m_vd; }
|
||||
|
||||
ShortenName GetShortenName() const { return m_vd.shortenName; }
|
||||
int GetNextGpuIdx() { return m_gpuIdx++; }
|
||||
|
||||
const MessageData* GetMessageHighlight() const { return m_msgHighlight; }
|
||||
uint32_t GetLockInfoWindow() const { return m_lockInfoWindow; }
|
||||
|
||||
tracy_force_inline bool& Vis( const void* ptr )
|
||||
{
|
||||
auto it = m_visMap.find( ptr );
|
||||
if( it == m_visMap.end() ) it = m_visMap.emplace( ptr, true ).first;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void HighlightThread( uint64_t thread );
|
||||
void ZoomToRange( int64_t start, int64_t end, bool pause = true );
|
||||
bool DrawPlot( const TimelineContext& ctx, PlotData& plot, const std::vector<uint32_t>& plotDraw, int& offset );
|
||||
void DrawThread( const TimelineContext& ctx, const ThreadData& thread, const std::vector<TimelineDraw>& draw, const std::vector<ContextSwitchDraw>& ctxDraw, const std::vector<SamplesDraw>& samplesDraw, const std::vector<std::unique_ptr<LockDraw>>& lockDraw, int& offset, int depth, bool hasCtxSwitches, bool hasSamples );
|
||||
void DrawThreadMessagesList( const TimelineContext& ctx, const std::vector<MessagesDraw>& drawList, int offset, uint64_t tid );
|
||||
void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr );
|
||||
bool DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offset );
|
||||
bool DrawCpuData( const TimelineContext& ctx, const std::vector<CpuUsageDraw>& cpuDraw, const std::vector<std::vector<CpuCtxDraw>>& ctxDraw, int& offset, bool hasCpuData );
|
||||
|
||||
bool IsBackgroundDone() const { return m_worker.IsBackgroundDone(); }
|
||||
|
||||
bool m_showRanges = false;
|
||||
Range m_statRange;
|
||||
Range m_waitStackRange;
|
||||
|
||||
private:
|
||||
enum class ShortcutAction : uint8_t
|
||||
{
|
||||
None,
|
||||
OpenFind
|
||||
};
|
||||
|
||||
enum { InvalidId = 0xFFFFFFFF };
|
||||
|
||||
struct MemPathData
|
||||
{
|
||||
uint32_t cnt;
|
||||
uint64_t mem;
|
||||
};
|
||||
|
||||
enum class ViewMode
|
||||
{
|
||||
Paused,
|
||||
LastFrames,
|
||||
LastRange
|
||||
};
|
||||
|
||||
enum class MemRange
|
||||
{
|
||||
Full,
|
||||
Active,
|
||||
Inactive
|
||||
};
|
||||
|
||||
struct KeyboardNavigation
|
||||
{
|
||||
enum Direction
|
||||
{
|
||||
// Pan left / right
|
||||
Left,
|
||||
Right,
|
||||
// Zoom in / out
|
||||
In,
|
||||
Out
|
||||
};
|
||||
|
||||
constexpr static auto DirectionToKeyMap = std::array<ImGuiKey, 4> { ImGuiKey_A, ImGuiKey_D, ImGuiKey_W, ImGuiKey_S };
|
||||
constexpr static auto StartRangeMod = std::array<int, 4> { -1, 1, 1, -1 };
|
||||
constexpr static auto EndRangeMod = std::array<int, 4> { -1, 1, -1, 1 };
|
||||
|
||||
std::array<float, 4> m_scrollInertia;
|
||||
};
|
||||
|
||||
struct ZoneColorData
|
||||
{
|
||||
uint32_t color;
|
||||
uint32_t accentColor;
|
||||
float thickness;
|
||||
bool highlight;
|
||||
};
|
||||
|
||||
struct SymList
|
||||
{
|
||||
uint64_t symAddr;
|
||||
uint32_t incl, excl;
|
||||
uint32_t count;
|
||||
};
|
||||
|
||||
void InitTextEditor();
|
||||
void SetupConfig( const Config& config );
|
||||
void Achieve( const char* id );
|
||||
|
||||
bool DrawImpl();
|
||||
void DrawNotificationArea();
|
||||
bool DrawConnection();
|
||||
void DrawFrames();
|
||||
void DrawTimelineFramesHeader();
|
||||
void DrawTimelineFrames( const FrameData& frames );
|
||||
void DrawTimeline();
|
||||
void DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset );
|
||||
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid );
|
||||
void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, const Vector<ContextSwitchData>& ctxSwitch, int offset, int endOffset, bool isFiber );
|
||||
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
|
||||
template<typename Adapter, typename V>
|
||||
int DrawGpuZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
|
||||
template<typename Adapter, typename V>
|
||||
int SkipGpuZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
|
||||
void DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint8_t tid );
|
||||
int DrawLocks( const TimelineContext& ctx, const std::vector<std::unique_ptr<LockDraw>>& lockDraw, uint64_t tid, int _offset, LockHighlight& highlight );
|
||||
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem& item, double prev, PlotType type, PlotValueFormatting format, float PlotHeight, uint64_t name );
|
||||
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, double val, PlotValueFormatting format, float PlotHeight );
|
||||
void DrawOptions();
|
||||
void DrawMessages();
|
||||
void DrawMessageLine( const MessageData& msg, bool hasCallstack, int& idx );
|
||||
void DrawFindZone();
|
||||
void AccumulationModeComboBox();
|
||||
void DrawStatistics();
|
||||
void DrawSamplesStatistics(Vector<SymList>& data, int64_t timeRange, AccumulationMode accumulationMode);
|
||||
void DrawMemory();
|
||||
void DrawAllocList();
|
||||
void DrawCompare();
|
||||
void DrawCallstackWindow();
|
||||
void DrawCallstackTable( uint32_t callstack, bool globalEntriesButton );
|
||||
void DrawMemoryAllocWindow();
|
||||
void DrawInfo();
|
||||
void DrawTextEditor();
|
||||
void DrawLockInfoWindow();
|
||||
void DrawPlayback();
|
||||
void DrawCpuDataWindow();
|
||||
void DrawSelectedAnnotation();
|
||||
void DrawAnnotationList();
|
||||
void DrawSampleParents();
|
||||
void DrawRanges();
|
||||
void DrawRangeEntry( Range& range, const char* label, uint32_t color, const char* popupLabel, int id );
|
||||
void DrawSourceTooltip( const char* filename, uint32_t line, int before = 3, int after = 3, bool separateTooltip = true );
|
||||
void DrawWaitStacks();
|
||||
|
||||
void ListMemData( std::vector<const MemEvent*>& vec, const std::function<void(const MemEvent*)>& DrawAddress, int64_t startTime = -1, uint64_t pool = 0 );
|
||||
|
||||
unordered_flat_map<uint32_t, MemPathData> GetCallstackPaths( const MemData& mem, MemRange memRange ) const;
|
||||
unordered_flat_map<uint64_t, MemCallstackFrameTree> GetCallstackFrameTreeBottomUp( const MemData& mem ) const;
|
||||
unordered_flat_map<uint64_t, MemCallstackFrameTree> GetCallstackFrameTreeTopDown( const MemData& mem ) const;
|
||||
void DrawFrameTreeLevel( const unordered_flat_map<uint64_t, MemCallstackFrameTree>& tree, int& idx );
|
||||
void DrawZoneList( int id, const Vector<short_ptr<ZoneEvent>>& zones );
|
||||
|
||||
unordered_flat_map<uint64_t, CallstackFrameTree> GetCallstackFrameTreeBottomUp( const unordered_flat_map<uint32_t, uint64_t>& stacks, bool group ) const;
|
||||
unordered_flat_map<uint64_t, CallstackFrameTree> GetCallstackFrameTreeTopDown( const unordered_flat_map<uint32_t, uint64_t>& stacks, bool group ) const;
|
||||
void DrawFrameTreeLevel( const unordered_flat_map<uint64_t, CallstackFrameTree>& tree, int& idx );
|
||||
|
||||
unordered_flat_map<uint64_t, CallstackFrameTree> GetParentsCallstackFrameTreeBottomUp( const unordered_flat_map<uint32_t, uint32_t>& stacks, bool group ) const;
|
||||
unordered_flat_map<uint64_t, CallstackFrameTree> GetParentsCallstackFrameTreeTopDown( const unordered_flat_map<uint32_t, uint32_t>& stacks, bool group ) const;
|
||||
void DrawParentsFrameTreeLevel( const unordered_flat_map<uint64_t, CallstackFrameTree>& tree, int& idx );
|
||||
|
||||
void DrawInfoWindow();
|
||||
void DrawZoneInfoWindow();
|
||||
void DrawGpuInfoWindow();
|
||||
|
||||
template<typename Adapter, typename V>
|
||||
void DrawZoneInfoChildren( const V& children, int64_t ztime );
|
||||
template<typename Adapter, typename V>
|
||||
void DrawGpuInfoChildren( const V& children, int64_t ztime );
|
||||
|
||||
void HandleRange( Range& range, int64_t timespan, const ImVec2& wpos, float w );
|
||||
void HandleTimelineMouse( int64_t timespan, const ImVec2& wpos, float w );
|
||||
void HandleTimelineKeyboard( int64_t timespan, const ImVec2& wpos, float w );
|
||||
|
||||
void AddAnnotation( int64_t start, int64_t end );
|
||||
|
||||
uint32_t GetThreadColor( uint64_t thread, int depth );
|
||||
uint32_t GetSrcLocColor( const SourceLocation& srcloc, int depth );
|
||||
uint32_t GetRawSrcLocColor( const SourceLocation& srcloc, int depth );
|
||||
uint32_t GetZoneColor( const ZoneEvent& ev, uint64_t thread, int depth );
|
||||
uint32_t GetZoneColor( const GpuEvent& ev );
|
||||
ZoneColorData GetZoneColorData( const ZoneEvent& ev, uint64_t thread, int depth );
|
||||
ZoneColorData GetZoneColorData( const GpuEvent& ev );
|
||||
|
||||
void ZoomToZone( const ZoneEvent& ev );
|
||||
void ZoomToZone( const GpuEvent& ev );
|
||||
void ZoomToPrevFrame();
|
||||
void ZoomToNextFrame();
|
||||
void CenterAtTime( int64_t t );
|
||||
|
||||
void ShowZoneInfo( const ZoneEvent& ev );
|
||||
void ShowZoneInfo( const GpuEvent& ev, uint64_t thread );
|
||||
|
||||
void ZoneTooltip( const ZoneEvent& ev );
|
||||
void ZoneTooltip( const GpuEvent& ev );
|
||||
void CallstackTooltip( uint32_t idx );
|
||||
void CallstackTooltipContents( uint32_t idx );
|
||||
void CrashTooltip();
|
||||
|
||||
const ZoneEvent* GetZoneParent( const ZoneEvent& zone ) const;
|
||||
const ZoneEvent* GetZoneParent( const ZoneEvent& zone, uint64_t tid ) const;
|
||||
const ZoneEvent* GetZoneChild( const ZoneEvent& zone, int64_t time ) const;
|
||||
bool IsZoneReentry( const ZoneEvent& zone ) const;
|
||||
bool IsZoneReentry( const ZoneEvent& zone, uint64_t tid ) const;
|
||||
const GpuEvent* GetZoneParent( const GpuEvent& zone ) const;
|
||||
const ThreadData* GetZoneThreadData( const ZoneEvent& zone ) const;
|
||||
uint64_t GetZoneThread( const ZoneEvent& zone ) const;
|
||||
uint64_t GetZoneThread( const GpuEvent& zone ) const;
|
||||
const GpuCtxData* GetZoneCtx( const GpuEvent& zone ) const;
|
||||
bool FindMatchingZone( int prev0, int prev1, int flags );
|
||||
const ZoneEvent* FindZoneAtTime( uint64_t thread, int64_t time ) const;
|
||||
uint64_t GetFrameNumber( const FrameData& fd, int i ) const;
|
||||
const char* GetFrameText( const FrameData& fd, int i, uint64_t ftime ) const;
|
||||
const char* GetFrameSetName( const FrameData& fd ) const;
|
||||
static const char* GetFrameSetName( const FrameData& fd, const Worker& worker );
|
||||
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
void FindZones();
|
||||
void FindZonesCompare();
|
||||
#endif
|
||||
|
||||
std::vector<MemoryPage> GetMemoryPages() const;
|
||||
|
||||
void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true );
|
||||
void DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const;
|
||||
void SetViewToLastFrames();
|
||||
int64_t GetZoneChildTime( const ZoneEvent& zone );
|
||||
int64_t GetZoneChildTime( const GpuEvent& zone );
|
||||
int64_t GetZoneChildTimeFast( const ZoneEvent& zone );
|
||||
int64_t GetZoneChildTimeFastClamped( const ZoneEvent& zone, int64_t t0, int64_t t1 );
|
||||
int64_t GetZoneSelfTime( const ZoneEvent& zone );
|
||||
int64_t GetZoneSelfTime( const GpuEvent& zone );
|
||||
bool GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt );
|
||||
const char* GetThreadContextData( uint64_t thread, bool& local, bool& untracked, const char*& program );
|
||||
|
||||
tracy_force_inline void CalcZoneTimeData( unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime, const ZoneEvent& zone );
|
||||
tracy_force_inline void CalcZoneTimeData( const ContextSwitch* ctx, unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime, const ZoneEvent& zone );
|
||||
template<typename Adapter, typename V>
|
||||
void CalcZoneTimeDataImpl( const V& children, unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime );
|
||||
template<typename Adapter, typename V>
|
||||
void CalcZoneTimeDataImpl( const V& children, const ContextSwitch* ctx, unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime );
|
||||
|
||||
void SetPlaybackFrame( uint32_t idx );
|
||||
bool Save( const char* fn, FileCompression comp, int zlevel, bool buildDict, int streams );
|
||||
|
||||
void Attention( bool& alreadyDone );
|
||||
void UpdateTitle();
|
||||
|
||||
unordered_flat_map<uint64_t, bool> m_visibleMsgThread;
|
||||
unordered_flat_map<uint64_t, bool> m_waitStackThread;
|
||||
unordered_flat_map<const void*, int> m_gpuDrift;
|
||||
unordered_flat_map<const PlotData*, PlotView> m_plotView;
|
||||
Vector<const ThreadData*> m_threadOrder;
|
||||
Vector<float> m_threadDnd;
|
||||
|
||||
tracy_force_inline bool& VisibleMsgThread( uint64_t thread )
|
||||
{
|
||||
auto it = m_visibleMsgThread.find( thread );
|
||||
if( it == m_visibleMsgThread.end() )
|
||||
{
|
||||
it = m_visibleMsgThread.emplace( thread, true ).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
tracy_force_inline bool& WaitStackThread( uint64_t thread )
|
||||
{
|
||||
auto it = m_waitStackThread.find( thread );
|
||||
if( it == m_waitStackThread.end() )
|
||||
{
|
||||
it = m_waitStackThread.emplace( thread, true ).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
tracy_force_inline int& GpuDrift( const void* ptr )
|
||||
{
|
||||
auto it = m_gpuDrift.find( ptr );
|
||||
if( it == m_gpuDrift.end() )
|
||||
{
|
||||
it = m_gpuDrift.emplace( ptr, 0 ).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
static int64_t AdjustGpuTime( int64_t time, int64_t begin, int drift );
|
||||
|
||||
static const char* DecodeContextSwitchState( uint8_t state );
|
||||
static const char* DecodeContextSwitchStateCode( uint8_t state );
|
||||
static const char* DecodeContextSwitchReason( uint8_t reason );
|
||||
static const char* DecodeContextSwitchReasonCode( uint8_t reason );
|
||||
|
||||
Worker m_worker;
|
||||
std::string m_filename, m_filenameStaging;
|
||||
bool m_staticView;
|
||||
ViewMode m_viewMode;
|
||||
bool m_viewModeHeuristicTry = false;
|
||||
DecayValue<bool> m_forceConnectionPopup = false;
|
||||
uint64_t m_totalMemory;
|
||||
|
||||
ViewData m_vd;
|
||||
TimelineController m_tc;
|
||||
KeyboardNavigation m_kbNavCtrl;
|
||||
|
||||
const ZoneEvent* m_zoneInfoWindow = nullptr;
|
||||
const ZoneEvent* m_zoneHighlight;
|
||||
DecayValue<int16_t> m_zoneSrcLocHighlight = 0;
|
||||
LockHighlight m_lockHighlight { -1 };
|
||||
LockHighlight m_nextLockHighlight;
|
||||
DecayValue<const MessageData*> m_msgHighlight = nullptr;
|
||||
DecayValue<uint32_t> m_lockHoverHighlight = InvalidId;
|
||||
DecayValue<const MessageData*> m_msgToFocus = nullptr;
|
||||
const GpuEvent* m_gpuInfoWindow = nullptr;
|
||||
const GpuEvent* m_gpuHighlight;
|
||||
uint64_t m_gpuInfoWindowThread;
|
||||
uint32_t m_callstackInfoWindow = 0;
|
||||
int64_t m_memoryAllocInfoWindow = -1;
|
||||
uint64_t m_memoryAllocInfoPool = 0;
|
||||
int64_t m_memoryAllocHover = -1;
|
||||
uint64_t m_memoryAllocHoverPool = 0;
|
||||
int m_memoryAllocHoverWait = 0;
|
||||
const FrameData* m_frames;
|
||||
uint32_t m_lockInfoWindow = InvalidId;
|
||||
const ZoneEvent* m_zoneHover = nullptr;
|
||||
DecayValue<const ZoneEvent*> m_zoneHover2 = nullptr;
|
||||
int m_frameHover = -1;
|
||||
bool m_messagesScrollBottom;
|
||||
ImGuiTextFilter m_messageFilter;
|
||||
bool m_showMessageImages = false;
|
||||
int m_visibleMessages = 0;
|
||||
size_t m_prevMessages = 0;
|
||||
bool m_messagesShowCallstack = false;
|
||||
Vector<uint32_t> m_msgList;
|
||||
bool m_disconnectIssued = false;
|
||||
DecayValue<uint64_t> m_drawThreadMigrations = 0;
|
||||
DecayValue<uint64_t> m_drawThreadHighlight = 0;
|
||||
Annotation* m_selectedAnnotation = nullptr;
|
||||
bool m_reactToCrash = false;
|
||||
bool m_reactToLostConnection = false;
|
||||
|
||||
ImGuiTextFilter m_statisticsFilter;
|
||||
ImGuiTextFilter m_statisticsImageFilter;
|
||||
ImGuiTextFilter m_userTextFilter;
|
||||
unordered_flat_set<Worker::ZoneThreadData*> m_filteredZones;
|
||||
|
||||
Region m_highlight;
|
||||
Region m_highlightZoom;
|
||||
|
||||
DecayValue<uint64_t> m_cpuDataThread = 0;
|
||||
uint64_t m_gpuThread = 0;
|
||||
int64_t m_gpuStart = 0;
|
||||
int64_t m_gpuEnd = 0;
|
||||
|
||||
bool m_showOptions = false;
|
||||
bool m_showMessages = false;
|
||||
bool m_showStatistics = false;
|
||||
bool m_showInfo = false;
|
||||
bool m_showPlayback = false;
|
||||
bool m_showCpuDataWindow = false;
|
||||
bool m_showAnnotationList = false;
|
||||
bool m_showWaitStacks = false;
|
||||
|
||||
AccumulationMode m_statAccumulationMode = AccumulationMode::SelfOnly;
|
||||
bool m_statSampleTime = true;
|
||||
int m_statMode = 0;
|
||||
int m_statSampleLocation = 2;
|
||||
bool m_statHideUnknown = true;
|
||||
bool m_showAllSymbols = false;
|
||||
int m_showCallstackFrameAddress = 0;
|
||||
bool m_showExternalFrames = true;
|
||||
bool m_showUnknownFrames = true;
|
||||
bool m_statSeparateInlines = false;
|
||||
bool m_mergeInlines = false;
|
||||
bool m_relativeInlines = false;
|
||||
bool m_statShowAddress = false;
|
||||
bool m_statShowKernel = true;
|
||||
bool m_groupChildrenLocations = false;
|
||||
bool m_allocTimeRelativeToZone = true;
|
||||
bool m_ctxSwitchTimeRelativeToZone = true;
|
||||
bool m_messageTimeRelativeToZone = true;
|
||||
bool m_messagesExcludeChildren = true;
|
||||
uint64_t m_zoneInfoMemPool = 0;
|
||||
int m_waitStack = 0;
|
||||
int m_waitStackMode = 0;
|
||||
bool m_groupWaitStackBottomUp = true;
|
||||
bool m_groupWaitStackTopDown = true;
|
||||
|
||||
ShortcutAction m_shortcut = ShortcutAction::None;
|
||||
Animation m_zoomAnim;
|
||||
BuzzAnim<int> m_callstackBuzzAnim;
|
||||
BuzzAnim<int> m_sampleParentBuzzAnim;
|
||||
BuzzAnim<int> m_callstackTreeBuzzAnim;
|
||||
BuzzAnim<const void*> m_zoneinfoBuzzAnim;
|
||||
BuzzAnim<int> m_findZoneBuzzAnim;
|
||||
BuzzAnim<int16_t> m_optionsLockBuzzAnim;
|
||||
BuzzAnim<uint32_t> m_lockInfoAnim;
|
||||
BuzzAnim<uint32_t> m_statBuzzAnim;
|
||||
|
||||
Vector<const ZoneEvent*> m_zoneInfoStack;
|
||||
Vector<const GpuEvent*> m_gpuInfoStack;
|
||||
|
||||
SourceContents m_srcHintCache;
|
||||
std::unique_ptr<SourceView> m_sourceView;
|
||||
const char* m_sourceViewFile;
|
||||
bool m_uarchSet = false;
|
||||
|
||||
ImFont* m_smallFont;
|
||||
ImFont* m_bigFont;
|
||||
ImFont* m_fixedFont;
|
||||
|
||||
float m_rootWidth, m_rootHeight;
|
||||
SetTitleCallback m_stcb;
|
||||
bool m_titleSet = false;
|
||||
SetScaleCallback m_sscb;
|
||||
AttentionCallback m_acb;
|
||||
|
||||
float m_notificationTime = 0;
|
||||
std::string m_notificationText;
|
||||
|
||||
bool m_groupCallstackTreeByNameBottomUp = true;
|
||||
bool m_groupCallstackTreeByNameTopDown = true;
|
||||
MemRange m_memRangeBottomUp = MemRange::Full;
|
||||
MemRange m_memRangeTopDown = MemRange::Full;
|
||||
|
||||
enum class SaveThreadState
|
||||
{
|
||||
Inert,
|
||||
Saving,
|
||||
NeedsJoin
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
FindMatchingZoneFlagDefault = 0,
|
||||
FindMatchingZoneFlagSourceFile = (1 << 0),
|
||||
FindMatchingZoneFlagLineNum = (1 << 1),
|
||||
};
|
||||
|
||||
std::atomic<SaveThreadState> m_saveThreadState { SaveThreadState::Inert };
|
||||
std::thread m_saveThread;
|
||||
std::atomic<size_t> m_srcFileBytes { 0 };
|
||||
std::atomic<size_t> m_dstFileBytes { 0 };
|
||||
|
||||
void* m_frameTexture = nullptr;
|
||||
const void* m_frameTexturePtr = nullptr;
|
||||
|
||||
void* m_frameTextureConn = nullptr;
|
||||
const void* m_frameTextureConnPtr = nullptr;
|
||||
|
||||
std::vector<std::unique_ptr<Annotation>> m_annotations;
|
||||
UserData m_userData;
|
||||
|
||||
bool m_wasActive = false;
|
||||
bool m_reconnectRequested = false;
|
||||
bool m_firstFrame = true;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> m_firstFrameTime;
|
||||
float m_yDelta;
|
||||
|
||||
std::vector<SourceRegex> m_sourceSubstitutions;
|
||||
bool m_sourceRegexValid = true;
|
||||
bool m_validateSourceAge = true;
|
||||
|
||||
RangeSlim m_setRangePopup;
|
||||
bool m_setRangePopupOpen = false;
|
||||
|
||||
unordered_flat_map<int16_t, StatisticsCache> m_statCache;
|
||||
unordered_flat_map<int16_t, StatisticsCache> m_gpuStatCache;
|
||||
|
||||
unordered_flat_map<const void*, bool> m_visMap;
|
||||
|
||||
void(*m_cbMainThread)(const std::function<void()>&, bool);
|
||||
|
||||
int m_gpuIdx = 0;
|
||||
|
||||
struct FindZone {
|
||||
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };
|
||||
enum class GroupBy : int { Thread, UserText, ZoneName, Callstack, Parent, NoGrouping };
|
||||
enum class SortBy : int { Order, Count, Time, Mtpc };
|
||||
|
||||
struct Group
|
||||
{
|
||||
uint16_t id;
|
||||
Vector<short_ptr<ZoneEvent>> zones;
|
||||
Vector<uint16_t> zonesTids;
|
||||
int64_t time = 0;
|
||||
};
|
||||
|
||||
bool show = false;
|
||||
bool ignoreCase = false;
|
||||
std::vector<int16_t> match;
|
||||
unordered_flat_map<uint64_t, Group> groups;
|
||||
size_t processed;
|
||||
uint16_t groupId;
|
||||
int selMatch = 0;
|
||||
uint64_t selGroup = Unselected;
|
||||
char pattern[1024] = {};
|
||||
bool logVal = false;
|
||||
bool logTime = true;
|
||||
bool cumulateTime = false;
|
||||
bool selfTime = false;
|
||||
bool runningTime = false;
|
||||
GroupBy groupBy = GroupBy::Thread;
|
||||
SortBy sortBy = SortBy::Count;
|
||||
Region highlight;
|
||||
int64_t hlOrig_t0, hlOrig_t1;
|
||||
int64_t numBins = -1;
|
||||
std::unique_ptr<int64_t[]> bins, binTime, selBin;
|
||||
Vector<int64_t> sorted, selSort;
|
||||
size_t sortedNum = 0, selSortNum, selSortActive;
|
||||
float average, selAverage;
|
||||
float median, selMedian;
|
||||
int64_t total, selTotal;
|
||||
int64_t selTime;
|
||||
bool drawAvgMed = true;
|
||||
bool drawSelAvgMed = true;
|
||||
bool scheduleResetMatch = false;
|
||||
int selCs = 0;
|
||||
int minBinVal = 1;
|
||||
int64_t tmin, tmax;
|
||||
bool showZoneInFrames = false;
|
||||
Range range;
|
||||
RangeSlim rangeSlim;
|
||||
|
||||
struct
|
||||
{
|
||||
int numBins = -1;
|
||||
ptrdiff_t distBegin;
|
||||
ptrdiff_t distEnd;
|
||||
} binCache;
|
||||
|
||||
struct {
|
||||
Vector<SymList> counts;
|
||||
bool scheduleUpdate = false;
|
||||
bool enabled = false;
|
||||
} samples;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
ResetMatch();
|
||||
match.clear();
|
||||
selMatch = 0;
|
||||
selGroup = Unselected;
|
||||
highlight.active = false;
|
||||
samples.counts.clear();
|
||||
}
|
||||
|
||||
void ResetMatch()
|
||||
{
|
||||
ResetGroups();
|
||||
sorted.clear();
|
||||
sortedNum = 0;
|
||||
average = 0;
|
||||
median = 0;
|
||||
total = 0;
|
||||
tmin = std::numeric_limits<int64_t>::max();
|
||||
tmax = std::numeric_limits<int64_t>::min();
|
||||
}
|
||||
|
||||
void ResetGroups()
|
||||
{
|
||||
ResetSelection();
|
||||
groups.clear();
|
||||
processed = 0;
|
||||
groupId = 0;
|
||||
selCs = 0;
|
||||
selGroup = Unselected;
|
||||
}
|
||||
|
||||
void ResetSelection()
|
||||
{
|
||||
selSort.clear();
|
||||
selSortNum = 0;
|
||||
selSortActive = 0;
|
||||
selAverage = 0;
|
||||
selMedian = 0;
|
||||
selTotal = 0;
|
||||
selTime = 0;
|
||||
binCache.numBins = -1;
|
||||
samples.scheduleUpdate = true;
|
||||
}
|
||||
|
||||
void ShowZone( int16_t srcloc, const char* name )
|
||||
{
|
||||
show = true;
|
||||
range.active = false;
|
||||
Reset();
|
||||
match.emplace_back( srcloc );
|
||||
strcpy( pattern, name );
|
||||
}
|
||||
|
||||
void ShowZone( int16_t srcloc, const char* name, int64_t limitMin, int64_t limitMax )
|
||||
{
|
||||
assert( limitMin <= limitMax );
|
||||
show = true;
|
||||
range.active = true;
|
||||
range.min = limitMin;
|
||||
range.max = limitMax;
|
||||
Reset();
|
||||
match.emplace_back( srcloc );
|
||||
strcpy( pattern, name );
|
||||
}
|
||||
} m_findZone;
|
||||
|
||||
tracy_force_inline uint64_t GetSelectionTarget( const Worker::ZoneThreadData& ev, FindZone::GroupBy groupBy ) const;
|
||||
|
||||
struct CompVal
|
||||
{
|
||||
double v0;
|
||||
double v1;
|
||||
};
|
||||
|
||||
struct {
|
||||
bool show = false;
|
||||
bool ignoreCase = false;
|
||||
bool link = true;
|
||||
std::unique_ptr<Worker> second;
|
||||
std::unique_ptr<UserData> userData;
|
||||
std::thread loadThread;
|
||||
BadVersionState badVer;
|
||||
char pattern[1024] = {};
|
||||
std::vector<int16_t> match[2];
|
||||
int selMatch[2] = { 0, 0 };
|
||||
bool logVal = false;
|
||||
bool logTime = true;
|
||||
bool cumulateTime = false;
|
||||
bool normalize = true;
|
||||
int64_t numBins = -1;
|
||||
std::unique_ptr<CompVal[]> bins, binTime;
|
||||
std::vector<int64_t> sorted[2];
|
||||
size_t sortedNum[2] = { 0, 0 };
|
||||
float average[2];
|
||||
float median[2];
|
||||
int64_t total[2];
|
||||
int minBinVal = 1;
|
||||
int compareMode = 0;
|
||||
bool diffDone = false;
|
||||
bool diffDirection;
|
||||
std::vector<const char*> thisUnique;
|
||||
std::vector<const char*> secondUnique;
|
||||
std::vector<std::pair<const char*, std::string>> diffs;
|
||||
|
||||
void ResetSelection()
|
||||
{
|
||||
for( int i=0; i<2; i++ )
|
||||
{
|
||||
sorted[i].clear();
|
||||
sortedNum[i] = 0;
|
||||
average[i] = 0;
|
||||
median[i] = 0;
|
||||
total[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
ResetSelection();
|
||||
for( int i=0; i<2; i++ )
|
||||
{
|
||||
match[i].clear();
|
||||
selMatch[i] = 0;
|
||||
}
|
||||
diffDone = false;
|
||||
thisUnique.clear();
|
||||
secondUnique.clear();
|
||||
diffs.clear();
|
||||
}
|
||||
} m_compare;
|
||||
|
||||
struct {
|
||||
bool show = false;
|
||||
char pattern[1024] = {};
|
||||
uint64_t ptrFind = 0;
|
||||
uint64_t pool = 0;
|
||||
bool showAllocList = false;
|
||||
std::vector<size_t> allocList;
|
||||
Range range;
|
||||
} m_memInfo;
|
||||
|
||||
struct {
|
||||
std::vector<int64_t> data;
|
||||
const FrameData* frameSet = nullptr;
|
||||
size_t frameNum = 0;
|
||||
float average = 0;
|
||||
float median = 0;
|
||||
int64_t total = 0;
|
||||
bool logVal = false;
|
||||
bool logTime = true;
|
||||
int64_t numBins = -1;
|
||||
std::unique_ptr<int64_t[]> bins;
|
||||
bool drawAvgMed = true;
|
||||
bool limitToView = false;
|
||||
std::pair<int, int> limitRange = { -1, 0 };
|
||||
int minBinVal = 1;
|
||||
} m_frameSortData;
|
||||
|
||||
struct {
|
||||
std::pair<const ZoneEvent*, int64_t> zoneSelfTime = { nullptr, 0 };
|
||||
std::pair<const ZoneEvent*, int64_t> zoneSelfTime2 = { nullptr, 0 };
|
||||
std::pair<const GpuEvent*, int64_t> gpuSelfTime = { nullptr, 0 };
|
||||
std::pair<const GpuEvent*, int64_t> gpuSelfTime2 = { nullptr, 0 };
|
||||
} m_cache;
|
||||
|
||||
struct {
|
||||
void* texture = nullptr;
|
||||
float timeLeft = 0;
|
||||
float speed = 1;
|
||||
uint32_t frame = 0;
|
||||
uint32_t currFrame = -1;
|
||||
bool pause = true;
|
||||
bool sync = false;
|
||||
bool zoom = false;
|
||||
} m_playback;
|
||||
|
||||
struct TimeDistribution {
|
||||
bool runningTime = false;
|
||||
bool exclusiveTime = true;
|
||||
unordered_flat_map<int16_t, ZoneTimeData> data;
|
||||
const ZoneEvent* dataValidFor = nullptr;
|
||||
float fztime;
|
||||
} m_timeDist;
|
||||
|
||||
struct {
|
||||
uint64_t symAddr = 0;
|
||||
int sel;
|
||||
bool withInlines = false;
|
||||
int mode = 0;
|
||||
bool groupBottomUp = true;
|
||||
bool groupTopDown = true;
|
||||
} m_sampleParents;
|
||||
|
||||
struct
|
||||
{
|
||||
bool enabled = false;
|
||||
bool monitor = false;
|
||||
int64_t time;
|
||||
} m_sendQueueWarning;
|
||||
|
||||
bool m_attnProtoMismatch = false;
|
||||
bool m_attnNotAvailable = false;
|
||||
bool m_attnDropped = false;
|
||||
bool m_attnFailure = false;
|
||||
bool m_attnWorking = false;
|
||||
bool m_attnDisconnected = false;
|
||||
|
||||
AchievementsMgr* m_achievementsMgr;
|
||||
bool m_achievements = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
81
subprojects/tracy/profiler/src/profiler/TracyViewData.hpp
Normal file
81
subprojects/tracy/profiler/src/profiler/TracyViewData.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef __TRACYVIEWDATA_HPP__
|
||||
#define __TRACYVIEWDATA_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <regex>
|
||||
|
||||
#include "TracyUtility.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct Range
|
||||
{
|
||||
void StartFrame() { hiMin = hiMax = false; }
|
||||
|
||||
int64_t min = 0;
|
||||
int64_t max = 0;
|
||||
bool active = false;
|
||||
bool hiMin = false;
|
||||
bool hiMax = false;
|
||||
bool modMin = false;
|
||||
bool modMax = false;
|
||||
};
|
||||
|
||||
struct RangeSlim
|
||||
{
|
||||
bool operator==( const Range& other ) const { return other.active == active && other.min == min && other.max == max; }
|
||||
bool operator!=( const Range& other ) const { return !(*this == other); }
|
||||
void operator=( const Range& other ) { active = other.active; min = other.min; max = other.max; }
|
||||
|
||||
int64_t min, max;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
|
||||
struct ViewData
|
||||
{
|
||||
int64_t zvStart = 0;
|
||||
int64_t zvEnd = 0;
|
||||
int32_t frameScale = 0;
|
||||
int32_t frameStart = 0;
|
||||
|
||||
uint8_t drawGpuZones = true;
|
||||
uint8_t drawZones = true;
|
||||
uint8_t drawLocks = true;
|
||||
uint8_t drawPlots = true;
|
||||
uint8_t onlyContendedLocks = true;
|
||||
uint8_t drawEmptyLabels = false;
|
||||
uint8_t drawFrameTargets = false;
|
||||
uint8_t drawContextSwitches = true;
|
||||
uint8_t darkenContextSwitches = true;
|
||||
uint8_t drawCpuData = true;
|
||||
uint8_t drawCpuUsageGraph = true;
|
||||
uint8_t drawSamples = true;
|
||||
uint8_t dynamicColors = 1;
|
||||
uint8_t forceColors = false;
|
||||
uint8_t ghostZones = true;
|
||||
ShortenName shortenName = ShortenName::NoSpaceAndNormalize;
|
||||
|
||||
uint32_t frameTarget = 60;
|
||||
|
||||
uint32_t plotHeight = 100;
|
||||
};
|
||||
|
||||
struct Annotation
|
||||
{
|
||||
std::string text;
|
||||
Range range;
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
struct SourceRegex
|
||||
{
|
||||
std::string pattern;
|
||||
std::string target;
|
||||
std::regex regex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,151 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
void View::AddAnnotation( int64_t start, int64_t end )
|
||||
{
|
||||
auto ann = std::make_unique<Annotation>();
|
||||
ann->range.active = true;
|
||||
ann->range.min = start;
|
||||
ann->range.max = end;
|
||||
ann->color = 0x888888;
|
||||
m_selectedAnnotation = ann.get();
|
||||
m_annotations.emplace_back( std::move( ann ) );
|
||||
pdqsort_branchless( m_annotations.begin(), m_annotations.end(), []( const auto& lhs, const auto& rhs ) { return lhs->range.min < rhs->range.min; } );
|
||||
}
|
||||
|
||||
void View::DrawSelectedAnnotation()
|
||||
{
|
||||
assert( m_selectedAnnotation );
|
||||
bool show = true;
|
||||
ImGui::Begin( "Annotation", &show, ImGuiWindowFlags_AlwaysAutoResize );
|
||||
if( !ImGui::GetCurrentWindowRead()->SkipItems )
|
||||
{
|
||||
if( ImGui::Button( ICON_FA_MICROSCOPE " Zoom to annotation" ) )
|
||||
{
|
||||
ZoomToRange( m_selectedAnnotation->range.min, m_selectedAnnotation->range.max );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( ICON_FA_TRASH_CAN " Remove" ) )
|
||||
{
|
||||
for( auto it = m_annotations.begin(); it != m_annotations.end(); ++it )
|
||||
{
|
||||
if( it->get() == m_selectedAnnotation )
|
||||
{
|
||||
m_annotations.erase( it );
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
m_selectedAnnotation = nullptr;
|
||||
return;
|
||||
}
|
||||
ImGui::Separator();
|
||||
{
|
||||
const auto desc = m_selectedAnnotation->text.c_str();
|
||||
const auto descsz = std::min<size_t>( 1023, m_selectedAnnotation->text.size() );
|
||||
char buf[1024];
|
||||
buf[descsz] = '\0';
|
||||
memcpy( buf, desc, descsz );
|
||||
if( ImGui::InputTextWithHint( "##anndesc", "Describe annotation", buf, 256 ) )
|
||||
{
|
||||
m_selectedAnnotation->text.assign( buf );
|
||||
}
|
||||
}
|
||||
ImVec4 col = ImGui::ColorConvertU32ToFloat4( m_selectedAnnotation->color );
|
||||
ImGui::ColorEdit3( "Color", &col.x );
|
||||
m_selectedAnnotation->color = ImGui::ColorConvertFloat4ToU32( col );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Annotation begin:", TimeToStringExact( m_selectedAnnotation->range.min ) );
|
||||
TextFocused( "Annotation end:", TimeToStringExact( m_selectedAnnotation->range.max ) );
|
||||
TextFocused( "Annotation length:", TimeToString( m_selectedAnnotation->range.max - m_selectedAnnotation->range.min ) );
|
||||
}
|
||||
ImGui::End();
|
||||
if( !show ) m_selectedAnnotation = nullptr;
|
||||
}
|
||||
|
||||
void View::DrawAnnotationList()
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
ImGui::SetNextWindowSize( ImVec2( 600 * scale, 300 * scale ), ImGuiCond_FirstUseEver );
|
||||
ImGui::Begin( "Annotation list", &m_showAnnotationList );
|
||||
if( ImGui::GetCurrentWindowRead()->SkipItems ) { ImGui::End(); return; }
|
||||
|
||||
if( ImGui::Button( ICON_FA_PLUS " Add annotation" ) )
|
||||
{
|
||||
AddAnnotation( m_vd.zvStart, m_vd.zvEnd );
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
||||
ImGui::SameLine();
|
||||
|
||||
if( m_annotations.empty() )
|
||||
{
|
||||
ImGui::TextWrapped( "No annotations." );
|
||||
ImGui::Separator();
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
TextFocused( "Annotations:", RealToString( m_annotations.size() ) );
|
||||
ImGui::Separator();
|
||||
ImGui::BeginChild( "##annotationList" );
|
||||
const bool ctrl = ImGui::GetIO().KeyCtrl;
|
||||
int remove = -1;
|
||||
int idx = 0;
|
||||
for( auto& ann : m_annotations )
|
||||
{
|
||||
ImGui::PushID( idx );
|
||||
if( ImGui::Button( ICON_FA_PEN_TO_SQUARE ) )
|
||||
{
|
||||
m_selectedAnnotation = ann.get();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( ICON_FA_MICROSCOPE ) )
|
||||
{
|
||||
ZoomToRange( ann->range.min, ann->range.max );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ButtonDisablable( ICON_FA_TRASH_CAN, !ctrl ) )
|
||||
{
|
||||
remove = idx;
|
||||
}
|
||||
if( !ctrl ) TooltipIfHovered( "Press ctrl key to enable removal" );
|
||||
ImGui::SameLine();
|
||||
ImGui::ColorButton( "c", ImGui::ColorConvertU32ToFloat4( ann->color ), ImGuiColorEditFlags_NoTooltip );
|
||||
ImGui::SameLine();
|
||||
if( m_selectedAnnotation == ann.get() )
|
||||
{
|
||||
bool t = true;
|
||||
ImGui::Selectable( "##annSelectable", &t );
|
||||
ImGui::SameLine( 0, 0 );
|
||||
}
|
||||
if( ann->text.empty() )
|
||||
{
|
||||
TextDisabledUnformatted( "Empty annotation" );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextUnformatted( ann->text.c_str() );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "%s - %s (%s)", TimeToStringExact( ann->range.min ), TimeToStringExact( ann->range.max ), TimeToString( ann->range.max - ann->range.min ) );
|
||||
ImGui::PopID();
|
||||
idx++;
|
||||
}
|
||||
if( remove >= 0 )
|
||||
{
|
||||
if( m_annotations[remove].get() == m_selectedAnnotation ) m_selectedAnnotation = nullptr;
|
||||
m_annotations.erase( m_annotations.begin() + remove );
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
}
|
||||
550
subprojects/tracy/profiler/src/profiler/TracyView_Callstack.cpp
Normal file
550
subprojects/tracy/profiler/src/profiler/TracyView_Callstack.cpp
Normal file
@@ -0,0 +1,550 @@
|
||||
#include <inttypes.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "../public/common/TracyStackFrames.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyUtility.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static bool IsFrameExternal( const char* filename, const char* image )
|
||||
{
|
||||
if( strncmp( filename, "/usr/", 5 ) == 0 || strncmp( filename, "/lib/", 5 ) == 0 || strcmp( filename, "[unknown]" ) == 0 ) return true;
|
||||
if( strncmp( filename, "C:\\Program Files\\", 17 ) == 0 || strncmp( filename, "d:\\a01\\_work\\", 13 ) == 0 ) return true;
|
||||
if( !image ) return false;
|
||||
return strncmp( image, "/usr/", 5 ) == 0 || strncmp( image, "/lib/", 5 ) == 0 || strncmp( image, "/lib64/", 7 ) == 0 || strcmp( image, "<kernel>" ) == 0;
|
||||
}
|
||||
|
||||
void View::DrawCallstackWindow()
|
||||
{
|
||||
bool show = true;
|
||||
const auto scale = GetScale();
|
||||
ImGui::SetNextWindowSize( ImVec2( 1400 * scale, 500 * scale ), ImGuiCond_FirstUseEver );
|
||||
ImGui::Begin( "Call stack", &show, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse );
|
||||
if( !ImGui::GetCurrentWindowRead()->SkipItems )
|
||||
{
|
||||
DrawCallstackTable( m_callstackInfoWindow, true );
|
||||
}
|
||||
ImGui::End();
|
||||
if( !show ) m_callstackInfoWindow = 0;
|
||||
}
|
||||
|
||||
void View::DrawCallstackTable( uint32_t callstack, bool globalEntriesButton )
|
||||
{
|
||||
auto& cs = m_worker.GetCallstack( callstack );
|
||||
if( ClipboardButton() )
|
||||
{
|
||||
std::ostringstream s;
|
||||
int fidx = 0;
|
||||
for( auto& entry : cs )
|
||||
{
|
||||
char buf[64*1024];
|
||||
auto frameData = m_worker.GetCallstackFrame( entry );
|
||||
if( !frameData )
|
||||
{
|
||||
sprintf( buf, "%3i. %p\n", fidx++, (void*)m_worker.GetCanonicalPointer( entry ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ptr = buf;
|
||||
const auto fsz = frameData->size;
|
||||
for( uint8_t f=0; f<fsz; f++ )
|
||||
{
|
||||
const auto& frame = frameData->data[f];
|
||||
auto txt = m_worker.GetString( frame.name );
|
||||
|
||||
if( fidx == 0 && f != fsz-1 )
|
||||
{
|
||||
auto test = tracy::s_tracyStackFrames;
|
||||
bool match = false;
|
||||
do
|
||||
{
|
||||
if( strcmp( txt, *test ) == 0 )
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while( *++test );
|
||||
if( match ) continue;
|
||||
}
|
||||
|
||||
if( f == fsz-1 )
|
||||
{
|
||||
ptr += sprintf( ptr, "%3i. ", fidx++ );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr += sprintf( ptr, "inl. " );
|
||||
}
|
||||
ptr += sprintf( ptr, "%s ", txt );
|
||||
txt = m_worker.GetString( frame.file );
|
||||
if( frame.line == 0 )
|
||||
{
|
||||
ptr += sprintf( ptr, "(%s)", txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr += sprintf( ptr, "(%s:%" PRIu32 ")", txt, frame.line );
|
||||
}
|
||||
if( frameData->imageName.Active() )
|
||||
{
|
||||
ptr += sprintf( ptr, " %s\n", m_worker.GetString( frameData->imageName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr += sprintf( ptr, "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
s << buf;
|
||||
}
|
||||
ImGui::SetClipboardText( s.str().c_str() );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
SmallCheckbox( "External frames", &m_showExternalFrames );
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( ICON_FA_AT " Frame location:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) );
|
||||
ImGui::RadioButton( "Source code", &m_showCallstackFrameAddress, 0 );
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton( "Entry point", &m_showCallstackFrameAddress, 3 );
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton( "Return address", &m_showCallstackFrameAddress, 1 );
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton( "Symbol address", &m_showCallstackFrameAddress, 2 );
|
||||
|
||||
if( globalEntriesButton && m_worker.AreCallstackSamplesReady() )
|
||||
{
|
||||
auto frame = m_worker.GetCallstackFrame( *cs.begin() );
|
||||
if( frame && frame->data[0].symAddr != 0 )
|
||||
{
|
||||
auto sym = m_worker.GetSymbolStats( frame->data[0].symAddr );
|
||||
if( sym && !sym->parents.empty() )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( ICON_FA_DOOR_OPEN " Global entry statistics" ) )
|
||||
{
|
||||
ShowSampleParents( frame->data[0].symAddr, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Separator();
|
||||
if( ImGui::BeginTable( "##callstack", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY ) )
|
||||
{
|
||||
ImGui::TableSetupScrollFreeze( 0, 1 );
|
||||
ImGui::TableSetupColumn( "Frame", ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
|
||||
ImGui::TableSetupColumn( "Function" );
|
||||
ImGui::TableSetupColumn( "Location" );
|
||||
ImGui::TableSetupColumn( "Image" );
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
bool external = false;
|
||||
int fidx = 0;
|
||||
int bidx = 0;
|
||||
for( auto& entry : cs )
|
||||
{
|
||||
auto frameData = m_worker.GetCallstackFrame( entry );
|
||||
if( !frameData )
|
||||
{
|
||||
if( !m_showExternalFrames )
|
||||
{
|
||||
external = true;
|
||||
continue;
|
||||
}
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text( "%i", fidx++ );
|
||||
ImGui::TableNextColumn();
|
||||
char buf[32];
|
||||
sprintf( buf, "%p", (void*)m_worker.GetCanonicalPointer( entry ) );
|
||||
ImGui::TextUnformatted( buf );
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
ImGui::SetClipboardText( buf );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto fsz = frameData->size;
|
||||
for( uint8_t f=0; f<fsz; f++ )
|
||||
{
|
||||
const auto& frame = frameData->data[f];
|
||||
auto txt = m_worker.GetString( frame.name );
|
||||
|
||||
if( fidx == 0 && f != fsz-1 )
|
||||
{
|
||||
auto test = s_tracyStackFrames;
|
||||
bool match = false;
|
||||
do
|
||||
{
|
||||
if( strcmp( txt, *test ) == 0 )
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while( *++test );
|
||||
if( match ) continue;
|
||||
}
|
||||
|
||||
auto filename = m_worker.GetString( frame.file );
|
||||
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
|
||||
|
||||
if( IsFrameExternal( filename, image ) )
|
||||
{
|
||||
if( !m_showExternalFrames )
|
||||
{
|
||||
if( f == fsz-1 ) fidx++;
|
||||
external = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( external )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
TextDisabledUnformatted( "external" );
|
||||
ImGui::PopFont();
|
||||
ImGui::TableNextColumn();
|
||||
TextDisabledUnformatted( "\xe2\x80\xa6" );
|
||||
external = false;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
bidx++;
|
||||
if( f == fsz-1 )
|
||||
{
|
||||
ImGui::Text( "%i", fidx++ );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushFont( m_smallFont );
|
||||
TextDisabledUnformatted( "inline" );
|
||||
ImGui::PopFont();
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::PushTextWrapPos( 0.0f );
|
||||
if( txt[0] == '[' )
|
||||
{
|
||||
TextDisabledUnformatted( txt );
|
||||
}
|
||||
else if( m_worker.GetCanonicalPointer( entry ) >> 63 != 0 )
|
||||
{
|
||||
TextColoredUnformatted( 0xFF8888FF, txt );
|
||||
}
|
||||
else if( m_vd.shortenName == ShortenName::Never )
|
||||
{
|
||||
ImGui::TextUnformatted( txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto normalized = ShortenZoneName( ShortenName::OnlyNormalize, txt );
|
||||
ImGui::TextUnformatted( normalized );
|
||||
TooltipNormalizedName( txt, normalized );
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
ImGui::SetClipboardText( txt );
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PushTextWrapPos( 0.0f );
|
||||
float indentVal = 0.f;
|
||||
if( m_callstackBuzzAnim.Match( bidx ) )
|
||||
{
|
||||
const auto time = m_callstackBuzzAnim.Time();
|
||||
indentVal = sin( time * 60.f ) * 10.f * time;
|
||||
ImGui::Indent( indentVal );
|
||||
}
|
||||
switch( m_showCallstackFrameAddress )
|
||||
{
|
||||
case 0:
|
||||
TextDisabledUnformatted( LocationToString( filename, frame.line ) );
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
ImGui::SetClipboardText( LocationToString( filename, frame.line ) );
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( entry.sel == 0 )
|
||||
{
|
||||
const auto addr = m_worker.GetCanonicalPointer( entry );
|
||||
ImGui::TextDisabled( "0x%" PRIx64, addr );
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
char tmp[32];
|
||||
sprintf( tmp, "0x%" PRIx64, addr );
|
||||
ImGui::SetClipboardText( tmp );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled( "Custom #%" PRIu64, entry.idx );
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if( entry.sel == 0 )
|
||||
{
|
||||
ImGui::TextDisabled( "0x%" PRIx64, frame.symAddr );
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
char tmp[32];
|
||||
sprintf( tmp, "0x%" PRIx64, frame.symAddr );
|
||||
ImGui::SetClipboardText( tmp );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled( "Custom #%" PRIu64, entry.idx );
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
const auto sym = m_worker.GetSymbolData( frame.symAddr );
|
||||
if( sym )
|
||||
{
|
||||
const auto symtxt = m_worker.GetString( sym->file );
|
||||
TextDisabledUnformatted( LocationToString( symtxt, sym->line ) );
|
||||
if( ImGui::IsItemClicked() )
|
||||
{
|
||||
ImGui::SetClipboardText( symtxt );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( "[unknown]" );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
if( m_showCallstackFrameAddress == 3 )
|
||||
{
|
||||
const auto sym = m_worker.GetSymbolData( frame.symAddr );
|
||||
if( sym )
|
||||
{
|
||||
const auto symtxt = m_worker.GetString( sym->file );
|
||||
DrawSourceTooltip( symtxt, sym->line );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSourceTooltip( filename, frame.line );
|
||||
}
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( m_showCallstackFrameAddress == 3 )
|
||||
{
|
||||
const auto sym = m_worker.GetSymbolData( frame.symAddr );
|
||||
if( sym )
|
||||
{
|
||||
const auto symtxt = m_worker.GetString( sym->file );
|
||||
if( !ViewDispatch( symtxt, sym->line, frame.symAddr ) )
|
||||
{
|
||||
m_callstackBuzzAnim.Enable( bidx, 0.5f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_callstackBuzzAnim.Enable( bidx, 0.5f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !ViewDispatch( filename, frame.line, frame.symAddr ) )
|
||||
{
|
||||
m_callstackBuzzAnim.Enable( bidx, 0.5f );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( indentVal != 0.f )
|
||||
{
|
||||
ImGui::Unindent( indentVal );
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::TableNextColumn();
|
||||
if( image ) TextDisabledUnformatted( image );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( external )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
TextDisabledUnformatted( "external" );
|
||||
ImGui::PopFont();
|
||||
ImGui::TableNextColumn();
|
||||
TextDisabledUnformatted( "\xe2\x80\xa6" );
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
void View::SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip )
|
||||
{
|
||||
bool hilite = m_callstackInfoWindow == callstack;
|
||||
if( hilite )
|
||||
{
|
||||
SetButtonHighlightColor();
|
||||
}
|
||||
ImGui::PushID( idx++ );
|
||||
if( ImGui::SmallButton( name ) )
|
||||
{
|
||||
m_callstackInfoWindow = callstack;
|
||||
}
|
||||
ImGui::PopID();
|
||||
if( hilite )
|
||||
{
|
||||
ImGui::PopStyleColor( 3 );
|
||||
}
|
||||
if( tooltip && ImGui::IsItemHovered() )
|
||||
{
|
||||
CallstackTooltip( callstack );
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const
|
||||
{
|
||||
const auto& csdata = m_worker.GetCallstack( callstack );
|
||||
const auto cssz = std::min( csdata.size(), limit );
|
||||
bool first = true;
|
||||
for( uint16_t i=0; i<cssz; i++ )
|
||||
{
|
||||
const auto frameData = m_worker.GetCallstackFrame( csdata[i] );
|
||||
if( !frameData ) break;
|
||||
if( first )
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::SameLine();
|
||||
TextDisabledUnformatted( ICON_FA_LEFT_LONG );
|
||||
ImGui::SameLine();
|
||||
}
|
||||
const auto& frame = frameData->data[frameData->size - 1];
|
||||
auto txt = m_worker.GetString( frame.name );
|
||||
if( txt[0] == '[' )
|
||||
{
|
||||
TextDisabledUnformatted( txt );
|
||||
}
|
||||
else if( m_vd.shortenName == ShortenName::Never )
|
||||
{
|
||||
ImGui::TextUnformatted( txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextUnformatted( ShortenZoneName( ShortenName::Always, txt ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::CallstackTooltip( uint32_t idx )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
CallstackTooltipContents( idx );
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
void View::CallstackTooltipContents( uint32_t idx )
|
||||
{
|
||||
auto& cs = m_worker.GetCallstack( idx );
|
||||
int fidx = 0;
|
||||
for( auto& entry : cs )
|
||||
{
|
||||
auto frameData = m_worker.GetCallstackFrame( entry );
|
||||
if( !frameData )
|
||||
{
|
||||
ImGui::TextDisabled( "%i.", fidx++ );
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%p", (void*)m_worker.GetCanonicalPointer( entry ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto fsz = frameData->size;
|
||||
for( uint8_t f=0; f<fsz; f++ )
|
||||
{
|
||||
const auto& frame = frameData->data[f];
|
||||
auto txt = m_worker.GetString( frame.name );
|
||||
|
||||
if( fidx == 0 && f != fsz-1 )
|
||||
{
|
||||
auto test = s_tracyStackFrames;
|
||||
bool match = false;
|
||||
do
|
||||
{
|
||||
if( strcmp( txt, *test ) == 0 )
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while( *++test );
|
||||
if( match ) continue;
|
||||
}
|
||||
if( f == fsz-1 )
|
||||
{
|
||||
ImGui::TextDisabled( "%i.", fidx++ );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( ICON_FA_CARET_RIGHT );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( txt[0] == '[' )
|
||||
{
|
||||
TextDisabledUnformatted( txt );
|
||||
}
|
||||
else if( m_worker.GetCanonicalPointer( entry ) >> 63 != 0 )
|
||||
{
|
||||
TextColoredUnformatted( 0xFF8888FF, txt );
|
||||
}
|
||||
else if( m_vd.shortenName == ShortenName::Never )
|
||||
{
|
||||
ImGui::TextUnformatted( txt );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextUnformatted( ShortenZoneName( ShortenName::OnlyNormalize, txt ) );
|
||||
}
|
||||
if( frameData->imageName.Active() )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( m_worker.GetString( frameData->imageName ) );
|
||||
ImGui::PopFont();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1319
subprojects/tracy/profiler/src/profiler/TracyView_Compare.cpp
Normal file
1319
subprojects/tracy/profiler/src/profiler/TracyView_Compare.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,249 @@
|
||||
#include "TracyFileselector.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTexture.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr size_t SendQueueEnableThreshold = 1000000;
|
||||
constexpr size_t SendQueueDisableThreshold = 500000;
|
||||
constexpr int64_t SendQueueTimespanMs = 10000; // 10 s
|
||||
|
||||
bool View::DrawConnection()
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
const auto cs = ty * 0.9f;
|
||||
const auto isConnected = m_worker.IsConnected();
|
||||
size_t sendQueue;
|
||||
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock( m_worker.GetMbpsDataLock() );
|
||||
TextFocused( isConnected ? "Connected to:" : "Disconnected:", m_worker.GetAddr().c_str() );
|
||||
const auto& mbpsVector = m_worker.GetMbpsData();
|
||||
const auto mbps = mbpsVector.back();
|
||||
char buf[64];
|
||||
if( mbps < 0.1f )
|
||||
{
|
||||
sprintf( buf, "%6.2f Kbps", mbps * 1000.f );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buf, "%6.2f Mbps", mbps );
|
||||
}
|
||||
ImGui::Dummy( ImVec2( cs, 0 ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::PlotLines( buf, mbpsVector.data(), mbpsVector.size(), 0, nullptr, 0, std::numeric_limits<float>::max(), ImVec2( 150 * scale, 0 ) );
|
||||
TextDisabledUnformatted( "Ratio" );
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%.1f%%", m_worker.GetCompRatio() * 100.f );
|
||||
ImGui::SameLine();
|
||||
TextDisabledUnformatted( "Real:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%6.2f Mbps", mbps / m_worker.GetCompRatio() );
|
||||
TextFocused( "Data transferred:", MemSizeToString( m_worker.GetDataTransferred() ) );
|
||||
sendQueue = m_worker.GetSendQueueSize();
|
||||
TextFocused( "Query backlog:", RealToString( sendQueue ) );
|
||||
}
|
||||
|
||||
if( !m_sendQueueWarning.enabled )
|
||||
{
|
||||
if( !m_sendQueueWarning.monitor )
|
||||
{
|
||||
if( sendQueue > SendQueueEnableThreshold )
|
||||
{
|
||||
m_sendQueueWarning.monitor = true;
|
||||
m_sendQueueWarning.time = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( sendQueue < SendQueueDisableThreshold )
|
||||
{
|
||||
m_sendQueueWarning.monitor = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto t = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
|
||||
if( t - m_sendQueueWarning.time > SendQueueTimespanMs )
|
||||
{
|
||||
m_sendQueueWarning.enabled = true;
|
||||
m_sendQueueWarning.monitor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto wpos = ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin();
|
||||
ImGui::GetWindowDrawList()->AddCircleFilled( wpos + ImVec2( 1 + cs * 0.5, 3 + ty * 1.75 ), cs * 0.5, isConnected ? 0xFF2222CC : 0xFF444444, 10 );
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "+", RealToString( m_worker.GetSendInFlight() ) );
|
||||
const auto sz = m_worker.GetFrameCount( *m_frames );
|
||||
if( sz > 1 )
|
||||
{
|
||||
const auto dt = m_worker.GetFrameTime( *m_frames, sz - 2 );
|
||||
const auto fps = 1000000000.f / dt;
|
||||
TextDisabledUnformatted( "FPS:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%6.1f", fps );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Frame time:", TimeToString( dt ) );
|
||||
}
|
||||
}
|
||||
|
||||
const auto& fis = m_worker.GetFrameImages();
|
||||
if( !fis.empty() )
|
||||
{
|
||||
const auto fiScale = scale * 0.5f;
|
||||
const auto& fi = fis.back();
|
||||
if( fi != m_frameTextureConnPtr )
|
||||
{
|
||||
if( !m_frameTextureConn ) m_frameTextureConn = MakeTexture();
|
||||
UpdateTexture( m_frameTextureConn, m_worker.UnpackFrameImage( *fi ), fi->w, fi->h );
|
||||
m_frameTextureConnPtr = fi;
|
||||
}
|
||||
ImGui::Separator();
|
||||
if( fi->flip )
|
||||
{
|
||||
ImGui::Image( m_frameTextureConn, ImVec2( fi->w * fiScale, fi->h * fiScale ), ImVec2( 0, 1 ), ImVec2( 1, 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Image( m_frameTextureConn, ImVec2( fi->w * fiScale, fi->h * fiScale ) );
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) && m_saveThreadState.load( std::memory_order_relaxed ) == SaveThreadState::Inert )
|
||||
{
|
||||
auto cb = [this]( const char* fn ) {
|
||||
const auto sz = strlen( fn );
|
||||
if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 )
|
||||
{
|
||||
char tmp[1024];
|
||||
sprintf( tmp, "%s.tracy", fn );
|
||||
m_filenameStaging = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_filenameStaging = fn;
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
Fileselector::SaveFile( "tracy", "Tracy Profiler trace file", cb );
|
||||
#else
|
||||
cb( "trace.tracy" );
|
||||
#endif
|
||||
}
|
||||
|
||||
ImGui::SameLine( 0, 2 * ty );
|
||||
const char* stopStr = ICON_FA_PLUG " Stop";
|
||||
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
|
||||
if( !m_disconnectIssued && m_worker.IsConnected() )
|
||||
{
|
||||
if( ImGui::Button( stopStr ) )
|
||||
{
|
||||
m_worker.Disconnect();
|
||||
m_disconnectIssued = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button( stopStr );
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( ICON_FA_TRIANGLE_EXCLAMATION " Discard" ) )
|
||||
{
|
||||
ImGui::OpenPopup( "Confirm trace discard" );
|
||||
}
|
||||
|
||||
if( ImGui::BeginPopupModal( "Confirm trace discard", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
ImGui::PushFont( m_bigFont );
|
||||
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::PopFont();
|
||||
ImGui::TextUnformatted( "All unsaved profiling data will be lost!" );
|
||||
ImGui::TextUnformatted( "Are you sure you want to proceed?" );
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( "Yes" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
return false;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( "Reconnect" ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
m_reconnectRequested = true;
|
||||
return false;
|
||||
}
|
||||
ImGui::SameLine( 0, ty * 2 );
|
||||
if( ImGui::Button( "No", ImVec2( ty * 6, 0 ) ) )
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if( m_worker.IsConnected() )
|
||||
{
|
||||
const auto& params = m_worker.GetParameters();
|
||||
if( !params.empty() )
|
||||
{
|
||||
ImGui::Separator();
|
||||
if( ImGui::TreeNode( "Trace parameters" ) )
|
||||
{
|
||||
if( ImGui::BeginTable( "##traceparams", 2, ImGuiTableFlags_Borders ) )
|
||||
{
|
||||
ImGui::TableSetupColumn( "Name" );
|
||||
ImGui::TableSetupColumn( "Value", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
|
||||
ImGui::TableHeadersRow();
|
||||
size_t idx = 0;
|
||||
for( auto& p : params )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted( m_worker.GetString( p.name ) );
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PushID( idx );
|
||||
if( p.isBool )
|
||||
{
|
||||
bool val = p.val;
|
||||
if( ImGui::Checkbox( "", &val ) )
|
||||
{
|
||||
m_worker.SetParameter( idx, int32_t( val ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto val = int( p.val );
|
||||
if( ImGui::InputInt( "", &val, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue ) )
|
||||
{
|
||||
m_worker.SetParameter( idx, int32_t( val ) );
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
idx++;
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,587 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
const char* View::DecodeContextSwitchReasonCode( uint8_t reason )
|
||||
{
|
||||
switch( reason )
|
||||
{
|
||||
case 0: return "Executive";
|
||||
case 1: return "FreePage";
|
||||
case 2: return "PageIn";
|
||||
case 3: return "PoolAllocation";
|
||||
case 4: return "DelayExecution";
|
||||
case 5: return "Suspended";
|
||||
case 6: return "UserRequest";
|
||||
case 7: return "WrExecutive";
|
||||
case 8: return "WrFreePage";
|
||||
case 9: return "WrPageIn";
|
||||
case 10: return "WrPoolAllocation";
|
||||
case 11: return "WrDelayExecution";
|
||||
case 12: return "WrSuspended";
|
||||
case 13: return "WrUserRequest";
|
||||
case 14: return "WrEventPair";
|
||||
case 15: return "WrQueue";
|
||||
case 16: return "WrLpcReceive";
|
||||
case 17: return "WrLpcReply";
|
||||
case 18: return "WrVirtualMemory";
|
||||
case 19: return "WrPageOut";
|
||||
case 20: return "WrRendezvous";
|
||||
case 21: return "WrKeyedEvent";
|
||||
case 22: return "WrTerminated";
|
||||
case 23: return "WrProcessInSwap";
|
||||
case 24: return "WrCpuRateControl";
|
||||
case 25: return "WrCalloutStack";
|
||||
case 26: return "WrKernel";
|
||||
case 27: return "WrResource";
|
||||
case 28: return "WrPushLock";
|
||||
case 29: return "WrMutex";
|
||||
case 30: return "WrQuantumEnd";
|
||||
case 31: return "WrDispatchInt";
|
||||
case 32: return "WrPreempted";
|
||||
case 33: return "WrYieldExecution";
|
||||
case 34: return "WrFastMutex";
|
||||
case 35: return "WrGuardedMutex";
|
||||
case 36: return "WrRundown";
|
||||
case 37: return "WrAlertByThreadId";
|
||||
case 38: return "WrDeferredPreempt";
|
||||
case 39: return "WrPhysicalFault";
|
||||
case 40: return "MaximumWaitReason";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* View::DecodeContextSwitchReason( uint8_t reason )
|
||||
{
|
||||
switch( reason )
|
||||
{
|
||||
case 0: return "(Thread is waiting for the scheduler)";
|
||||
case 1: return "(Thread is waiting for a free virtual memory page)";
|
||||
case 2: return "(Thread is waiting for a virtual memory page to arrive in memory)";
|
||||
case 4: return "(Thread execution is delayed)";
|
||||
case 5: return "(Thread execution is suspended)";
|
||||
case 6: return "(Thread is waiting on object - WaitForSingleObject, etc.)";
|
||||
case 7: return "(Thread is waiting for the scheduler)";
|
||||
case 8: return "(Thread is waiting for a free virtual memory page)";
|
||||
case 9: return "(Thread is waiting for a virtual memory page to arrive in memory)";
|
||||
case 11: return "(Thread execution is delayed)";
|
||||
case 12: return "(Thread execution is suspended)";
|
||||
case 13: return "(Thread is waiting for window messages)";
|
||||
case 15: return "(Thread is waiting on KQUEUE)";
|
||||
case 24: return "(CPU rate limiting)";
|
||||
case 34: return "(Waiting for a Fast Mutex)";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
const char* View::DecodeContextSwitchStateCode( uint8_t state )
|
||||
{
|
||||
switch( state )
|
||||
{
|
||||
case 0: return "Initialized";
|
||||
case 1: return "Ready";
|
||||
case 2: return "Running";
|
||||
case 3: return "Standby";
|
||||
case 4: return "Terminated";
|
||||
case 5: return "Waiting";
|
||||
case 6: return "Transition";
|
||||
case 7: return "DeferredReady";
|
||||
case 101: return "D (disk sleep)";
|
||||
case 102: return "I (idle)";
|
||||
case 103: return "R (running)";
|
||||
case 104: return "S (sleeping)";
|
||||
case 105: return "T (stopped)";
|
||||
case 106: return "t (tracing stop)";
|
||||
case 107: return "W";
|
||||
case 108: return "X (dead)";
|
||||
case 109: return "Z (zombie)";
|
||||
case 110: return "P (parked)";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* View::DecodeContextSwitchState( uint8_t state )
|
||||
{
|
||||
switch( state )
|
||||
{
|
||||
case 0: return "(Thread has been initialized, but has not yet started)";
|
||||
case 1: return "(Thread is waiting to use a processor because no processor is free. The thread is prepared to run on the next available processor)";
|
||||
case 2: return "(Thread is currently using a processor)";
|
||||
case 3: return "(Thread is about to use a processor)";
|
||||
case 4: return "(Thread has finished executing and has exited)";
|
||||
case 5: return "(Thread is not ready to use the processor because it is waiting for a peripheral operation to complete or a resource to become free)";
|
||||
case 6: return "(Thread is waiting for a resource, other than the processor, before it can execute)";
|
||||
case 7: return "(Thread has been selected to run on a specific processor but have not yet beed scheduled)";
|
||||
case 101: return "(Uninterruptible sleep, usually IO)";
|
||||
case 102: return "(Idle kernel thread)";
|
||||
case 103: return "(Running or on run queue)";
|
||||
case 104: return "(Interruptible sleep, waiting for an event to complete)";
|
||||
case 105: return "(Stopped by job control signal)";
|
||||
case 106: return "(Stopped by debugger during the tracing)";
|
||||
case 107: return "(Paging)";
|
||||
case 108: return "(Dead task is scheduling one last time)";
|
||||
case 109: return "(Zombie process)";
|
||||
case 110: return "(Parked)";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, const Vector<ContextSwitchData>& ctxSwitch, int offset, int endOffset, bool isFiber )
|
||||
{
|
||||
constexpr float MinCtxSize = 4;
|
||||
|
||||
const auto vStart = ctx.vStart;
|
||||
const auto& wpos = ctx.wpos;
|
||||
const auto pxns = ctx.pxns;
|
||||
const auto hover = ctx.hover;
|
||||
const auto w = ctx.w;
|
||||
const auto ty = round( ctx.ty * 0.75f );
|
||||
|
||||
const auto lineSize = 2 * GetScale();
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto ty05 = round( ty * 0.5f );
|
||||
|
||||
double minpx = -10;
|
||||
|
||||
for( auto& v : drawList )
|
||||
{
|
||||
const auto it = ctxSwitch.begin() + v.idx;
|
||||
const auto& ev = *it;
|
||||
switch( v.type )
|
||||
{
|
||||
case ContextSwitchDrawType::Waiting:
|
||||
{
|
||||
const auto& prev = *(it-1);
|
||||
const bool migration = prev.Cpu() != ev.Cpu();
|
||||
const auto px0 = std::max( { ( prev.End() - vStart ) * pxns, -10.0, double( minpx ) } );
|
||||
const auto pxw = ( ev.WakeupVal() - vStart ) * pxns;
|
||||
const auto px1 = std::min( ( ev.Start() - vStart ) * pxns, w + 10.0 );
|
||||
const auto color = migration ? 0xFFEE7711 : 0xFF2222AA;
|
||||
if( m_vd.darkenContextSwitches )
|
||||
{
|
||||
draw->AddRectFilled( dpos + ImVec2( px0, offset + ty05 ), dpos + ImVec2( px1, endOffset ), 0x661C2321 );
|
||||
}
|
||||
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( std::min( pxw, w+10.0 ), offset + ty05 - 0.5f ), color, lineSize );
|
||||
if( ev.WakeupVal() != ev.Start() )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( std::max( pxw, 10.0 ), offset + ty05 - 0.5f ), dpos + ImVec2( px1, offset + ty05 - 0.5f ), 0xFF2280A0, lineSize );
|
||||
}
|
||||
|
||||
if( hover )
|
||||
{
|
||||
bool tooltip = false;
|
||||
if( ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( pxw, offset + ty ) ) )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
if( isFiber )
|
||||
{
|
||||
TextFocused( "Fiber is", "yielding" );
|
||||
TextFocused( "Yield time:", TimeToString( ev.Start() - prev.End() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Thread is", migration ? "migrating CPUs" : "waiting" );
|
||||
TextFocused( "Waiting time:", TimeToString( ev.WakeupVal() - prev.End() ) );
|
||||
if( migration )
|
||||
{
|
||||
TextFocused( "CPU:", RealToString( prev.Cpu() ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( ICON_FA_RIGHT_LONG, RealToString( ev.Cpu() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
|
||||
}
|
||||
if( prev.Reason() != 100 )
|
||||
{
|
||||
TextFocused( "Wait reason:", DecodeContextSwitchReasonCode( prev.Reason() ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( DecodeContextSwitchReason( prev.Reason() ) );
|
||||
ImGui::PopFont();
|
||||
}
|
||||
TextFocused( "Wait state:", DecodeContextSwitchStateCode( prev.State() ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( DecodeContextSwitchState( prev.State() ) );
|
||||
ImGui::PopFont();
|
||||
}
|
||||
tooltip = true;
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( prev.End(), ev.WakeupVal() );
|
||||
}
|
||||
}
|
||||
else if( ev.WakeupVal() != ev.Start() && ImGui::IsMouseHoveringRect( wpos + ImVec2( pxw, offset ), wpos + ImVec2( px1, offset + ty ) ) )
|
||||
{
|
||||
assert( !isFiber );
|
||||
ImGui::BeginTooltip();
|
||||
TextFocused( "Thread is", "waking up" );
|
||||
TextFocused( "Scheduling delay:", TimeToString( ev.Start() - ev.WakeupVal() ) );
|
||||
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( prev.End(), ev.WakeupVal() );
|
||||
}
|
||||
tooltip = true;
|
||||
}
|
||||
if( tooltip )
|
||||
{
|
||||
const auto waitStack = v.data;
|
||||
if( waitStack )
|
||||
{
|
||||
ImGui::Separator();
|
||||
TextDisabledUnformatted( ICON_FA_HOURGLASS_HALF " Wait stack:" );
|
||||
CallstackTooltipContents( waitStack );
|
||||
if( ImGui::IsMouseClicked( 0 ) )
|
||||
{
|
||||
m_callstackInfoWindow = waitStack;
|
||||
}
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ContextSwitchDrawType::Folded:
|
||||
{
|
||||
const auto num = v.data;
|
||||
const auto px0 = std::max( ( ev.Start() - vStart ) * pxns, -10.0 );
|
||||
const auto eit = it + num - 1;
|
||||
const auto end = eit->IsEndValid() ? eit->End() : eit->Start();
|
||||
const auto px1ns = end - vStart;
|
||||
minpx = std::min( std::max( px1ns * pxns, px0+MinCtxSize ), double( w + 10 ) );
|
||||
if( num == 1 )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( minpx, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize );
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
if( isFiber )
|
||||
{
|
||||
const auto tid = m_worker.DecompressThread( ev.Thread() );
|
||||
TextFocused( "Fiber is", "running" );
|
||||
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
|
||||
TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( tid ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Thread is", "running" );
|
||||
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
|
||||
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( ev.Start(), end );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, offset + ty05 ), px0, minpx, ty/4, 0xFF888888 );
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
TextFocused( isFiber ? "Fiber is" : "Thread is", "changing activity multiple times" );
|
||||
TextFocused( "Number of running regions:", RealToString( num ) );
|
||||
TextFocused( "Time:", TimeToString( end - ev.Start() ) );
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( ev.Start(), end );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ContextSwitchDrawType::Running:
|
||||
{
|
||||
const auto end = ev.IsEndValid() ? ev.End() : ev.Start();
|
||||
const auto px0 = std::max( { ( ev.Start() - vStart ) * pxns, -10.0, double( minpx ) } );
|
||||
const auto px1 = std::min( ( end - vStart ) * pxns, w + 10.0 );
|
||||
DrawLine( draw, dpos + ImVec2( px0, offset + ty05 - 0.5f ), dpos + ImVec2( px1, offset + ty05 - 0.5f ), 0xFF22DD22, lineSize );
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + ty + 1 ) ) )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
if( isFiber )
|
||||
{
|
||||
const auto tid = m_worker.DecompressThread( ev.Thread() );
|
||||
TextFocused( "Fiber is", "running" );
|
||||
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
|
||||
TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( tid ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Thread is", "running" );
|
||||
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
|
||||
TextFocused( "CPU:", RealToString( ev.Cpu() ) );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( ev.Start(), end );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawWaitStacks()
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
ImGui::SetNextWindowSize( ImVec2( 1400 * scale, 500 * scale ), ImGuiCond_FirstUseEver );
|
||||
ImGui::Begin( "Wait stacks", &m_showWaitStacks );
|
||||
if( ImGui::GetCurrentWindowRead()->SkipItems ) { ImGui::End(); return; }
|
||||
#ifdef TRACY_NO_STATISTICS
|
||||
ImGui::TextWrapped( "Rebuild without the TRACY_NO_STATISTICS macro to enable wait stacks." );
|
||||
#else
|
||||
uint64_t totalCount = 0;
|
||||
unordered_flat_map<uint32_t, uint64_t> stacks;
|
||||
for( auto& t : m_threadOrder )
|
||||
{
|
||||
if( WaitStackThread( t->id ) )
|
||||
{
|
||||
auto it = t->ctxSwitchSamples.begin();
|
||||
auto end = t->ctxSwitchSamples.end();
|
||||
if( m_waitStackRange.active )
|
||||
{
|
||||
it = std::lower_bound( it, end, m_waitStackRange.min, [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } );
|
||||
end = std::lower_bound( it, end, m_waitStackRange.max, [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs; } );
|
||||
}
|
||||
totalCount += std::distance( it, end );
|
||||
while( it != end )
|
||||
{
|
||||
auto cs = it->callstack.Val();
|
||||
auto cit = stacks.find( cs );
|
||||
if( cit == stacks.end() )
|
||||
{
|
||||
stacks.emplace( cs, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
cit->second++;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 2, 2 ) );
|
||||
if( ImGui::RadioButton( ICON_FA_TABLE " List", m_waitStackMode == 0 ) ) m_waitStackMode = 0;
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
if( ImGui::RadioButton( ICON_FA_TREE " Bottom-up tree", m_waitStackMode == 1 ) ) m_waitStackMode = 1;
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
if( ImGui::RadioButton( ICON_FA_TREE " Top-down tree", m_waitStackMode == 2 ) ) m_waitStackMode = 2;
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Total wait stacks:", RealToString( m_worker.GetContextSwitchSampleCount() ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Selected:", RealToString( totalCount ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Checkbox( "Limit range", &m_waitStackRange.active ) )
|
||||
{
|
||||
if( m_waitStackRange.active && m_waitStackRange.min == 0 && m_waitStackRange.max == 0 )
|
||||
{
|
||||
m_waitStackRange.min = m_vd.zvStart;
|
||||
m_waitStackRange.max = m_vd.zvEnd;
|
||||
}
|
||||
}
|
||||
if( m_waitStackRange.active )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( 0xFF00FFFF, ICON_FA_TRIANGLE_EXCLAMATION );
|
||||
ImGui::SameLine();
|
||||
ToggleButton( ICON_FA_RULER " Limits", m_showRanges );
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
bool threadsChanged = false;
|
||||
auto expand = ImGui::TreeNode( ICON_FA_SHUFFLE " Visible threads:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%zu)", m_threadOrder.size() );
|
||||
if( expand )
|
||||
{
|
||||
auto& crash = m_worker.GetCrashEvent();
|
||||
|
||||
ImGui::SameLine();
|
||||
if( ImGui::SmallButton( "Select all" ) )
|
||||
{
|
||||
for( const auto& t : m_threadOrder )
|
||||
{
|
||||
WaitStackThread( t->id ) = true;
|
||||
}
|
||||
threadsChanged = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::SmallButton( "Unselect all" ) )
|
||||
{
|
||||
for( const auto& t : m_threadOrder )
|
||||
{
|
||||
WaitStackThread( t->id ) = false;
|
||||
}
|
||||
threadsChanged = true;
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
for( const auto& t : m_threadOrder )
|
||||
{
|
||||
if( t->ctxSwitchSamples.empty() ) continue;
|
||||
ImGui::PushID( idx++ );
|
||||
const auto threadColor = GetThreadColor( t->id, 0 );
|
||||
SmallColorBox( threadColor );
|
||||
ImGui::SameLine();
|
||||
if( SmallCheckbox( m_worker.GetThreadName( t->id ), &WaitStackThread( t->id ) ) )
|
||||
{
|
||||
threadsChanged = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( t->ctxSwitchSamples.size() ) );
|
||||
if( crash.thread == t->id )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( ImVec4( 1.f, 0.2f, 0.2f, 1.f ), ICON_FA_SKULL " Crashed" );
|
||||
}
|
||||
if( t->isFiber )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
|
||||
}
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
if( threadsChanged ) m_waitStack = 0;
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::BeginChild( "##waitstacks" );
|
||||
if( stacks.empty() )
|
||||
{
|
||||
ImGui::TextUnformatted( "No wait stacks to display." );
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( m_waitStackMode )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
TextDisabledUnformatted( "Wait stack:" );
|
||||
ImGui::SameLine();
|
||||
if( ImGui::SmallButton( " " ICON_FA_CARET_LEFT " " ) )
|
||||
{
|
||||
m_waitStack = std::max( m_waitStack - 1, 0 );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%s / %s", RealToString( m_waitStack + 1 ), RealToString( stacks.size() ) );
|
||||
if( ImGui::IsItemClicked() ) ImGui::OpenPopup( "WaitStacksPopup" );
|
||||
ImGui::SameLine();
|
||||
if( ImGui::SmallButton( " " ICON_FA_CARET_RIGHT " " ) )
|
||||
{
|
||||
m_waitStack = std::min<int>( m_waitStack + 1, stacks.size() - 1 );
|
||||
}
|
||||
if( ImGui::BeginPopup( "WaitStacksPopup" ) )
|
||||
{
|
||||
int sel = m_waitStack + 1;
|
||||
ImGui::SetNextItemWidth( 120 * scale );
|
||||
const bool clicked = ImGui::InputInt( "##waitStack", &sel, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue );
|
||||
if( clicked ) m_waitStack = std::min( std::max( sel, 1 ), int( stacks.size() ) ) - 1;
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
Vector<decltype(stacks.begin())> data;
|
||||
data.reserve( stacks.size() );
|
||||
for( auto it = stacks.begin(); it != stacks.end(); ++it ) data.push_back( it );
|
||||
pdqsort_branchless( data.begin(), data.end(), []( const auto& l, const auto& r ) { return l->second > r->second; } );
|
||||
TextFocused( "Counts:", RealToString( data[m_waitStack]->second ) );
|
||||
ImGui::SameLine();
|
||||
char buf[64];
|
||||
PrintStringPercent( buf, 100. * data[m_waitStack]->second / totalCount );
|
||||
TextDisabledUnformatted( buf );
|
||||
ImGui::Separator();
|
||||
DrawCallstackTable( data[m_waitStack]->first, false );
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
SmallCheckbox( ICON_FA_LAYER_GROUP " Group by function name", &m_groupWaitStackBottomUp );
|
||||
auto tree = GetCallstackFrameTreeBottomUp( stacks, m_groupCallstackTreeByNameBottomUp );
|
||||
if( !tree.empty() )
|
||||
{
|
||||
int idx = 0;
|
||||
DrawFrameTreeLevel( tree, idx );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( "No call stacks to show" );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
SmallCheckbox( ICON_FA_LAYER_GROUP " Group by function name", &m_groupWaitStackTopDown );
|
||||
auto tree = GetCallstackFrameTreeTopDown( stacks, m_groupCallstackTreeByNameTopDown );
|
||||
if( !tree.empty() )
|
||||
{
|
||||
int idx = 0;
|
||||
DrawFrameTreeLevel( tree, idx );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( "No call stacks to show" );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
}
|
||||
725
subprojects/tracy/profiler/src/profiler/TracyView_CpuData.cpp
Normal file
725
subprojects/tracy/profiler/src/profiler/TracyView_CpuData.cpp
Normal file
@@ -0,0 +1,725 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "TracyColor.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTimelineDraw.hpp"
|
||||
#include "TracyTimelineItem.hpp"
|
||||
#include "TracyTimelineContext.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
constexpr float MinVisSize = 3;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
bool View::DrawCpuData( const TimelineContext& ctx, const std::vector<CpuUsageDraw>& cpuDraw, const std::vector<std::vector<CpuCtxDraw>>& ctxDraw, int& offset, bool hasCpuData )
|
||||
{
|
||||
auto cpuData = m_worker.GetCpuData();
|
||||
const auto cpuCnt = m_worker.GetCpuDataCpuCount();
|
||||
assert( cpuCnt != 0 );
|
||||
|
||||
const auto& wpos = ctx.wpos;
|
||||
const auto w = ctx.w;
|
||||
const auto ty = ctx.ty;
|
||||
const auto sty = ctx.sty;
|
||||
const auto pxns = ctx.pxns;
|
||||
const auto nspx = ctx.nspx;
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto yMin = ctx.yMin;
|
||||
const auto yMax = ctx.yMax;
|
||||
const auto hover = ctx.hover;
|
||||
const auto vStart = ctx.vStart;
|
||||
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
|
||||
if( hasCpuData && m_vd.drawCpuUsageGraph )
|
||||
{
|
||||
const auto cpuUsageHeight = floor( 30.f * GetScale() );
|
||||
if( wpos.y + offset + cpuUsageHeight + 3 >= yMin && wpos.y + offset <= yMax )
|
||||
{
|
||||
const float cpuCntRev = 1.f / cpuCnt;
|
||||
int pos = 0;
|
||||
for( auto& v : cpuDraw )
|
||||
{
|
||||
float base;
|
||||
if( v.own != 0 )
|
||||
{
|
||||
base = dpos.y + offset + ( 1.f - v.own * cpuCntRev ) * cpuUsageHeight;
|
||||
DrawLine( draw, ImVec2( dpos.x + pos, dpos.y + offset + cpuUsageHeight ), ImVec2( dpos.x + pos, base ), 0xFF55BB55 );
|
||||
}
|
||||
else
|
||||
{
|
||||
base = dpos.y + offset + cpuUsageHeight;
|
||||
}
|
||||
if( v.other != 0 )
|
||||
{
|
||||
int usageTotal = v.own + v.other;
|
||||
DrawLine( draw, ImVec2( dpos.x + pos, base ), ImVec2( dpos.x + pos, dpos.y + offset + ( 1.f - usageTotal * cpuCntRev ) * cpuUsageHeight ), 0xFF666666 );
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
DrawLine( draw, dpos + ImVec2( 0, offset+cpuUsageHeight+2 ), dpos + ImVec2( w, offset+cpuUsageHeight+2 ), 0x22DD88DD );
|
||||
|
||||
if( hover && ImGui::IsMouseHoveringRect( ImVec2( wpos.x, wpos.y + offset ), ImVec2( wpos.x + w, wpos.y + offset + cpuUsageHeight ), true ) )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
if( cpuDraw.size() > ( ImGui::GetIO().MousePos.x - wpos.x ) )
|
||||
{
|
||||
const auto& usage = cpuDraw[ImGui::GetIO().MousePos.x - wpos.x];
|
||||
TextFocused( "Cores used by profiled program:", RealToString( usage.own ) );
|
||||
ImGui::SameLine();
|
||||
char buf[64];
|
||||
PrintStringPercent( buf, usage.own * cpuCntRev * 100 );
|
||||
TextDisabledUnformatted( buf );
|
||||
TextFocused( "Cores used by other programs:", RealToString( usage.other ) );
|
||||
ImGui::SameLine();
|
||||
PrintStringPercent( buf, usage.other * cpuCntRev * 100 );
|
||||
TextDisabledUnformatted( buf );
|
||||
TextFocused( "Number of cores:", RealToString( cpuCnt ) );
|
||||
if( usage.own + usage.other != 0 )
|
||||
{
|
||||
const auto mt = m_vd.zvStart + ( ImGui::GetIO().MousePos.x - wpos.x ) * nspx;
|
||||
ImGui::Separator();
|
||||
for( int i=0; i<cpuCnt; i++ )
|
||||
{
|
||||
if( !cpuData[i].cs.empty() )
|
||||
{
|
||||
auto& cs = cpuData[i].cs;
|
||||
auto it = std::lower_bound( cs.begin(), cs.end(), mt, [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
|
||||
if( it != cs.end() && it->Start() <= mt && it->End() >= mt )
|
||||
{
|
||||
auto tt = m_worker.GetThreadTopology( i );
|
||||
if( tt )
|
||||
{
|
||||
ImGui::TextDisabled( "[%i:%i] CPU %i:", tt->package, tt->core, i );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled( "CPU %i:", i );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
const auto thread = m_worker.DecompressThreadExternal( it->Thread() );
|
||||
bool local, untracked;
|
||||
const char* txt;
|
||||
auto label = GetThreadContextData( thread, local, untracked, txt );
|
||||
if( local || untracked )
|
||||
{
|
||||
uint32_t color;
|
||||
if( m_vd.dynamicColors != 0 )
|
||||
{
|
||||
color = local ? GetThreadColor( thread, 0 ) : ( untracked ? 0xFF663333 : 0xFF444444 );
|
||||
}
|
||||
else
|
||||
{
|
||||
color = local ? 0xFF334488 : ( untracked ? 0xFF663333 : 0xFF444444 );
|
||||
}
|
||||
TextColoredUnformatted( HighlightColor<75>( color ), label );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( thread ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( label );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Cores used by profiled program:", "0" );
|
||||
TextFocused( "Cores used by other programs:", "0" );
|
||||
TextFocused( "Number of cores:", RealToString( cpuCnt ) );
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
offset += cpuUsageHeight + 3;
|
||||
}
|
||||
|
||||
ImGui::PushFont( m_smallFont );
|
||||
const auto sstep = sty + 1;
|
||||
|
||||
const auto origOffset = offset;
|
||||
for( int i=0; i<cpuCnt; i++ )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 0, offset+sty ), dpos + ImVec2( w, offset+sty ), 0x22DD88DD );
|
||||
auto tt = m_worker.GetThreadTopology( i );
|
||||
if( !ctxDraw[i].empty() && wpos.y + offset + sty >= yMin && wpos.y + offset <= yMax )
|
||||
{
|
||||
auto& cs = cpuData[i].cs;
|
||||
for( auto& v : ctxDraw[i] )
|
||||
{
|
||||
const auto& ev = cs[v.idx];
|
||||
const auto t0 = ev.Start();
|
||||
const auto px0 = ( t0 - vStart ) * pxns;
|
||||
if( v.num > 0 )
|
||||
{
|
||||
const auto& eev = cs[v.idx + v.num - 1];
|
||||
const auto t1 = eev.IsEndValid() ? eev.End() : eev.Start();
|
||||
const auto px1 = ( t1 - vStart ) * pxns;
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, offset + sty/2 ), std::max( px0, -10.0 ), std::min( std::max( px1, px0+MinVisSize ), double( w + 10 ) ), sty/4, 0xFF888888 );
|
||||
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset-1 ), wpos + ImVec2( std::max( px1, px0+MinVisSize ), offset + sty ) ) )
|
||||
{
|
||||
ImGui::PopFont();
|
||||
ImGui::BeginTooltip();
|
||||
TextFocused( "CPU:", RealToString( i ) );
|
||||
if( tt )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Package:", RealToString( tt->package ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Core:", RealToString( tt->core ) );
|
||||
}
|
||||
TextFocused( "Context switch regions:", RealToString( v.num ) );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Start time:", TimeToString( t0 ) );
|
||||
TextFocused( "End time:", TimeToString( t1 ) );
|
||||
TextFocused( "Activity time:", TimeToString( t1 - t0 ) );
|
||||
ImGui::EndTooltip();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( t0, t1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto end = ev.IsEndValid() ? ev.End() : ev.Start();
|
||||
const auto px1 = ( end - vStart ) * pxns;
|
||||
|
||||
const auto thread = m_worker.DecompressThreadExternal( ev.Thread() );
|
||||
bool local, untracked;
|
||||
const char* txt;
|
||||
auto label = GetThreadContextData( thread, local, untracked, txt );
|
||||
|
||||
uint32_t color;
|
||||
if( m_vd.dynamicColors != 0 )
|
||||
{
|
||||
color = local ? GetThreadColor( thread, 0 ) : ( untracked ? 0xFF663333 : 0xFF444444 );
|
||||
}
|
||||
else
|
||||
{
|
||||
color = local ? 0xFF334488 : ( untracked ? 0xFF663333 : 0xFF444444 );
|
||||
}
|
||||
|
||||
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + sty ), color );
|
||||
if( m_drawThreadHighlight == thread )
|
||||
{
|
||||
draw->AddRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + sty ), 0xFFFFFFFF );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto accentColor = HighlightColor( color );
|
||||
const auto darkColor = DarkenColor( color );
|
||||
DrawLine( draw, dpos + ImVec2( px0, offset + sty ), dpos + ImVec2( px0, offset ), dpos + ImVec2( px1-1, offset ), accentColor, 1.f );
|
||||
DrawLine( draw, dpos + ImVec2( px0, offset + sty ), dpos + ImVec2( px1-1, offset + sty ), dpos + ImVec2( px1-1, offset ), darkColor, 1.f );
|
||||
}
|
||||
|
||||
const auto zsz = px1 - px0;
|
||||
auto tsz = ImGui::CalcTextSize( label );
|
||||
if( tsz.x < zsz )
|
||||
{
|
||||
const auto x = ( ev.Start() - m_vd.zvStart ) * pxns + ( ( end - ev.Start() ) * pxns - tsz.x ) / 2;
|
||||
if( x < 0 || x > w - tsz.x )
|
||||
{
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( std::max( std::max( 0., px0 ), std::min( double( w - tsz.x ), x ) ), offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, label );
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
else if( ev.Start() == ev.End() )
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( px0 + ( px1 - px0 - tsz.x ) * 0.5, offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, label );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextContrast( draw, wpos + ImVec2( x, offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, label );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
|
||||
DrawTextContrast( draw, wpos + ImVec2( ( ev.Start() - vStart ) * pxns, offset-1 ), local ? 0xFFFFFFFF : 0xAAFFFFFF, label );
|
||||
ImGui::PopClipRect();
|
||||
}
|
||||
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset-1 ), wpos + ImVec2( px1, offset + sty ) ) )
|
||||
{
|
||||
m_drawThreadHighlight = thread;
|
||||
ImGui::PopFont();
|
||||
ImGui::BeginTooltip();
|
||||
TextFocused( "CPU:", RealToString( i ) );
|
||||
if( tt )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Package:", RealToString( tt->package ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Core:", RealToString( tt->core ) );
|
||||
}
|
||||
if( local )
|
||||
{
|
||||
TextFocused( "Program:", m_worker.GetCaptureProgram().c_str() );
|
||||
ImGui::SameLine();
|
||||
TextDisabledUnformatted( "(profiled program)" );
|
||||
SmallColorBox( GetThreadColor( thread, 0 ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Thread:", m_worker.GetThreadName( thread ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( thread ) );
|
||||
m_drawThreadMigrations = thread;
|
||||
m_cpuDataThread = thread;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( untracked )
|
||||
{
|
||||
TextFocused( "Program:", m_worker.GetCaptureProgram().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFocused( "Program:", txt );
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( untracked )
|
||||
{
|
||||
TextDisabledUnformatted( "(untracked thread in profiled program)" );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( "(external)" );
|
||||
}
|
||||
TextFocused( "Thread:", m_worker.GetExternalName( thread ).second );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( thread ) );
|
||||
}
|
||||
ImGui::Separator();
|
||||
TextFocused( "Start time:", TimeToStringExact( ev.Start() ) );
|
||||
TextFocused( "End time:", TimeToStringExact( end ) );
|
||||
TextFocused( "Activity time:", TimeToString( end - ev.Start() ) );
|
||||
ImGui::EndTooltip();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
|
||||
if( local && IsMouseClicked( 0 ) )
|
||||
{
|
||||
auto& item = m_tc.GetItem( m_worker.GetThreadData( thread ) );
|
||||
item.SetVisible( true );
|
||||
item.SetShowFull( true );
|
||||
}
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( ev.Start(), end );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char buf[64];
|
||||
if( tt )
|
||||
{
|
||||
sprintf( buf, "[%i:%i] CPU %i", tt->package, tt->core, i );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buf, "CPU %i", i );
|
||||
}
|
||||
const auto txtx = ImGui::CalcTextSize( buf ).x;
|
||||
DrawTextSuperContrast( draw, wpos + ImVec2( ty, offset-1 ), 0xFFDD88DD, buf );
|
||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, offset-1 ), wpos + ImVec2( sty + txtx, offset + sty ) ) )
|
||||
{
|
||||
ImGui::PopFont();
|
||||
ImGui::BeginTooltip();
|
||||
TextFocused( "CPU:", RealToString( i ) );
|
||||
if( tt )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Package:", RealToString( tt->package ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Core:", RealToString( tt->core ) );
|
||||
}
|
||||
TextFocused( "Context switch regions:", RealToString( cpuData[i].cs.size() ) );
|
||||
ImGui::EndTooltip();
|
||||
ImGui::PushFont( m_smallFont );
|
||||
}
|
||||
|
||||
offset += sstep;
|
||||
}
|
||||
|
||||
if( m_drawThreadMigrations != 0 )
|
||||
{
|
||||
auto ctxSwitch = m_worker.GetContextSwitchData( m_drawThreadMigrations );
|
||||
if( ctxSwitch )
|
||||
{
|
||||
const auto color = HighlightColor( GetThreadColor( m_drawThreadMigrations, -8 ) );
|
||||
|
||||
auto& v = ctxSwitch->v;
|
||||
auto it = std::lower_bound( v.begin(), v.end(), m_vd.zvStart, [] ( const auto& l, const auto& r ) { return l.End() < r; } );
|
||||
if( it != v.begin() ) --it;
|
||||
auto end = std::lower_bound( it, v.end(), m_vd.zvEnd, [] ( const auto& l, const auto& r ) { return l.Start() < r; } );
|
||||
if( end == v.end() ) --end;
|
||||
|
||||
const auto bgSize = GetScale() * 4.f;
|
||||
const auto lnSize = GetScale() * 2.f;
|
||||
|
||||
while( it < end )
|
||||
{
|
||||
const auto t0 = it->End();
|
||||
const auto cpu0 = it->Cpu();
|
||||
|
||||
++it;
|
||||
|
||||
const auto t1 = it->Start();
|
||||
const auto cpu1 = it->Cpu();
|
||||
|
||||
const auto px0 = ( t0 - m_vd.zvStart ) * pxns;
|
||||
const auto px1 = ( t1 - m_vd.zvStart ) * pxns;
|
||||
|
||||
if( px1 - px0 < 2 )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), dpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), color );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), dpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), 0xFF000000, bgSize );
|
||||
DrawLine( draw, dpos + ImVec2( px0, origOffset + sty * 0.5f + cpu0 * sstep ), dpos + ImVec2( px1, origOffset + sty * 0.5f + cpu1 * sstep ), color, lnSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PopFont();
|
||||
return true;
|
||||
}
|
||||
|
||||
void View::DrawCpuDataWindow()
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
ImGui::SetNextWindowSize( ImVec2( 700 * scale, 800 * scale ), ImGuiCond_FirstUseEver );
|
||||
ImGui::Begin( "CPU data", &m_showCpuDataWindow );
|
||||
if( ImGui::GetCurrentWindowRead()->SkipItems ) { ImGui::End(); return; }
|
||||
|
||||
struct PidData
|
||||
{
|
||||
std::vector<uint64_t> tids;
|
||||
CpuThreadData data;
|
||||
};
|
||||
|
||||
const auto& ctd = m_worker.GetCpuThreadData();
|
||||
unordered_flat_map<uint64_t, PidData> pids;
|
||||
for( auto& v : ctd )
|
||||
{
|
||||
uint64_t pid = m_worker.GetPidFromTid( v.first );
|
||||
auto it = pids.find( pid );
|
||||
if( it == pids.end() )
|
||||
{
|
||||
it = pids.emplace( pid, PidData {} ).first;
|
||||
}
|
||||
it->second.tids.emplace_back( v.first );
|
||||
it->second.data.runningTime += v.second.runningTime;
|
||||
it->second.data.runningRegions += v.second.runningRegions;
|
||||
it->second.data.migrations += v.second.migrations;
|
||||
}
|
||||
|
||||
TextFocused( "Tracked threads:", RealToString( ctd.size() ) );
|
||||
ImGui::SameLine();
|
||||
TextFocused( "Tracked processes:", RealToString( pids.size() ) );
|
||||
ImGui::Separator();
|
||||
ImGui::BeginChild( "##cpudata" );
|
||||
if( ImGui::BeginTable( "##cpudata", 5, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY ) )
|
||||
{
|
||||
ImGui::TableSetupScrollFreeze( 0, 1 );
|
||||
ImGui::TableSetupColumn( "PID/TID", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
|
||||
ImGui::TableSetupColumn( "Name" );
|
||||
ImGui::TableSetupColumn( "Running time", ImGuiTableColumnFlags_PreferSortDescending );
|
||||
ImGui::TableSetupColumn( "Slices", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
|
||||
ImGui::TableSetupColumn( "Core jumps", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
std::vector<unordered_flat_map<uint64_t, PidData>::iterator> psort;
|
||||
psort.reserve( pids.size() );
|
||||
for( auto it = pids.begin(); it != pids.end(); ++it ) psort.emplace_back( it );
|
||||
const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs;
|
||||
switch( sortspec.ColumnIndex )
|
||||
{
|
||||
case 0:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->first > r->first; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->first < r->first; } );
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [this] ( const auto& l, const auto& r ) { return strcmp( m_worker.GetExternalName( l->second.tids[0] ).first, m_worker.GetExternalName( r->second.tids[0] ).first ) > 0; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [this] ( const auto& l, const auto& r ) { return strcmp( m_worker.GetExternalName( l->second.tids[0] ).first, m_worker.GetExternalName( r->second.tids[0] ).first ) < 0; } );
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.runningTime > r->second.data.runningTime; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.runningTime < r->second.data.runningTime; } );
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.runningRegions > r->second.data.runningRegions; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.runningRegions < r->second.data.runningRegions; } );
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.migrations > r->second.data.migrations; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( psort.begin(), psort.end(), [] ( const auto& l, const auto& r ) { return l->second.data.migrations < r->second.data.migrations; } );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
|
||||
const auto thisPid = m_worker.GetPid();
|
||||
const auto rtimespan = 1.0 / ( m_worker.GetLastTime() - m_worker.GetFirstTime() );
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
|
||||
auto& style = ImGui::GetStyle();
|
||||
const auto framePaddingY = style.FramePadding.y;
|
||||
bool drawSeparator = false;
|
||||
for( auto& pidit : psort )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
|
||||
char buf[128];
|
||||
auto& pid = *pidit;
|
||||
const auto pidMatch = thisPid != 0 && thisPid == pid.first;
|
||||
auto name = m_worker.GetExternalName( pid.second.tids[0] ).first;
|
||||
if( pidMatch )
|
||||
{
|
||||
name = m_worker.GetCaptureProgram().c_str();
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.2f, 1.0f, 0.2f, 1.0f ) );
|
||||
}
|
||||
const auto pidtxt = pid.first == 0 ? "Unknown" : RealToString( pid.first );
|
||||
const auto expand = ImGui::TreeNode( pidtxt );
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
if( pidMatch )
|
||||
{
|
||||
m_drawThreadMigrations = pid.first;
|
||||
m_cpuDataThread = pid.first;
|
||||
}
|
||||
m_drawThreadHighlight = pid.first;
|
||||
}
|
||||
const auto tsz = pid.second.tids.size();
|
||||
if( tsz > 1 )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", RealToString( tsz ) );
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
ImGui::TextUnformatted( pid.first == 0 ? "???" : name );
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
if( pidMatch )
|
||||
{
|
||||
m_drawThreadMigrations = pid.first;
|
||||
m_cpuDataThread = pid.first;
|
||||
}
|
||||
m_drawThreadHighlight = pid.first;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
PrintStringPercent( buf, TimeToString( pid.second.data.runningTime ), double( pid.second.data.runningTime ) * rtimespan * 100 );
|
||||
style.FramePadding.y = 0;
|
||||
ImGui::ProgressBar( double( pid.second.data.runningTime ) * rtimespan, ImVec2( -1, ty ), buf );
|
||||
style.FramePadding.y = framePaddingY;
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
ImGui::TextUnformatted( RealToString( pid.second.data.runningRegions ) );
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator )
|
||||
{
|
||||
drawSeparator = false;
|
||||
ImGui::Separator();
|
||||
}
|
||||
ImGui::TextUnformatted( RealToString( pid.second.data.migrations ) );
|
||||
ImGui::SameLine();
|
||||
PrintStringPercent( buf, double( pid.second.data.migrations ) / pid.second.data.runningRegions * 100 );
|
||||
TextDisabledUnformatted( buf );
|
||||
if( expand )
|
||||
{
|
||||
switch( sortspec.ColumnIndex )
|
||||
{
|
||||
case 0:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), []( const auto& l, const auto& r ) { return l > r; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end() );
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [this] ( const auto& l, const auto& r ) { return strcmp( m_worker.GetExternalName( l ).second, m_worker.GetExternalName( r ).second ) > 0; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [this] ( const auto& l, const auto& r ) { return strcmp( m_worker.GetExternalName( l ).second, m_worker.GetExternalName( r ).second ) < 0; } );
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.runningTime > ctd.find( r )->second.runningTime; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.runningTime < ctd.find( r )->second.runningTime; } );
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.runningRegions > ctd.find( r )->second.runningRegions; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.runningRegions < ctd.find( r )->second.runningRegions; } );
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.migrations > ctd.find( r )->second.migrations; } );
|
||||
}
|
||||
else
|
||||
{
|
||||
pdqsort_branchless( pid.second.tids.begin(), pid.second.tids.end(), [&ctd] ( const auto& l, const auto& r ) { return ctd.find( l )->second.migrations < ctd.find( r )->second.migrations; } );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
drawSeparator = true;
|
||||
for( auto& tid : pid.second.tids )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
|
||||
const auto tidMatch = pidMatch && m_worker.IsThreadLocal( tid );
|
||||
const char* tname;
|
||||
if( tidMatch )
|
||||
{
|
||||
tname = m_worker.GetThreadName( tid );
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.0f, 1.0f, 0.2f, 1.0f ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
tname = m_worker.GetExternalName( tid ).second;
|
||||
}
|
||||
const auto& tit = ctd.find( tid );
|
||||
assert( tit != ctd.end() );
|
||||
ImGui::TextUnformatted( RealToString( tid ) );
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
if( tidMatch )
|
||||
{
|
||||
m_drawThreadMigrations = tid;
|
||||
m_cpuDataThread = tid;
|
||||
}
|
||||
m_drawThreadHighlight = tid;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
if( tidMatch )
|
||||
{
|
||||
SmallColorBox( GetThreadColor( tid, 0 ) );
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::TextUnformatted( tname );
|
||||
if( ImGui::IsItemHovered() )
|
||||
{
|
||||
if( tidMatch )
|
||||
{
|
||||
m_drawThreadMigrations = tid;
|
||||
m_cpuDataThread = tid;
|
||||
}
|
||||
m_drawThreadHighlight = tid;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
PrintStringPercent( buf, TimeToString( tit->second.runningTime ), double( tit->second.runningTime ) * rtimespan * 100 );
|
||||
style.FramePadding.y = 0;
|
||||
ImGui::ProgressBar( double( tit->second.runningTime ) * rtimespan, ImVec2( -1, ty ), buf );
|
||||
style.FramePadding.y = framePaddingY;
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator ) ImGui::Separator();
|
||||
ImGui::TextUnformatted( RealToString( tit->second.runningRegions ) );
|
||||
ImGui::TableNextColumn();
|
||||
if( drawSeparator )
|
||||
{
|
||||
drawSeparator = false;
|
||||
ImGui::Separator();
|
||||
}
|
||||
ImGui::TextUnformatted( RealToString( tit->second.migrations ) );
|
||||
ImGui::SameLine();
|
||||
PrintStringPercent( buf, double( tit->second.migrations ) / tit->second.runningRegions * 100 );
|
||||
TextDisabledUnformatted( buf );
|
||||
if( tidMatch )
|
||||
{
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
ImGui::TreePop();
|
||||
drawSeparator = true;
|
||||
}
|
||||
if( pidMatch )
|
||||
{
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1992
subprojects/tracy/profiler/src/profiler/TracyView_FindZone.cpp
Normal file
1992
subprojects/tracy/profiler/src/profiler/TracyView_FindZone.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,452 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTexture.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static uint32_t GetFrameColor( uint64_t time, uint64_t target )
|
||||
{
|
||||
return time > target * 2 ? 0xFF2222DD :
|
||||
time > target ? 0xFF22DDDD :
|
||||
time > target / 2 ? 0xFF22DD22 : 0xFFDD9900;
|
||||
}
|
||||
|
||||
static int GetFrameWidth( int frameScale )
|
||||
{
|
||||
return frameScale == 0 ? 4 : ( frameScale < 0 ? 6 : 1 );
|
||||
}
|
||||
|
||||
static int GetFrameGroup( int frameScale )
|
||||
{
|
||||
return frameScale < 2 ? 1 : ( 1 << ( frameScale - 1 ) );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr const T& clamp( const T& v, const T& lo, const T& hi )
|
||||
{
|
||||
return v < lo ? lo : v > hi ? hi : v;
|
||||
}
|
||||
|
||||
void View::DrawFrames()
|
||||
{
|
||||
assert( m_worker.GetFrameCount( *m_frames ) != 0 );
|
||||
|
||||
const auto scale = GetScale();
|
||||
const auto Height = 50 * scale;
|
||||
|
||||
constexpr uint64_t MaxFrameTime = 50 * 1000 * 1000; // 50ms
|
||||
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
|
||||
if( window->SkipItems ) return;
|
||||
|
||||
const uint64_t frameTarget = 1000 * 1000 * 1000 / m_vd.frameTarget;
|
||||
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
const auto wpos = ImGui::GetCursorScreenPos();
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto wspace = ImGui::GetWindowContentRegionMax() - ImGui::GetWindowContentRegionMin();
|
||||
const auto w = wspace.x;
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
|
||||
ImGui::InvisibleButton( "##frames", ImVec2( w, Height ) );
|
||||
bool hover = ImGui::IsItemHovered();
|
||||
|
||||
draw->AddRectFilled( wpos, wpos + ImVec2( w, Height ), 0x33FFFFFF );
|
||||
const auto wheel = io.MouseWheel;
|
||||
const auto prevScale = m_vd.frameScale;
|
||||
if( hover )
|
||||
{
|
||||
if( wheel > 0 )
|
||||
{
|
||||
if( m_vd.frameScale >= 0 ) m_vd.frameScale--;
|
||||
}
|
||||
else if( wheel < 0 )
|
||||
{
|
||||
if( m_vd.frameScale < 10 ) m_vd.frameScale++;
|
||||
}
|
||||
}
|
||||
|
||||
const int fwidth = GetFrameWidth( m_vd.frameScale );
|
||||
const int group = GetFrameGroup( m_vd.frameScale );
|
||||
const int total = m_worker.GetFrameCount( *m_frames );
|
||||
const int onScreen = ( w - 2 ) / fwidth;
|
||||
if( m_viewMode != ViewMode::Paused )
|
||||
{
|
||||
m_vd.frameStart = ( total < onScreen * group ) ? 0 : total - onScreen * group;
|
||||
if( m_viewMode == ViewMode::LastFrames )
|
||||
{
|
||||
SetViewToLastFrames();
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( m_viewMode == ViewMode::LastRange );
|
||||
const auto delta = m_worker.GetLastTime() - m_vd.zvEnd;
|
||||
if( delta != 0 )
|
||||
{
|
||||
m_vd.zvStart += delta;
|
||||
m_vd.zvEnd += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( hover )
|
||||
{
|
||||
const auto hwheel_delta = io.MouseWheelH * 100.f;
|
||||
if( IsMouseDragging( 1 ) || hwheel_delta != 0 )
|
||||
{
|
||||
m_viewMode = ViewMode::Paused;
|
||||
m_viewModeHeuristicTry = false;
|
||||
auto delta = GetMouseDragDelta( 1 ).x;
|
||||
if( delta == 0 ) delta = hwheel_delta;
|
||||
if( abs( delta ) >= fwidth )
|
||||
{
|
||||
const auto d = (int)delta / fwidth;
|
||||
m_vd.frameStart = std::max( 0, m_vd.frameStart - d * group );
|
||||
io.MouseClickedPos[1].x = io.MousePos.x + d * fwidth - delta;
|
||||
}
|
||||
}
|
||||
|
||||
const auto mx = io.MousePos.x;
|
||||
if( mx > wpos.x && mx < wpos.x + w - 1 )
|
||||
{
|
||||
const auto mo = mx - ( wpos.x + 1 );
|
||||
const auto off = mo * group / fwidth;
|
||||
|
||||
const int sel = m_vd.frameStart + off;
|
||||
if( sel < total )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
if( group > 1 )
|
||||
{
|
||||
auto f = m_worker.GetFrameTime( *m_frames, sel );
|
||||
auto g = std::min( group, total - sel );
|
||||
for( int j=1; j<g; j++ )
|
||||
{
|
||||
f = std::max( f, m_worker.GetFrameTime( *m_frames, sel + j ) );
|
||||
}
|
||||
|
||||
TextDisabledUnformatted( "Frames:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::Text( "%s - %s (%s)", RealToString( sel ), RealToString( sel + g - 1 ), RealToString( g ) );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Max frame time:", TimeToString( f ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%.1f FPS)", 1000000000.0 / f );
|
||||
|
||||
if( IsMouseClickReleased( 1 ) ) m_setRangePopup = RangeSlim { m_worker.GetFrameTime( *m_frames, sel ), m_worker.GetFrameTime( *m_frames, sel + g - 1 ), true };
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto fnum = GetFrameNumber( *m_frames, sel );
|
||||
m_frameHover = sel;
|
||||
if( m_frames->name == 0 )
|
||||
{
|
||||
if( sel == 0 )
|
||||
{
|
||||
ImGui::TextUnformatted( "Tracy initialization" );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Time:", TimeToString( m_worker.GetFrameTime( *m_frames, sel ) ) );
|
||||
}
|
||||
else if( !m_worker.IsOnDemand() )
|
||||
{
|
||||
TextDisabledUnformatted( "Frame:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( RealToString( fnum ) );
|
||||
ImGui::Separator();
|
||||
const auto frameTime = m_worker.GetFrameTime( *m_frames, sel );
|
||||
TextFocused( "Frame time:", TimeToString( frameTime ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%.1f FPS)", 1000000000.0 / frameTime );
|
||||
}
|
||||
else if( sel == 1 )
|
||||
{
|
||||
ImGui::TextUnformatted( "Missed frames" );
|
||||
ImGui::Separator();
|
||||
TextFocused( "Time:", TimeToString( m_worker.GetFrameTime( *m_frames, 1 ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
TextDisabledUnformatted( "Frame:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( RealToString( fnum ) );
|
||||
ImGui::Separator();
|
||||
const auto frameTime = m_worker.GetFrameTime( *m_frames, sel );
|
||||
TextFocused( "Frame time:", TimeToString( frameTime ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%.1f FPS)", 1000000000.0 / frameTime );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled( "%s:", GetFrameSetName( *m_frames ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( RealToString( fnum ) );
|
||||
ImGui::Separator();
|
||||
const auto frameTime = m_worker.GetFrameTime( *m_frames, sel );
|
||||
TextFocused( "Frame time:", TimeToString( frameTime ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%.1f FPS)", 1000000000.0 / frameTime );
|
||||
}
|
||||
}
|
||||
TextFocused( "Time from start of program:", TimeToStringExact( m_worker.GetFrameBegin( *m_frames, sel ) ) );
|
||||
auto fi = m_worker.GetFrameImage( *m_frames, sel );
|
||||
if( fi )
|
||||
{
|
||||
if( fi != m_frameTexturePtr )
|
||||
{
|
||||
if( !m_frameTexture ) m_frameTexture = MakeTexture();
|
||||
UpdateTexture( m_frameTexture, m_worker.UnpackFrameImage( *fi ), fi->w, fi->h );
|
||||
m_frameTexturePtr = fi;
|
||||
}
|
||||
ImGui::Separator();
|
||||
if( fi->flip )
|
||||
{
|
||||
ImGui::Image( m_frameTexture, ImVec2( fi->w * scale, fi->h * scale ), ImVec2( 0, 1 ), ImVec2( 1, 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Image( m_frameTexture, ImVec2( fi->w * scale, fi->h * scale ) );
|
||||
}
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( io.KeyCtrl )
|
||||
{
|
||||
if( fi && IsMouseDown( 0 ) )
|
||||
{
|
||||
m_showPlayback = true;
|
||||
m_playback.pause = true;
|
||||
SetPlaybackFrame( m_frames->frames[sel].frameImage );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( IsMouseClicked( 0 ) )
|
||||
{
|
||||
m_viewMode = ViewMode::Paused;
|
||||
m_viewModeHeuristicTry = false;
|
||||
m_zoomAnim.active = false;
|
||||
if( !m_playback.pause && m_playback.sync ) m_playback.pause = true;
|
||||
m_vd.zvStart = m_worker.GetFrameBegin( *m_frames, sel );
|
||||
m_vd.zvEnd = m_worker.GetFrameEnd( *m_frames, sel + group - 1 );
|
||||
if( m_vd.zvStart == m_vd.zvEnd ) m_vd.zvStart--;
|
||||
}
|
||||
else if( IsMouseDragging( 0 ) )
|
||||
{
|
||||
const auto t0 = std::min( m_vd.zvStart, m_worker.GetFrameBegin( *m_frames, sel ) );
|
||||
const auto t1 = std::max( m_vd.zvEnd, m_worker.GetFrameEnd( *m_frames, sel + group - 1 ) );
|
||||
ZoomToRange( t0, t1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( IsMouseClickReleased( 1 ) ) m_setRangePopup = RangeSlim { m_worker.GetFrameBegin( *m_frames, sel ), m_worker.GetFrameEnd( *m_frames, sel + group - 1 ), true };
|
||||
}
|
||||
|
||||
if( ( !m_worker.IsConnected() || m_viewMode == ViewMode::Paused ) && wheel != 0 )
|
||||
{
|
||||
const int pfwidth = GetFrameWidth( prevScale );
|
||||
const int pgroup = GetFrameGroup( prevScale );
|
||||
|
||||
const auto oldoff = mo * pgroup / pfwidth;
|
||||
m_vd.frameStart = std::min( total, std::max( 0, m_vd.frameStart - int( off - oldoff ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0, idx = 0;
|
||||
#ifndef TRACY_NO_STATISTICS
|
||||
if( m_worker.AreSourceLocationZonesReady() && m_findZone.show && m_findZone.showZoneInFrames && !m_findZone.match.empty() )
|
||||
{
|
||||
auto& zoneData = m_worker.GetZonesForSourceLocation( m_findZone.match[m_findZone.selMatch] );
|
||||
zoneData.zones.ensure_sorted();
|
||||
auto begin = zoneData.zones.begin();
|
||||
while( i < onScreen && m_vd.frameStart + idx < total )
|
||||
{
|
||||
const auto f0 = m_worker.GetFrameBegin( *m_frames, m_vd.frameStart + idx );
|
||||
auto f1 = m_worker.GetFrameEnd( *m_frames, m_vd.frameStart + idx );
|
||||
auto f = f1 - f0;
|
||||
if( group > 1 )
|
||||
{
|
||||
const int g = std::min( group, total - ( m_vd.frameStart + idx ) );
|
||||
for( int j=1; j<g; j++ )
|
||||
{
|
||||
f = std::max( f, m_worker.GetFrameTime( *m_frames, m_vd.frameStart + idx + j ) );
|
||||
}
|
||||
f1 = m_worker.GetFrameEnd( *m_frames, m_vd.frameStart + idx + g - 1 );
|
||||
}
|
||||
|
||||
int64_t zoneTime = 0;
|
||||
// This search is not valid, as zones are sorted according to their start time, not end time.
|
||||
auto itStart = std::lower_bound( begin, zoneData.zones.end(), f0, [] ( const auto& l, const auto& r ) { return l.Zone()->End() < r; } );
|
||||
if( itStart != zoneData.zones.end() )
|
||||
{
|
||||
auto itEnd = std::lower_bound( itStart, zoneData.zones.end(), f1, [] ( const auto& l, const auto& r ) { return l.Zone()->Start() < r; } );
|
||||
if( m_frames->continuous )
|
||||
{
|
||||
if( m_findZone.selfTime )
|
||||
{
|
||||
while( itStart != itEnd )
|
||||
{
|
||||
const auto t0 = clamp( itStart->Zone()->Start(), f0, f1 );
|
||||
const auto t1 = clamp( m_worker.GetZoneEndDirect( *itStart->Zone() ), f0, f1 );
|
||||
zoneTime += t1 - t0 - GetZoneChildTimeFastClamped( *itStart->Zone(), t0, t1 );
|
||||
itStart++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while( itStart != itEnd )
|
||||
{
|
||||
const auto t0 = clamp( itStart->Zone()->Start(), f0, f1 );
|
||||
const auto t1 = clamp( m_worker.GetZoneEndDirect( *itStart->Zone() ), f0, f1 );
|
||||
zoneTime += t1 - t0;
|
||||
itStart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( m_findZone.selfTime )
|
||||
{
|
||||
while( itStart != itEnd )
|
||||
{
|
||||
const int g = std::min( group, total - ( m_vd.frameStart + idx ) );
|
||||
for( int j=0; j<g; j++ )
|
||||
{
|
||||
const auto ft0 = m_worker.GetFrameBegin( *m_frames, m_vd.frameStart + idx + j );
|
||||
const auto ft1 = m_worker.GetFrameEnd( *m_frames, m_vd.frameStart + idx + j );
|
||||
const auto t0 = clamp( itStart->Zone()->Start(), ft0, ft1 );
|
||||
const auto t1 = clamp( m_worker.GetZoneEndDirect( *itStart->Zone() ), ft0, ft1 );
|
||||
zoneTime += t1 - t0 - GetZoneChildTimeFastClamped( *itStart->Zone(), t0, t1 );
|
||||
}
|
||||
itStart++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while( itStart != itEnd )
|
||||
{
|
||||
const int g = std::min( group, total - ( m_vd.frameStart + idx ) );
|
||||
for( int j=0; j<g; j++ )
|
||||
{
|
||||
const auto ft0 = m_worker.GetFrameBegin( *m_frames, m_vd.frameStart + idx + j );
|
||||
const auto ft1 = m_worker.GetFrameEnd( *m_frames, m_vd.frameStart + idx + j );
|
||||
const auto t0 = clamp( itStart->Zone()->Start(), ft0, ft1 );
|
||||
const auto t1 = clamp( m_worker.GetZoneEndDirect( *itStart->Zone() ), ft0, ft1 );
|
||||
zoneTime += t1 - t0;
|
||||
}
|
||||
itStart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin = itStart;
|
||||
}
|
||||
|
||||
zoneTime /= group;
|
||||
const auto h = std::max( 1.f, float( std::min<uint64_t>( MaxFrameTime, f ) ) / MaxFrameTime * ( Height - 2 ) );
|
||||
if( zoneTime == 0 )
|
||||
{
|
||||
if( fwidth != 1 )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), 0xFF888888 );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2 ), 0xFF888888 );
|
||||
}
|
||||
}
|
||||
else if( zoneTime <= f )
|
||||
{
|
||||
const auto zh = float( std::min<uint64_t>( MaxFrameTime, zoneTime ) ) / MaxFrameTime * ( Height - 2 );
|
||||
if( fwidth != 1 )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1-zh ), 0xFF888888 );
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-zh ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), 0xFFEEEEEE );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2-zh ), 0xFF888888 );
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-zh ), dpos + ImVec2( 1+i, Height-2 ), 0xFFEEEEEE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto zh = float( std::min<uint64_t>( MaxFrameTime, zoneTime ) ) / MaxFrameTime * ( Height - 2 );
|
||||
if( fwidth != 1 )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-zh ), wpos + ImVec2( fwidth + i*fwidth, Height-1-h ), 0xFF2222BB );
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), 0xFFEEEEEE );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-zh ), dpos + ImVec2( 1+i, Height-2-h ), 0xFF2222BB );
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2 ), 0xFFEEEEEE );
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
idx += group;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
while( i < onScreen && m_vd.frameStart + idx < total )
|
||||
{
|
||||
auto f = m_worker.GetFrameTime( *m_frames, m_vd.frameStart + idx );
|
||||
if( group > 1 )
|
||||
{
|
||||
const int g = std::min( group, total - ( m_vd.frameStart + idx ) );
|
||||
for( int j=1; j<g; j++ )
|
||||
{
|
||||
f = std::max( f, m_worker.GetFrameTime( *m_frames, m_vd.frameStart + idx + j ) );
|
||||
}
|
||||
}
|
||||
|
||||
const auto h = std::max( 1.f, float( std::min<uint64_t>( MaxFrameTime, f ) ) / MaxFrameTime * ( Height - 2 ) );
|
||||
if( fwidth != 1 )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), GetFrameColor( f, frameTarget ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2 ), GetFrameColor( f, frameTarget ) );
|
||||
}
|
||||
|
||||
i++;
|
||||
idx += group;
|
||||
}
|
||||
}
|
||||
|
||||
const auto zrange = m_worker.GetFrameRange( *m_frames, m_vd.zvStart, m_vd.zvEnd );
|
||||
if( zrange.second > m_vd.frameStart && zrange.first < m_vd.frameStart + onScreen * group )
|
||||
{
|
||||
auto x1 = std::min( onScreen * fwidth, ( zrange.second - m_vd.frameStart ) * fwidth / group );
|
||||
auto x0 = std::max( 0, ( zrange.first - m_vd.frameStart ) * fwidth / group );
|
||||
|
||||
if( x0 == x1 ) x1 = x0 + 1;
|
||||
if( x1 - x0 >= 3 )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 2+x0, 0 ), wpos + ImVec2( x1, Height ), 0x55DD22DD );
|
||||
DrawLine( draw, dpos + ImVec2( 1+x0, -1 ), dpos + ImVec2( 1+x0, Height-1 ), 0x55FF55FF );
|
||||
DrawLine( draw, dpos + ImVec2( x1, -1 ), dpos + ImVec2( x1, Height-1 ), 0x55FF55FF );
|
||||
}
|
||||
else
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( 1+x0, 0 ), wpos + ImVec2( 1+x1, Height ), 0x55FF55FF );
|
||||
}
|
||||
}
|
||||
|
||||
if( frameTarget * 2 <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget * 2 / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget * 2 / MaxFrameTime ) ), 0x442222DD );
|
||||
if( frameTarget <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget / MaxFrameTime ) ), 0x4422DDDD );
|
||||
if( frameTarget / 2 <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget / 2 / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget / 2 / MaxFrameTime ) ), 0x4422DD22 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyTexture.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
constexpr float MinVisSize = 3;
|
||||
constexpr float MinFrameSize = 5;
|
||||
|
||||
static tracy_force_inline uint32_t GetColorMuted( uint32_t color, bool active )
|
||||
{
|
||||
if( active )
|
||||
{
|
||||
return 0xFF000000 | color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0x66000000 | color;
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawTimelineFramesHeader()
|
||||
{
|
||||
const auto wpos = ImGui::GetCursorScreenPos();
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto w = ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize;
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
const auto ty025 = round( ty * 0.25f );
|
||||
const auto ty0375 = round( ty * 0.375f );
|
||||
const auto ty05 = round( ty * 0.5f );
|
||||
|
||||
const auto timespan = m_vd.zvEnd - m_vd.zvStart;
|
||||
const auto pxns = w / double( timespan );
|
||||
const auto nspx = 1.0 / pxns;
|
||||
const auto scale = std::max( 0.0, round( log10( nspx ) + 2 ) );
|
||||
const auto step = pow( 10, scale );
|
||||
|
||||
ImGui::InvisibleButton( "##zoneFrames", ImVec2( w, ty * 1.5f ) );
|
||||
TooltipIfHovered( TimeToStringExact( m_vd.zvStart + ( ImGui::GetIO().MousePos.x - wpos.x ) * nspx ) );
|
||||
|
||||
const auto dx = step * pxns;
|
||||
double x = 0;
|
||||
int tw = 0;
|
||||
int tx = 0;
|
||||
int64_t tt = 0;
|
||||
while( x < w )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( x, 0 ), dpos + ImVec2( x, ty05 ), 0x66FFFFFF );
|
||||
if( tw == 0 )
|
||||
{
|
||||
char buf[128];
|
||||
auto txt = TimeToStringExact( m_vd.zvStart );
|
||||
if( m_vd.zvStart >= 0 )
|
||||
{
|
||||
sprintf( buf, "+%s", txt );
|
||||
txt = buf;
|
||||
}
|
||||
draw->AddText( wpos + ImVec2( x, ty05 ), 0x66FFFFFF, txt );
|
||||
tw = ImGui::CalcTextSize( txt ).x;
|
||||
}
|
||||
else if( x > tx + tw + ty * 2 )
|
||||
{
|
||||
tx = x;
|
||||
auto txt = TimeToString( tt );
|
||||
draw->AddText( wpos + ImVec2( x, ty05 ), 0x66FFFFFF, txt );
|
||||
tw = ImGui::CalcTextSize( txt ).x;
|
||||
}
|
||||
|
||||
if( scale != 0 )
|
||||
{
|
||||
for( int i=1; i<5; i++ )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( x + i * dx / 10, 0 ), dpos + ImVec2( x + i * dx / 10, ty025 ), 0x33FFFFFF );
|
||||
}
|
||||
DrawLine( draw, dpos + ImVec2( x + 5 * dx / 10, 0 ), dpos + ImVec2( x + 5 * dx / 10, ty0375 ), 0x33FFFFFF );
|
||||
for( int i=6; i<10; i++ )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( x + i * dx / 10, 0 ), dpos + ImVec2( x + i * dx / 10, ty025 ), 0x33FFFFFF );
|
||||
}
|
||||
}
|
||||
|
||||
x += dx;
|
||||
tt += step;
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawTimelineFrames( const FrameData& frames )
|
||||
{
|
||||
const std::pair <int, int> zrange = m_worker.GetFrameRange( frames, m_vd.zvStart, m_vd.zvEnd );
|
||||
if( zrange.first < 0 ) return;
|
||||
if( m_worker.GetFrameBegin( frames, zrange.first ) > m_vd.zvEnd || m_worker.GetFrameEnd( frames, zrange.second ) < m_vd.zvStart ) return;
|
||||
|
||||
const auto wpos = ImGui::GetCursorScreenPos();
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
const auto w = ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize;
|
||||
const auto wh = ImGui::GetContentRegionAvail().y;
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto ty = ImGui::GetTextLineHeight();
|
||||
const auto ty025 = ty * 0.25f;
|
||||
const auto ty05 = round( ty * 0.5f );
|
||||
|
||||
ImGui::InvisibleButton( "##zoneFrames", ImVec2( w, ty ) );
|
||||
bool hover = ImGui::IsItemHovered();
|
||||
|
||||
auto timespan = m_vd.zvEnd - m_vd.zvStart;
|
||||
auto pxns = w / double( timespan );
|
||||
|
||||
const auto nspx = 1.0 / pxns;
|
||||
|
||||
int64_t prev = -1;
|
||||
int64_t prevEnd = -1;
|
||||
int64_t endPos = -1;
|
||||
bool tooltipDisplayed = false;
|
||||
const auto activeFrameSet = m_frames == &frames;
|
||||
const int64_t frameTarget = ( activeFrameSet && m_vd.drawFrameTargets ) ? 1000000000ll / m_vd.frameTarget : std::numeric_limits<int64_t>::max();
|
||||
|
||||
const auto inactiveColor = GetColorMuted( 0x888888, activeFrameSet );
|
||||
const auto activeColor = GetColorMuted( 0xFFFFFF, activeFrameSet );
|
||||
const auto redColor = GetColorMuted( 0x4444FF, activeFrameSet );
|
||||
|
||||
int i = zrange.first;
|
||||
auto x1 = ( m_worker.GetFrameBegin( frames, i ) - m_vd.zvStart ) * pxns;
|
||||
while( i < zrange.second )
|
||||
{
|
||||
const auto ftime = m_worker.GetFrameTime( frames, i );
|
||||
const auto fbegin = m_worker.GetFrameBegin( frames, i );
|
||||
const auto fend = m_worker.GetFrameEnd( frames, i );
|
||||
const auto fsz = pxns * ftime;
|
||||
|
||||
if( hover )
|
||||
{
|
||||
const auto x0 = frames.continuous ? x1 : ( fbegin - m_vd.zvStart ) * pxns;
|
||||
x1 = ( fend - m_vd.zvStart ) * pxns;
|
||||
if( ImGui::IsMouseHoveringRect( wpos + ImVec2( x0, 0 ), wpos + ImVec2( x1, ty ) ) )
|
||||
{
|
||||
tooltipDisplayed = true;
|
||||
if( IsMouseClickReleased( 1 ) ) m_setRangePopup = RangeSlim { fbegin, fend, true };
|
||||
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted( GetFrameText( frames, i, ftime ) );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%.1f FPS)", 1000000000.0 / ftime );
|
||||
TextFocused( "Time from start of program:", TimeToStringExact( m_worker.GetFrameBegin( frames, i ) ) );
|
||||
auto fi = m_worker.GetFrameImage( frames, i );
|
||||
if( fi )
|
||||
{
|
||||
const auto scale = GetScale();
|
||||
if( fi != m_frameTexturePtr )
|
||||
{
|
||||
if( !m_frameTexture ) m_frameTexture = MakeTexture();
|
||||
UpdateTexture( m_frameTexture, m_worker.UnpackFrameImage( *fi ), fi->w, fi->h );
|
||||
m_frameTexturePtr = fi;
|
||||
}
|
||||
ImGui::Separator();
|
||||
if( fi->flip )
|
||||
{
|
||||
ImGui::Image( m_frameTexture, ImVec2( fi->w * scale, fi->h * scale ), ImVec2( 0, 1 ), ImVec2( 1, 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Image( m_frameTexture, ImVec2( fi->w * scale, fi->h * scale ) );
|
||||
}
|
||||
|
||||
if( ImGui::GetIO().KeyCtrl && IsMouseClicked( 0 ) )
|
||||
{
|
||||
m_showPlayback = true;
|
||||
m_playback.pause = true;
|
||||
SetPlaybackFrame( frames.frames[i].frameImage );
|
||||
}
|
||||
}
|
||||
ImGui::EndTooltip();
|
||||
|
||||
if( IsMouseClicked( 2 ) )
|
||||
{
|
||||
ZoomToRange( fbegin, fend );
|
||||
}
|
||||
|
||||
if( activeFrameSet ) m_frameHover = i;
|
||||
}
|
||||
}
|
||||
|
||||
if( fsz < MinFrameSize )
|
||||
{
|
||||
if( !frames.continuous && prev != -1 )
|
||||
{
|
||||
if( ( fbegin - prevEnd ) * pxns >= MinFrameSize )
|
||||
{
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, ty05 ), ( prev - m_vd.zvStart ) * pxns, ( prevEnd - m_vd.zvStart ) * pxns, ty025, inactiveColor );
|
||||
prev = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevEnd = std::max<int64_t>( fend, fbegin + MinFrameSize * nspx );
|
||||
}
|
||||
}
|
||||
if( prev == -1 )
|
||||
{
|
||||
prev = fbegin;
|
||||
prevEnd = std::max<int64_t>( fend, fbegin + MinFrameSize * nspx );
|
||||
}
|
||||
|
||||
const auto begin = frames.frames.begin() + i;
|
||||
const auto end = frames.frames.begin() + zrange.second;
|
||||
auto it = std::lower_bound( begin, end, int64_t( fbegin + MinVisSize * nspx ), [this, &frames] ( const auto& l, const auto& r ) { return m_worker.GetFrameEnd( frames, std::distance( frames.frames.begin(), &l ) ) < r; } );
|
||||
if( it == begin ) ++it;
|
||||
i += std::distance( begin, it );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( prev != -1 )
|
||||
{
|
||||
if( frames.continuous )
|
||||
{
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, ty05 ), ( prev - m_vd.zvStart ) * pxns, ( fbegin - m_vd.zvStart ) * pxns, ty025, inactiveColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, ty05 ), ( prev - m_vd.zvStart ) * pxns, ( prevEnd - m_vd.zvStart ) * pxns, ty025, inactiveColor );
|
||||
}
|
||||
prev = -1;
|
||||
}
|
||||
|
||||
if( activeFrameSet )
|
||||
{
|
||||
if( fend - fbegin > frameTarget )
|
||||
{
|
||||
draw->AddRectFilled( wpos + ImVec2( ( fbegin + frameTarget - m_vd.zvStart ) * pxns, 0 ), wpos + ImVec2( ( fend - m_vd.zvStart ) * pxns, wh ), 0x224444FF );
|
||||
}
|
||||
if( fbegin >= m_vd.zvStart && endPos != fbegin )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( ( fbegin - m_vd.zvStart ) * pxns, 0 ), dpos + ImVec2( ( fbegin - m_vd.zvStart ) * pxns, wh ), 0x22FFFFFF );
|
||||
}
|
||||
if( fend <= m_vd.zvEnd )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( ( fend - m_vd.zvStart ) * pxns, 0 ), dpos + ImVec2( ( fend - m_vd.zvStart ) * pxns, wh ), 0x22FFFFFF );
|
||||
}
|
||||
endPos = fend;
|
||||
}
|
||||
|
||||
auto buf = GetFrameText( frames, i, ftime );
|
||||
auto tx = ImGui::CalcTextSize( buf ).x;
|
||||
uint32_t color = ( frames.name == 0 && i == 0 ) ? redColor : activeColor;
|
||||
|
||||
if( fsz - 7 <= tx )
|
||||
{
|
||||
static char tmp[256];
|
||||
sprintf( tmp, "%s (%s)", RealToString( i ), TimeToString( ftime ) );
|
||||
buf = tmp;
|
||||
tx = ImGui::CalcTextSize( buf ).x;
|
||||
}
|
||||
if( fsz - 7 <= tx )
|
||||
{
|
||||
buf = TimeToString( ftime );
|
||||
tx = ImGui::CalcTextSize( buf ).x;
|
||||
}
|
||||
|
||||
if( fbegin >= m_vd.zvStart )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( ( fbegin - m_vd.zvStart ) * pxns + 2, 1 ), dpos + ImVec2( ( fbegin - m_vd.zvStart ) * pxns + 2, ty - 1 ), color );
|
||||
}
|
||||
if( fend <= m_vd.zvEnd )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( ( fend - m_vd.zvStart ) * pxns - 2, 1 ), dpos + ImVec2( ( fend - m_vd.zvStart ) * pxns - 2, ty - 1 ), color );
|
||||
}
|
||||
if( fsz - 7 > tx )
|
||||
{
|
||||
const auto f0 = ( fbegin - m_vd.zvStart ) * pxns + 2;
|
||||
const auto f1 = ( fend - m_vd.zvStart ) * pxns - 2;
|
||||
const auto x0 = f0 + 1;
|
||||
const auto x1 = f1 - 1;
|
||||
const auto te = x1 - tx;
|
||||
|
||||
auto tpos = ( x0 + te ) / 2;
|
||||
if( tpos < 0 )
|
||||
{
|
||||
tpos = std::min( std::min( 0., te - tpos ), te );
|
||||
}
|
||||
else if( tpos > w - tx )
|
||||
{
|
||||
tpos = std::max( double( w - tx ), x0 );
|
||||
}
|
||||
tpos = round( tpos );
|
||||
|
||||
DrawLine( draw, dpos + ImVec2( std::max( -10.0, f0 ), ty05 ), dpos + ImVec2( tpos, ty05 ), color );
|
||||
DrawLine( draw, dpos + ImVec2( std::max( -10.0, tpos + tx + 1 ), ty05 ), dpos + ImVec2( std::min( w + 20.0, f1 ), ty05 ), color );
|
||||
draw->AddText( wpos + ImVec2( tpos, 0 ), color, buf );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( std::max( -10.0, ( fbegin - m_vd.zvStart ) * pxns + 2 ), ty05 ), dpos + ImVec2( std::min( w + 20.0, ( fend - m_vd.zvStart ) * pxns - 2 ), ty05 ), color );
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if( prev != -1 )
|
||||
{
|
||||
if( frames.continuous )
|
||||
{
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, ty05 ), ( prev - m_vd.zvStart ) * pxns, ( m_worker.GetFrameBegin( frames, zrange.second-1 ) - m_vd.zvStart ) * pxns, ty025, inactiveColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto begin = ( prev - m_vd.zvStart ) * pxns;
|
||||
const auto end = ( m_worker.GetFrameBegin( frames, zrange.second-1 ) - m_vd.zvStart ) * pxns;
|
||||
DrawZigZag( draw, wpos + ImVec2( 0, ty05 ), begin, std::max( begin + MinFrameSize, end ), ty025, inactiveColor );
|
||||
}
|
||||
}
|
||||
|
||||
if( hover )
|
||||
{
|
||||
if( !tooltipDisplayed )
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
TextDisabledUnformatted( "Frame set:" );
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted( GetFrameSetName( frames ) );
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
if( IsMouseClicked( 0 ) )
|
||||
{
|
||||
m_frames = &frames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user