Refactor bindings to allow for eliminating duplicates... (#1831)

Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Tim Sylvester
2023-11-06 10:12:34 -08:00
committed by GitHub
parent 1670b2c3ee
commit ef69472f56
29 changed files with 441 additions and 244 deletions

View File

@@ -93,5 +93,45 @@ void RenderPass::addDebugSignpost(const char* name) {
}
}
void RenderPass::bindVertex(const BufferResource& buf, std::size_t offset, std::size_t index, std::size_t size) {
assert(0 <= index && index < maxBinds);
if (0 <= index && index < maxBinds) {
if (auto& bind = vertexBinds[index]) {
// Is this the same buffer already bound to this index?
if (bind->buf == &buf && !buf.needReBind(bind->version)) {
// Yes, but is the offset different?
if (bind->offset != offset) {
// Yes, update just the offset
buf.updateVertexBindOffset(encoder, offset, index, size);
bind->offset = offset;
}
return;
}
}
vertexBinds[index] = BindInfo{&buf, offset};
}
buf.bindVertex(encoder, offset, index, size);
}
void RenderPass::bindFragment(const BufferResource& buf, std::size_t offset, std::size_t index, std::size_t size) {
assert(0 <= index && index < maxBinds);
if (0 <= index && index < maxBinds) {
if (auto& bind = fragmentBinds[index]) {
// Is this the same buffer already bound to this index?
if (bind->buf == &buf && !buf.needReBind(bind->version)) {
// Yes, but is the offset different?
if (bind->offset != offset) {
// Yes, update just the offset
buf.updateFragmentBindOffset(encoder, offset, index, size);
bind->offset = offset;
}
return;
}
}
fragmentBinds[index] = BindInfo{&buf, offset};
}
buf.bindFragment(encoder, offset, index, size);
}
} // namespace mtl
} // namespace mbgl