Page MenuHome

View3D: Optimize depth buffer reading
Changes PlannedPublic

Authored by Germano Cavalcante (mano-wii) on Feb 23 2021, 9:53 PM.

Details

Summary

This patch proposes to optimize Auto Depth and operations involving
occlusion in Grease Pencil

Current issue:
When AutoDepth is enabled, at each Zoom event, the 3DView is redrawn to
get a customized depth buffer.

With this depth buffer created, a maximum of 4 GPU_framebuffer_read_depth
operations are performed with buffers of different sizes, each having to
create and destroy a temporary framebuffer due to different context.

Grease Pencil and Annotations have similar issues. However,
occlusion operations in these cases call the read depth operation on
the GPU for each point.

Main solution:
This patch proposes to reuse the viewport's depthbuffer for Auto Depth.

The only differences I identified are that, in the custom depth buffer,
Grease Pencil objects are not drawn and objects "in_front" are drawn
as if they were not "in_front".

With this patch now Grease Pencil are drawn and objects "in_front"
are prioritized.

This patch also proposes the use of a cached depth buffer for operations
in Grease Pencil and Annotation.

Other changes in the patch:

  • The gl_clip_alpha property, found in the users' preferences, is not used, so it was removed.
  • ED_view3d_backbuf_depth_validate, ED_view3d_draw_depth and ED_view3d_draw_depth_gpencil were unified in ED_view3d_depth_override with modes (modified from ED_view3d_autodist_init)
  • ED_view3d_depth_read_cached was created to replace ED_view3d_autodist_depth and use the depth buffer salved in cache (rv3d->depths)
  • ED_view3d_depth_read_cached_seg was created to replace ED_view3d_autodist_depth_seg and use the depth buffer salved in cache (rv3d->depths)
  • GreasePencil and Anotations operations now use the depth buffer salved in cache
  • The BLI_array_iter_nearest_to_point_v2 utility has been created. It is used to find closest values to a point in the selection buffer and the depth buffer
  • The V3D_INVALID_BACKBUF flag has been replaced with V3D_RUNTIME_DEPTHBUF_OVERRIDDEN

Diff Detail

Repository
rB Blender
Branch
gpu_py-h (branched from master)
Build Status
Buildable 13096
Build 13096: arc lint + arc unit

Event Timeline

Germano Cavalcante (mano-wii) requested review of this revision.Feb 23 2021, 9:53 PM
Germano Cavalcante (mano-wii) created this revision.
Germano Cavalcante (mano-wii) planned changes to this revision.Feb 23 2021, 10:14 PM

Problems with Eevee and Cycles

Could we get any before and after numbers or percentatge on the optimization you made?, plis

  • Fixes Auto Depth with Cycles and Eevee
  • Auto Depth: Compute a depth buffer when the Cycles is set without overlays

Could we get any before and after numbers or percentatge on the optimization you made?, plis

With Auto Depth I do not expect very significant changes as the depth only engine is very simple and fast.
Basically now this "depth engine" is no longer used during Zoom with Auto Depth which is equivalent to one single drawing frame less.
But I will test in complex scenes.

For Grease Pencil operations with depth testing I was able to visually see the difference.
For example, here the Eraser tool with the Occlude option enabled:

Also note that this option used to fail sometimes.

Germano Cavalcante (mano-wii) planned changes to this revision.Mar 16 2021, 4:42 PM

Split into different patches.