Refactor the Command / DrawList System
Use Command Pool instead of always allocating. This gives us e big performance diffrence on the 3ds Fixed IDS of ui7 for now
This commit is contained in:
@@ -34,7 +34,7 @@ class Command {
|
||||
Command() = default;
|
||||
~Command() = default;
|
||||
|
||||
PD_UNIQUE(Command);
|
||||
PD_RAW(Command);
|
||||
|
||||
Command& AddIdx(const u16& idx) {
|
||||
IndexBuffer.push_back(VertexBuffer.size() + idx);
|
||||
@@ -52,6 +52,16 @@ class Command {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
VertexBuffer.clear();
|
||||
IndexBuffer.clear();
|
||||
Index = 0;
|
||||
Layer = 0;
|
||||
Tex = 0;
|
||||
ScissorOn = false;
|
||||
ScissorRect = ivec4();
|
||||
}
|
||||
|
||||
std::vector<Vertex> VertexBuffer;
|
||||
std::vector<u16> IndexBuffer;
|
||||
ivec4 ScissorRect;
|
||||
@@ -60,5 +70,71 @@ class Command {
|
||||
int Index;
|
||||
Texture::Ref Tex;
|
||||
};
|
||||
|
||||
class CmdPool {
|
||||
public:
|
||||
CmdPool() {}
|
||||
~CmdPool() {}
|
||||
|
||||
Command::Ref NewCmd() {
|
||||
if (pPoolIdx >= pPool.size()) {
|
||||
Resize(pPool.size() + 128);
|
||||
}
|
||||
Command::Ref nu = pPool[pPoolIdx++];
|
||||
nu->Layer = Layer;
|
||||
nu->Index = pPoolIdx - 1;
|
||||
return nu;
|
||||
}
|
||||
|
||||
void Init(size_t initial_size) { Resize(initial_size); }
|
||||
|
||||
void Deinit() {
|
||||
for (auto it : pPool) {
|
||||
Command::Delete(it);
|
||||
}
|
||||
pPool.clear();
|
||||
}
|
||||
|
||||
void Resize(size_t nulen) {
|
||||
if (nulen <= pPool.size()) {
|
||||
return; // no idea yet
|
||||
}
|
||||
size_t oldlen = pPool.size();
|
||||
pPool.resize(nulen);
|
||||
for (size_t i = oldlen; i < pPool.size(); i++) {
|
||||
pPool[i] = Command::New();
|
||||
}
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
for (u32 i = 0; i < pPoolIdx; i++) {
|
||||
pPool[i]->Clear();
|
||||
}
|
||||
pPoolIdx = 0;
|
||||
}
|
||||
|
||||
Command::Ref GetCmd(size_t idx) const { return pPool[idx]; }
|
||||
Command::Ref GetCmd(size_t idx) { return pPool[idx]; }
|
||||
|
||||
size_t Size() const { return pPoolIdx; }
|
||||
size_t Cap() const { return pPool.size(); }
|
||||
|
||||
void Merge(CmdPool& p) {
|
||||
if (pPoolIdx + p.Size() > pPool.size()) {
|
||||
Resize(pPoolIdx + p.Size());
|
||||
}
|
||||
for (size_t i = 0; i < p.Size(); i++) {
|
||||
size_t idx = pPoolIdx++;
|
||||
*pPool[idx] = *p.GetCmd(i);
|
||||
pPool[idx]->Index = idx;
|
||||
}
|
||||
p.Reset();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Command::Ref> pPool;
|
||||
u32 pPoolIdx = 0;
|
||||
int Layer = 0;
|
||||
};
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user