Bring back global lithium pools
why? cause sorting around the global driver pool would basically use more cpu power then just copy data sequences into the right order And sorting data references costs 0 performance at all
This commit is contained in:
+50
-12
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/drawlist.hpp>
|
||||
#include <pd/lithium/pools.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using PDGfxBackendFlags = PD::u32;
|
||||
@@ -37,7 +38,7 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
return Li::Texture();
|
||||
}
|
||||
virtual void DeleteTexture(const Li::Texture& tex) {}
|
||||
virtual void Draw(const Pool<Li::Command>& commands) {}
|
||||
virtual void Draw(const Li::Drawlist& commands) {}
|
||||
Li::Texture::Ptr GetWhiteTexture() { return &pWhite; }
|
||||
PDGfxBackendFlags GetFlags() { return Flags; }
|
||||
|
||||
@@ -110,28 +111,67 @@ class GfxDriverBase : public GfxDriver {
|
||||
pWhite = LoadTexture(img, 16, 16);
|
||||
}
|
||||
|
||||
void Draw(const Pool<Li::Command>& commands) override {
|
||||
void Draw(const Li::Drawlist& dl) override {
|
||||
const auto& commands = dl.Data();
|
||||
if (commands.size() == 0) return;
|
||||
pCountCommands += commands.size();
|
||||
size_t index = 0;
|
||||
|
||||
size_t vtotal = dl.GetNumVertices();
|
||||
size_t itotal = dl.GetNumIndices();
|
||||
|
||||
size_t start_vtx = pVtxPool.size();
|
||||
pVtxPool.Allocate(vtotal);
|
||||
CurrentVertex += vtotal;
|
||||
|
||||
size_t start_idx = pIdxPool.size();
|
||||
pIdxPool.Allocate(itotal);
|
||||
CurrentIndex += itotal;
|
||||
|
||||
size_t current_vtx = start_vtx;
|
||||
size_t current_idx = start_idx;
|
||||
|
||||
const auto& vpool = Li::GetVertexPool();
|
||||
const auto& ipool = Li::GetIndexPool();
|
||||
/** Build Pools */
|
||||
for (size_t i = 0; i < commands.size(); i++) {
|
||||
const auto& cmd = commands[i];
|
||||
if (cmd.VertexCount > 0) {
|
||||
std::memcpy(pVtxPool.begin() + current_vtx,
|
||||
vpool.begin() + cmd.FirstVertex,
|
||||
cmd.VertexCount * sizeof(Li::Vertex));
|
||||
}
|
||||
for (size_t idx = 0; idx < cmd.IndexCount; idx++) {
|
||||
u16 local_idx = ipool[cmd.FirstIndex + idx];
|
||||
pIdxPool[current_idx + idx] = static_cast<u16>(current_vtx + local_idx);
|
||||
}
|
||||
current_vtx += cmd.VertexCount;
|
||||
current_idx += cmd.IndexCount;
|
||||
}
|
||||
|
||||
UploadPools();
|
||||
|
||||
size_t index = 0;
|
||||
size_t ioff = start_idx;
|
||||
|
||||
while (index < commands.size()) {
|
||||
CurrentTex = commands[index].Tex;
|
||||
CurrentTexIsSDF = commands[index].SDF;
|
||||
if (!CurrentTex) {
|
||||
CurrentTex = pWhite.GetID();
|
||||
}
|
||||
size_t startidx = commands[index].FirstIndex;
|
||||
size_t num_indices = 0;
|
||||
while (index < commands.size() &&
|
||||
CurrentTexIsSDF == commands[index].SDF &&
|
||||
(CurrentTex == commands[index].Tex ||
|
||||
(CurrentTex == pWhite.GetID() && commands[index].Tex == 0)) &&
|
||||
commands[index].FirstIndex == startidx + num_indices) {
|
||||
(CurrentTex == pWhite.GetID() && commands[index].Tex == 0))) {
|
||||
num_indices += commands[index].IndexCount;
|
||||
index++;
|
||||
}
|
||||
Submit(num_indices, startidx);
|
||||
pCountDrawcalls++;
|
||||
if (num_indices > 0) {
|
||||
Submit(num_indices, ioff);
|
||||
ioff += num_indices;
|
||||
pCountDrawcalls++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,9 +251,7 @@ class PD_API Gfx {
|
||||
static void SetViewPort(const ivec2& vp) { driver->SetViewPort(vp); }
|
||||
static void SetViewPort(int w, int h) { driver->SetViewPort(w, h); }
|
||||
static void Reset() { driver->Reset(); }
|
||||
static void Draw(const Pool<Li::Command>& commands) {
|
||||
driver->Draw(commands);
|
||||
}
|
||||
static void Draw(const Li::Drawlist& dl) { driver->Draw(dl); }
|
||||
static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
|
||||
Reference in New Issue
Block a user