Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: ReflectionProbe consumes far too much VRAM #64683

Open
Tracked by #66628
lyuma opened this issue Aug 21, 2022 · 9 comments
Open
Tracked by #66628

Vulkan: ReflectionProbe consumes far too much VRAM #64683

lyuma opened this issue Aug 21, 2022 · 9 comments

Comments

@lyuma
Copy link
Contributor

lyuma commented Aug 21, 2022

Godot version

4.0.dev 11abffb + patches

System information

Windows 10, Vulkan Nvidia Rtx 2080 Ti

Issue description

I've been noticing extraordinarily huge VRAM usage when playing a test scene in my game, upwards of 5GB.

This issue is about Reflection Probes having an effect on memory usage. There's a sister issue #64677 about WorldEnvironment radiance size.

The test project I use has reflection size set to 1024. This causes half my VRAM to be consumed. Normally a 1024x1024x6 reflection probe should only take about 25MB or so.

Godot's default reflection size is 256, which is 16 times less VRAM, but even at 256, it is taking way more than it should be (you can still see a spike when toggling on the reflection probe).

Here is a screenshot of task manager
task manager showing VRAM usage

Steps to reproduce

  1. Open the attached project.
  2. Open task manager's GPU Performance tab or a VRAM monitor.
  3. Play the scene. Note the VRAM usage.
  4. toggle on the ReflectionProbe object.
  5. Check the VRAM usage again.

Minimal reproduction project

reflectionprobe_vram.zip

@arkology
Copy link
Contributor

@lyuma looks like MRP link is broken

@Griefchief
Copy link
Contributor

A number like 2048 or 1024 feels like it should take 16 to 64 megabytes of whatever kind of RAM, not gigabytes. We need to measure this differently, or with an additional number in the setting mentioning VRAM size, i feel.

@Calinou Calinou changed the title Reflection Probe consumes far too much VRAM Vulkan: ReflectionProbe consumes far too much VRAM Aug 21, 2022
@clayjohn
Copy link
Member

So it looks like it is using about 1.2 GB's. The expected size of a 1024 reflection probe is:
1024px x 1024px x 6 sides x 8 array layers x 64 bits x ~1.33 for mipmaps = ~536 mbs. So it looks like we are allocating about twice as much memory as needed.

@lyuma
Copy link
Contributor Author

lyuma commented Aug 28, 2022

@arkology Uploaded the MRP again.

Can I ask why there are 8 array layers allocated at a time?

If this is really the case, I think it shows why compressed reflection probes are necessary. 512x512 reflection probes just don't cut it for some scenes, and I shouldn't have to pay 500MB to have a single 1024x1024 reflection probe.

@clayjohn
Copy link
Member

Can I ask why there are 8 array layers allocated at a time?

It matches the 8 roughness_layers which is the default amount in project settings. You need a layer for each different roughness level. This is what allows you to smoothly blend between 0 and 1 roughness.

To use a mipmapped single texture instead of a texture array you can set texture-array-reflections to false.

@clayjohn
Copy link
Member

I think a satisfactory resolution to this issue would be for us to raise the quality of non-array reflections to the point that we could make it default. Non-array reflections are significantly faster to generate and take up much less space (one eighth as much by default), but the quality suffers

@Calinou
Copy link
Member

Calinou commented May 30, 2024

@lyuma The Discord download link for the MRP is no longer working, as Discord prevented all old download links from working outside of Discord. Could you reupload the MRP somewhere else?

@lyuma
Copy link
Contributor Author

lyuma commented May 30, 2024

there was a second github link hidden next to the discord one. I diffed them and can confirm they are the same so I removed the broken discord link to avoid confusion
https://github.com/godotengine/godot/files/9440590/reflectionprobe_vram.zip

(it seems you can paste a dead discord link into a discord message, and the client will resolve it into a working link. that's how I re-gained access to it. it might have to be the same server, in this case V-Sekai)

@Calinou
Copy link
Member

Calinou commented Jun 3, 2024

I can reproduce this on 4.3.beta1. I stepped through RenderDoc and didn't find anything obvious about accidentally duplicating the reflection atlas or something.

Here's the system VRAM utilization difference1 with various settings and the default window size of 1152x648. This encapsules the entire project's VRAM utilization (the editor is not running in the background). Texture arrays are always enabled:

Settings VRAM usage
1024x1024, Count = 64 5,696 MB
512x512, Count = 64 1,594 MB
1024x1024, Count = 1 564 MB
No reflection probe 308 MB

The same with 1x1 window size (to rule out any framebuffer VRAM usage based on viewport size):

Settings VRAM usage
1024x1024, Count = 64 5,428 MB
512x512, Count = 64 1,582 MB
1024x1024, Count = 1 553 MB
No reflection probe 287 MB

The issue is in the Reflection Count project setting. It defaults to 64 to allow for 64 reflection probes to be drawn at a time. (Note that if you set it to 0, the engine will crash on startup. We should tweak the property hint to prevent that.)

If you decrease it to 1, VRAM usage is much more reasonable and in line with what I'd expect. If you use high-resolution reflection probes, you'll probably use fewer of them – especially in a racing game where you generally use a single probe for all cars centered around the player's.

I guess we should document this caveat about reflection resolutions higher than the default: if you want lower VRAM utilization, you should decrease reflection count at the same time you're increasing resolution.

PC specifications
  • CPU: Intel Core i9-13900K
  • GPU: NVIDIA GeForce RTX 4090
  • RAM: 64 GB (2×32 GB DDR5-5800 C30)
  • SSD: Solidigm P44 Pro 2 TB
  • OS: Linux (Fedora 39)

Footnotes

  1. Measured using watch -n0.1 nvidia-smi and running the project with godot --quit-after 50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants