Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-08-04 20:52:18 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-08-05 03:26:44 +0300
commit6be8b6af4006e088ac4a2cd8c1adc8f18c04035b (patch)
treeb1fdd6632646e8cc87015294b6a394087ee54583 /source/blender/draw/engines/eevee/eevee_lightcache.c
parentd1b3da697d814bcb35a718d2d7c660bd2120cb4b (diff)
EEVEE: LightCache: Prevent crash when using a lightcache too big
Some implementation have different maximum texture size. This patch avoid crash when texture allocation fails when: - trying to bake a lightcache too big for the OpenGL imeplementaion. - loading a cache from file that is too big for the OpenGL imeplementation.
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_lightcache.c')
-rw-r--r--source/blender/draw/engines/eevee/eevee_lightcache.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index 78fcd28eb5d..92bb9227e13 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -228,7 +228,14 @@ void EEVEE_lightcache_info_update(SceneEEVEE *eevee)
if (lcache->cube_tx.tex_size[2] > GPU_max_texture_layers()) {
BLI_strncpy(eevee->light_cache_info,
- TIP_("Error: Light cache is too big for your GPU to be loaded"),
+ TIP_("Error: Light cache is too big for the GPU to be loaded"),
+ sizeof(eevee->light_cache_info));
+ return;
+ }
+
+ if (lcache->flag & LIGHTCACHE_INVALID) {
+ BLI_strncpy(eevee->light_cache_info,
+ TIP_("Error: Light cache dimensions not supported by the GPU"),
sizeof(eevee->light_cache_info));
return;
}
@@ -281,7 +288,7 @@ static bool EEVEE_lightcache_validate(const LightCache *light_cache,
const int grid_len,
const int irr_size[3])
{
- if (light_cache) {
+ if (light_cache && !(light_cache->flag & LIGHTCACHE_INVALID)) {
/* See if we need the same amount of texture space. */
if ((irr_size[0] == light_cache->grid_tx.tex_size[0]) &&
(irr_size[1] == light_cache->grid_tx.tex_size[1]) &&
@@ -343,12 +350,18 @@ LightCache *EEVEE_lightcache_create(const int grid_len,
light_cache->cube_mips = MEM_callocN(sizeof(LightCacheTexture) * light_cache->mips_len,
"LightCacheTexture");
- for (int mip = 0; mip < light_cache->mips_len; mip++) {
- GPU_texture_get_mipmap_size(
- light_cache->cube_tx.tex, mip + 1, light_cache->cube_mips[mip].tex_size);
+ if (light_cache->grid_tx.tex == NULL || light_cache->cube_tx.tex == NULL) {
+ /* We could not create the requested textures size. Stop baking and do not use the cache. */
+ light_cache->flag = LIGHTCACHE_INVALID;
}
+ else {
+ light_cache->flag = LIGHTCACHE_UPDATE_WORLD | LIGHTCACHE_UPDATE_CUBE | LIGHTCACHE_UPDATE_GRID;
- light_cache->flag = LIGHTCACHE_UPDATE_WORLD | LIGHTCACHE_UPDATE_CUBE | LIGHTCACHE_UPDATE_GRID;
+ for (int mip = 0; mip < light_cache->mips_len; mip++) {
+ GPU_texture_get_mipmap_size(
+ light_cache->cube_tx.tex, mip + 1, light_cache->cube_mips[mip].tex_size);
+ }
+ }
return light_cache;
}
@@ -376,6 +389,12 @@ static bool eevee_lightcache_static_load(LightCache *lcache)
0,
false,
NULL);
+
+ if (lcache->grid_tx.tex == NULL) {
+ lcache->flag |= LIGHTCACHE_NOT_USABLE;
+ return false;
+ }
+
GPU_texture_filter_mode(lcache->grid_tx.tex, true);
}
@@ -401,6 +420,11 @@ static bool eevee_lightcache_static_load(LightCache *lcache)
NULL);
}
+ if (lcache->cube_tx.tex == NULL) {
+ lcache->flag |= LIGHTCACHE_NOT_USABLE;
+ return false;
+ }
+
for (int mip = 0; mip < lcache->mips_len; mip++) {
GPU_texture_add_mipmap(
lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, mip + 1, lcache->cube_mips[mip].data);
@@ -420,6 +444,10 @@ bool EEVEE_lightcache_load(LightCache *lcache)
return false;
}
+ if (lcache->flag & (LIGHTCACHE_INVALID | LIGHTCACHE_NOT_USABLE)) {
+ return false;
+ }
+
switch (lcache->type) {
case LIGHTCACHE_TYPE_STATIC:
return eevee_lightcache_static_load(lcache);
@@ -590,9 +618,7 @@ static void eevee_lightbake_create_resources(EEVEE_LightBake *lbake)
if (lbake->lcache == NULL) {
lbake->lcache = EEVEE_lightcache_create(
lbake->grid_len, lbake->cube_len, lbake->ref_cube_res, lbake->vis_res, lbake->irr_size);
- lbake->lcache->flag = LIGHTCACHE_UPDATE_WORLD | LIGHTCACHE_UPDATE_CUBE |
- LIGHTCACHE_UPDATE_GRID;
- lbake->lcache->vis_res = lbake->vis_res;
+
lbake->own_light_cache = true;
eevee->light_cache_data = lbake->lcache;
@@ -1269,6 +1295,17 @@ void EEVEE_lightbake_job(void *custom_data, short *stop, short *do_update, float
* We cannot do it in the main thread. */
eevee_lightbake_context_enable(lbake);
eevee_lightbake_create_resources(lbake);
+
+ /* Resource allocation can fail. Early exit in this case. */
+ if (lbake->lcache->flag & LIGHTCACHE_INVALID) {
+ *lbake->stop = 1;
+ *lbake->do_update = 1;
+ lbake->lcache->flag &= ~LIGHTCACHE_BAKING;
+ eevee_lightbake_context_disable(lbake);
+ eevee_lightbake_delete_resources(lbake);
+ return;
+ }
+
eevee_lightbake_create_render_target(lbake, lbake->rt_res);
eevee_lightbake_context_disable(lbake);