Vertex buffer caching.

Doesn't help, though, as buffers are weird. Need to rethink all of this.
This commit is contained in:
Ben Vanik
2014-06-01 09:42:07 -07:00
parent 2d173ea62b
commit 3a8065b7b1
9 changed files with 175 additions and 46 deletions

View File

@@ -47,6 +47,28 @@ IndexBuffer* BufferCache::FetchIndexBuffer(
}
}
VertexBuffer* BufferCache::FetchVertexBuffer(
const VertexBufferInfo& info,
const uint8_t* src_ptr, size_t length) {
size_t key = reinterpret_cast<size_t>(src_ptr);
size_t hash = xe_hash64(src_ptr, length);
auto it = vertex_buffer_map_.find(key);
if (it != vertex_buffer_map_.end()) {
if (hash == it->second->hash()) {
return it->second;
} else {
return it->second->FetchDirty(hash) ? it->second : nullptr;
}
} else {
auto buffer = CreateVertexBuffer(info, src_ptr, length);
vertex_buffer_map_.insert({ key, buffer });
if (!buffer->FetchNew(hash)) {
return nullptr;
}
return buffer;
}
}
void BufferCache::Clear() {
for (auto it = index_buffer_map_.begin();
it != index_buffer_map_.end(); ++it) {