Skip to content

Commit

Permalink
#5943: Reduce code duplication when recording the transactions. Take …
Browse files Browse the repository at this point in the history
…shortcuts when only one buffer is involved.
  • Loading branch information
codereader committed Apr 19, 2022
1 parent 538ef67 commit f892bcd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 2 additions & 0 deletions include/igeometrystore.h
Expand Up @@ -87,6 +87,8 @@ class IBufferObjectProvider
class IGeometryStore
{
public:
virtual ~IGeometryStore() {}

// Slot ID handed out to client code
using Slot = std::uint64_t;

Expand Down
16 changes: 16 additions & 0 deletions libs/render/ContinuousBuffer.h
Expand Up @@ -239,6 +239,22 @@ class ContinuousBuffer
void applyTransactions(const std::vector<detail::BufferTransaction>& transactions, const ContinuousBuffer<ElementType>& other,
const std::function<std::uint32_t(IGeometryStore::Slot)>& getHandle)
{
// We might reach this point in single-buffer mode, trying to sync with ourselves
// in which case we can take the shortcut to just mark the transactions that need to be GPU-synced
if (&other == this)
{
for (const auto& transaction : transactions)
{
// Only the updated slots will actually have altered any data
if (transaction.type == detail::BufferTransaction::Type::Update)
{
_unsyncedSlots.push_back(getHandle(transaction.slot));
}
}

return;
}

// Ensure the buffer is at least the same size
auto otherSize = other._buffer.size();

Expand Down
31 changes: 12 additions & 19 deletions libs/render/GeometryStore.h
Expand Up @@ -8,7 +8,7 @@
namespace render
{

class GeometryStore :
class GeometryStore final :
public IGeometryStore
{
public:
Expand Down Expand Up @@ -49,6 +49,11 @@ class GeometryStore :
vertices.syncModificationsToBufferObject(vertexBufferObject);
indices.syncModificationsToBufferObject(indexBufferObject);
}

void recordTransaction(Slot slot, detail::BufferTransaction::Type type)
{
transactionLog.emplace_back(detail::BufferTransaction{ slot, type });
}
};

// We keep a fixed number of frame buffers
Expand Down Expand Up @@ -129,9 +134,7 @@ class GeometryStore :

auto slot = GetSlot(SlotType::Regular, vertexSlot, indexSlot);

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Allocate
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Allocate);

return slot;
}
Expand All @@ -153,9 +156,7 @@ class GeometryStore :
// In an IndexRemap slot, the vertex slot ID refers to the one containing the vertices
auto slot = GetSlot(SlotType::IndexRemap, GetVertexSlot(slotContainingVertexData), indexSlot);

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Allocate
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Allocate);

return slot;
}
Expand All @@ -178,9 +179,7 @@ class GeometryStore :
assert(!indices.empty());
current.indices.setData(GetIndexSlot(slot), indices);

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Update
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Update);
}

void updateSubData(Slot slot, std::size_t vertexOffset, const std::vector<RenderVertex>& vertices,
Expand All @@ -201,9 +200,7 @@ class GeometryStore :
assert(!indices.empty());
current.indices.setSubData(GetIndexSlot(slot), indexOffset, indices);

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Update
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Update);
}

void resizeData(Slot slot, std::size_t vertexSize, std::size_t indexSize) override
Expand All @@ -221,9 +218,7 @@ class GeometryStore :

current.indices.resizeData(GetIndexSlot(slot), indexSize);

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Update
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Update);
}

void deallocateSlot(Slot slot) override
Expand All @@ -239,9 +234,7 @@ class GeometryStore :

current.indices.deallocate(GetIndexSlot(slot));

current.transactionLog.emplace_back(detail::BufferTransaction{
slot, detail::BufferTransaction::Type::Deallocate
});
current.recordTransaction(slot, detail::BufferTransaction::Type::Deallocate);
}

RenderParameters getRenderParameters(Slot slot) override
Expand Down

0 comments on commit f892bcd

Please sign in to comment.