Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HdSt] Enhance the current implementation of batching in HdSt #528

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions pxr/imaging/lib/hdSt/commandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <boost/functional/hash.hpp>

#include <functional>
#include <unordered_map>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -161,7 +162,7 @@ HdStCommandBuffer::_RebuildDrawBatches()
.bindlessTextureEnabled;

// XXX: Temporary sorting by shader.
std::map<size_t, HdSt_DrawBatchSharedPtr> batchMap;
std::unordered_map<size_t, std::vector<HdSt_DrawBatchSharedPtr>> batchMap;

for (size_t i = 0; i < _drawItems.size(); i++) {
HdStDrawItem const * drawItem = _drawItems[i];
Expand Down Expand Up @@ -191,13 +192,32 @@ HdStCommandBuffer::_RebuildDrawBatches()
key,
drawItem->GetBufferArraysHash());
//, drawItem->GetRprimID().GetText());

HdSt_DrawBatchSharedPtr batch;
TfMapLookup(batchMap, key, &batch);
if (!batch || !batch->Append(drawItemInstance)) {
batch = _NewDrawBatch(drawItemInstance);
_drawBatches.push_back(batch);
batchMap[key] = batch;

std::vector<HdSt_DrawBatchSharedPtr> batches;
auto batchIter = batchMap.find(key);
if (batchIter == batchMap.end()) {
HdSt_DrawBatchSharedPtr batch = _NewDrawBatch(drawItemInstance);
_drawBatches.push_back(batch);
batches.push_back(batch);
batchMap[key] = batches;
}
else
{
batches = (batchIter->second);
bool hasAppended = false;
for (auto iter : batches) {
if (iter->Append(drawItemInstance)) {
hasAppended = true;
break;
}
}

if (!hasAppended) {
HdSt_DrawBatchSharedPtr batch = _NewDrawBatch(drawItemInstance);
_drawBatches.push_back(batch);
batches.push_back(batch);
batchIter->second = batches;
}
}
}
}
Expand Down