Refactor: Store BLF Glyphs in blender::Map #118528
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118528
Loading…
Reference in New Issue
No description provided.
Delete Branch "Harley/blender:GlyphMap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Store the GlyphBLFs in a blender::Map rather than our current hash
table, which is an array of 257 ListBases.
@HooglyBoogly
As mentioned this PR works fine, but the Map is of
<int, GlyphBLF *>
. Is that okay? I tried making the map store< int, std::unique_ptr<GlyphBLF>>
instead and just got errors I couldn't get past.Very nice! If you share the errors with
unique_ptr
I'll take a look, but doing that separately is okay too.There's one more thing that's worth doing in this PR, to avoid the need for repeating
g->c << 6 | subpixel
everywhere: adding a struct containing the character and the subpixel value and giving it the necessary methods to be used as a key, as described here: https://developer.blender.org/docs/features/core/blenlib/containers/#hashingYes, wasn't quite sure how best to show you. But with this PR as a base, since it works, I then try the following changes...
But the compiler then complains about "'std::unique_ptr<GlyphBLF,std::default_delete>::unique_ptr(const std::unique_ptr<GlyphBLF,std::default_delete> &)': attempting to reference a deleted function" and points at
ForwardKey
at about line 190 in BLI_map_slots.hh.Generally looking at the full call stack in an error message is necessary to pinpoint where the problem is. This one means that
unique_ptr
has no copy constructor. So it has to be moved instead. The problem is with this line:Passing
g
here requires a copy constructor. Withstd::move
it will use the move constructor instead.Keep in mind that moving from the original unique_ptr will empty the original, so you'll need to store the raw pointer from before in order to return it from the function.
Yes, not seeing anything in my IDE that helps show where this is. This is at compile time so I don't have a call stack. There are more error messages in my Output , but almost all chatter about what it is doing in BLI_memory_utils.hh.
This one means that
unique_ptr
has no copy constructor. So it has to be moved instead. The problem is with this line:If I change that to
gc->glyphs.add(g->c << 6 | subpixel, std::move(g));
this error message doesn't change for me at all.and
did the trick for me
@HooglyBoogly
Ray's change here, seemingly disconnected from all this since for GlyphCacheBLF, was the biggest change to get rid of the template errors:
Another unexpected thing was that
Map.lookup
returns a reference to the value. But asserts if the item is not found in the cache. ButMap.lookup_default
, although allows a default value if not found, returns a COPY of the value and so needs that copy constructor.But just used
lookup_ptr_as
instead, which allows a check for null and returns a reference.@blender-bot build
@ -119,0 +126,4 @@
}
uint64_t hash() const
{
return (charcode << 6 | subpixel);
get_default_hash(charcode, subpixel)
might be more straightforward, unless there's still a reason to use this hashMy hesitancy is mostly about my own unknowns with
get_default_hash
Unicode codepoints max out at U+10FFFF, so with a byte for subpixel I am well within 32-bit integer. But then I see that
DefaultHash
drops the lower four bits of each before multiplying them?DefaultHash
for all integer types is just the value unchanged. Then the two hashes are combined like this:h1 ^ (h2 * 19349669);
My reasoning was more like "just use the default unless we know some reason to do it differently"
I can see the multiples being combined like that. The only part that gives me pause is that each part first goes through a change that looks like it drops 4 bits.
Seems like you're looking at the
DefaultHash
specialization for pointers. For integers it's this:Yup, I sure was. LOL