Grease Pencil: drawing shapes on surface causes intense viewport flickering #65955

Closed
opened 2019-06-20 13:25:54 +02:00 by MACHIN3 · 13 comments

System Information
Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits
Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67

Blender Version
Broken: version: 2.80 (sub 74), branch: master, commit date: 2019-06-19 18:29, hash: d30f72dfd8

Drawing GP shapes on the surface of an object causes viewport flickering.

See video demo .

grease_pencil_shape_on_surface_viewport_flicker.blend

Exact steps for others to reproduce the error

  • open the blend file
    • everything is setup for surface drawing already
  • start drawing lines or other shapes
    • the viewport should flicker(cyclce through various buffers?)
**System Information** Operating system: Linux-4.13.10-041310-generic-x86_64-with-debian-stretch-sid 64 Bits Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 390.67 **Blender Version** Broken: version: 2.80 (sub 74), branch: master, commit date: 2019-06-19 18:29, hash: `d30f72dfd8` Drawing GP shapes on the surface of an object causes viewport flickering. See [video demo ](https://www.youtube.com/watch?v=Wa7clEDLeFI). [grease_pencil_shape_on_surface_viewport_flicker.blend](https://archive.blender.org/developer/F7352773/grease_pencil_shape_on_surface_viewport_flicker.blend) **Exact steps for others to reproduce the error** * open the blend file * everything is setup for surface drawing already * start drawing lines or other shapes * the viewport should flicker(cyclce through various buffers?)
Author

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3

Added subscriber: @MizManFryinPan

Added subscriber: @MizManFryinPan

Can confirm. Doesn't work on 'd30f72dfd8ac'
Seems to have worked fine on Hash: '12da679fa094' though it could've also worked later on. Its just the latest one before today's build that I have on my computer.

Can confirm. Doesn't work on 'd30f72dfd8ac' Seems to have worked fine on Hash: '12da679fa094' though it could've also worked later on. Its just the latest one before today's build that I have on my computer.

Added subscriber: @brecht

Added subscriber: @brecht
Clément Foucault was assigned by Brecht Van Lommel 2019-06-20 16:53:40 +02:00

Caused by 741641f4c3.

Caused by 741641f4c3.

Ok it is caused by a VERY bad usage of DRW in GPencil. My patch just unveiled the problem.

Ok it is caused by a VERY bad usage of DRW in GPencil. My patch just unveiled the problem.
Clément Foucault removed their assignment 2019-06-21 01:31:10 +02:00
Antonio Vazquez was assigned by Clément Foucault 2019-06-21 01:31:10 +02:00

Added subscribers: @antoniov, @fclem

Added subscribers: @antoniov, @fclem

@antoniov The issue comes from these lines. When drawing a line, the draw depth function is called first, and only used basic engine and GPencil. But then when the viewport is redrawn, an other set of engine is enabled which reset all engines data for this viewport.

This makes stl->storage->buffer_stroke false even if the stl->storage->buffer_stroke is still valid. That leads to memory leak and other
So the easy fix should be to free just after finishing drawing.

In the long run we should reuse the batches to avoid memory allocations.

Source of the issue.

        if (stl->storage->buffer_stroke) {
          GPU_BATCH_DISCARD_SAFE(e_data->batch_buffer_stroke);
          MEM_SAFE_FREE(e_data->batch_buffer_stroke);
          stl->storage->buffer_stroke = false;
        }
      ...
      /* temp textures for ping-pong buffers */
      e_data.temp_depth_tx_a = DRW_texture_pool_query_2d(
          size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type);
      ...

Don't use e_data for things that will change or can be volatile. Use stl->g_data for that and be sure to reset it before reuse

Pretty much all these vars should be inside stl->g_data

  /* textures */
  struct GPUTexture *background_depth_tx;
  struct GPUTexture *background_color_tx;

  struct GPUTexture *gpencil_blank_texture;

  /* runtime pointers texture */
  struct GPUTexture *input_depth_tx;
  struct GPUTexture *input_color_tx;

  /* working textures */
  struct GPUTexture *temp_color_tx_a;
  struct GPUTexture *temp_depth_tx_a;

  struct GPUTexture *temp_color_tx_b;
  struct GPUTexture *temp_depth_tx_b;

  struct GPUTexture *temp_color_tx_fx;
  struct GPUTexture *temp_depth_tx_fx;

  /* for buffer only one batch is nedeed because the drawing is only of one stroke */
  GPUBatch *batch_buffer_stroke;
  GPUBatch *batch_buffer_fill;
  GPUBatch *batch_buffer_ctrlpoint;

  /* grid geometry */
  GPUBatch *batch_grid;

If you are using temp textures, then you cannot assume they will be the same when the next redraw comes up. Use txl and real texture for that.

@antoniov The issue comes from these lines. When drawing a line, the draw depth function is called first, and only used basic engine and GPencil. But then when the viewport is redrawn, an other set of engine is enabled which reset all engines data for this viewport. This makes `stl->storage->buffer_stroke` false even if the stl->storage->buffer_stroke is still valid. That leads to memory leak and other So the easy fix should be to free just after finishing drawing. In the long run we should reuse the batches to avoid memory allocations. Source of the issue. ``` if (stl->storage->buffer_stroke) { GPU_BATCH_DISCARD_SAFE(e_data->batch_buffer_stroke); MEM_SAFE_FREE(e_data->batch_buffer_stroke); stl->storage->buffer_stroke = false; } ``` ``` ... /* temp textures for ping-pong buffers */ e_data.temp_depth_tx_a = DRW_texture_pool_query_2d( size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type); ... ``` Don't use e_data for things that will change or can be volatile. Use stl->g_data for that and be sure to reset it before reuse Pretty much all these vars should be inside stl->g_data ``` /* textures */ struct GPUTexture *background_depth_tx; struct GPUTexture *background_color_tx; struct GPUTexture *gpencil_blank_texture; /* runtime pointers texture */ struct GPUTexture *input_depth_tx; struct GPUTexture *input_color_tx; /* working textures */ struct GPUTexture *temp_color_tx_a; struct GPUTexture *temp_depth_tx_a; struct GPUTexture *temp_color_tx_b; struct GPUTexture *temp_depth_tx_b; struct GPUTexture *temp_color_tx_fx; struct GPUTexture *temp_depth_tx_fx; /* for buffer only one batch is nedeed because the drawing is only of one stroke */ GPUBatch *batch_buffer_stroke; GPUBatch *batch_buffer_fill; GPUBatch *batch_buffer_ctrlpoint; /* grid geometry */ GPUBatch *batch_grid; ``` If you are using temp textures, then you cannot assume they will be the same when the next redraw comes up. Use txl and real texture for that.

@fclem I will take a look of the bug, but not sure now it's the moment to make the other changes so near of 2.80 release date. I thinkis better wait for 2.81.

@fclem I will take a look of the bug, but not sure now it's the moment to make the other changes so near of 2.80 release date. I thinkis better wait for 2.81.

I have tested and in Windows 10 NVIDIA RTX2080TI I'm unable to reproduce it.

EDIT: With a new file I can reproduce it now.

I have tested and in Windows 10 NVIDIA RTX2080TI I'm unable to reproduce it. EDIT: With a new file I can reproduce it now.

Working in the fix in D5115

Working in the fix in [D5115](https://archive.blender.org/developer/D5115)

This issue was referenced by 8bf1977d31

This issue was referenced by 8bf1977d311fc7d8b5979fdd6ac5b982076b1e60

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#65955
No description provided.