godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.55k stars 20.27k forks source link

iOS uses more RAM than other platforms when using large AtlasTextures #36105

Open Valeryn4 opened 4 years ago

Valeryn4 commented 4 years ago

Godot version: 3.2

OS/device including version: IOS (iphone 6, iphone x)

Issue description: Im use big atlas 2048x2048, LOSSY 0.7 IOS uses too much memory. More than android and windows I do not like the fact that applications on iOS (arm, arm64, x86, x86_64) weigh minimum ~40 mb (*.a file weight 193mb, all arch) p.s. andoid apk size min ~15-20mb

android ~200mb peak (Im used cat /adb shell "cat /proc/meminfo")

windows ~190mb image

apple in xcode ~300mb (Memory warnings appear)

Calinou commented 4 years ago

Im use big atlas 2048x2048, LOSSY 0.7

Lossy (= WebP) image compression will still upload the image uncompressed to the GPU, so high memory is usage is expected. In other words, lossy compression only helps decrease the amount of storage space required for the texture.

You need to use VRAM compression to decrease memory usage. It seems that on iOS, only PVRTC is available; you need to encode it manually using the reference PVRTC encoding tool.

volzhs commented 4 years ago

are you using one big atlas? I'm using many big images for my project with lossy but I didn't have a problem even with 5s. the project is running on 3.1 though.

Valeryn4 commented 4 years ago

are you using one big atlas?

nope... Several large(5-6 2048x2048) and many small (10-15 512x512-1024x1024)

IOS uses memory more than other platforms

volzhs commented 4 years ago

it would be better not to use atlas if you can then. but, yeah, still need to know why iOS requires more than others.

HEAVYPOLY commented 3 years ago

Same behavior here, except more extreme.

iOS - 1.18GB Windows, Android ~ 550mb

Getting memory crash on Xcode.

Calinou commented 3 years ago

@Valeryn4 @HEAVYPOLY Please upload a minimal reproduction project to make this easier to troubleshoot.

HEAVYPOLY commented 3 years ago

@Calinou https://www.dropbox.com/sh/tb5zoez4mih6h45/AABrDG5lPFTu15L8mz33Fr5Ca?dl=0 here's the project, open the autosave.hp from top left hamburger file menu (or draw a bit and compare memory consumption). You can press N to create new layers which will accentuate the difference.

On an empty canvas with 1 screenshot of the viewport (1920X1920 viewport size):

iOS - 400mb Android - 54MB

Same setup without the screenshot: iOS 382mb Android - 26MB

screenshot method: var img: Image = VP.get_texture().get_data() img.lock() var tex = ImageTexture.new() tex.create_from_image(img, 0) return tex

I've tried turning on PRTVC compression in project settings, importing all textures with VRAM compression, and built Godot and export templates from commit e9a8e1a1 from today

Calinou commented 3 years ago

I've tried turning on PRTVC compression in project settings

If you enable PVRTC in the project settings, you also have to specify the path to the command line Imagination Technologies PVRTC encoder in the Editor Settings. This is because Godot doesn't include a PVRTC encoder. Otherwise, textures will still be uncompressed in the final project.

That said, PVRTC support was broken before 3.2.4beta3.

HEAVYPOLY commented 3 years ago

Thanks, just tried with the Imagination Technologies encoder added and doesn't seem to change memory usage. Another weird note:

This is a drawing app, I have sub viewports that represent each layer in a canvas. I take screenshots after every stroke to save the stroke to the layer. If I disable the screenshot, on OSX the memory doesn't change if I add empty layers/viewports. on IOS, ram jumps up 200mb for each empty layer/viewport (1920X1920) What could be happening here?

HEAVYPOLY commented 3 years ago

Ok, here is a much more stripped down reproduction project: https://www.dropbox.com/sh/l0qpxwzyats3o0f/AAAcyNeZXSB7Oo6mep7GxwnAa?dl=0

it's just a color rect and the required iOS icons/textures. iOS - 187mb OSX - ~30mb

Also not sure if this is related, failed to create frame buffer: 2020-12-15 13:53:01.874356-0800 HEAVYPAINT[4102:151003] Metal GPU Frame Capture Enabled 2020-12-15 13:53:01.875431-0800 HEAVYPAINT[4102:151003] Metal API Validation Enabled 2020-12-15 13:53:02.177638-0800 HEAVYPAINT[4102:151003] Setting up an OpenGL ES 3.0 context. Based on Project Settings "rendering/quality/driver/driver_name" 2020-12-15 13:53:02.178189-0800 HEAVYPAINT[4102:151003] failed to make complete framebuffer object 8cd6 2020-12-15 13:53:02.178303-0800 HEAVYPAINT[4102:151003] Failed to create frame buffer!

avnerh1 commented 3 years ago

Also not sure if this is related, failed to create frame buffer: 2020-12-15 13:53:01.874356-0800 HEAVYPAINT[4102:151003] Metal GPU Frame Capture Enabled 2020-12-15 13:53:01.875431-0800 HEAVYPAINT[4102:151003] Metal API Validation Enabled 2020-12-15 13:53:02.177638-0800 HEAVYPAINT[4102:151003] Setting up an OpenGL ES 3.0 context. Based on Project Settings "rendering/quality/driver/driver_name" 2020-12-15 13:53:02.178189-0800 HEAVYPAINT[4102:151003] failed to make complete framebuffer object 8cd6 2020-12-15 13:53:02.178303-0800 HEAVYPAINT[4102:151003] Failed to create frame buffer!

I'm also facing this error message. Did you learn anything useful about it?

Valeryn4 commented 3 years ago

Good day! The problem is still present in 3.3.

2D projects in IOS consume more memory in x2 / x3. On Android and Windows, I just cache scenes and textures. On an iPhone, you have to load scenes at runtime. From what there are sagging between scenes in 1-2 seconds.

For iPhones, you have to hide the load under intermediate scenes =(

Valeryn4 commented 2 years ago

3.4.4-stable 3D project has the same problem Render settings between platforms are equivalent

Windows Mem used: image Sum mem equal ~220mb

IOS 15.5: image sum mem > 600mb max

iphone 6 has defects on GLES3. Most likely due to lack of memory.

Skinning defect Iphone 6 (OpenGL ES 3.0 Renderer: Apple A8 GPU): image Log warrning *********** did receive memory warning!

ipad pro 4 (OpenGL ES 3.0 Renderer: Apple A12Z GPU): image no warrning

Calinou commented 2 years ago

Note that seeing the "did receive memory warning" message won't let you know the exact cause of the high memory usage, as the error message is printed regardless of the cause of the memory warning:

https://github.com/godotengine/godot/blob/f0cfe3a83b60543dafb520eceb01fc4497822766/platform/iphone/view_controller.mm#L93-L96

Valeryn4 commented 2 years ago

Note that seeing the "did receive memory warning" message won't let you know the exact cause of the high memory usage, as the error message is printed regardless of the cause of the memory warning:

There is no such warning on iphone X and ipad pro 4.. But the game still uses a lot of memory. This not normal.

Valeryn4 commented 2 years ago

Screenshot_240 Screenshot_241 Can alloc/malloc allocate large chunks of memory?

Valeryn4 commented 2 years ago

found out experimentally in IOS. GLES3 uses a LOT of memory. ~600mb GLES2 - uses ~200mb

also found out: on iphone6 FPS drops to 20 if "DOF FAR BLUR" is enabled on iphone X and ipad gen 4 there is no such problem. res 1080p

Calinou commented 2 years ago

res 1080p

On old iOS devices, you should render at a lower resolution (such as 540p). See https://github.com/godotengine/godot-demo-projects/tree/master/viewport/3d_scaling for an example of this.

Asking a 2014 phone to render a modern game in 1920×1080 is asking a lot from it – no matter how high-end it is :slightly_smiling_face:

Valeryn4 commented 2 years ago

DOF Disable, Far 20-30 meters, disable all shadow, disable water shader. I managed to get 60+ FPS at a resolution of 1600x900 on an iPhone 6. But the output came with a huge number of compromises, and the game was similar to the game of the 90s. I'm going to lower fps to 30 on this device and make false shadows. =)

Zireael07 commented 2 years ago

Unfortunately real shadows are a performance killer on mobiles and even some older desktops :I

Calinou commented 2 years ago

Unfortunately real shadows are a performance killer on mobiles and even some older desktops :I

Games that aim to run on all kinds of devices shouldn't shy away from adding "potato settings", such as disabling shadows for all lights entirely. (You can set Specular to 0 to make the light leaking a bit less noticeable.)

See Fortnite for an example of this – it does this even on desktop when Performance mode is enabled :slightly_smiling_face:

Valeryn4 commented 2 years ago

anyway. iOS GLES3 uses a lot of memory. This is the main problem.

Valeryn4 commented 2 years ago

Unfortunately real shadows are a performance killer on mobiles and even some older desktops :I

In practice, as I found out, blur reduces performance several times more than shadows. on the iphone 6 the shadows lower me by ~10fps and the blur is almost ~40fps.

That's if Force Vertex Shadow is worth it.

Zireael07 commented 2 years ago

Yep, blur is also a performance killer :(

Valeryn4 commented 1 year ago

18.11.2022 godot 3.5.1

mem use

Windows (Editor) mem used: 559 mb sum image

iphone X - iOS Xcode (Release build): 759 mb image

Valeryn4 commented 7 months ago

20.02.2024 The project was transferred from GLES3 to GLES2 godot 3.5.3

MEM use on Android: image

MEM use on IOS 1.4 Gb Crash MSG

The app “KnowledgePark3D” has been killed by the operating system because it is using too much memory.
Domain: IDEDebugSessionErrorDomain
Code: 11
Recovery Suggestion: Use a memory profiling tool to track the process memory usage.
User Info: {
    DVTErrorCreationDateKey = "2024-02-20 01:29:38 +0000";
    IDERunOperationFailingWorker = DBGLLDBLauncher;
}
--

Event Metadata: com.apple.dt.IDERunOperationWorkerFinished : {
    "device_model" = "iPhone9,3";
    "device_osBuild" = "15.8 (19H370)";
    "device_platform" = "com.apple.platform.iphoneos";
    "dvt_coredevice_version" = "355.7.7";
    "dvt_mobiledevice_version" = "1643.60.2";
    "launchSession_schemeCommand" = Run;
    "launchSession_state" = 2;
    "launchSession_targetArch" = arm64;
    "operation_duration_ms" = 44976;
    "operation_errorCode" = 11;
    "operation_errorDomain" = IDEDebugSessionErrorDomain;
    "operation_errorWorker" = DBGLLDBLauncher;
    "operation_name" = IDEiPhoneRunOperationWorkerGroup;
    "param_debugger_attachToExtensions" = 0;
    "param_debugger_attachToXPC" = 1;
    "param_debugger_type" = 5;
    "param_destination_isProxy" = 0;
    "param_destination_platform" = "com.apple.platform.iphoneos";
    "param_diag_MainThreadChecker_stopOnIssue" = 0;
    "param_diag_MallocStackLogging_enableDuringAttach" = 0;
    "param_diag_MallocStackLogging_enableForXPC" = 1;
    "param_diag_allowLocationSimulation" = 1;
    "param_diag_checker_tpc_enable" = 1;
    "param_diag_gpu_frameCapture_enable" = 2;
    "param_diag_gpu_shaderValidation_enable" = 0;
    "param_diag_gpu_validation_enable" = 0;
    "param_diag_memoryGraphOnResourceException" = 0;
    "param_diag_queueDebugging_enable" = 1;
    "param_diag_runtimeProfile_generate" = 0;
    "param_diag_sanitizer_asan_enable" = 0;
    "param_diag_sanitizer_tsan_enable" = 0;
    "param_diag_sanitizer_tsan_stopOnIssue" = 0;
    "param_diag_sanitizer_ubsan_stopOnIssue" = 0;
    "param_diag_showNonLocalizedStrings" = 0;
    "param_diag_viewDebugging_enabled" = 1;
    "param_diag_viewDebugging_insertDylibOnLaunch" = 1;
    "param_install_style" = 0;
    "param_launcher_UID" = 2;
    "param_launcher_allowDeviceSensorReplayData" = 0;
    "param_launcher_kind" = 0;
    "param_launcher_style" = 0;
    "param_launcher_substyle" = 0;
    "param_runnable_appExtensionHostRunMode" = 0;
    "param_runnable_productType" = "com.apple.product-type.application";
    "param_structuredConsoleMode" = 1;
    "param_testing_launchedForTesting" = 0;
    "param_testing_suppressSimulatorApp" = 0;
    "param_testing_usingCLI" = 0;
    "sdk_canonicalName" = "iphoneos17.2";
    "sdk_osVersion" = "17.2";
    "sdk_variant" = iphoneos;
}
--

System Information

macOS Version 14.3 (Build 23D56)
Xcode 15.2 (22503) (Build 15C500b)
Timestamp: 2024-02-19T20:29:38-05:00
Valeryn4 commented 7 months ago

Godot allocates memory for Shadow Atlas. Even if there are no shadows in the game.

image image

In my project, something creates large LumAlpha8 textures, 4k. In the game, the largest texture has a size of 2k What can create these textures? I have to fight for every byte.

image image