EEVEE-Next: Skip bake if there's not enough VRAM #113509

Merged
Miguel Pozo merged 4 commits from pragma37/blender:pull-eevee-bake-out-of-mem into main 2023-10-18 18:49:30 +02:00
3 changed files with 34 additions and 1 deletions
Showing only changes of commit 0dc02b1c53 - Show all commits

View File

@ -610,12 +610,21 @@ void Instance::light_bake_irradiance(
capture_view.render_world();
irradiance_cache.bake.surfels_create(probe);
if (irradiance_cache.bake.should_break()) {
return;
}
irradiance_cache.bake.surfels_lights_eval();
irradiance_cache.bake.clusters_build();
irradiance_cache.bake.irradiance_offset();
});
if (irradiance_cache.bake.should_break()) {
return;
}
sampling.init(probe);
while (!sampling.finished()) {
context_wrapper([&]() {

View File

@ -947,10 +947,25 @@ void IrradianceBake::surfels_create(const Object &probe_object)
capture_info_buf_.read();
if (capture_info_buf_.surfel_len == 0) {
/* No surfel to allocated. */
do_break_ = true;
return;
}
/* TODO(fclem): Check for GL limit and abort if the surfel cache doesn't fit the GPU memory. */
if (capture_info_buf_.surfel_len > surfels_buf_.size() && GPU_mem_stats_supported()) {

While this is nice to check when it is supported, we should also check GL_MAX_SHADER_STORAGE_BLOCK_SIZE in any cases.

While this is nice to check when it is supported, we should also check `GL_MAX_SHADER_STORAGE_BLOCK_SIZE` in any cases.

There was no way to query that info, so I made a separate commit to add a GPU_max_storage_buffer_size function.

There was no way to query that info, so I made a separate commit to add a `GPU_max_storage_buffer_size` function.
int total_mem_kb, free_mem_kb;
GPU_mem_stats_get(&total_mem_kb, &free_mem_kb);
size_t free_mem = size_t(free_mem_kb) * 1024;
size_t required_mem = (size_t(capture_info_buf_.surfel_len) - surfels_buf_.size()) *
size_t(sizeof(Surfel));
if (required_mem > free_mem) {
capture_info_buf_.surfel_len = 0u;
capture_info_buf_.push_update();
inst_.info = "Error: Not enough memory to bake " + std::string(probe_object.id.name) + ".";
do_break_ = true;
return;
}
}
surfels_buf_.resize(capture_info_buf_.surfel_len);
surfels_buf_.clear_to_zero();

View File

@ -130,12 +130,21 @@ class IrradianceBake {
/** True if emission is recorded during the light propagation. */
bool capture_emission_ = false;
/** True if the bake job should stop. */
bool do_break_ = false;
public:
IrradianceBake(Instance &inst) : inst_(inst){};
void init(const Object &probe_object);
void sync();
/** True if the bake job should stop. */
bool should_break()
{
return do_break_;
}
/** Create the views used to rasterize the scene into surfel representation. */
void surfel_raster_views_sync(float3 scene_min, float3 scene_max, float4x4 probe_to_world);
/** Create a surfel representation of the scene from the probe using the capture pipeline. */