Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcristici committed Dec 16, 2024
1 parent edcabc7 commit 20bd898
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 52 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/gfx/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UniformBuffer {

public:
virtual ~UniformBuffer() = default;
virtual void update(const void* data, std::size_t size_) = 0;
virtual void update(const void* data, std::size_t dataSize) = 0;

std::size_t getSize() const { return size; }

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/gl/uniform_buffer_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UniformBufferGL final : public gfx::UniformBuffer {
UniformBufferGL clone() const { return {*this}; }

// gfx::UniformBuffer
void update(const void* data, std::size_t size_) override;
void update(const void* data, std::size_t dataSize) override;

private:
// unique id used for debugging and profiling purposes
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/mtl/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UniformBuffer final : public gfx::UniformBuffer {

UniformBuffer clone() const { return {buffer.clone()}; }

void update(const void* data, std::size_t size_) override;
void update(const void* data, std::size_t dataSize) override;

protected:
BufferResource buffer;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/vulkan/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UniformBuffer final : public gfx::UniformBuffer {

UniformBuffer clone() const { return {buffer.clone()}; }

void update(const void* data, std::size_t size_) override;
void update(const void* data, std::size_t dataSize) override;

protected:
BufferResource buffer;
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/gl/uniform_buffer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ BufferID UniformBufferGL::getID() const {
}
}

void UniformBufferGL::update(const void* data_, std::size_t size_) {
assert(isManagedAllocation ? managedBuffer.getContents().size() == size_ : size == size_);
void UniformBufferGL::update(const void* data, std::size_t dataSize) {
assert(isManagedAllocation ? dataSize <= managedBuffer.getContents().size() : dataSize <= size);

if (size != size_ || (isManagedAllocation && managedBuffer.getContents().size() != size_)) {
if (dataSize > size || (isManagedAllocation && dataSize > managedBuffer.getContents().size())) {
Log::Error(
Event::General,
"Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_));
"Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize));
return;
}

if (std::memcmp(data_, managedBuffer.getContents().data(), managedBuffer.getContents().size()) == 0) {
if (std::memcmp(data, managedBuffer.getContents().data(), dataSize) == 0) {
return;
}

if (isManagedAllocation) {
managedBuffer.allocate(data_, size);
managedBuffer.allocate(data, dataSize);
} else {
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, localID));
MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, size_, data_));
MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, dataSize, data));
MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, 0));
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/mtl/uniform_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ 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()) {
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 " + std::to_string(size) + ", got " + std::to_string(size_));
"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 {
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/layers/background_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ constexpr auto BackgroundPatternShaderName = "BackgroundPatternShader";
#endif

void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
const auto& state = parameters.state;
auto& context = parameters.context;

if (layerGroup.empty()) {
return;
}

const auto& state = parameters.state;
auto& context = parameters.context;

#if defined(DEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/layers/circle_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ using namespace style;
using namespace shaders;

void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context;
const auto& evaluated = static_cast<const CircleLayerProperties&>(*evaluatedProperties).evaluated;

if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto& evaluated = static_cast<const CircleLayerProperties&>(*evaluatedProperties).evaluated;

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ using namespace shaders;
using namespace style;

void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto& props = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties);
const auto& evaluated = props.evaluated;
const auto& crossfade = props.crossfade;
const auto& state = parameters.state;

if (layerGroup.empty()) {
return;
}

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/fill_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ using namespace style;
using namespace shaders;

void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto& props = static_cast<const FillLayerProperties&>(*evaluatedProperties);
const auto& evaluated = props.evaluated;
const auto& crossfade = props.crossfade;

if (layerGroup.empty()) {
return;
}

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ using namespace style;
using namespace shaders;

void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context;
const auto zoom = static_cast<float>(parameters.state.getZoom());
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;

if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto zoom = static_cast<float>(parameters.state.getZoom());
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ using namespace style;
using namespace shaders;

void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;

if (layerGroup.empty()) {
return;
}

const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ std::array<float, 2> getLight(const PaintParameters& parameters,
} // namespace

void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
const auto& evaluated = static_cast<const HillshadeLayerProperties&>(*evaluatedProperties).evaluated;

if (layerGroup.empty()) {
return;
}

const auto& evaluated = static_cast<const HillshadeLayerProperties&>(*evaluatedProperties).evaluated;

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/layers/line_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ auto LineLayerTweaker::evaluate([[maybe_unused]] const PaintParameters& paramete
}

void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto& evaluated = static_cast<const LineLayerProperties&>(*evaluatedProperties).evaluated;
const auto& crossfade = static_cast<const LineLayerProperties&>(*evaluatedProperties).crossfade;
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/layers/raster_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ using namespace shaders;

void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup,
[[maybe_unused]] const PaintParameters& parameters) {
if (layerGroup.empty()) {
return;
}

const auto& evaluated = static_cast<const RasterLayerProperties&>(*evaluatedProperties).evaluated;

const auto spinWeights = [](float spin) -> std::array<float, 4> {
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/symbol_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ auto getInterpFactor(const SymbolBucket::PaintProperties& paintProps, bool isTex
} // namespace

void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context;
const auto& state = parameters.state;
const auto& evaluated = static_cast<const SymbolLayerProperties&>(*evaluatedProperties).evaluated;

if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
const auto& state = parameters.state;
const auto& evaluated = static_cast<const SymbolLayerProperties&>(*evaluatedProperties).evaluated;

#if !defined(NDEBUG)
const auto label = layerGroup.getName() + "-update-uniforms";
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/sources/render_tile_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class PolylineLayerTweaker : public LayerTweaker {
propsUBO(properties) {}

void execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) override {
if (layerGroup.empty()) {
return;
}

auto& context = parameters.context;
auto& layerUniforms = layerGroup.mutableUniformBuffers();
layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, context);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/vulkan/buffer_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ BufferResource::BufferResource(
const auto& align = deviceProps.limits.minUniformBufferOffsetAlignment;
bufferWindowSize = (size + align - 1) & ~(align - 1);

// assert(bufferWindowSize != 0);
assert(bufferWindowSize != 0);

totalSize = bufferWindowSize * backend.getMaxFrames();
}
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/vulkan/uniform_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ 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()) {
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 " + std::to_string(size) + ", got " + std::to_string(size_));
"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);
}

const std::shared_ptr<gfx::UniformBuffer>& UniformBufferArray::set(const size_t id,
Expand Down

0 comments on commit 20bd898

Please sign in to comment.