UBO consolidation (#3089)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/mtl/uniform_buffer.hpp>
|
||||
|
||||
#include <mbgl/mtl/render_pass.hpp>
|
||||
#include <mbgl/mtl/context.hpp>
|
||||
#include <mbgl/shaders/layer_ubo.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <cassert>
|
||||
@@ -24,18 +25,33 @@ UniformBuffer::~UniformBuffer() {
|
||||
buffer.getContext().renderingStats().memUniformBuffers -= size;
|
||||
}
|
||||
|
||||
void UniformBuffer::update(const void* data, std::size_t size_) {
|
||||
assert(size == size_);
|
||||
if (size != size_ || size != buffer.getSizeInBytes()) {
|
||||
Log::Error(
|
||||
Event::General,
|
||||
"Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_));
|
||||
void UniformBuffer::update(const void* data, std::size_t dataSize) {
|
||||
assert(dataSize <= size);
|
||||
if (dataSize > size || dataSize > buffer.getSizeInBytes()) {
|
||||
Log::Error(Event::General,
|
||||
"Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " +
|
||||
std::to_string(dataSize));
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.getContext().renderingStats().numUniformUpdates++;
|
||||
buffer.getContext().renderingStats().uniformUpdateBytes += size_;
|
||||
buffer.update(data, size, /*offset=*/0);
|
||||
buffer.getContext().renderingStats().uniformUpdateBytes += dataSize;
|
||||
buffer.update(data, dataSize, /*offset=*/0);
|
||||
}
|
||||
|
||||
void UniformBufferArray::bind(RenderPass& renderPass) const noexcept {
|
||||
for (size_t id = 0; id < allocatedSize(); id++) {
|
||||
const auto& uniformBuffer = get(id);
|
||||
if (!uniformBuffer) continue;
|
||||
const auto& buffer = static_cast<UniformBuffer&>(*uniformBuffer.get());
|
||||
const auto& resource = buffer.getBufferResource();
|
||||
if (id != shaders::idDrawableReservedFragmentOnlyUBO) {
|
||||
renderPass.bindVertex(resource, 0, id);
|
||||
}
|
||||
if (id != shaders::idDrawableReservedVertexOnlyUBO) {
|
||||
renderPass.bindFragment(resource, 0, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mtl
|
||||
|
||||
Reference in New Issue
Block a user