Implement first pass at texture compile estimation
This commit is contained in:
parent
a4f2cbe577
commit
373f3931e9
@ -39,7 +39,6 @@ struct ClampedLinearCostFunction1D
|
||||
|
||||
double operator() (unsigned int input) const
|
||||
{
|
||||
OSG_NOTICE<<"ClampedLinearCostFunction1D::operator("<<input<<")"<<std::endl;
|
||||
return _cost0 + _dcost_di * double(input<=_min_input ? 0u : input-_min_input);
|
||||
}
|
||||
double _cost0;
|
||||
@ -115,7 +114,7 @@ public:
|
||||
CostPair estimateCompileCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateCompileCost(geometry); }
|
||||
CostPair estimateDrawCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateDrawCost(geometry); }
|
||||
|
||||
CostPair estimateCompileCost(const osg::Texture* texture) const { return _textureEstimator->estimateDrawCost(texture); }
|
||||
CostPair estimateCompileCost(const osg::Texture* texture) const { return _textureEstimator->estimateCompileCost(texture); }
|
||||
CostPair estimateDrawCost(const osg::Texture* texture) const { return _textureEstimator->estimateDrawCost(texture); }
|
||||
|
||||
CostPair estimateCompileCost(const osg::Program* program) const { return _programEstimator->estimateCompileCost(program); }
|
||||
|
@ -46,7 +46,7 @@ void GeometryCostEstimator::calibrate(osg::RenderInfo& renderInfo)
|
||||
|
||||
CostPair GeometryCostEstimator::estimateCompileCost(const osg::Geometry* geometry) const
|
||||
{
|
||||
OSG_NOTICE<<"GeometryCostEstimator::estimateCompileCost(..)"<<std::endl;
|
||||
OSG_INFO<<"GeometryCostEstimator::estimateCompileCost(..)"<<std::endl;
|
||||
|
||||
bool usesVBO = geometry->getUseVertexBufferObjects() && geometry->areFastPathsUsed();
|
||||
bool usesDL = !usesVBO && geometry->getUseDisplayList() && geometry->getSupportsDisplayList();
|
||||
@ -79,7 +79,7 @@ CostPair GeometryCostEstimator::estimateCompileCost(const osg::Geometry* geometr
|
||||
cost.first = _displayListCompileConstant + _displayListCompileFactor * cost.first ;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<" cost.first="<<cost.first<<std::endl;
|
||||
OSG_INFO<<" cost.first="<<cost.first<<std::endl;
|
||||
|
||||
return cost;
|
||||
}
|
||||
@ -100,10 +100,16 @@ CostPair GeometryCostEstimator::estimateDrawCost(const osg::Geometry* geometry)
|
||||
//
|
||||
TextureCostEstimator::TextureCostEstimator()
|
||||
{
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
void TextureCostEstimator::setDefaults()
|
||||
{
|
||||
double transfer_bandwidth = 10000000000.0; // 1GB/sec
|
||||
double gpu_bandwidth = 50000000000.0; // 50 GB/second
|
||||
double min_time = 0.00001; // 10 nano seconds.
|
||||
_compileCost.set(min_time, 1.0/transfer_bandwidth, 256); // min time 1/10th of millisecond, min size 256
|
||||
_drawCost.set(min_time, 1.0/gpu_bandwidth, 256); // min time 1/10th of millisecond, min size 256
|
||||
}
|
||||
|
||||
void TextureCostEstimator::calibrate(osg::RenderInfo& renderInfo)
|
||||
@ -112,7 +118,14 @@ void TextureCostEstimator::calibrate(osg::RenderInfo& renderInfo)
|
||||
|
||||
CostPair TextureCostEstimator::estimateCompileCost(const osg::Texture* texture) const
|
||||
{
|
||||
return CostPair(0.0,0.0);
|
||||
CostPair cost;
|
||||
for(unsigned int i=0; i<texture->getNumImages(); ++i)
|
||||
{
|
||||
const osg::Image* image = texture->getImage(i);
|
||||
if (image) cost.first += _compileCost(image->getTotalDataSize());
|
||||
}
|
||||
OSG_NOTICE<<"TextureCostEstimator::estimateCompileCost(), size="<<cost.first<<std::endl;
|
||||
return cost;
|
||||
}
|
||||
|
||||
CostPair TextureCostEstimator::estimateDrawCost(const osg::Texture* texture) const
|
||||
@ -232,8 +245,6 @@ public:
|
||||
|
||||
CostPair cost = _gce->estimateCompileCost(geometry);
|
||||
|
||||
OSG_NOTICE<<"apply(Geometry), cost.first="<<cost.first<<std::endl;
|
||||
|
||||
_costs.first += cost.first;
|
||||
_costs.second += cost.second;
|
||||
}
|
||||
|
@ -174,7 +174,13 @@ IncrementalCompileOperation::CompileDrawableOp::CompileDrawableOp(osg::Drawable*
|
||||
|
||||
double IncrementalCompileOperation::CompileDrawableOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
|
||||
{
|
||||
return 0.0;
|
||||
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
|
||||
osg::Geometry* geometry = _drawable->asGeometry();
|
||||
if (gce && geometry)
|
||||
{
|
||||
return gce->estimateCompileCost(geometry).first;
|
||||
}
|
||||
else return 0.0;
|
||||
}
|
||||
|
||||
bool IncrementalCompileOperation::CompileDrawableOp::compile(CompileInfo& compileInfo)
|
||||
@ -191,7 +197,9 @@ IncrementalCompileOperation::CompileTextureOp::CompileTextureOp(osg::Texture* te
|
||||
|
||||
double IncrementalCompileOperation::CompileTextureOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
|
||||
{
|
||||
return 0.0;
|
||||
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
|
||||
if (gce) return gce->estimateCompileCost(_texture.get()).first;
|
||||
else return 0.0;
|
||||
}
|
||||
|
||||
bool IncrementalCompileOperation::CompileTextureOp::compile(CompileInfo& compileInfo)
|
||||
@ -224,7 +232,9 @@ IncrementalCompileOperation::CompileProgramOp::CompileProgramOp(osg::Program* pr
|
||||
|
||||
double IncrementalCompileOperation::CompileProgramOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
|
||||
{
|
||||
return 0.0;
|
||||
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
|
||||
if (gce) return gce->estimateCompileCost(_program.get()).first;
|
||||
else return 0.0;
|
||||
}
|
||||
|
||||
bool IncrementalCompileOperation::CompileProgramOp::compile(CompileInfo& compileInfo)
|
||||
@ -276,14 +286,21 @@ bool IncrementalCompileOperation::CompileList::compile(CompileInfo& compileInfo)
|
||||
itr != _compileOps.end() && compileInfo.availableTime()>0.0 && compileInfo.maxNumObjectsToCompile>0;
|
||||
)
|
||||
{
|
||||
double estimatedCompileCost = (*itr)->estimatedTimeForCompile(compileInfo);
|
||||
|
||||
--compileInfo.maxNumObjectsToCompile;
|
||||
|
||||
osg::ElapsedTime timer;
|
||||
|
||||
CompileOps::iterator saved_itr(itr);
|
||||
++itr;
|
||||
if ((*saved_itr)->compile(compileInfo))
|
||||
{
|
||||
_compileOps.erase(saved_itr);
|
||||
}
|
||||
|
||||
double actualCompileCost = timer.elapsedTime();
|
||||
OSG_NOTICE<<"IncrementalCompileOperation::CompileList::compile() estimatedTimForCompile= "<<estimatedCompileCost<<", actual="<<actualCompileCost<<", ratio="<<(estimatedCompileCost/actualCompileCost)<<std::endl;
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user