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>2021-09-29 20:53:28 +0300
committerClément Foucault <foucault.clem@gmail.com>2021-09-29 20:53:28 +0300
commit84bba36429acbafc1bccd0b0b22e99e73b48398b (patch)
tree2b8b427ad1c877d50222755acfc856d3ed619c69 /source/blender/draw/intern/draw_view_data.cc
parent56b601e3a07d20b58da3b11a8dd17ce55cb2c5f2 (diff)
Viewport Compositor: Fix memory leak after rendering multi-scenes
This was caused by the per view `draw_view` not being freed correctly. Fixing this also caused issue because the `draw_view` would keep ownership of the renderbuffer and would free it a second time. Moving all renderbuffers ownership to `draw_view` for now.
Diffstat (limited to 'source/blender/draw/intern/draw_view_data.cc')
-rw-r--r--source/blender/draw/intern/draw_view_data.cc50
1 files changed, 29 insertions, 21 deletions
diff --git a/source/blender/draw/intern/draw_view_data.cc b/source/blender/draw/intern/draw_view_data.cc
index aa7f666173c..d793e07b0e6 100644
--- a/source/blender/draw/intern/draw_view_data.cc
+++ b/source/blender/draw/intern/draw_view_data.cc
@@ -61,45 +61,53 @@ DRWViewData *DRW_view_data_create(ListBase *engine_types)
return view_data;
}
+/* TODO(fclem): This is just a way to get something working quickly.
+ * Eventually, it would be the responsibility of the draw engine to fill each buffer
+ * directly. And we could drop the texture list and framebuffer list alltogether. */
void DRW_view_data_color_from_compositor_scene(DRWViewData *view_data,
DRWRenderScene *rscene,
int view)
{
+ DefaultFramebufferList *dfbl = &view_data->dfbl;
+ DefaultTextureList *dtxl = &view_data->dtxl;
+
+ int list_size[2] = {UNPACK2(view_data->texture_list_size)};
+
/* Ensure correct size of the render buffers.
* Assumes DRW_view_data_texture_list_size_validate() was run first
* and texture_list_size is up to date. */
- GPUTexture **tex_p = &rscene->views[view].combined.pass_tx;
- if (*tex_p != NULL) {
- int tex_size[2] = {GPU_texture_width(*tex_p), GPU_texture_height(*tex_p)};
- if (!equals_v2v2_int(tex_size, view_data->texture_list_size)) {
- GPU_TEXTURE_FREE_SAFE(*tex_p);
+ if (dtxl->color != NULL) {
+ int tex_size[2] = {GPU_texture_width(dtxl->color), GPU_texture_height(dtxl->color)};
+ if (!equals_v2v2_int(tex_size, list_size)) {
+ GPU_TEXTURE_FREE_SAFE(dtxl->color);
+ GPU_TEXTURE_FREE_SAFE(dtxl->depth);
}
}
- if (*tex_p == NULL) {
- *tex_p = GPU_texture_create_2d(
- rscene->scene->id.name, UNPACK2(view_data->texture_list_size), 1, GPU_RGBA16F, NULL);
+ if (dtxl->color == NULL) {
+ dtxl->color = GPU_texture_create_2d(
+ rscene->scene->id.name, UNPACK2(list_size), 1, GPU_RGBA16F, NULL);
+ dtxl->depth = GPU_texture_create_2d(
+ rscene->scene->id.name, UNPACK2(list_size), 1, GPU_DEPTH24_STENCIL8, NULL);
}
- /* TODO(fclem): This is just a way to get something working quickly.
- * Eventually, it would be the responsibility of the draw engine to fill each buffer
- * directly. And we could drop the texture list and framebuffer list alltogether. */
+ /* Set the pointers. But keep ownership. */
+ rscene->views[view].combined.pass_tx = dtxl->color;
- DefaultFramebufferList *dfbl = &view_data->dfbl;
- DefaultTextureList *dtxl = &view_data->dtxl;
-
- GPU_framebuffer_ensure_config(&rscene->views[view].combined.pass_fb,
+ GPU_framebuffer_ensure_config(&dfbl->default_fb,
{
GPU_ATTACHMENT_TEXTURE(dtxl->depth),
- GPU_ATTACHMENT_TEXTURE(rscene->views[view].combined.pass_tx),
+ GPU_ATTACHMENT_TEXTURE(dtxl->color),
+ });
+ GPU_framebuffer_ensure_config(&dfbl->depth_only_fb,
+ {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_NONE,
});
- GPU_framebuffer_ensure_config(&rscene->views[view].combined.color_only_fb,
+ GPU_framebuffer_ensure_config(&dfbl->color_only_fb,
{
GPU_ATTACHMENT_NONE,
- GPU_ATTACHMENT_TEXTURE(rscene->views[view].combined.pass_tx),
+ GPU_ATTACHMENT_TEXTURE(dtxl->color),
});
- dtxl->color = rscene->views[view].combined.pass_tx;
- dfbl->default_fb = rscene->views[view].combined.pass_fb;
- dfbl->color_only_fb = rscene->views[view].combined.color_only_fb;
}
void DRW_view_data_default_lists_from_viewport(DRWViewData *view_data, GPUViewport *viewport)