Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Optims found while profiling, and dumb benchmark tool #1825

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions xbmc/Application.cpp
Expand Up @@ -2333,7 +2333,7 @@ void CApplication::Render()
flip = true; flip = true;


//fps limiter, make sure each frame lasts at least singleFrameTime milliseconds //fps limiter, make sure each frame lasts at least singleFrameTime milliseconds
if (limitFrames || !flip) if ((limitFrames || !flip) && !m_benchmarkTimer)
{ {
if (!limitFrames) if (!limitFrames)
singleFrameTime = 40; //if not flipping, loop at 25 fps singleFrameTime = 40; //if not flipping, loop at 25 fps
Expand Down Expand Up @@ -5036,7 +5036,11 @@ bool CApplication::ExecuteXBMCAction(std::string actionStr)
void CApplication::Process() void CApplication::Process()
{ {
MEASURE_FUNCTION; MEASURE_FUNCTION;

if (m_benchmarkTimer && XbmcThreads::SystemClockMillis() >= m_benchmarkTimer)
{
Stop(0);
return;
}
// dispatch the messages generated by python or other threads to the current window // dispatch the messages generated by python or other threads to the current window
g_windowManager.DispatchThreadMessages(); g_windowManager.DispatchThreadMessages();


Expand Down
5 changes: 5 additions & 0 deletions xbmc/Application.h
Expand Up @@ -348,6 +348,11 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
return m_bTestMode; return m_bTestMode;
} }


void SetBenchmarkTimer(unsigned int timer)
{
m_benchmarkTimer = timer;
}

bool IsPresentFrame(); bool IsPresentFrame();


void Minimize(); void Minimize();
Expand Down
6 changes: 2 additions & 4 deletions xbmc/GUIInfoManager.cpp
Expand Up @@ -2045,6 +2045,8 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI
bool bReturn = false; bool bReturn = false;
int condition = abs(condition1); int condition = abs(condition1);


if (condition >= MULTI_INFO_START && condition <= MULTI_INFO_END)
return GetMultiInfoBool(m_multiInfo[condition - MULTI_INFO_START], contextWindow, item);
if (item && condition >= LISTITEM_START && condition < LISTITEM_END) if (item && condition >= LISTITEM_START && condition < LISTITEM_END)
bReturn = GetItemBool(item, condition); bReturn = GetItemBool(item, condition);
// Ethernet Link state checking // Ethernet Link state checking
Expand Down Expand Up @@ -2145,10 +2147,6 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI
bReturn = m_playerShowInfo; bReturn = m_playerShowInfo;
else if (condition == PLAYER_SHOWCODEC) else if (condition == PLAYER_SHOWCODEC)
bReturn = m_playerShowCodec; bReturn = m_playerShowCodec;
else if (condition >= MULTI_INFO_START && condition <= MULTI_INFO_END)
{
return GetMultiInfoBool(m_multiInfo[condition - MULTI_INFO_START], contextWindow, item);
}
else if (condition == SYSTEM_HASLOCKS) else if (condition == SYSTEM_HASLOCKS)
bReturn = g_settings.GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE; bReturn = g_settings.GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE;
else if (condition == SYSTEM_HAS_PVR) else if (condition == SYSTEM_HAS_PVR)
Expand Down
13 changes: 13 additions & 0 deletions xbmc/XBApplicationEx.cpp
Expand Up @@ -42,6 +42,7 @@ CXBApplicationEx::CXBApplicationEx()
m_AppFocused = true; m_AppFocused = true;
m_ExitCode = EXITCODE_QUIT; m_ExitCode = EXITCODE_QUIT;
m_renderGUI = false; m_renderGUI = false;
m_benchmarkTimer = 0;
} }


CXBApplicationEx::~CXBApplicationEx() CXBApplicationEx::~CXBApplicationEx()
Expand Down Expand Up @@ -91,6 +92,10 @@ INT CXBApplicationEx::Run()
const BYTE MAX_EXCEPTION_COUNT = 10; const BYTE MAX_EXCEPTION_COUNT = 10;
#endif #endif


m_firstFrameTime = XbmcThreads::SystemClockMillis();
if (m_benchmarkTimer)
m_benchmarkTimer += m_firstFrameTime;

// Run xbmc // Run xbmc
while (!m_bStop) while (!m_bStop)
{ {
Expand Down Expand Up @@ -209,9 +214,17 @@ INT CXBApplicationEx::Run()
} }
} }
#endif #endif
m_totalFrames++;
} // while (!m_bStop) } // while (!m_bStop)
unsigned int uptime = lastFrameTime - m_firstFrameTime;
Destroy(); Destroy();


CLog::Log(LOGNOTICE, "application stopped..." ); CLog::Log(LOGNOTICE, "application stopped..." );

if (m_benchmarkTimer)
{
printf("Processed %llu Frames in %i msec.\n",m_totalFrames, uptime);
}

return m_ExitCode; return m_ExitCode;
} }
3 changes: 3 additions & 0 deletions xbmc/XBApplicationEx.h
Expand Up @@ -55,6 +55,9 @@ class CXBApplicationEx : public IWindowManagerCallback
INT Run(); INT Run();
VOID Destroy(); VOID Destroy();


unsigned long long m_totalFrames;
unsigned int m_benchmarkTimer;
unsigned int m_firstFrameTime;
private: private:
}; };


Expand Down
11 changes: 8 additions & 3 deletions xbmc/guilib/GUIControl.cpp
Expand Up @@ -58,7 +58,8 @@ CGUIControl::CGUIControl()
} }


CGUIControl::CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height) CGUIControl::CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height)
: m_hitRect(posX, posY, posX + width, posY + height) : m_hitRect(posX, posY, posX + width, posY + height),
m_cachedRenderRegion(0,0,0,0)
{ {
m_posX = posX; m_posX = posX;
m_posY = posY; m_posY = posY;
Expand Down Expand Up @@ -161,9 +162,13 @@ void CGUIControl::DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyreg
void CGUIControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) void CGUIControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
{ {
// update our render region // update our render region
m_renderRegion = g_graphicsContext.generateAABB(CalcRenderRegion()); CRect region(CalcRenderRegion());
if (region != m_cachedRenderRegion)
{
m_cachedRenderRegion = region;
m_renderRegion = g_graphicsContext.generateAABB(m_cachedRenderRegion);
}
} }

// the main render routine. // the main render routine.
// 1. set the animation transform // 1. set the animation transform
// 2. if visible, paint // 2. if visible, paint
Expand Down
1 change: 1 addition & 0 deletions xbmc/guilib/GUIControl.h
Expand Up @@ -357,6 +357,7 @@ class CGUIControl


bool m_controlIsDirty; bool m_controlIsDirty;
CRect m_renderRegion; // In screen coordinates CRect m_renderRegion; // In screen coordinates
CRect m_cachedRenderRegion;
}; };


#endif #endif
3 changes: 2 additions & 1 deletion xbmc/guilib/GraphicContext.cpp
Expand Up @@ -52,7 +52,8 @@ CGraphicContext::CGraphicContext(void) :
m_Resolution(RES_INVALID), m_Resolution(RES_INVALID),
/*m_windowResolution,*/ /*m_windowResolution,*/
m_guiScaleX(1.0f), m_guiScaleX(1.0f),
m_guiScaleY(1.0f) m_guiScaleY(1.0f),
m_groupTransformSize(0)
/*,m_cameras, */ /*,m_cameras, */
/*m_origins, */ /*m_origins, */
/*m_clipRegions,*/ /*m_clipRegions,*/
Expand Down
27 changes: 16 additions & 11 deletions xbmc/guilib/GraphicContext.h
Expand Up @@ -171,37 +171,42 @@ class CGraphicContext : public CCriticalSection
void ClipRect(CRect &vertex, CRect &texture, CRect *diffuse = NULL); void ClipRect(CRect &vertex, CRect &texture, CRect *diffuse = NULL);
inline unsigned int AddGUITransform() inline unsigned int AddGUITransform()
{ {
unsigned int size = m_groupTransform.size();
m_groupTransform.push(m_guiTransform); m_groupTransform.push(m_guiTransform);
UpdateFinalTransform(m_groupTransform.top()); m_groupTransformSize++;
return size; UpdateFinalTransform(m_guiTransform);
return m_groupTransformSize - 1;
} }
inline TransformMatrix AddTransform(const TransformMatrix &matrix) inline TransformMatrix AddTransform(const TransformMatrix &matrix)
{ {
ASSERT(m_groupTransform.size()); ASSERT(m_groupTransformSize);
TransformMatrix absoluteMatrix = m_groupTransform.size() ? m_groupTransform.top() * matrix : matrix; TransformMatrix absoluteMatrix = m_groupTransformSize ? m_groupTransform.top() * matrix : matrix;
m_groupTransform.push(absoluteMatrix); m_groupTransform.push(absoluteMatrix);
m_groupTransformSize++;
UpdateFinalTransform(absoluteMatrix); UpdateFinalTransform(absoluteMatrix);
return absoluteMatrix; return absoluteMatrix;
} }
inline void SetTransform(const TransformMatrix &matrix) inline void SetTransform(const TransformMatrix &matrix)
{ {
// TODO: We only need to add it to the group transform as other transforms may be added on top of this one later on // TODO: We only need to add it to the group transform as other transforms may be added on top of this one later on
// Once all transforms are cached then this can be removed and UpdateFinalTransform can be called directly // Once all transforms are cached then this can be removed and UpdateFinalTransform can be called directly
ASSERT(m_groupTransform.size()); ASSERT(m_groupTransformSize);
m_groupTransform.push(matrix); m_groupTransform.push(matrix);
m_groupTransformSize++;
UpdateFinalTransform(m_groupTransform.top()); UpdateFinalTransform(m_groupTransform.top());
} }
inline unsigned int RemoveTransform() inline unsigned int RemoveTransform()
{ {
ASSERT(m_groupTransform.size()); ASSERT(m_groupTransformSize);
if (m_groupTransform.size()) if (m_groupTransformSize)
{
m_groupTransform.pop(); m_groupTransform.pop();
if (m_groupTransform.size()) m_groupTransformSize--;
}
if (m_groupTransformSize)
UpdateFinalTransform(m_groupTransform.top()); UpdateFinalTransform(m_groupTransform.top());
else else
UpdateFinalTransform(TransformMatrix()); UpdateFinalTransform(TransformMatrix());
return m_groupTransform.size(); return m_groupTransformSize;
} }


CRect generateAABB(const CRect &rect) const; CRect generateAABB(const CRect &rect) const;
Expand Down Expand Up @@ -232,7 +237,7 @@ class CGraphicContext : public CCriticalSection
TransformMatrix m_guiTransform; TransformMatrix m_guiTransform;
TransformMatrix m_finalTransform; TransformMatrix m_finalTransform;
std::stack<TransformMatrix> m_groupTransform; std::stack<TransformMatrix> m_groupTransform;

unsigned int m_groupTransformSize;
CRect m_scissors; CRect m_scissors;
}; };


Expand Down
8 changes: 8 additions & 0 deletions xbmc/settings/AppParamParser.cpp
Expand Up @@ -92,6 +92,7 @@ void CAppParamParser::DisplayHelp()
printf("Usage: xbmc [OPTION]... [FILE]...\n\n"); printf("Usage: xbmc [OPTION]... [FILE]...\n\n");
printf("Arguments:\n"); printf("Arguments:\n");
printf(" -d <n>\t\tdelay <n> seconds before starting\n"); printf(" -d <n>\t\tdelay <n> seconds before starting\n");
printf(" --benchmark=n\t\tEnable meaningless benchmark mode. Run for <n> msec then display the number of frames rendered\n");
printf(" -fs\t\t\tRuns XBMC in full screen\n"); printf(" -fs\t\t\tRuns XBMC in full screen\n");
printf(" --standalone\t\tXBMC runs in a stand alone environment without a window \n"); printf(" --standalone\t\tXBMC runs in a stand alone environment without a window \n");
printf("\t\t\tmanager and supporting applications. For example, that\n"); printf("\t\t\tmanager and supporting applications. For example, that\n");
Expand Down Expand Up @@ -137,6 +138,13 @@ void CAppParamParser::ParseArg(const CStdString &arg)
m_testmode = true; m_testmode = true;
else if (arg.substr(0, 11) == "--settings=") else if (arg.substr(0, 11) == "--settings=")
g_advancedSettings.AddSettingsFile(arg.substr(11)); g_advancedSettings.AddSettingsFile(arg.substr(11));
else if (arg.substr(0, 12) == "--benchmark=")
{
unsigned int benchmark_time = atoi(arg.substr(12).c_str());
if (benchmark_time)
g_application.SetBenchmarkTimer(benchmark_time);
}

else if (arg.length() != 0 && arg[0] != '-') else if (arg.length() != 0 && arg[0] != '-')
{ {
if (m_testmode) if (m_testmode)
Expand Down