From 45154f0716e470f46bf8c5797b2334af9563f7a2 Mon Sep 17 00:00:00 2001 From: ponchio Date: Wed, 15 Dec 2004 16:37:55 +0000 Subject: [PATCH] Optimizing realtime vis. --- apps/nexus/lrupserver.h | 10 ++++++---- apps/nexus/nexusmt.cpp | 7 +++++-- apps/nexus/nexusview.cpp | 8 ++++++-- apps/nexus/nxsedit.cpp | 12 +++++++----- apps/nexus/prefetch.cpp | 40 +++++++++++++++++++++------------------ apps/nexus/prefetch.h | 2 ++ apps/nexus/pserver.cpp | 16 ++++++++-------- apps/nexus/pserver.h | 3 +-- apps/nexus/queuepserver.h | 2 +- 9 files changed, 58 insertions(+), 42 deletions(-) diff --git a/apps/nexus/lrupserver.h b/apps/nexus/lrupserver.h index ac5eb6c3..ca916668 100644 --- a/apps/nexus/lrupserver.h +++ b/apps/nexus/lrupserver.h @@ -3,6 +3,7 @@ #include #include +#include #include "pserver.h" namespace nxs { @@ -19,7 +20,7 @@ class LruPServer: public PServer { Flush(); } - Patch &Lookup(unsigned int patch, unsigned short nv, unsigned short nf) { + Patch &Lookup(unsigned int patch, unsigned short nv, unsigned short nf) { if(index.count(patch)) { Items::iterator &i = index[patch]; Item item = *i; @@ -27,10 +28,11 @@ class LruPServer: public PServer { items.push_front(item); i = items.begin(); return *((*i).second); - } else { + } else { while(ram_used > ram_max) { - index.erase(items.back().first); - FlushPatch(patch, items.back().second); + Item item = items.back(); + index.erase(item.first); + FlushPatch(item.first, item.second); items.pop_back(); } Item item; diff --git a/apps/nexus/nexusmt.cpp b/apps/nexus/nexusmt.cpp index 060281e6..3a86e4a7 100644 --- a/apps/nexus/nexusmt.cpp +++ b/apps/nexus/nexusmt.cpp @@ -65,8 +65,11 @@ bool NexusMt::Expand(TNode &tnode) { //expand if node error > target error if(extraction_used >= extraction_max) return false; if(draw_used >= draw_max) return false; - if(disk_used >= disk_max) return false; - + if(disk_used >= disk_max) { + float ratio = disk_max / (float)disk_used; + float error = tnode.error * ratio; + return error > target_error; + } return tnode.error > target_error; } diff --git a/apps/nexus/nexusview.cpp b/apps/nexus/nexusview.cpp index 7bdbfeb4..89e3514c 100644 --- a/apps/nexus/nexusview.cpp +++ b/apps/nexus/nexusview.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.26 2004/12/15 13:50:32 ponchio +Optimizing realtime vis. + Revision 1.25 2004/12/15 08:46:16 ponchio Optimizing realtime vis. @@ -459,8 +462,9 @@ int main(int argc, char *argv[]) { nexus.patches.ram_used * nexus.chunk_size/(float)(1<<20)); gl_print(0.03, 0.09, buffer); - sprintf(buffer, "Vbo size : %.3fMb(cur)", - nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20)); + sprintf(buffer, "Vbo size : %.3fMb(cur) Load: %.4fK Pref: %.4fK", + nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20), + nexus.prefetch.loading, nexus.prefetch.prefetching); gl_print(0.03, 0.06, buffer); sprintf(buffer, "Triangles: %.2fK (tot) %.2fK (vis) " diff --git a/apps/nexus/nxsedit.cpp b/apps/nexus/nxsedit.cpp index 435a6881..ac487d5e 100644 --- a/apps/nexus/nxsedit.cpp +++ b/apps/nexus/nxsedit.cpp @@ -211,11 +211,12 @@ int main(int argc, char *argv[]) { Nexus nexus; - nexus.MaxRamBuffer(ram_size); + if(!nexus.Load(input, true)) { cerr << "Could not open nexus file: " << input << "\n"; return -1; } + nexus.MaxRamBuffer(ram_size); //Sanity tests @@ -312,7 +313,7 @@ int main(int argc, char *argv[]) { cout << "Writing to nexus: " << output << endl; Nexus out; - out.MaxRamBuffer(ram_size); + if(!chunk_size) chunk_size = nexus.patches.chunk_size; @@ -320,6 +321,7 @@ int main(int argc, char *argv[]) { cerr << "Could not open output: " << output << endl; return -1; } + out.MaxRamBuffer(ram_size); //TODO set rambuffer low (or even direct access!) @@ -397,9 +399,9 @@ int main(int argc, char *argv[]) { Border dst_border = out.GetBorder(patch); out.borders.ResizeBorder(patch, src_border.Size()); memcpy(dst_border.Start(), src_border.Start(), - src_border.Size() * sizeof(Link)); + src_border.Size() * sizeof(Link)); } - report.Finish(); + report.Finish(); //TODO this is ok only if we have faces still! if(add_normals) { @@ -429,7 +431,7 @@ int main(int argc, char *argv[]) { out.sphere = nexus.sphere; out.history = nexus.history; - + out.Close(); nexus.Close(); return 0; diff --git a/apps/nexus/prefetch.cpp b/apps/nexus/prefetch.cpp index 9666ddf2..8572d279 100644 --- a/apps/nexus/prefetch.cpp +++ b/apps/nexus/prefetch.cpp @@ -16,19 +16,19 @@ void Prefetch::init(NexusMt *m, std::vector &selected, mt = m; missing.clear(); mt->todraw.clear(); - + float loaded = 0; unsigned int notloaded = 0; set tmp; //std::map tmp; vector flush; for(unsigned int i = 0; i < selected.size(); i++) { unsigned int patch = selected[i]; - tmp.insert(patch); - //tmp[patch] = 0.0f; - if(!mt->patches.entries[patch].patch) { - //cerr << "miss: " << patch << endl; + tmp.insert(patch); + + if(!mt->patches.entries[patch].patch) { + PServer::Entry &entry = mt->patches.entries[patch]; load.post(patch); - notloaded++; + loaded += entry.disk_size; } else { PatchInfo &info = mt->index[patch]; //WORKING QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, 0.0f, flush); @@ -46,8 +46,7 @@ void Prefetch::init(NexusMt *m, std::vector &selected, } //missing.push_back(PServer::Item(patch, 0.0f)); } - if(notloaded) - cerr << "Patches to load: " << notloaded << endl; + loading = 0.2 * loaded + 0.8 * loading; for(unsigned int i = 0; i < visited.size(); i++) { PServer::Item &item = visited[i]; @@ -78,22 +77,23 @@ void Prefetch::init(NexusMt *m, std::vector &selected, safety.unlock(); } -void Prefetch::execute() { - unsigned int prefetched = 0; +void Prefetch::execute() { + + float prefetch; + prefetching = 0; + loading = 0; while(1) { if(get_signaled()) return; vector flush; - if(load.get_count() || missing.size() == 0) { - if(prefetched) - cerr << "Prefetched: " << prefetched << endl; - prefetched = 0; - + if(load.get_count() || missing.size() == 0) { + prefetch = 0; pt::message *msg = load.getmessage(); if(msg->id != 0xffffffff) { safety.lock(); PatchInfo &info = mt->index[msg->id]; - + PServer::Entry &entry = mt->patches.entries[msg->id]; + loading += entry.disk_size; //posting draw message //WORKING QueuePServer::Data &data = mt->patches.Lookup(msg->id, info.nvert, info.nface, 0.0f, flush); QueuePServer::Data &data = mt->patches.Lookup(msg->id, info.nvert, info.nface, flush); @@ -108,6 +108,8 @@ void Prefetch::execute() { draw.post(QueuePServer::FLUSH, (unsigned int)data); } safety.unlock(); + } else { + prefetching = 0.2 * prefetch + 0.8 * prefetching; } delete msg; } else { @@ -124,8 +126,10 @@ void Prefetch::execute() { //cerr << "prefetching: " << item.patch << endl; //WORKING mt->patches.Lookup(item.patch, info.nvert, info.nface, item.priority, flush); if(!mt->patches.entries[item.patch].patch) { - mt->patches.Lookup(item.patch, info.nvert, info.nface, flush); - prefetched++; + PServer::Entry &entry = mt->patches.entries[item.patch]; + prefetch += entry.disk_size; + + mt->patches.Lookup(item.patch, info.nvert, info.nface, flush); for(unsigned int i = 0; i < flush.size(); i++) { QueuePServer::Data *data = new QueuePServer::Data; *data = flush[i]; diff --git a/apps/nexus/prefetch.h b/apps/nexus/prefetch.h index defcdad1..85f5e4c9 100644 --- a/apps/nexus/prefetch.h +++ b/apps/nexus/prefetch.h @@ -24,6 +24,8 @@ class Prefetch: public pt::thread{ std::vector missing; pt::jobqueue draw; pt::jobqueue load; + float prefetching; + float loading; Prefetch(): thread(false), draw(20000), load(64000) {} ~Prefetch() { diff --git a/apps/nexus/pserver.cpp b/apps/nexus/pserver.cpp index 5ea81efb..bdbc67b5 100644 --- a/apps/nexus/pserver.cpp +++ b/apps/nexus/pserver.cpp @@ -31,7 +31,7 @@ bool PServer::Load(const std::string &filename, Signature sig, return MFile::Load(filename, readonly); } -void PServer::Close() { +void PServer::Close() { Flush(); MFile::Close(); } @@ -76,7 +76,7 @@ Patch *PServer::LoadPatch(unsigned int idx, // ramlock.rdlock(); assert(idx < entries.size()); - Entry &entry = entries[idx]; + Entry &entry = entries[idx]; if(entry.patch) return entry.patch; char *ram = new char[entry.ram_size * chunk_size]; @@ -111,10 +111,10 @@ Patch *PServer::LoadPatch(unsigned int idx, } void PServer::FlushPatch(unsigned int id, Patch *patch) { - //TODO move this into an assert!!!! - if(!patch) return; - Entry &entry = entries[id]; - assert(entry.patch == patch); + //TODO move this into an assert!!!! + if(!patch) return; + Entry &entry = entries[id]; +// cerr << "entry: " << (void *)(entry.patch) << " patch: " << (void *)patch << endl; entry.patch = NULL; if(!readonly) { //write back patch @@ -150,6 +150,6 @@ void PServer::FlushPatch(unsigned int id, Patch *patch) { ram_used -= entry.ram_size; } -void PServer::MaxRamBuffer(unsigned int r_buffer) { - ram_max = (unsigned int)(r_buffer/chunk_size) + 1; +void PServer::MaxRamBuffer(unsigned int r_buffer) { + ram_max = (unsigned int)(r_buffer/chunk_size) + 1; } diff --git a/apps/nexus/pserver.h b/apps/nexus/pserver.h index f87f9581..32f2dffc 100644 --- a/apps/nexus/pserver.h +++ b/apps/nexus/pserver.h @@ -49,8 +49,7 @@ class PServer: public MFile { PServer(): chunk_size(1024), ram_max(128000000), ram_used(0) {} - virtual ~PServer() { - std::cerr << "Closing pserver" << std::endl; + virtual ~PServer() { MFile::Close(); } diff --git a/apps/nexus/queuepserver.h b/apps/nexus/queuepserver.h index 1fbef819..f2812be3 100644 --- a/apps/nexus/queuepserver.h +++ b/apps/nexus/queuepserver.h @@ -51,7 +51,7 @@ class QueuePServer: public PServer { Data &data = items.back().second; //TODO i should not flush current extraction! index.erase(items.back().first); - FlushPatch(patch, data.patch); + FlushPatch(items.back().first, data.patch); flush.push_back(data); items.pop_back(); }