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>2017-05-30 23:29:20 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-05-30 23:30:16 +0300
commitc2d81f257f608f00f827eccaff33df62ad91e29f (patch)
tree0ef098a5911d0e026ad6940dbf13ad60f0db5f1d
parente7fb013a60dd91caef1b1dd80f52b3996f06a21c (diff)
Eevee: Put shadows and probes inside SceneLayerEngineData
This remove the duplication of data for each viewport improving memory usage.
-rw-r--r--source/blender/draw/engines/eevee/eevee_engine.c79
-rw-r--r--source/blender/draw/engines/eevee/eevee_lights.c134
-rw-r--r--source/blender/draw/engines/eevee/eevee_private.h94
-rw-r--r--source/blender/draw/engines/eevee/eevee_probes.c111
-rw-r--r--source/blender/draw/intern/DRW_render.h14
5 files changed, 239 insertions, 193 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c
index ccd098b24a8..cd3819b88e1 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -88,6 +88,9 @@ extern char datatoc_background_vert_glsl[];
extern Material defmaterial;
extern GlobalsUboStorage ts;
+/* Prototypes */
+static void EEVEE_scene_layer_data_free(void *storage);
+
static struct GPUTexture *create_jitter_texture(int w, int h)
{
struct GPUTexture *tex;
@@ -187,7 +190,11 @@ static void EEVEE_engine_init(void *ved)
EEVEE_Data *vedata = (EEVEE_Data *)ved;
EEVEE_TextureList *txl = vedata->txl;
EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_SceneLayerData **sldata = (EEVEE_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_eevee_type, &EEVEE_scene_layer_data_free);
+
+ if (*sldata == NULL) {
+ *sldata = MEM_callocN(sizeof(EEVEE_SceneLayerData), "EEVEE_SceneLayerData");
+ }
DRWFboTexture tex = {&txl->color, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER};
@@ -259,9 +266,9 @@ static void EEVEE_engine_init(void *ved)
copy_v3_v3(e_data.camera_pos, viewinvmat[3]);
}
- EEVEE_lights_init(stl);
+ EEVEE_lights_init(*sldata);
- EEVEE_probes_init(vedata);
+ EEVEE_probes_init(*sldata);
EEVEE_effects_init(vedata);
@@ -283,8 +290,9 @@ static void EEVEE_cache_init(void *vedata)
static int zero = 0;
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
- EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ EEVEE_SceneLayerData *sldata = *(EEVEE_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_eevee_type, &EEVEE_scene_layer_data_free);
+
if (!stl->g_data) {
/* Alloc transient pointers */
@@ -410,15 +418,15 @@ static void EEVEE_cache_init(void *vedata)
shgrp = DRW_shgroup_create(shader, psl->default_pass);
}
- DRW_shgroup_uniform_block(shgrp, "light_block", stl->light_ubo);
- DRW_shgroup_uniform_block(shgrp, "shadow_block", stl->shadow_ubo);
- DRW_shgroup_uniform_int(shgrp, "light_count", &stl->lamps->num_light, 1);
- DRW_shgroup_uniform_float(shgrp, "lodMax", &stl->probes->lodmax, 1);
- DRW_shgroup_uniform_vec3(shgrp, "shCoefs[0]", (float *)stl->probes->shcoefs, 9);
+ DRW_shgroup_uniform_block(shgrp, "light_block", sldata->light_ubo);
+ DRW_shgroup_uniform_block(shgrp, "shadow_block", sldata->shadow_ubo);
+ DRW_shgroup_uniform_int(shgrp, "light_count", &sldata->lamps->num_light, 1);
+ DRW_shgroup_uniform_float(shgrp, "lodMax", &sldata->probes->lodmax, 1);
+ DRW_shgroup_uniform_vec3(shgrp, "shCoefs[0]", (float *)sldata->probes->shcoefs, 9);
DRW_shgroup_uniform_vec3(shgrp, "cameraPos", e_data.camera_pos, 1);
DRW_shgroup_uniform_texture(shgrp, "ltcMat", e_data.ltc_mat);
DRW_shgroup_uniform_texture(shgrp, "brdfLut", e_data.brdf_lut);
- DRW_shgroup_uniform_texture(shgrp, "probeFiltered", txl->probe_pool);
+ DRW_shgroup_uniform_texture(shgrp, "probeFiltered", sldata->probe_pool);
/* NOTE : Adding Shadow Map textures uniform in EEVEE_cache_finish */
}
}
@@ -428,16 +436,16 @@ static void EEVEE_cache_init(void *vedata)
psl->material_pass = DRW_pass_create("Material Shader Pass", state);
}
- EEVEE_probes_cache_init(vedata);
- EEVEE_lights_cache_init(stl, psl, txl);
+ EEVEE_probes_cache_init(sldata, psl);
+ EEVEE_lights_cache_init(sldata, psl);
EEVEE_effects_cache_init(vedata);
}
static void EEVEE_cache_populate(void *vedata, Object *ob)
{
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
- EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_SceneLayerData *sldata = *(EEVEE_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_eevee_type, &EEVEE_scene_layer_data_free);
const DRWContextState *draw_ctx = DRW_context_state_get();
const bool is_active = (ob == draw_ctx->obact);
@@ -492,15 +500,15 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
DRWShadingGroup *shgrp = DRW_shgroup_material_create(gpumat, psl->material_pass);
if (shgrp) {
- DRW_shgroup_uniform_block(shgrp, "light_block", stl->light_ubo);
- DRW_shgroup_uniform_block(shgrp, "shadow_block", stl->shadow_ubo);
- DRW_shgroup_uniform_int(shgrp, "light_count", &stl->lamps->num_light, 1);
- DRW_shgroup_uniform_float(shgrp, "lodMax", &stl->probes->lodmax, 1);
- DRW_shgroup_uniform_vec3(shgrp, "shCoefs[0]", (float *)stl->probes->shcoefs, 9);
+ DRW_shgroup_uniform_block(shgrp, "light_block", sldata->light_ubo);
+ DRW_shgroup_uniform_block(shgrp, "shadow_block", sldata->shadow_ubo);
+ DRW_shgroup_uniform_int(shgrp, "light_count", &sldata->lamps->num_light, 1);
+ DRW_shgroup_uniform_float(shgrp, "lodMax", &sldata->probes->lodmax, 1);
+ DRW_shgroup_uniform_vec3(shgrp, "shCoefs[0]", (float *)sldata->probes->shcoefs, 9);
DRW_shgroup_uniform_vec3(shgrp, "cameraPos", e_data.camera_pos, 1);
DRW_shgroup_uniform_texture(shgrp, "ltcMat", e_data.ltc_mat);
DRW_shgroup_uniform_texture(shgrp, "brdfLut", e_data.brdf_lut);
- DRW_shgroup_uniform_texture(shgrp, "probeFiltered", txl->probe_pool);
+ DRW_shgroup_uniform_texture(shgrp, "probeFiltered", sldata->probe_pool);
if (is_sculpt_mode) {
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
@@ -521,7 +529,7 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
DRW_shgroup_uniform_float(shgrp, "roughness", &half, 1);
DRW_shgroup_uniform_texture(shgrp, "ltcMat", e_data.ltc_mat);
DRW_shgroup_uniform_texture(shgrp, "brdfLut", e_data.brdf_lut);
- DRW_shgroup_uniform_texture(shgrp, "probeFiltered", txl->probe_pool);
+ DRW_shgroup_uniform_texture(shgrp, "probeFiltered", sldata->probe_pool);
if (is_sculpt_mode) {
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
@@ -539,7 +547,7 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
DRW_shgroup_uniform_float(shgrp, "roughness", &ma->gloss_mir, 1);
DRW_shgroup_uniform_texture(shgrp, "ltcMat", e_data.ltc_mat);
DRW_shgroup_uniform_texture(shgrp, "brdfLut", e_data.brdf_lut);
- DRW_shgroup_uniform_texture(shgrp, "probeFiltered", txl->probe_pool);
+ DRW_shgroup_uniform_texture(shgrp, "probeFiltered", sldata->probe_pool);
if (is_sculpt_mode) {
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
@@ -556,11 +564,11 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
const bool cast_shadow = true;
if (cast_shadow) {
- EEVEE_lights_cache_shcaster_add(psl, stl, geom, ob->obmat);
+ EEVEE_lights_cache_shcaster_add(sldata, psl, geom, ob->obmat);
}
}
else if (ob->type == OB_LAMP) {
- EEVEE_lights_cache_add(stl, ob);
+ EEVEE_lights_cache_add(sldata, ob);
}
}
@@ -579,18 +587,16 @@ static void eevee_bind_shadow(void *data, DRWShadingGroup *shgrp)
static void EEVEE_cache_finish(void *vedata)
{
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
- EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
- EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
- EEVEE_FramebufferList *fbl = ((EEVEE_Data *)vedata)->fbl;
+ EEVEE_SceneLayerData *sldata = *(EEVEE_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_eevee_type, &EEVEE_scene_layer_data_free);
- EEVEE_lights_cache_finish(stl, txl, fbl);
- EEVEE_probes_cache_finish(vedata);
+ EEVEE_lights_cache_finish(sldata);
+ EEVEE_probes_cache_finish(sldata);
/* Shadows binding */
eevee_bind_shadow_data data;
- data.shadow_depth_cube_pool = txl->shadow_depth_cube_pool;
- data.shadow_depth_cascade_pool = txl->shadow_depth_cascade_pool;
+ data.shadow_depth_cube_pool = sldata->shadow_depth_cube_pool;
+ data.shadow_depth_cascade_pool = sldata->shadow_depth_cascade_pool;
DRW_pass_foreach_shgroup(psl->default_pass, eevee_bind_shadow, &data);
DRW_pass_foreach_shgroup(psl->material_pass, eevee_bind_shadow, &data);
@@ -600,15 +606,16 @@ static void EEVEE_draw_scene(void *vedata)
{
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
EEVEE_FramebufferList *fbl = ((EEVEE_Data *)vedata)->fbl;
+ EEVEE_SceneLayerData *sldata = *(EEVEE_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_eevee_type, &EEVEE_scene_layer_data_free);
/* Default framebuffer and texture */
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
/* Refresh Probes */
- EEVEE_refresh_probe((EEVEE_Data *)vedata);
+ EEVEE_refresh_probe(sldata, psl);
/* Refresh shadows */
- EEVEE_draw_shadows((EEVEE_Data *)vedata);
+ EEVEE_draw_shadows(sldata, psl);
/* Attach depth to the hdr buffer and bind it */
DRW_framebuffer_texture_detach(dtxl->depth);
@@ -643,6 +650,13 @@ static void EEVEE_engine_free(void)
DRW_TEXTURE_FREE_SAFE(e_data.jitter);
}
+static void EEVEE_scene_layer_data_free(void *storage)
+{
+ EEVEE_SceneLayerData *sldata = (EEVEE_SceneLayerData *)storage;
+ EEVEE_scene_layer_lights_free(sldata);
+ EEVEE_scene_layer_probes_free(sldata);
+}
+
static void EEVEE_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
{
BLI_assert(props &&
@@ -652,7 +666,6 @@ static void EEVEE_layer_collection_settings_create(RenderEngine *UNUSED(engine),
UNUSED_VARS_NDEBUG(props);
}
-
static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
{
BLI_assert(props &&
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index 2423fda2dd3..4c992fca8e0 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -61,7 +61,7 @@ extern char datatoc_shadow_store_frag_glsl[];
/* *********** FUNCTIONS *********** */
-void EEVEE_lights_init(EEVEE_StorageList *stl)
+void EEVEE_lights_init(EEVEE_SceneLayerData *sldata)
{
const unsigned int shadow_ubo_size = sizeof(EEVEE_ShadowCube) * MAX_SHADOW_CUBE +
sizeof(EEVEE_ShadowMap) * MAX_SHADOW_MAP +
@@ -75,17 +75,17 @@ void EEVEE_lights_init(EEVEE_StorageList *stl)
datatoc_shadow_store_vert_glsl, datatoc_shadow_store_geom_glsl, datatoc_shadow_store_frag_glsl, NULL);
}
- if (!stl->lamps) {
- stl->lamps = MEM_callocN(sizeof(EEVEE_LampsInfo), "EEVEE_LampsInfo");
- stl->light_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_Light) * MAX_LIGHT, NULL);
- stl->shadow_ubo = DRW_uniformbuffer_create(shadow_ubo_size, NULL);
- stl->shadow_render_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_ShadowRender), NULL);
+ if (!sldata->lamps) {
+ sldata->lamps = MEM_callocN(sizeof(EEVEE_LampsInfo), "EEVEE_LampsInfo");
+ sldata->light_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_Light) * MAX_LIGHT, NULL);
+ sldata->shadow_ubo = DRW_uniformbuffer_create(shadow_ubo_size, NULL);
+ sldata->shadow_render_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_ShadowRender), NULL);
}
}
-void EEVEE_lights_cache_init(EEVEE_StorageList *stl, EEVEE_PassList *psl, EEVEE_TextureList *txl)
+void EEVEE_lights_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl)
{
- EEVEE_LampsInfo *linfo = stl->lamps;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
linfo->num_light = linfo->num_cube = linfo->num_map = linfo->num_cascade = 0;
memset(linfo->light_ref, 0, sizeof(linfo->light_ref));
@@ -97,8 +97,8 @@ void EEVEE_lights_cache_init(EEVEE_StorageList *stl, EEVEE_PassList *psl, EEVEE_
psl->shadow_cube_store_pass = DRW_pass_create("Shadow Storage Pass", DRW_STATE_WRITE_COLOR);
DRWShadingGroup *grp = DRW_shgroup_create(e_data.shadow_store_sh, psl->shadow_cube_store_pass);
- DRW_shgroup_uniform_buffer(grp, "shadowCube", &txl->shadow_color_cube_target);
- DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
+ DRW_shgroup_uniform_buffer(grp, "shadowCube", &sldata->shadow_color_cube_target);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
}
@@ -111,9 +111,9 @@ void EEVEE_lights_cache_init(EEVEE_StorageList *stl, EEVEE_PassList *psl, EEVEE_
}
}
-void EEVEE_lights_cache_add(EEVEE_StorageList *stl, Object *ob)
+void EEVEE_lights_cache_add(EEVEE_SceneLayerData *sldata, Object *ob)
{
- EEVEE_LampsInfo *linfo = stl->lamps;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
/* Step 1 find all lamps in the scene and setup them */
if (linfo->num_light > MAX_LIGHT) {
@@ -159,92 +159,92 @@ void EEVEE_lights_cache_add(EEVEE_StorageList *stl, Object *ob)
}
/* Add a shadow caster to the shadowpasses */
-void EEVEE_lights_cache_shcaster_add(EEVEE_PassList *psl, EEVEE_StorageList *stl, struct Batch *geom, float (*obmat)[4])
+void EEVEE_lights_cache_shcaster_add(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, struct Batch *geom, float (*obmat)[4])
{
DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cube_pass, geom);
- DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
for (int i = 0; i < 6; ++i)
DRW_shgroup_call_dynamic_add_empty(grp);
grp = DRW_shgroup_instance_create(e_data.shadow_sh, psl->shadow_cascade_pass, geom);
- DRW_shgroup_uniform_block(grp, "shadow_render_block", stl->shadow_render_ubo);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
for (int i = 0; i < MAX_CASCADE_NUM; ++i)
DRW_shgroup_call_dynamic_add_empty(grp);
}
-void EEVEE_lights_cache_finish(EEVEE_StorageList *stl, EEVEE_TextureList *txl, EEVEE_FramebufferList *fbl)
+void EEVEE_lights_cache_finish(EEVEE_SceneLayerData *sldata)
{
- EEVEE_LampsInfo *linfo = stl->lamps;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
/* Step 4 Update Lamp UBOs */
- EEVEE_lights_update(stl);
+ EEVEE_lights_update(sldata);
/* Step 5 Setup enough layers */
/* Free textures if number mismatch */
if (linfo->num_cube != linfo->cache_num_cube) {
- DRW_TEXTURE_FREE_SAFE(txl->shadow_depth_cube_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_cube_pool);
linfo->cache_num_cube = linfo->num_cube;
}
if (linfo->num_map != linfo->cache_num_map) {
- DRW_TEXTURE_FREE_SAFE(txl->shadow_depth_map_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_map_pool);
linfo->cache_num_map = linfo->num_map;
}
if (linfo->num_cascade != linfo->cache_num_cascade) {
- DRW_TEXTURE_FREE_SAFE(txl->shadow_depth_cascade_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_cascade_pool);
linfo->cache_num_cascade = linfo->num_cascade;
}
/* Initialize Textures Arrays first so DRW_framebuffer_init just bind them. */
- if (!txl->shadow_depth_cube_target) {
+ if (!sldata->shadow_depth_cube_target) {
/* Render Cubemap */
- txl->shadow_depth_cube_target = DRW_texture_create_cube(512, DRW_TEX_DEPTH_24, 0, NULL);
- txl->shadow_color_cube_target = DRW_texture_create_cube(512, DRW_TEX_R_32, DRW_TEX_FILTER, NULL);
- if (fbl->shadow_cube_fb) {
- DRW_framebuffer_texture_attach(fbl->shadow_cube_fb, txl->shadow_depth_cube_target, 0, 0);
- DRW_framebuffer_texture_attach(fbl->shadow_cube_fb, txl->shadow_color_cube_target, 0, 0);
+ sldata->shadow_depth_cube_target = DRW_texture_create_cube(512, DRW_TEX_DEPTH_24, 0, NULL);
+ sldata->shadow_color_cube_target = DRW_texture_create_cube(512, DRW_TEX_R_32, DRW_TEX_FILTER, NULL);
+ if (sldata->shadow_cube_fb) {
+ DRW_framebuffer_texture_attach(sldata->shadow_cube_fb, sldata->shadow_depth_cube_target, 0, 0);
+ DRW_framebuffer_texture_attach(sldata->shadow_cube_fb, sldata->shadow_color_cube_target, 0, 0);
}
}
- if (!txl->shadow_depth_cube_pool) {
+ if (!sldata->shadow_depth_cube_pool) {
/* Cubemap / octahedral map pool */
/* TODO Cubemap array */
- txl->shadow_depth_cube_pool = DRW_texture_create_2D_array(
+ sldata->shadow_depth_cube_pool = DRW_texture_create_2D_array(
512, 512, max_ff(1, linfo->num_cube), DRW_TEX_R_32,
DRW_TEX_FILTER | DRW_TEX_COMPARE, NULL);
- if (fbl->shadow_cube_fb) {
- DRW_framebuffer_texture_attach(fbl->shadow_cube_fb, txl->shadow_depth_cube_pool, 0, 0);
+ if (sldata->shadow_cube_fb) {
+ DRW_framebuffer_texture_attach(sldata->shadow_cube_fb, sldata->shadow_depth_cube_pool, 0, 0);
}
}
- if (!txl->shadow_depth_map_pool) {
- txl->shadow_depth_map_pool = DRW_texture_create_2D_array(
+ if (!sldata->shadow_depth_map_pool) {
+ sldata->shadow_depth_map_pool = DRW_texture_create_2D_array(
512, 512, max_ff(1, linfo->num_map), DRW_TEX_DEPTH_24,
DRW_TEX_FILTER | DRW_TEX_COMPARE, NULL);
- if (fbl->shadow_map_fb) {
- DRW_framebuffer_texture_attach(fbl->shadow_map_fb, txl->shadow_depth_map_pool, 0, 0);
+ if (sldata->shadow_map_fb) {
+ DRW_framebuffer_texture_attach(sldata->shadow_map_fb, sldata->shadow_depth_map_pool, 0, 0);
}
}
- if (!txl->shadow_depth_cascade_pool) {
- txl->shadow_depth_cascade_pool = DRW_texture_create_2D_array(
+ if (!sldata->shadow_depth_cascade_pool) {
+ sldata->shadow_depth_cascade_pool = DRW_texture_create_2D_array(
512, 512, max_ff(1, linfo->num_cascade * MAX_CASCADE_NUM), DRW_TEX_DEPTH_24,
DRW_TEX_FILTER | DRW_TEX_COMPARE, NULL);
- if (fbl->shadow_cascade_fb) {
- DRW_framebuffer_texture_attach(fbl->shadow_cascade_fb, txl->shadow_depth_map_pool, 0, 0);
+ if (sldata->shadow_cascade_fb) {
+ DRW_framebuffer_texture_attach(sldata->shadow_cascade_fb, sldata->shadow_depth_map_pool, 0, 0);
}
}
DRWFboTexture tex_cube_target[2] = {
- {&txl->shadow_depth_cube_target, DRW_TEX_DEPTH_24, 0},
- {&txl->shadow_color_cube_target, DRW_TEX_R_32, DRW_TEX_FILTER}};
- DRW_framebuffer_init(&fbl->shadow_cube_target_fb, &draw_engine_eevee_type, 512, 512, tex_cube_target, 2);
+ {&sldata->shadow_depth_cube_target, DRW_TEX_DEPTH_24, 0},
+ {&sldata->shadow_color_cube_target, DRW_TEX_R_32, DRW_TEX_FILTER}};
+ DRW_framebuffer_init(&sldata->shadow_cube_target_fb, &draw_engine_eevee_type, 512, 512, tex_cube_target, 2);
- DRWFboTexture tex_cube = {&txl->shadow_depth_cube_pool, DRW_TEX_R_32, DRW_TEX_FILTER};
- DRW_framebuffer_init(&fbl->shadow_cube_fb, &draw_engine_eevee_type, 512, 512, &tex_cube, 1);
+ DRWFboTexture tex_cube = {&sldata->shadow_depth_cube_pool, DRW_TEX_R_32, DRW_TEX_FILTER};
+ DRW_framebuffer_init(&sldata->shadow_cube_fb, &draw_engine_eevee_type, 512, 512, &tex_cube, 1);
- DRWFboTexture tex_cascade = {&txl->shadow_depth_cascade_pool, DRW_TEX_DEPTH_24, DRW_TEX_FILTER | DRW_TEX_COMPARE};
- DRW_framebuffer_init(&fbl->shadow_cascade_fb, &draw_engine_eevee_type, 512, 512, &tex_cascade, 1);
+ DRWFboTexture tex_cascade = {&sldata->shadow_depth_cascade_pool, DRW_TEX_DEPTH_24, DRW_TEX_FILTER | DRW_TEX_COMPARE};
+ DRW_framebuffer_init(&sldata->shadow_cascade_fb, &draw_engine_eevee_type, 512, 512, &tex_cascade, 1);
}
/* Update buffer with lamp data */
@@ -546,9 +546,9 @@ static void eevee_shadow_cascade_setup(Object *ob, EEVEE_LampsInfo *linfo, EEVEE
evli->shadowid = (float)(MAX_SHADOW_CUBE + MAX_SHADOW_MAP + evscp->shadow_id);
}
-void EEVEE_lights_update(EEVEE_StorageList *stl)
+void EEVEE_lights_update(EEVEE_SceneLayerData *sldata)
{
- EEVEE_LampsInfo *linfo = stl->lamps;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
Object *ob;
int i;
@@ -572,17 +572,14 @@ void EEVEE_lights_update(EEVEE_StorageList *stl)
eevee_shadow_cascade_setup(ob, linfo, led);
}
- DRW_uniformbuffer_update(stl->light_ubo, &linfo->light_data);
- DRW_uniformbuffer_update(stl->shadow_ubo, &linfo->shadow_cube_data); /* Update all data at once */
+ DRW_uniformbuffer_update(sldata->light_ubo, &linfo->light_data);
+ DRW_uniformbuffer_update(sldata->shadow_ubo, &linfo->shadow_cube_data); /* Update all data at once */
}
/* this refresh lamps shadow buffers */
-void EEVEE_draw_shadows(EEVEE_Data *vedata)
+void EEVEE_draw_shadows(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl)
{
- EEVEE_PassList *psl = vedata->psl;
- EEVEE_StorageList *stl = vedata->stl;
- EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_LampsInfo *linfo = stl->lamps;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
Object *ob;
int i;
float clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
@@ -599,15 +596,15 @@ void EEVEE_draw_shadows(EEVEE_Data *vedata)
for (int j = 0; j < 6; ++j) {
copy_m4_m4(srd->shadowmat[j], evscd->viewprojmat[j]);
}
- DRW_uniformbuffer_update(stl->shadow_render_ubo, &linfo->shadow_render_data);
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
- DRW_framebuffer_bind(fbl->shadow_cube_target_fb);
+ DRW_framebuffer_bind(sldata->shadow_cube_target_fb);
DRW_framebuffer_clear(true, true, false, clear_color, 1.0);
/* Render shadow cube */
DRW_draw_pass(psl->shadow_cube_pass);
/* Push it to shadowmap array */
- DRW_framebuffer_bind(fbl->shadow_cube_fb);
+ DRW_framebuffer_bind(sldata->shadow_cube_fb);
DRW_draw_pass(psl->shadow_cube_store_pass);
}
@@ -641,7 +638,7 @@ void EEVEE_draw_shadows(EEVEE_Data *vedata)
// for (int j = 0; j < MAX_CASCADE_NUM; ++j) {
// copy_m4_m4(srd->shadowmat[j], evscd->viewprojmat[j]);
// }
-// DRW_uniformbuffer_update(stl->shadow_render_ubo, &linfo->shadow_render_data);
+// DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
// DRW_draw_pass(psl->shadow_cascade_pass);
// }
@@ -651,4 +648,21 @@ void EEVEE_lights_free(void)
{
DRW_SHADER_FREE_SAFE(e_data.shadow_sh);
DRW_SHADER_FREE_SAFE(e_data.shadow_store_sh);
-} \ No newline at end of file
+}
+
+void EEVEE_scene_layer_lights_free(EEVEE_SceneLayerData *sldata)
+{
+ MEM_SAFE_FREE(sldata->lamps);
+ DRW_UBO_FREE_SAFE(sldata->light_ubo);
+ DRW_UBO_FREE_SAFE(sldata->shadow_ubo);
+ DRW_UBO_FREE_SAFE(sldata->shadow_render_ubo);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_target_fb);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_fb);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_map_fb);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_fb);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_cube_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_color_cube_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_cube_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_map_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_depth_cascade_pool);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index ae984fa5056..6a073e58a3e 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -69,15 +69,6 @@ typedef struct EEVEE_PassList {
} EEVEE_PassList;
typedef struct EEVEE_FramebufferList {
- /* Shadows */
- struct GPUFrameBuffer *shadow_cube_target_fb;
- struct GPUFrameBuffer *shadow_cube_fb;
- struct GPUFrameBuffer *shadow_map_fb;
- struct GPUFrameBuffer *shadow_cascade_fb;
- /* Probes */
- struct GPUFrameBuffer *probe_fb;
- struct GPUFrameBuffer *probe_filter_fb;
- struct GPUFrameBuffer *probe_sh_fb;
/* Effects */
struct GPUFrameBuffer *effect_fb; /* HDR */
struct GPUFrameBuffer *bloom_blit_fb; /* HDR */
@@ -91,17 +82,6 @@ typedef struct EEVEE_FramebufferList {
} EEVEE_FramebufferList;
typedef struct EEVEE_TextureList {
- /* Shadows */
- struct GPUTexture *shadow_depth_cube_target;
- struct GPUTexture *shadow_color_cube_target;
- struct GPUTexture *shadow_depth_cube_pool;
- struct GPUTexture *shadow_depth_map_pool;
- struct GPUTexture *shadow_depth_cascade_pool;
- /* Probes */
- struct GPUTexture *probe_rt; /* R16_G16_B16 */
- struct GPUTexture *probe_depth_rt;
- struct GPUTexture *probe_pool; /* R11_G11_B10 */
- struct GPUTexture *probe_sh; /* R16_G16_B16 */
/* Effects */
struct GPUTexture *color_post; /* R16_G16_B16 */
struct GPUTexture *dof_down_near; /* R16_G16_B16_A16 */
@@ -117,17 +97,6 @@ typedef struct EEVEE_TextureList {
} EEVEE_TextureList;
typedef struct EEVEE_StorageList {
- /* Lamps */
- /* XXX this should be per-scenelayer and not per_viewport */
- struct EEVEE_LampsInfo *lamps;
- struct GPUUniformBuffer *light_ubo;
- struct GPUUniformBuffer *shadow_ubo;
- struct GPUUniformBuffer *shadow_render_ubo;
-
- /* Probes */
- struct EEVEE_ProbesInfo *probes;
- struct GPUUniformBuffer *probe_ubo;
-
/* Effects */
struct EEVEE_EffectsInfo *effects;
@@ -243,6 +212,41 @@ enum {
EFFECT_DOF = (1 << 2),
};
+/* ************** SCENE LAYER DATA ************** */
+typedef struct EEVEE_SceneLayerData {
+ /* Lamps */
+ struct EEVEE_LampsInfo *lamps;
+
+ struct GPUUniformBuffer *light_ubo;
+ struct GPUUniformBuffer *shadow_ubo;
+ struct GPUUniformBuffer *shadow_render_ubo;
+
+ struct GPUFrameBuffer *shadow_cube_target_fb;
+ struct GPUFrameBuffer *shadow_cube_fb;
+ struct GPUFrameBuffer *shadow_map_fb;
+ struct GPUFrameBuffer *shadow_cascade_fb;
+
+ struct GPUTexture *shadow_depth_cube_target;
+ struct GPUTexture *shadow_color_cube_target;
+ struct GPUTexture *shadow_depth_cube_pool;
+ struct GPUTexture *shadow_depth_map_pool;
+ struct GPUTexture *shadow_depth_cascade_pool;
+
+ /* Probes */
+ struct EEVEE_ProbesInfo *probes;
+
+ struct GPUUniformBuffer *probe_ubo;
+
+ struct GPUFrameBuffer *probe_fb;
+ struct GPUFrameBuffer *probe_filter_fb;
+ struct GPUFrameBuffer *probe_sh_fb;
+
+ struct GPUTexture *probe_rt;
+ struct GPUTexture *probe_depth_rt;
+ struct GPUTexture *probe_pool;
+ struct GPUTexture *probe_sh;
+} EEVEE_SceneLayerData;
+
/* *********************************** */
typedef struct EEVEE_Data {
@@ -268,23 +272,25 @@ typedef struct EEVEE_PrivateData {
} EEVEE_PrivateData; /* Transient data */
/* eevee_lights.c */
-void EEVEE_lights_init(EEVEE_StorageList *stl);
-void EEVEE_lights_cache_init(EEVEE_StorageList *stl, EEVEE_PassList *psl, EEVEE_TextureList *txl);
-void EEVEE_lights_cache_add(EEVEE_StorageList *stl, struct Object *ob);
-void EEVEE_lights_cache_shcaster_add(EEVEE_PassList *psl, EEVEE_StorageList *stl, struct Batch *geom, float (*obmat)[4]);
-void EEVEE_lights_cache_finish(EEVEE_StorageList *stl, EEVEE_TextureList *txl, EEVEE_FramebufferList *fbl);
-void EEVEE_lights_update(EEVEE_StorageList *stl);
-void EEVEE_draw_shadows(EEVEE_Data *vedata);
+void EEVEE_lights_init(EEVEE_SceneLayerData *sldata);
+void EEVEE_lights_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl);
+void EEVEE_lights_cache_add(EEVEE_SceneLayerData *sldata, struct Object *ob);
+void EEVEE_lights_cache_shcaster_add(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, struct Batch *geom, float (*obmat)[4]);
+void EEVEE_lights_cache_finish(EEVEE_SceneLayerData *sldata);
+void EEVEE_lights_update(EEVEE_SceneLayerData *sldata);
+void EEVEE_draw_shadows(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl);
void EEVEE_lights_free(void);
+void EEVEE_scene_layer_lights_free(EEVEE_SceneLayerData *sldata);
/* eevee_probes.c */
-void EEVEE_probes_init(EEVEE_Data *vedata);
-void EEVEE_probes_cache_init(EEVEE_Data *vedata);
-void EEVEE_probes_cache_add(EEVEE_Data *vedata, Object *ob);
-void EEVEE_probes_cache_finish(EEVEE_Data *vedata);
-void EEVEE_probes_update(EEVEE_Data *vedata);
-void EEVEE_refresh_probe(EEVEE_Data *vedata);
+void EEVEE_probes_init(EEVEE_SceneLayerData *sldata);
+void EEVEE_probes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl);
+void EEVEE_probes_cache_add(EEVEE_SceneLayerData *sldata, Object *ob);
+void EEVEE_probes_cache_finish(EEVEE_SceneLayerData *sldata);
+void EEVEE_probes_update(EEVEE_SceneLayerData *sldata);
+void EEVEE_refresh_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl);
void EEVEE_probes_free(void);
+void EEVEE_scene_layer_probes_free(EEVEE_SceneLayerData *sldata);
/* eevee_effects.c */
void EEVEE_effects_init(EEVEE_Data *vedata);
diff --git a/source/blender/draw/engines/eevee/eevee_probes.c b/source/blender/draw/engines/eevee/eevee_probes.c
index 41ed2b0bf40..9c9fc052b3f 100644
--- a/source/blender/draw/engines/eevee/eevee_probes.c
+++ b/source/blender/draw/engines/eevee/eevee_probes.c
@@ -91,12 +91,8 @@ static struct GPUTexture *create_hammersley_sample_texture(int samples)
return tex;
}
-void EEVEE_probes_init(EEVEE_Data *vedata)
+void EEVEE_probes_init(EEVEE_SceneLayerData *sldata)
{
- EEVEE_StorageList *stl = vedata->stl;
- EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_TextureList *txl = vedata->txl;
-
if (!e_data.probe_filter_sh) {
char *shader_str = NULL;
@@ -123,58 +119,54 @@ void EEVEE_probes_init(EEVEE_Data *vedata)
e_data.probe_spherical_harmonic_sh = DRW_shader_create_fullscreen(datatoc_probe_sh_frag_glsl, NULL);
}
- if (!stl->probes) {
- stl->probes = MEM_callocN(sizeof(EEVEE_ProbesInfo), "EEVEE_ProbesInfo");
+ if (!sldata->probes) {
+ sldata->probes = MEM_callocN(sizeof(EEVEE_ProbesInfo), "EEVEE_ProbesInfo");
}
- if (!txl->probe_rt) {
- txl->probe_rt = DRW_texture_create_cube(PROBE_CUBE_SIZE, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
- txl->probe_depth_rt = DRW_texture_create_cube(PROBE_CUBE_SIZE, DRW_TEX_DEPTH_24, DRW_TEX_FILTER, NULL);
+ if (!sldata->probe_rt) {
+ sldata->probe_rt = DRW_texture_create_cube(PROBE_CUBE_SIZE, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ sldata->probe_depth_rt = DRW_texture_create_cube(PROBE_CUBE_SIZE, DRW_TEX_DEPTH_24, DRW_TEX_FILTER, NULL);
}
- DRWFboTexture tex_probe[2] = {{&txl->probe_depth_rt, DRW_TEX_DEPTH_24, DRW_TEX_FILTER},
- {&txl->probe_rt, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP}};
+ DRWFboTexture tex_probe[2] = {{&sldata->probe_depth_rt, DRW_TEX_DEPTH_24, DRW_TEX_FILTER},
+ {&sldata->probe_rt, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP}};
- DRW_framebuffer_init(&fbl->probe_fb, &draw_engine_eevee_type, PROBE_CUBE_SIZE, PROBE_CUBE_SIZE, tex_probe, 2);
+ DRW_framebuffer_init(&sldata->probe_fb, &draw_engine_eevee_type, PROBE_CUBE_SIZE, PROBE_CUBE_SIZE, tex_probe, 2);
- if (!txl->probe_pool) {
+ if (!sldata->probe_pool) {
/* TODO array */
- txl->probe_pool = DRW_texture_create_2D(PROBE_SIZE, PROBE_SIZE, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ sldata->probe_pool = DRW_texture_create_2D(PROBE_SIZE, PROBE_SIZE, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
}
- DRWFboTexture tex_filter = {&txl->probe_pool, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
+ DRWFboTexture tex_filter = {&sldata->probe_pool, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
- DRW_framebuffer_init(&fbl->probe_filter_fb, &draw_engine_eevee_type, PROBE_SIZE, PROBE_SIZE, &tex_filter, 1);
+ DRW_framebuffer_init(&sldata->probe_filter_fb, &draw_engine_eevee_type, PROBE_SIZE, PROBE_SIZE, &tex_filter, 1);
/* Spherical Harmonic Buffer */
- DRWFboTexture tex_sh = {&txl->probe_sh, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
+ DRWFboTexture tex_sh = {&sldata->probe_sh, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
- DRW_framebuffer_init(&fbl->probe_sh_fb, &draw_engine_eevee_type, 9, 1, &tex_sh, 1);
+ DRW_framebuffer_init(&sldata->probe_sh_fb, &draw_engine_eevee_type, 9, 1, &tex_sh, 1);
}
-void EEVEE_probes_cache_init(EEVEE_Data *vedata)
+void EEVEE_probes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl)
{
- EEVEE_StorageList *stl = vedata->stl;
- EEVEE_TextureList *txl = vedata->txl;
- EEVEE_PassList *psl = vedata->psl;
-
{
psl->probe_prefilter = DRW_pass_create("Probe Filtering", DRW_STATE_WRITE_COLOR);
struct Batch *geom = DRW_cache_fullscreen_quad_get();
DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.probe_filter_sh, psl->probe_prefilter, geom);
- DRW_shgroup_uniform_float(grp, "sampleCount", &stl->probes->samples_ct, 1);
- DRW_shgroup_uniform_float(grp, "invSampleCount", &stl->probes->invsamples_ct, 1);
- DRW_shgroup_uniform_float(grp, "roughnessSquared", &stl->probes->roughness, 1);
- DRW_shgroup_uniform_float(grp, "lodFactor", &stl->probes->lodfactor, 1);
- DRW_shgroup_uniform_float(grp, "lodMax", &stl->probes->lodmax, 1);
- DRW_shgroup_uniform_float(grp, "texelSize", &stl->probes->texel_size, 1);
- DRW_shgroup_uniform_float(grp, "paddingSize", &stl->probes->padding_size, 1);
- DRW_shgroup_uniform_int(grp, "Layer", &stl->probes->layer, 1);
+ DRW_shgroup_uniform_float(grp, "sampleCount", &sldata->probes->samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &sldata->probes->invsamples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "roughnessSquared", &sldata->probes->roughness, 1);
+ DRW_shgroup_uniform_float(grp, "lodFactor", &sldata->probes->lodfactor, 1);
+ DRW_shgroup_uniform_float(grp, "lodMax", &sldata->probes->lodmax, 1);
+ DRW_shgroup_uniform_float(grp, "texelSize", &sldata->probes->texel_size, 1);
+ DRW_shgroup_uniform_float(grp, "paddingSize", &sldata->probes->padding_size, 1);
+ DRW_shgroup_uniform_int(grp, "Layer", &sldata->probes->layer, 1);
DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley);
// DRW_shgroup_uniform_texture(grp, "texJitter", e_data.jitter);
- DRW_shgroup_uniform_texture(grp, "probeHdr", txl->probe_rt);
+ DRW_shgroup_uniform_texture(grp, "probeHdr", sldata->probe_rt);
DRW_shgroup_call_dynamic_add_empty(grp);
}
@@ -183,37 +175,33 @@ void EEVEE_probes_cache_init(EEVEE_Data *vedata)
psl->probe_sh_compute = DRW_pass_create("Probe SH Compute", DRW_STATE_WRITE_COLOR);
DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_spherical_harmonic_sh, psl->probe_sh_compute);
- DRW_shgroup_uniform_int(grp, "probeSize", &stl->probes->shres, 1);
- DRW_shgroup_uniform_float(grp, "lodBias", &stl->probes->lodfactor, 1);
- DRW_shgroup_uniform_texture(grp, "probeHdr", txl->probe_rt);
+ DRW_shgroup_uniform_int(grp, "probeSize", &sldata->probes->shres, 1);
+ DRW_shgroup_uniform_float(grp, "lodBias", &sldata->probes->lodfactor, 1);
+ DRW_shgroup_uniform_texture(grp, "probeHdr", sldata->probe_rt);
struct Batch *geom = DRW_cache_fullscreen_quad_get();
DRW_shgroup_call_add(grp, geom, NULL);
}
}
-void EEVEE_probes_cache_add(EEVEE_Data *UNUSED(vedata), Object *UNUSED(ob))
+void EEVEE_probes_cache_add(EEVEE_SceneLayerData *UNUSED(sldata), Object *UNUSED(ob))
{
return;
}
-void EEVEE_probes_cache_finish(EEVEE_Data *UNUSED(vedata))
+void EEVEE_probes_cache_finish(EEVEE_SceneLayerData *UNUSED(sldata))
{
return;
}
-void EEVEE_probes_update(EEVEE_Data *UNUSED(vedata))
+void EEVEE_probes_update(EEVEE_SceneLayerData *UNUSED(sldata))
{
return;
}
-void EEVEE_refresh_probe(EEVEE_Data *vedata)
+void EEVEE_refresh_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl)
{
- EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_TextureList *txl = vedata->txl;
- EEVEE_PassList *psl = vedata->psl;
- EEVEE_StorageList *stl = vedata->stl;
- EEVEE_ProbesInfo *pinfo = stl->probes;
+ EEVEE_ProbesInfo *pinfo = sldata->probes;
float projmat[4][4];
@@ -225,17 +213,17 @@ void EEVEE_refresh_probe(EEVEE_Data *vedata)
mul_m4_m4m4(pinfo->probemat[i], projmat, cubefacemat[i]);
}
- DRW_framebuffer_bind(fbl->probe_fb);
+ DRW_framebuffer_bind(sldata->probe_fb);
DRW_draw_pass(psl->probe_background);
/* 2 - Let gpu create Mipmaps for Filtered Importance Sampling. */
/* Bind next framebuffer to be able to gen. mips for probe_rt. */
- DRW_framebuffer_bind(fbl->probe_filter_fb);
- DRW_texture_generate_mipmaps(txl->probe_rt);
+ DRW_framebuffer_bind(sldata->probe_filter_fb);
+ DRW_texture_generate_mipmaps(sldata->probe_rt);
/* 3 - Render to probe array to the specified layer, do prefiltering. */
/* Detach to rebind the right mipmap. */
- DRW_framebuffer_texture_detach(txl->probe_pool);
+ DRW_framebuffer_texture_detach(sldata->probe_pool);
float mipsize = PROBE_SIZE;
const int maxlevel = (int)floorf(log2f(PROBE_SIZE));
const int min_lod_level = 3;
@@ -279,10 +267,10 @@ void EEVEE_refresh_probe(EEVEE_Data *vedata)
pinfo->lodfactor = bias + 0.5f * log((float)(PROBE_CUBE_SIZE * PROBE_CUBE_SIZE) * pinfo->invsamples_ct) / log(2);
pinfo->lodmax = floorf(log2f(PROBE_CUBE_SIZE)) - 2.0f;
- DRW_framebuffer_texture_attach(fbl->probe_filter_fb, txl->probe_pool, 0, i);
- DRW_framebuffer_viewport_size(fbl->probe_filter_fb, mipsize, mipsize);
+ DRW_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->probe_pool, 0, i);
+ DRW_framebuffer_viewport_size(sldata->probe_filter_fb, mipsize, mipsize);
DRW_draw_pass(psl->probe_prefilter);
- DRW_framebuffer_texture_detach(txl->probe_pool);
+ DRW_framebuffer_texture_detach(sldata->probe_pool);
mipsize /= 2;
CLAMP_MIN(mipsize, 1);
@@ -290,13 +278,13 @@ void EEVEE_refresh_probe(EEVEE_Data *vedata)
/* For shading, save max level of the octahedron map */
pinfo->lodmax = (float)(maxlevel - min_lod_level) - 1.0f;
/* reattach to have a valid framebuffer. */
- DRW_framebuffer_texture_attach(fbl->probe_filter_fb, txl->probe_pool, 0, 0);
+ DRW_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->probe_pool, 0, 0);
/* 4 - Compute spherical harmonics */
/* Tweaking parameters to balance perf. vs precision */
pinfo->shres = 16; /* Less texture fetches & reduce branches */
pinfo->lodfactor = 4.0f; /* Improve cache reuse */
- DRW_framebuffer_bind(fbl->probe_sh_fb);
+ DRW_framebuffer_bind(sldata->probe_sh_fb);
DRW_draw_pass(psl->probe_sh_compute);
DRW_framebuffer_read_data(0, 0, 9, 1, 3, 0, (float *)pinfo->shcoefs);
}
@@ -306,4 +294,17 @@ void EEVEE_probes_free(void)
DRW_SHADER_FREE_SAFE(e_data.probe_filter_sh);
DRW_SHADER_FREE_SAFE(e_data.probe_spherical_harmonic_sh);
DRW_TEXTURE_FREE_SAFE(e_data.hammersley);
-} \ No newline at end of file
+}
+
+void EEVEE_scene_layer_probes_free(EEVEE_SceneLayerData *sldata)
+{
+ MEM_SAFE_FREE(sldata->probes);
+ DRW_UBO_FREE_SAFE(sldata->probe_ubo);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_fb);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_filter_fb);
+ DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_sh_fb);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_depth_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_sh);
+}
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 7285b3c3311..12cdf04a826 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -175,6 +175,12 @@ void DRW_texture_free(struct GPUTexture *tex);
struct GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data);
void DRW_uniformbuffer_update(struct GPUUniformBuffer *ubo, const void *data);
void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo);
+#define DRW_UBO_FREE_SAFE(ubo) do { \
+ if (ubo != NULL) { \
+ DRW_uniformbuffer_free(ubo); \
+ ubo = NULL; \
+ } \
+} while (0)
/* Buffers */
#define MAX_FBO_TEX 5
@@ -188,7 +194,6 @@ typedef struct DRWFboTexture {
void DRW_framebuffer_init(
struct GPUFrameBuffer **fb, void *engine_type, int width, int height,
DRWFboTexture textures[MAX_FBO_TEX], int textures_len);
-void DRW_framebuffer_free(struct GPUFrameBuffer *fb);
void DRW_framebuffer_bind(struct GPUFrameBuffer *fb);
void DRW_framebuffer_clear(bool color, bool depth, bool stencil, float clear_col[4], float clear_depth);
void DRW_framebuffer_read_data(int x, int y, int w, int h, int channels, int slot, float *data);
@@ -196,6 +201,13 @@ void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, struct GPUTexture
void DRW_framebuffer_texture_detach(struct GPUTexture *tex);
void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth);
void DRW_framebuffer_viewport_size(struct GPUFrameBuffer *UNUSED(fb_read), int w, int h);
+void DRW_framebuffer_free(struct GPUFrameBuffer *fb);
+#define DRW_FRAMEBUFFER_FREE_SAFE(fb) do { \
+ if (fb != NULL) { \
+ DRW_framebuffer_free(fb); \
+ fb = NULL; \
+ } \
+} while (0)
void DRW_transform_to_display(struct GPUTexture *tex);