From 0e81034513da12ecfd74b796cc049e86fd209504 Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Sat, 29 May 2021 14:45:59 +0200 Subject: [PATCH] Error correction buffer optimization --- msdf-atlas-gen/ImmediateAtlasGenerator.h | 1 + msdf-atlas-gen/ImmediateAtlasGenerator.hpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/msdf-atlas-gen/ImmediateAtlasGenerator.h b/msdf-atlas-gen/ImmediateAtlasGenerator.h index 2dc789e..c627ab6 100644 --- a/msdf-atlas-gen/ImmediateAtlasGenerator.h +++ b/msdf-atlas-gen/ImmediateAtlasGenerator.h @@ -34,6 +34,7 @@ class ImmediateAtlasGenerator { AtlasStorage storage; std::vector layout; std::vector glyphBuffer; + std::vector errorCorrectionBuffer; GeneratorAttributes attributes; int threadCount; diff --git a/msdf-atlas-gen/ImmediateAtlasGenerator.hpp b/msdf-atlas-gen/ImmediateAtlasGenerator.hpp index cdfd705..67351de 100644 --- a/msdf-atlas-gen/ImmediateAtlasGenerator.hpp +++ b/msdf-atlas-gen/ImmediateAtlasGenerator.hpp @@ -22,14 +22,21 @@ void ImmediateAtlasGenerator::generate(const GlyphGe int threadBufferSize = N*maxBoxArea; if (threadCount*threadBufferSize > (int) glyphBuffer.size()) glyphBuffer.resize(threadCount*threadBufferSize); + if (threadCount*maxBoxArea > (int) errorCorrectionBuffer.size()) + errorCorrectionBuffer.resize(threadCount*maxBoxArea); + std::vector threadAttributes(threadCount); + for (int i = 0; i < threadCount; ++i) { + threadAttributes[i] = attributes; + threadAttributes[i].config.errorCorrection.buffer = errorCorrectionBuffer.data()+i*maxBoxArea; + } - Workload([this, &glyphs, threadBufferSize](int i, int threadNo) -> bool { + Workload([this, glyphs, &threadAttributes, threadBufferSize](int i, int threadNo) -> bool { const GlyphGeometry &glyph = glyphs[i]; if (!glyph.isWhitespace()) { int l, b, w, h; glyph.getBoxRect(l, b, w, h); msdfgen::BitmapRef glyphBitmap(glyphBuffer.data()+threadNo*threadBufferSize, w, h); - GEN_FN(glyphBitmap, glyph, attributes); + GEN_FN(glyphBitmap, glyph, threadAttributes[threadNo]); storage.put(l, b, msdfgen::BitmapConstRef(glyphBitmap)); } return true;