DrawManager: Make instance data persistent.
When resizing a viewport all engine instance data was cleared. This wasn't the intended design and lead to performance regressions in the image engine. This patch makes sure that the instance data isn't cleared when the viewport size changes. When using instance data, draw engines are responsible to update the textures accordingly. This could also reduce flickering/stalling when resizing the viewport in eevee-next. Fixes T95428. Reviewed By: fclem Maniphest Tasks: T95428 Differential Revision: https://developer.blender.org/D14874
This commit is contained in:
parent
acafc7327e
commit
a7417ba845
Notes:
blender-bot
2023-02-14 10:54:29 +01:00
Referenced by issue #95428, Regression: 3.1 & 3.2 Image/UV Editor poor performance (Byte textures, window dragging, maximizing area)
|
@ -75,8 +75,10 @@ struct IMAGE_InstanceData {
|
|||
TextureInfo &info = texture_infos[i];
|
||||
const bool is_allocated = info.texture != nullptr;
|
||||
const bool is_visible = info.visible;
|
||||
const bool should_be_freed = !is_visible && is_allocated;
|
||||
const bool should_be_created = is_visible && !is_allocated;
|
||||
const bool resolution_changed = assign_if_different(info.last_viewport_size,
|
||||
float2(DRW_viewport_size_get()));
|
||||
const bool should_be_freed = is_allocated && (!is_visible || resolution_changed);
|
||||
const bool should_be_created = is_visible && (!is_allocated || resolution_changed);
|
||||
|
||||
if (should_be_freed) {
|
||||
GPU_texture_free(info.texture);
|
||||
|
|
|
@ -46,6 +46,8 @@ struct TextureInfo {
|
|||
*/
|
||||
GPUTexture *texture;
|
||||
|
||||
float2 last_viewport_size = float2(0.0f, 0.0f);
|
||||
|
||||
~TextureInfo()
|
||||
{
|
||||
if (batch != nullptr) {
|
||||
|
|
|
@ -88,7 +88,7 @@ void DRW_view_data_default_lists_from_viewport(DRWViewData *view_data, GPUViewpo
|
|||
});
|
||||
}
|
||||
|
||||
static void draw_viewport_engines_data_clear(ViewportEngineData *data)
|
||||
static void draw_viewport_engines_data_clear(ViewportEngineData *data, bool clear_instance_data)
|
||||
{
|
||||
DrawEngineType *engine_type = data->engine_type->draw_engine;
|
||||
const DrawEngineDataSize *data_size = engine_type->vedata_size;
|
||||
|
@ -103,7 +103,7 @@ static void draw_viewport_engines_data_clear(ViewportEngineData *data)
|
|||
MEM_SAFE_FREE(data->stl->storage[i]);
|
||||
}
|
||||
|
||||
if (data->instance_data) {
|
||||
if (clear_instance_data && data->instance_data) {
|
||||
BLI_assert(engine_type->instance_free != nullptr);
|
||||
engine_type->instance_free(data->instance_data);
|
||||
data->instance_data = nullptr;
|
||||
|
@ -120,7 +120,7 @@ static void draw_viewport_engines_data_clear(ViewportEngineData *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void draw_view_data_clear(DRWViewData *view_data)
|
||||
static void draw_view_data_clear(DRWViewData *view_data, bool free_instance_data)
|
||||
{
|
||||
GPU_FRAMEBUFFER_FREE_SAFE(view_data->dfbl.default_fb);
|
||||
GPU_FRAMEBUFFER_FREE_SAFE(view_data->dfbl.overlay_fb);
|
||||
|
@ -137,23 +137,20 @@ static void draw_view_data_clear(DRWViewData *view_data)
|
|||
GPU_TEXTURE_FREE_SAFE(view_data->dtxl.depth_in_front);
|
||||
|
||||
for (ViewportEngineData &engine : view_data->engines) {
|
||||
draw_viewport_engines_data_clear(&engine);
|
||||
draw_viewport_engines_data_clear(&engine, free_instance_data);
|
||||
}
|
||||
|
||||
view_data->texture_list_size[0] = view_data->texture_list_size[1] = 0;
|
||||
view_data->cache_time = 0.0f;
|
||||
}
|
||||
|
||||
void DRW_view_data_free(DRWViewData *view_data)
|
||||
{
|
||||
draw_view_data_clear(view_data);
|
||||
draw_view_data_clear(view_data, true);
|
||||
delete view_data;
|
||||
}
|
||||
|
||||
void DRW_view_data_texture_list_size_validate(DRWViewData *view_data, const int size[2])
|
||||
{
|
||||
if (!equals_v2v2_int(view_data->texture_list_size, size)) {
|
||||
draw_view_data_clear(view_data);
|
||||
draw_view_data_clear(view_data, false);
|
||||
copy_v2_v2_int(view_data->texture_list_size, size);
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +192,7 @@ void DRW_view_data_free_unused(DRWViewData *view_data)
|
|||
{
|
||||
for (ViewportEngineData &engine : view_data->engines) {
|
||||
if (view_data->enabled_engines.first_index_of_try(&engine) == -1) {
|
||||
draw_viewport_engines_data_clear(&engine);
|
||||
draw_viewport_engines_data_clear(&engine, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue