mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 08:53:07 +02:00
Aggressive batch pre-allocation
This commit is contained in:
parent
7724065298
commit
721cd79b57
3 changed files with 52 additions and 58 deletions
|
@ -30,24 +30,39 @@ ProfileRangeBatch::~ProfileRangeBatch() {
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
Batch::Batch(const CacheState& cacheState) : Batch() {
|
size_t Batch::_commandsMax { 128 };
|
||||||
_commands.reserve(cacheState.commandsSize);
|
size_t Batch::_commandOffsetsMax { 128 };
|
||||||
_commandOffsets.reserve(cacheState.offsetsSize);
|
size_t Batch::_paramsMax { 128 };
|
||||||
_params.reserve(cacheState.paramsSize);
|
size_t Batch::_dataMax { 128 };
|
||||||
_data.reserve(cacheState.dataSize);
|
size_t Batch::_objectsMax { 128 };
|
||||||
}
|
size_t Batch::_drawCallInfosMax { 128 };
|
||||||
|
|
||||||
Batch::CacheState Batch::getCacheState() {
|
Batch::Batch() {
|
||||||
return CacheState(_commands.size(), _commandOffsets.size(), _params.size(), _data.size(),
|
_commands.reserve(_commandsMax);
|
||||||
_buffers.size(), _textures.size(), _streamFormats.size(), _transforms.size(), _pipelines.size(),
|
_commandOffsets.reserve(_commandOffsetsMax);
|
||||||
_framebuffers.size(), _queries.size());
|
_params.reserve(_paramsMax);
|
||||||
|
_data.reserve(_dataMax);
|
||||||
|
_objects.reserve(_objectsMax);
|
||||||
|
_drawCallInfos.reserve(_drawCallInfosMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
Batch::~Batch() {
|
Batch::~Batch() {
|
||||||
//qDebug() << "Batch::~Batch()... " << getCacheState();
|
_commandsMax = std::max(_commands.size(), _commandsMax);
|
||||||
|
_commandOffsetsMax = std::max(_commandOffsets.size(), _commandOffsetsMax);
|
||||||
|
_paramsMax = std::max(_params.size(), _paramsMax);
|
||||||
|
_dataMax = std::max(_data.size(), _dataMax);
|
||||||
|
_objectsMax = std::max(_objects.size(), _objectsMax);
|
||||||
|
_drawCallInfosMax = std::max(_drawCallInfos.size(), _drawCallInfosMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::clear() {
|
void Batch::clear() {
|
||||||
|
_commandsMax = std::max(_commands.size(), _commandsMax);
|
||||||
|
_commandOffsetsMax = std::max(_commandOffsets.size(), _commandOffsetsMax);
|
||||||
|
_paramsMax = std::max(_params.size(), _paramsMax);
|
||||||
|
_dataMax = std::max(_data.size(), _dataMax);
|
||||||
|
_objectsMax = std::max(_objects.size(), _objectsMax);
|
||||||
|
_drawCallInfosMax = std::max(_drawCallInfos.size(), _drawCallInfosMax);
|
||||||
|
|
||||||
_commands.clear();
|
_commands.clear();
|
||||||
_commandOffsets.clear();
|
_commandOffsets.clear();
|
||||||
_params.clear();
|
_params.clear();
|
||||||
|
@ -58,6 +73,8 @@ void Batch::clear() {
|
||||||
_transforms.clear();
|
_transforms.clear();
|
||||||
_pipelines.clear();
|
_pipelines.clear();
|
||||||
_framebuffers.clear();
|
_framebuffers.clear();
|
||||||
|
_objects.clear();
|
||||||
|
_drawCallInfos.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Batch::cacheData(size_t size, const void* data) {
|
size_t Batch::cacheData(size_t size, const void* data) {
|
||||||
|
@ -458,17 +475,6 @@ void Batch::preExecute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug& operator<<(QDebug& debug, const Batch::CacheState& cacheState) {
|
|
||||||
debug << "Batch::CacheState[ "
|
|
||||||
<< "commandsSize:" << cacheState.commandsSize
|
|
||||||
<< "offsetsSize:" << cacheState.offsetsSize
|
|
||||||
<< "paramsSize:" << cacheState.paramsSize
|
|
||||||
<< "dataSize:" << cacheState.dataSize
|
|
||||||
<< "]";
|
|
||||||
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
void Batch::pushProfileRange(const char* name) {
|
void Batch::pushProfileRange(const char* name) {
|
||||||
#if defined(NSIGHT_FOUND)
|
#if defined(NSIGHT_FOUND)
|
||||||
|
|
|
@ -87,6 +87,7 @@ public:
|
||||||
using NamedBatchDataMap = std::map<std::string, NamedBatchData>;
|
using NamedBatchDataMap = std::map<std::string, NamedBatchData>;
|
||||||
|
|
||||||
DrawCallInfoBuffer _drawCallInfos;
|
DrawCallInfoBuffer _drawCallInfos;
|
||||||
|
static size_t _drawCallInfosMax;
|
||||||
|
|
||||||
std::string _currentNamedCall;
|
std::string _currentNamedCall;
|
||||||
|
|
||||||
|
@ -96,34 +97,7 @@ public:
|
||||||
void captureDrawCallInfo();
|
void captureDrawCallInfo();
|
||||||
void captureNamedDrawCallInfo(std::string name);
|
void captureNamedDrawCallInfo(std::string name);
|
||||||
|
|
||||||
class CacheState {
|
Batch();
|
||||||
public:
|
|
||||||
size_t commandsSize;
|
|
||||||
size_t offsetsSize;
|
|
||||||
size_t paramsSize;
|
|
||||||
size_t dataSize;
|
|
||||||
|
|
||||||
size_t buffersSize;
|
|
||||||
size_t texturesSize;
|
|
||||||
size_t streamFormatsSize;
|
|
||||||
size_t transformsSize;
|
|
||||||
size_t pipelinesSize;
|
|
||||||
size_t framebuffersSize;
|
|
||||||
size_t queriesSize;
|
|
||||||
|
|
||||||
CacheState() : commandsSize(0), offsetsSize(0), paramsSize(0), dataSize(0), buffersSize(0), texturesSize(0),
|
|
||||||
streamFormatsSize(0), transformsSize(0), pipelinesSize(0), framebuffersSize(0), queriesSize(0) { }
|
|
||||||
|
|
||||||
CacheState(size_t commandsSize, size_t offsetsSize, size_t paramsSize, size_t dataSize, size_t buffersSize,
|
|
||||||
size_t texturesSize, size_t streamFormatsSize, size_t transformsSize, size_t pipelinesSize,
|
|
||||||
size_t framebuffersSize, size_t queriesSize) :
|
|
||||||
commandsSize(commandsSize), offsetsSize(offsetsSize), paramsSize(paramsSize), dataSize(dataSize),
|
|
||||||
buffersSize(buffersSize), texturesSize(texturesSize), streamFormatsSize(streamFormatsSize),
|
|
||||||
transformsSize(transformsSize), pipelinesSize(pipelinesSize), framebuffersSize(framebuffersSize), queriesSize(queriesSize) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
Batch() {}
|
|
||||||
Batch(const CacheState& cacheState);
|
|
||||||
explicit Batch(const Batch& batch);
|
explicit Batch(const Batch& batch);
|
||||||
~Batch();
|
~Batch();
|
||||||
|
|
||||||
|
@ -131,9 +105,6 @@ public:
|
||||||
|
|
||||||
void preExecute();
|
void preExecute();
|
||||||
|
|
||||||
CacheState getCacheState();
|
|
||||||
|
|
||||||
|
|
||||||
// Batches may need to override the context level stereo settings
|
// Batches may need to override the context level stereo settings
|
||||||
// if they're performing framebuffer copy operations, like the
|
// if they're performing framebuffer copy operations, like the
|
||||||
// deferred lighting resolution mechanism
|
// deferred lighting resolution mechanism
|
||||||
|
@ -401,11 +372,21 @@ public:
|
||||||
typedef T Data;
|
typedef T Data;
|
||||||
Data _data;
|
Data _data;
|
||||||
Cache<T>(const Data& data) : _data(data) {}
|
Cache<T>(const Data& data) : _data(data) {}
|
||||||
|
static size_t _max;
|
||||||
|
|
||||||
class Vector {
|
class Vector {
|
||||||
public:
|
public:
|
||||||
std::vector< Cache<T> > _items;
|
std::vector< Cache<T> > _items;
|
||||||
|
|
||||||
|
Vector() {
|
||||||
|
_items.reserve(_max);
|
||||||
|
}
|
||||||
|
|
||||||
|
~Vector() {
|
||||||
|
_max = std::max(_items.size(), _max);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t size() const { return _items.size(); }
|
size_t size() const { return _items.size(); }
|
||||||
size_t cache(const Data& data) {
|
size_t cache(const Data& data) {
|
||||||
size_t offset = _items.size();
|
size_t offset = _items.size();
|
||||||
|
@ -449,9 +430,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands _commands;
|
Commands _commands;
|
||||||
|
static size_t _commandsMax;
|
||||||
|
|
||||||
CommandOffsets _commandOffsets;
|
CommandOffsets _commandOffsets;
|
||||||
|
static size_t _commandOffsetsMax;
|
||||||
|
|
||||||
Params _params;
|
Params _params;
|
||||||
|
static size_t _paramsMax;
|
||||||
|
|
||||||
Bytes _data;
|
Bytes _data;
|
||||||
|
static size_t _dataMax;
|
||||||
|
|
||||||
// SSBO class... layout MUST match the layout in Transform.slh
|
// SSBO class... layout MUST match the layout in Transform.slh
|
||||||
class TransformObject {
|
class TransformObject {
|
||||||
|
@ -464,6 +452,7 @@ public:
|
||||||
bool _invalidModel { true };
|
bool _invalidModel { true };
|
||||||
Transform _currentModel;
|
Transform _currentModel;
|
||||||
TransformObjects _objects;
|
TransformObjects _objects;
|
||||||
|
static size_t _objectsMax;
|
||||||
|
|
||||||
BufferCaches _buffers;
|
BufferCaches _buffers;
|
||||||
TextureCaches _textures;
|
TextureCaches _textures;
|
||||||
|
@ -491,6 +480,9 @@ protected:
|
||||||
void captureDrawCallInfoImpl();
|
void captureDrawCallInfoImpl();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
size_t Batch::Cache<T>::_max = 128;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(NSIGHT_FOUND)
|
#if defined(NSIGHT_FOUND)
|
||||||
|
@ -512,6 +504,4 @@ private:
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QDebug& operator<<(QDebug& debug, const gpu::Batch::CacheState& cacheState);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -231,11 +231,9 @@ typedef std::shared_ptr<Context> ContextPointer;
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void doInBatch(std::shared_ptr<gpu::Context> context, F f) {
|
void doInBatch(std::shared_ptr<gpu::Context> context, F f) {
|
||||||
static gpu::Batch::CacheState cacheState;
|
gpu::Batch batch;
|
||||||
gpu::Batch batch(cacheState);
|
|
||||||
f(batch);
|
f(batch);
|
||||||
context->render(batch);
|
context->render(batch);
|
||||||
cacheState = batch.getCacheState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue