2009-02-09 21:15:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GS.h"
|
2009-05-11 08:18:00 +00:00
|
|
|
#include "GSCodeBuffer.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
struct GSRasterizerStats
|
|
|
|
{
|
2009-05-15 11:11:26 +00:00
|
|
|
int64 ticks;
|
2009-02-09 21:15:56 +00:00
|
|
|
int prims, pixels;
|
|
|
|
|
|
|
|
GSRasterizerStats()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
ticks = 0;
|
|
|
|
pixels = prims = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-02-11 07:05:44 +00:00
|
|
|
template<class KEY, class VALUE> class GSFunctionMap
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
struct ActivePtr
|
|
|
|
{
|
2009-05-15 11:11:26 +00:00
|
|
|
uint64 frame, frames;
|
|
|
|
int64 ticks, pixels;
|
2009-02-11 07:05:44 +00:00
|
|
|
VALUE f;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
hash_map<KEY, VALUE> m_map;
|
|
|
|
hash_map<KEY, ActivePtr*> m_map_active;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
ActivePtr* m_active;
|
|
|
|
|
2009-02-11 07:05:44 +00:00
|
|
|
virtual VALUE GetDefaultFunction(KEY key) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GSFunctionMap()
|
|
|
|
: m_active(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GSFunctionMap()
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
for(hash_map<KEY, ActivePtr*>::iterator i = m_map_active.begin(); i != m_map_active.end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
delete (*i).second;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-11 07:05:44 +00:00
|
|
|
VALUE Lookup(KEY key)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
m_active = NULL;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
hash_map<KEY, ActivePtr*>::iterator i = m_map_active.find(key);
|
|
|
|
|
|
|
|
if(i != m_map_active.end())
|
|
|
|
{
|
|
|
|
m_active = (*i).second;
|
|
|
|
}
|
|
|
|
else
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
hash_map<KEY, VALUE>::iterator i = m_map.find(key);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
ActivePtr* p = new ActivePtr();
|
|
|
|
|
|
|
|
memset(p, 0, sizeof(*p));
|
|
|
|
|
2009-05-15 11:11:26 +00:00
|
|
|
p->frame = (uint64)-1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
p->f = i != m_map.end() ? (*i).second : GetDefaultFunction(key);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
m_map_active[key] = p;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_active = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_active->f;
|
|
|
|
}
|
|
|
|
|
2009-05-15 11:11:26 +00:00
|
|
|
void UpdateStats(const GSRasterizerStats& stats, uint64 frame)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(m_active)
|
|
|
|
{
|
|
|
|
if(m_active->frame != frame)
|
|
|
|
{
|
|
|
|
m_active->frame = frame;
|
|
|
|
m_active->frames++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_active->pixels += stats.pixels;
|
|
|
|
m_active->ticks += stats.ticks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void PrintStats()
|
|
|
|
{
|
2009-05-15 11:11:26 +00:00
|
|
|
int64 ttpf = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(hash_map<KEY, ActivePtr*>::iterator i = m_map_active.begin(); i != m_map_active.end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
ActivePtr* p = (*i).second;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(p->frames)
|
|
|
|
{
|
|
|
|
ttpf += p->ticks / p->frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(hash_map<KEY, ActivePtr*>::iterator i = m_map_active.begin(); i != m_map_active.end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
KEY key = (*i).first;
|
|
|
|
ActivePtr* p = (*i).second;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(p->frames > 0)
|
|
|
|
{
|
2009-05-15 11:11:26 +00:00
|
|
|
int64 tpp = p->pixels > 0 ? p->ticks / p->pixels : 0;
|
|
|
|
int64 tpf = p->frames > 0 ? p->ticks / p->frames : 0;
|
|
|
|
int64 ppf = p->frames > 0 ? p->pixels / p->frames : 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-13 09:28:51 +00:00
|
|
|
printf("[%012I64x]%c %6.2f%% | %5.2f%% | f %4I64d | p %10I64d | tpp %4I64d | tpf %9I64d | ppf %7I64d\n",
|
2009-05-15 11:11:26 +00:00
|
|
|
(uint64)key, m_map.find(key) == m_map.end() ? '*' : ' ',
|
2009-02-09 21:15:56 +00:00
|
|
|
(float)(tpf * 10000 / 50000000) / 100,
|
|
|
|
(float)(tpf * 10000 / ttpf) / 100,
|
|
|
|
p->frames, p->pixels,
|
|
|
|
tpp, tpf, ppf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-02-13 09:28:51 +00:00
|
|
|
|
2009-02-22 16:28:39 +00:00
|
|
|
#include "vtune/JITProfiling.h"
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2009-02-13 09:28:51 +00:00
|
|
|
template<class CG, class KEY, class VALUE>
|
|
|
|
class GSCodeGeneratorFunctionMap : public GSFunctionMap<KEY, VALUE>
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 m_id;
|
2009-05-11 08:18:00 +00:00
|
|
|
string m_name;
|
2009-05-14 16:41:52 +00:00
|
|
|
hash_map<uint64, CG*> m_cgmap;
|
2009-02-19 13:13:20 +00:00
|
|
|
GSCodeBuffer m_cb;
|
|
|
|
|
|
|
|
enum {MAX_SIZE = 4096};
|
2009-02-13 09:28:51 +00:00
|
|
|
|
|
|
|
protected:
|
2009-02-19 13:13:20 +00:00
|
|
|
virtual CG* Create(KEY key, void* ptr, size_t maxsize = MAX_SIZE) = 0;
|
2009-02-13 09:28:51 +00:00
|
|
|
|
|
|
|
public:
|
2009-05-11 08:18:00 +00:00
|
|
|
GSCodeGeneratorFunctionMap(const char* name)
|
2009-02-22 16:28:39 +00:00
|
|
|
: m_id(0x100000)
|
|
|
|
, m_name(name)
|
2009-02-13 09:28:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GSCodeGeneratorFunctionMap()
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
for(hash_map<uint64, CG*>::iterator i = m_cgmap.begin(); i != m_cgmap.end(); i++)
|
2009-02-13 09:28:51 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
delete (*i).second;
|
2009-02-13 09:28:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE GetDefaultFunction(KEY key)
|
|
|
|
{
|
|
|
|
CG* cg = NULL;
|
|
|
|
|
2009-05-15 11:11:26 +00:00
|
|
|
hash_map<uint64, CG*>::iterator i = m_cgmap.find(key);
|
2009-05-11 08:18:00 +00:00
|
|
|
|
|
|
|
if(i != m_cgmap.end())
|
|
|
|
{
|
|
|
|
cg = (*i).second;
|
|
|
|
}
|
|
|
|
else
|
2009-02-13 09:28:51 +00:00
|
|
|
{
|
2009-02-19 13:13:20 +00:00
|
|
|
void* ptr = m_cb.GetBuffer(MAX_SIZE);
|
|
|
|
|
|
|
|
cg = Create(key, ptr, MAX_SIZE);
|
2009-02-13 09:28:51 +00:00
|
|
|
|
|
|
|
ASSERT(cg);
|
|
|
|
|
2009-02-19 13:13:20 +00:00
|
|
|
m_cb.ReleaseBuffer(cg->getSize());
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
m_cgmap[key] = cg;
|
2009-02-22 16:28:39 +00:00
|
|
|
|
|
|
|
// vtune method registration
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
string name = format("%s<%016I64x>()", m_name.c_str(), (uint64)key);
|
2009-02-22 16:28:39 +00:00
|
|
|
|
|
|
|
iJIT_Method_Load ml;
|
|
|
|
|
|
|
|
memset(&ml, 0, sizeof(ml));
|
|
|
|
|
|
|
|
ml.method_id = m_id++;
|
2009-05-11 08:18:00 +00:00
|
|
|
ml.method_name = (char*)name.c_str();
|
2009-02-22 16:28:39 +00:00
|
|
|
ml.method_load_address = (void*)cg->getCode();
|
|
|
|
ml.method_size = cg->getSize();
|
|
|
|
|
|
|
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &ml);
|
2009-02-13 09:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (VALUE)cg->getCode();
|
|
|
|
}
|
|
|
|
};
|