Repository: godot
Issue: Vulkan graphics pipelines use excessive amount of memory on Galaxy S23
Labels: bug,platform:android,topic:rendering,topic:porting,crash,regression

### Tested versions

- Reproducible in: 4.4.dev7, master starting from 98deb2a0005cf654e667679cd72904d9b5d4c734
- Not reproducible in: 4.3.stable

### System information

Samsung Galaxy S23 Ultra, Android 14, Vulkan (Mobile), Adreno 740

### Issue description

After trying to update our project to Godot 4.4 we found that it crashes while loading on my Android phone.
The profiler showed that graphics memory was exceeding 4GB before the app closes while the game running on Godot 4.3 only uses around 800mb of graphics memory.

I have bisected everything between 4.3 and 4.4 and traced the problem to https://github.com/godotengine/godot/pull/90400 getting merged.

Here is a memory report generated by RenderingDevice.get_driver_and_device_memory_report from a version of our game with lots of content removed so it starts at all:

```
Total Driver Memory:76.373 MB
Total Driver Num Allocations: 51018
Total Device Memory:3755.699 MB
Total Device Num Allocations: 854

Memory use by object type (CSV format):

Category; Driver memory in MB; Driver Allocation Count; Device memory in MB; 
UNKNOWN;0.0;0;0.0;0
INSTANCE;19.86637;1520;0.0;0
PHYSICAL_DEVICE;0.0;0;0.0;0
DEVICE;0.136612;580;0.247704;42
QUEUE;0.0;0;27.88282;11
SEMAPHORE;0.00267;10;0.0;0
COMMAND_BUFFER;0.0;0;1.484375;101
FENCE;0.001068;4;0.0;0
DEVICE_MEMORY;0.0;0;1056.0;8
BUFFER;10.4068;25260;0.0;0
IMAGE;1.001448;1756;0.181641;1
EVENT;0.0;0;0.0;0
QUERY_POOL;0.001633;6;0.007828;2
BUFFER_VIEW;0.000992;1;0.0;0
IMAGE_VIEW;0.836527;857;0.0;0
SHADER_MODULE;29.46983;1736;0.0;0
PIPELINE_CACHE;4.005884;286;0.0;0
PIPELINE_LAYOUT;1.361336;936;0.0;0
RENDER_PASS;0.018356;189;0.0;0
PIPELINE;2.593163;3315;2668.945;607
DESCRIPTOR_SET_LAYOUT;3.279724;8207;0.0;0
SAMPLER;0.01339;39;0.0;0
DESCRIPTOR_POOL;1.765778;1800;0.800781;46
DESCRIPTOR_SET;0.0;0;0.0;0
FRAMEBUFFER;1.206264;538;0.1492;36
COMMAND_POOL;0.403104;3976;0.0;0
DESCRIPTOR_UPDATE_TEMPLATE_KHR;0.0;0;0.0;0
SURFACE_KHR;0.000031;1;0.0;0
SWAPCHAIN_KHR;0.002022;1;0.0;0
DEBUG_UTILS_MESSENGER_EXT;0.0;0;0.0;0
DEBUG_REPORT_CALLBACK_EXT;0.0;0;0.0;0
ACCELERATION_STRUCTURE;0.0;0;0.0;0
VMA_BUFFER_OR_IMAGE;0.0;0;0.0;0
```

You can see that device memory for pipelines is 2668.945mb. The same line in Godot 4.3 (and 4.4 before https://github.com/godotengine/godot/pull/90400 got merged) shows a little over 1mb.

I modified my engine build to log every allocation related to pipeline objects and found that it allocates a block of 24mb for some of the pipelines. Adding up those 24mb allocations gives me pretty much exactly the excess amount of memory use compared to without that PR

I suspect that it is related to the Ubershader that is used while the optimized pipeline is compiled. 
A hacky attempt to disable the feature by preventing the "define UBERSHADER" in the shader from being set resulted in the weird allocations disappearing. 
But I am not that familiar with the code yet and I am also running out of time that I can invest in this problem so hopefully someone here can find a proper workaround.

The attached MRP contains just a camera looking at a single cube and a script to print the memory report.
On my device this already uses 72mb for pipelines. Strangely on a Oneplus 6 it was only 6.6mb and on a Oneplus 8 it uses 12.6mb for pipelines which still seems excessive compared to 1mb but apparently this depends heavily on hardware or driver version. 
I could not test yet how this scales with the real project on those other devices.

I understand that this is likely related to a driver issue that we can't fix but maybe it can be mitigated somehow? If not maybe ubershaders can be deactivated depending on hardware or a project setting?

### Steps to reproduce

1. Open the attached project
2. Enable Deploy with Remote Debug
3. Deploy to Android device
4. Observe the logged memory report

### Minimal reproduction project (MRP)

[pipeline_memory_mrp.zip](https://github.com/user-attachments/files/18437403/pipeline_memory_mrp.zip)