Add basic support to display GPU markers in the profiler
This commit is contained in:
parent
cc368103b0
commit
c8638ec968
@ -3,6 +3,7 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "config/user_config.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
|
||||
#ifdef _IRR_WINDOWS_API_
|
||||
#define IRR_OGL_LOAD_EXTENSION(X) wglGetProcAddress(reinterpret_cast<const char*>(X))
|
||||
@ -371,6 +372,9 @@ void blitFBO(GLuint Src, GLuint Dst, size_t width, size_t height)
|
||||
|
||||
ScopedGPUTimer::ScopedGPUTimer(GPUTimer &timer)
|
||||
{
|
||||
if (!UserConfigParams::m_profiler_enabled) return;
|
||||
if (profiler.isFrozen()) return;
|
||||
|
||||
irr::video::COpenGLDriver *gl_driver = (irr::video::COpenGLDriver *)irr_driver->getDevice()->getVideoDriver();
|
||||
if (!timer.initialised)
|
||||
{
|
||||
@ -381,6 +385,9 @@ ScopedGPUTimer::ScopedGPUTimer(GPUTimer &timer)
|
||||
}
|
||||
ScopedGPUTimer::~ScopedGPUTimer()
|
||||
{
|
||||
if (!UserConfigParams::m_profiler_enabled) return;
|
||||
if (profiler.isFrozen()) return;
|
||||
|
||||
irr::video::COpenGLDriver *gl_driver = (irr::video::COpenGLDriver *)irr_driver->getDevice()->getVideoDriver();
|
||||
gl_driver->extGlEndQuery(GL_TIME_ELAPSED);
|
||||
}
|
||||
|
@ -299,9 +299,6 @@ void IrrDriver::renderGLSL(float dt)
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
for (unsigned i = 0; i < Q_LAST; i++)
|
||||
Log::info("GPU Perf", "Phase %d : %d us\n", i, getGPUTimer(i).elapsedTimeus());
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
@ -446,7 +443,9 @@ void IrrDriver::renderSolidFirstPass()
|
||||
return;
|
||||
|
||||
{
|
||||
#ifdef DEBUG
|
||||
ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS1));
|
||||
#endif
|
||||
glUseProgram(MeshShader::ObjectPass1Shader::Program);
|
||||
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT>::MeshSet.size(); ++i)
|
||||
{
|
||||
@ -497,7 +496,9 @@ void IrrDriver::renderSolidSecondPass()
|
||||
setTexture(2, m_rtts->getRenderTarget(RTT_SSAO), GL_NEAREST, GL_NEAREST);
|
||||
|
||||
{
|
||||
#ifdef DEBUG
|
||||
ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS2));
|
||||
#endif
|
||||
m_scene_manager->drawAll(scene::ESNRP_SOLID);
|
||||
|
||||
glUseProgram(MeshShader::ObjectPass2Shader::Program);
|
||||
@ -681,7 +682,9 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb,
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
|
||||
{
|
||||
#ifdef DEBUG
|
||||
ScopedGPUTimer Timer(getGPUTimer(Q_SHADOWS));
|
||||
#endif
|
||||
m_scene_manager->drawAll(scene::ESNRP_SOLID);
|
||||
}
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
@ -904,7 +907,9 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
|
||||
irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition();
|
||||
|
||||
{
|
||||
#ifdef DEBUG
|
||||
ScopedGPUTimer Timer(getGPUTimer(Q_LIGHT));
|
||||
#endif
|
||||
std::vector<LightNode *> BucketedLN[15];
|
||||
for (unsigned int i = 0; i < lightcount; i++)
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ Profiler profiler;
|
||||
#define LINE_HEIGHT 0.030f // height of a line representing a thread
|
||||
|
||||
#define MARKERS_NAMES_POS core::rect<s32>(50,100,150,200)
|
||||
#define GPU_MARKERS_NAMES_POS core::rect<s32>(50,165,150,250)
|
||||
|
||||
#define TIME_DRAWN_MS 30.0f // the width of the profiler corresponds to TIME_DRAWN_MS milliseconds
|
||||
|
||||
@ -315,6 +316,48 @@ void Profiler::draw()
|
||||
}
|
||||
}
|
||||
|
||||
QueryPerf hovered_gpu_marker = Q_LAST;
|
||||
long hovered_gpu_marker_elapsed = 0;
|
||||
if (hovered_markers.size() == 0)
|
||||
{
|
||||
int gpu_y = y_offset + nb_thread_infos*line_height + line_height/2;
|
||||
float total = 0;
|
||||
for (unsigned i = 0; i < Q_LAST; i++)
|
||||
{
|
||||
total += irr_driver->getGPUTimer(i).elapsedTimeus();
|
||||
}
|
||||
|
||||
static video::SColor colors[] = {
|
||||
video::SColor(255, 255, 0, 0),
|
||||
video::SColor(255, 0, 255, 0),
|
||||
video::SColor(255, 0, 0, 255),
|
||||
video::SColor(255, 255, 255, 0),
|
||||
video::SColor(255, 255, 0, 255),
|
||||
video::SColor(255, 0, 255, 255)
|
||||
};
|
||||
|
||||
float curr_val = 0;
|
||||
for (unsigned i = 0; i < Q_LAST; i++)
|
||||
{
|
||||
//Log::info("GPU Perf", "Phase %d : %d us\n", i, irr_driver->getGPUTimer(i).elapsedTimeus());
|
||||
|
||||
float elapsed = irr_driver->getGPUTimer(i).elapsedTimeus();
|
||||
core::rect<s32> pos((s32)(x_offset + (curr_val / total)*profiler_width),
|
||||
(s32)(y_offset + gpu_y),
|
||||
(s32)(x_offset + ((curr_val + elapsed) / total)*profiler_width),
|
||||
(s32)(y_offset + gpu_y + line_height));
|
||||
|
||||
curr_val += elapsed;
|
||||
GL32_draw2DRectangle(colors[i % 6], pos);
|
||||
|
||||
if (pos.isPointInside(mouse_pos))
|
||||
{
|
||||
hovered_gpu_marker = (QueryPerf)i;
|
||||
hovered_gpu_marker_elapsed = irr_driver->getGPUTimer(i).elapsedTimeus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the end of the frame
|
||||
{
|
||||
s32 x_sync = (s32)(x_offset + factor*m_time_between_sync);
|
||||
@ -343,6 +386,13 @@ void Profiler::draw()
|
||||
hovered_markers.pop();
|
||||
}
|
||||
font->draw(text, MARKERS_NAMES_POS, video::SColor(0xFF, 0xFF, 0x00, 0x00));
|
||||
|
||||
if (hovered_gpu_marker != Q_LAST)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "GPU marker " << hovered_gpu_marker << " : " << hovered_gpu_marker_elapsed << " us";
|
||||
font->draw(oss.str().c_str(), GPU_MARKERS_NAMES_POS, video::SColor(0xFF, 0xFF, 0x00, 0x00));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_capture_report)
|
||||
@ -397,6 +447,6 @@ void Profiler::drawBackground()
|
||||
(int)((1.0-MARGIN_X) * screen_size.Width),
|
||||
(int)((MARGIN_Y + 1.75f*LINE_HEIGHT) * screen_size.Height));
|
||||
|
||||
video::SColor color(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
video::SColor color(0x88, 0xFF, 0xFF, 0xFF);
|
||||
GL32_draw2DRectangle(color, background_rect);
|
||||
}
|
||||
|
@ -164,11 +164,15 @@ public:
|
||||
|
||||
bool getCaptureReport() const { return m_capture_report; }
|
||||
void setCaptureReport(bool captureReport);
|
||||
|
||||
bool isFrozen() const { return m_freeze_state == FROZEN; }
|
||||
|
||||
protected:
|
||||
// TODO: detect on which thread this is called to support multithreading
|
||||
ThreadInfo& getThreadInfo() { return m_thread_infos[0]; }
|
||||
void drawBackground();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // PROFILER_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user