I am having problems with baking APVs. I want to bake the volume only for this house as seen on the image. But no matter the settings i put i always get the error:
“OpenCL Error. Error callback from context: CL_MEM_OBJECT_ALLOCATION_FAILURE error executing CL_COMMAND_MAP_BUFFER on NVIDIA GeForce RTX 3080 (Device 0).”
The scene contains 181 terrains (100x125x600). Using SSGI with no baked lighting.
If anyone knows why this happens or needs anymore info about the scene to help me with the problem… please tell me.
This usually means you have hit the max amount of triangles in the scene for baking. It’s currently somewhere between 2gb and 25% of our VRAM depending on your GPU. This is a fairly common pitfall with APV because it triangulates the terrains in order to raytrace against them.
One way to work around it is to lower the resolution of your terrains before baking. Pretty tedious, I know.
We are actually working on a better solution to this at the moment - we will use heightmap-based raymarching for terrains, which should massively reduce the memory usage. I can’t provide an ETA for this other than ‘hopefully soon’, though.
We’ve recently landed a fix in Unity 6000.6.0a7 for the bake failures that occurred when baking a terrain for APV with Virtual Offsets or Sky Occlusion enabled.
The root cause
To perform the bake, we previously converted a terrain’s height field into a mesh. While that sounds innocuous, the resulting mesh consumes an enormous amount of GPU memory. For instance, a single 4K terrain converted to a mesh yields 33 million vertices. That translates to:
800 MB of geometry attributes (position, normal, and UVs)
2.5 GB of BVH memory (the acceleration structure used to trace rays)
This problem is exacerbated when baking with Virtual Offsets or Sky Occlusion enabled, as they use a different code path from most kinds of baking, which is more prone to running out of memory.
Our fix
We now completely forgo the terrain-to-mesh conversion. Instead of generating and uploading a massive mesh to the GPU, the Sky Occlusion and Virtual Offsets baking steps trace rays directly against the height field texture using ray marching.
With that change, a 4K terrain now takes only 32 MB of height field data and 20 MB of BVH memory on the GPU.
To be clear, a bake can still fail if your scene contains too many terrains, but the ceiling has been pushed significantly higher. The Sky Occlusion / Virtual Offsets baking steps are no longer the bottleneck.
If, as a dev, you’re curious about the implementation, you can check out the ray marching code here, or play around with this Shadertoy demo.
@YvainR Glad to read this, I’ve been waiting for a fix like this for a long time!
We’re currently using a 4K terrain and, as you mentioned, Virtual Offsets were devouring the memory. I actually had to close down every single background application on my machine before starting a bake, watching the VRAM peak at 15.8 GB. I was genuinely starting to look into buying a 32 GB VRAM workstation GPU just to get bakes through!
This ray-marching approach is great. A few quick questions regarding availability:
Are there any plans to backport this fix to older Unity versions (like Unity 6.4, 6.5)?
Is there a public issue tracker link for this bug/optimization so I can follow its status for older versions?
Thank you so much to the team for the work on this!
There are no plans to backport this. It’s a large and invasive change to the architecture of the light baker. The chance of regressions was deemed too high.
No, sorry.
This landed in Unity 6.6.0a7, and is of course also available in the 6.7 alpha. 6.7 will eventually become the next LTS.
This is a really nasty problem that causes many headaches.
It happens even with much less terrain tiles and people waste their time diagnosing their scene pointlessly thinking something has corrupted their scene or that they have driver issues.
I have encountered it with all kinds of APV implementations, entire levels with 180K probes or tiny local APVs with a couple of thousands.
How about doing that automatically as you bake so the users do not need to do that.
Reduce the resolution internally that is. As an option.
Or at least handle the situation more gracefully, it often ends in a crash.
6.7 will come in many months, could even be a year, and having such a major issue for so many versions now is not a small thing. A major limitation preventing people from using APV which was touted as a major advancement.
The APV experience is riddled with showstopper issues and not just that one.