Page MenuHome

Fix T89204: slow repeated rendering with GPUOffscreen.draw_view3d.
ClosedPublic

Authored by Christian Stolze (regcs) on Nov 16 2021, 12:32 PM.

Details

Summary

Cache the GPUViewport so the framebuffers and associated textures are not reallocated each time.
This fixes the initial patch (d03b26edbdc3) which was reverted due to issues with GPUViewport
updates. A new function was introduced which takes care of updating views for viewports bound to a GPUOffscreen.

Diff Detail

Repository
rB Blender
Branch
blender-v3.0-release
Build Status
Buildable 18717
Build 18717: arc lint + arc unit

Event Timeline

Christian Stolze (regcs) requested review of this revision.Nov 16 2021, 12:32 PM
Christian Stolze (regcs) created this revision.

From the comment it appears that DRW_draw_render_loop_ex is used for regular drawing as well, not just offscreen. I don't think that should be affected?

From what I understand DRW_notify_view_update takes care of this for regular drawing, so perhaps a new function similar to for offscreen could be added.

But I'm not sure which solution @Clément Foucault (fclem) and @Jeroen Bakker (jbakker) think is best here.

From the comment it appears that DRW_draw_render_loop_ex is used for regular drawing as well, not just offscreen. I don't think that should be affected?

Yes, it is used for regular drawing as well. At the moment I don't see where this could cause issues, but I see that it would be safer to update elsewhere.

From what I understand DRW_notify_view_update takes care of this for regular drawing, so perhaps a new function similar to for offscreen could be added.

Suggestion:
Instead of updating the offscreen viewport inside DRW_draw_render_loop_ex(), we introduce a DRW_notify_view_update_offscreen, which takes care of the offscreen viewport updating.
In contrast to DRW_notify_view_update() the offscreen-specific function is not called on depsgraph updates, but inside DRW_draw_render_loop_offscreen(). The latter is called by the offscreen drawing pipeline prior to DRW_draw_render_loop_ex(). That way we'd get the offscreen viewport update out of DRW_draw_render_loop_ex() as you suggested.

What do you think?

I agree the update should be put out of DRW_draw_render_loop_ex. However, it is not clear to me how to pass the update down to the offscreen drawing. Do you assume there is a view update because there is a redraw? Or maybe it's not par of this patch.

@Clément Foucault (fclem) It is part of the current patch and executed during redrawing, yes. In the current patch the viewport of the GPUOffscreen is tagged for update upon calling the GPUOffscreen.draw_view3d() (see line 364 of source/blender/python/gpu/gpu_py_offscreen.c in the patch). During each redrawing, drw_engines_offscreen_ensure(void) checks for the tag and in case the viewport is tagged, requests a view_update before drawing (see line 1028 of source/blender/draw/intern/draw_manager.c). So, upon each GPUOffscreen.draw_view3d() call a view update is enforced.

I will prepare a revision, which shifts a modified drw_engines_offscreen_ensure() call into the DRW_draw_render_loop_offscreen().

Christian Stolze (regcs) updated this revision to Diff 44843.EditedNov 16 2021, 11:28 PM
  • shifted the view update out of the general drawing loop into the offscreen drawing loop

Looks good to me. Be sure to apply clang-format.

  • apply clang-format for patch D13235.

@Clément Foucault (fclem) @Jeroen Bakker (jbakker) Is the formatting ok or does the patch require any other modifications? If everything is fine, it would be great if you could accept the patch because Brecht signed of and assigned you as reviewer. :)

Thanks! I will commit the patch.

This revision is now accepted and ready to land.Nov 17 2021, 8:40 PM