Avoid redundant pool destroy/allocs

This commit is contained in:
Jack Andersen 2019-03-04 22:34:03 -10:00
parent f262e59e68
commit 3759bf1b3d
3 changed files with 31 additions and 21 deletions

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 8b0927ead0a13f0fcb1305688997191b026a9190
Subproject commit 21f9fcf914488a25926e781a99df4d4f19f4ee8a

View File

@ -65,7 +65,11 @@ private:
Bucket& operator=(Bucket&& other) = default;
void updateBuffer() {
if (cpuBuffer) {
if (useCount == 0) {
destroy();
return;
}
if (dirty && cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
@ -73,18 +77,20 @@ private:
}
void increment(UniformBufferPool& pool) {
if (useCount.fetch_add(1) == 0)
if (useCount.fetch_add(1) == 0 && !buffer)
buffer = pool.m_factory->newPoolBuffer(boo::BufferUse::Uniform, pool.m_stride, pool.m_countPerBucket BooTrace);
}
void decrement(UniformBufferPool& pool) {
if (useCount.fetch_sub(1) == 1) {
if (cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
buffer.reset();
--useCount;
}
void destroy() {
if (cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
buffer.reset();
}
};
std::vector<std::unique_ptr<Bucket>> m_buckets;
@ -157,8 +163,7 @@ public:
/** Load dirty buffer data into GPU */
void updateBuffers() {
for (auto& bucket : m_buckets)
if (bucket->dirty)
bucket->updateBuffer();
bucket->updateBuffer();
}
/** Allocate free block into client-owned Token */

View File

@ -65,7 +65,11 @@ private:
Bucket& operator=(Bucket&& other) = delete;
void updateBuffer() {
if (cpuBuffer) {
if (useCount == 0) {
destroy();
return;
}
if (dirty && cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
@ -73,18 +77,20 @@ private:
}
void increment(VertexBufferPool& pool) {
if (useCount.fetch_add(1) == 0)
if (useCount.fetch_add(1) == 0 && !buffer)
buffer = pool.m_factory->newPoolBuffer(boo::BufferUse::Vertex, pool.m_stride, pool.m_countPerBucket BooTrace);
}
void decrement(VertexBufferPool& pool) {
if (useCount.fetch_sub(1) == 1) {
if (cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
buffer.reset();
--useCount;
}
void destroy() {
if (cpuBuffer) {
buffer->unmap();
cpuBuffer = nullptr;
}
buffer.reset();
}
};
std::vector<std::unique_ptr<Bucket>> m_buckets;
@ -162,8 +168,7 @@ public:
/** Load dirty buffer data into GPU */
void updateBuffers() {
for (auto& bucket : m_buckets)
if (bucket->dirty)
bucket->updateBuffer();
bucket->updateBuffer();
}
/** Allocate free block into client-owned Token */