grovesNL / glyphon

🦅🦁 Fast, simple 2D text renderer for wgpu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Out of memory error when max_texture_dimension_2d isn't limited

ecton opened this issue · comments

The hello-world example uses wgpu::Limits::downlevel_defaults(), which creates a set of limits with max_texture_dimension_2d set to 2048. In my wgpu application, I'm using wgpu::Limits::downlevel_webgl2_defaults().using_resolution(adapter.limits()) which is what many of the wgpu examples use. This results in a max_texture_dimension_2d of 32,768.

When the texture atlas is initialized against this device, it attempts to allocate a 32kx32k texture which is 4 gigs with the SrgbUnorm texture format. This causes an out of memory error on my machine.

I can of course restrict my limits further, but it seems like TextAtlas shouldn't be attempting to create the largest possible texture. Ideally it would start small and dynamically grow as needed. However, I know that's really complicated, so as an alternative, perhaps allow the developer a way to specify the atlas size explicitly?

Hi @ecton! Yeah absolutely - this was planned from the start to be configurable and optionally grow (#7).

If you'd like to try it out, #34 implements the first version of an initially smaller atlas that grows as needed.

That's always great news when the issue you report turns out to already be in process of being resolved! Sorry I didn't notice the existing issue for resizing the atlas before submitting this report.

I can confirm that the branch in #34 at least causes the out of memory error to go away. I'm going to go ahead and close this since it's mostly a duplicate of #7.

Thank you for the quick response!