Refactor: Select Engine: Draw actual indices instead of 'Original Indices' #119977

Merged
Germano Cavalcante merged 6 commits from mano-wii/blender:draw_select_id_cleanup into main 2024-04-16 14:58:12 +02:00

The selection engine renders a uint texture with the selectable mesh indices.

When these meshes have modifiers, the original index is used for the texture.

However this does not seem to be necessary. The real mesh indexes can be used in the texture and, only at the end, the original index can be retrieved on the CPU itself.

Advantages of this approach:

  • Optimizes the code to generate selection buffers.
  • Makes the select id texture more informative as it identifies the real elements instead of the original ones.

I thought of this when investigating #119932.
To fix #119932 more conveniently, it would be interesting to select the real edge of an evaluated mesh and then use the original index on that edge.

The selection engine renders a uint texture with the selectable mesh indices. When these meshes have modifiers, the original index is used for the texture. However this does not seem to be necessary. The real mesh indexes can be used in the texture and, only at the end, the original index can be retrieved on the CPU itself. Advantages of this approach: - Optimizes the code to generate selection buffers. - Makes the select id texture more informative as it identifies the real elements instead of the original ones. --- I thought of this when investigating #119932. To fix #119932 more conveniently, it would be interesting to select the real edge of an evaluated mesh and then use the original index on that edge.
Germano Cavalcante added 1 commit 2024-03-27 18:58:42 +01:00
f7d2a77871 Cleanup: Select Engine: Draw actual indices instead of 'Original Index'
The selection engine renders a uint texture with the selectable mesh indices.

When these meshes have modifiers, the original index is used for the texture.

However this does not seem to be necessary. The real mesh indexes can be used in the texture and, only at the end, the original index can be retrieved on the CPU itself.

Advantages of this approach:
- Optimizes the code to generate selection buffers.
- Makes the select id texture more informative as it identifies the real elements instead of the original ones.
Germano Cavalcante requested review from Clément Foucault 2024-03-27 18:58:58 +01:00
Member

How is this a "Cleanup"? At the very least it's a refactor, or a performance improvement. But it seems to add complexity everywhere in most places in this diff.

How is this a "Cleanup"? At the very least it's a refactor, or a performance improvement. But it seems to add complexity everywhere in most places in this diff.
Hans Goudey reviewed 2024-03-27 19:11:58 +01:00
@ -17,6 +17,7 @@ enum MeshForeachFlag {
void BKE_mesh_foreach_mapped_vert(
const Mesh *mesh,
const bool use_orig_index,
Member

const doesn't have meaning in the declaration for arguments passed by value

`const` doesn't have meaning in the declaration for arguments passed by value
@ -94,3 +94,3 @@
DRW_shgroup_call_no_cull(face_shgrp, geom_facedots, ob);
}
*r_face_offset = initial_offset + em->bm->totface;
*r_face_offset = initial_offset + mesh->faces_num;
Member

Seems this change is unrelated? Or it's a bug fix that could be applied separately?

Seems this change is unrelated? Or it's a bug fix that could be applied separately?
Author
Member

This change is related, since this offset indicates the number of indexes of the object.
Before we only had the original indices, now we have the real indices that can be greater or less than the original indices.
em->bm->totface: number of original indices
mesh->faces_num: number real of indices

This change is related, since this offset indicates the number of indexes of the object. Before we only had the original indices, now we have the real indices that can be greater or less than the original indices. `em->bm->totface`: number of original indices `mesh->faces_num`: number real of indices
Author
Member

How is this a "Cleanup"? At the very least it's a refactor, or a performance improvement. But it seems to add complexity everywhere in most places in this diff.

In fact, since we have changes to the DRW API and performance, Refactor is the correct one.
I try to prioritize the name Cleanup when there are no functional changes and the changes are more localized, (even when adding complexity to the code), but this time I exaggerated.

> How is this a "Cleanup"? At the very least it's a refactor, or a performance improvement. But it seems to add complexity everywhere in most places in this diff. In fact, since we have changes to the DRW API and performance, `Refactor` is the correct one. I try to prioritize the name `Cleanup` when there are no functional changes and the changes are more localized, (even when adding complexity to the code), but this time I exaggerated.
Germano Cavalcante reopened this pull request 2024-03-27 19:52:02 +01:00
Germano Cavalcante changed title from Cleanup: Select Engine: Draw actual indices instead of 'Original Index' to Refactor: Select Engine: Draw actual indices instead of 'Original Indices' 2024-03-27 19:52:44 +01:00
Germano Cavalcante added 2 commits 2024-04-15 15:56:15 +02:00
Author
Member

The PR was mixing two changes:

  • Changes to the selection engine and DRW_select API to use orig_index only on the CPU after reading the pixel with the element's real index.
  • Changed the mesh_iterators API to have a "use_orig_index" parameter.

This increased changes too much and made review difficult.

The PR is now edited to only have the changes in the DRW manager.

The PR was mixing two changes: - Changes to the selection engine and DRW_select API to use orig_index only on the CPU after reading the pixel with the element's real index. - Changed the mesh_iterators API to have a "use_orig_index" parameter. This increased changes too much and made review difficult. The PR is now edited to only have the changes in the DRW manager.
Germano Cavalcante requested review from Hans Goudey 2024-04-15 16:02:26 +02:00
Hans Goudey approved these changes 2024-04-15 16:14:07 +02:00
Dismissed
Hans Goudey left a comment
Member

This change is a nice simplification.

This change is a nice simplification.
@ -70,2 +70,3 @@
bool DRW_select_buffer_elem_get(uint sel_id, uint *r_elem, uint *r_base_index, char *r_elem_type);
bool DRW_select_buffer_elem_get(
uint sel_id, uint *r_elem, uint *r_base_index, char *r_elem_type, const bool use_orig_index);
Member

const bool -> bool

`const bool` -> `bool`
mano-wii marked this conversation as resolved
@ -435,2 +438,4 @@
}
if (use_orig_index) {
Object *object = select_ctx->objects[base_index];
Member

Use const pointers for the object and mesh

Use const pointers for the object and mesh
mano-wii marked this conversation as resolved
@ -436,1 +439,4 @@
if (use_orig_index) {
Object *object = select_ctx->objects[base_index];
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object);
Member

How does this work for GPU subdivision where this lazily calculates the CPU mesh?

How does this work for GPU subdivision where this lazily calculates the CPU mesh?
Author
Member

The code was actually forcing the generation of the subdivided mesh to be accessed by the CPU. And the edge orig_index was all zeros. Problem fixed now.

The code was actually forcing the generation of the subdivided mesh to be accessed by the CPU. And the edge orig_index was all zeros. Problem fixed now.
@ -437,0 +440,4 @@
if (use_orig_index) {
Object *object = select_ctx->objects[base_index];
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object);
const int *orig_index = reinterpret_cast<const int *>(
Member

reinterpret_cast -> static_cast

`reinterpret_cast` -> `static_cast`
mano-wii marked this conversation as resolved
@ -437,0 +441,4 @@
Object *object = select_ctx->objects[base_index];
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object);
const int *orig_index = reinterpret_cast<const int *>(
CustomData_get_layer(elem_type == SCE_SELECT_FACE ? &mesh_eval->face_data :
Member

It would be better to split this to a separate function that takes the elem_type and returns a custom data reference

It would be better to split this to a separate function that takes the elem_type and returns a custom data reference
mano-wii marked this conversation as resolved
Hans Goudey requested changes 2024-04-15 16:14:47 +02:00
Dismissed
Hans Goudey left a comment
Member

Actually didn't mean to accept yet

Actually didn't mean to accept yet
Germano Cavalcante added 1 commit 2024-04-15 17:13:02 +02:00
Author
Member

There was an error with Subdivision.
It should now be all OK.

There was an error with Subdivision. It should now be all OK.
Hans Goudey reviewed 2024-04-15 18:26:31 +02:00
@ -396,0 +401,4 @@
case SCE_SELECT_EDGE:
return &mesh_eval->edge_data;
case SCE_SELECT_VERTEX:
default:
Member

I don't think there should be a default case here. Better to add BLI_assert_unreachable(); and return nullptr outside of the switch.

I don't think there should be a default case here. Better to add `BLI_assert_unreachable();` and `return nullptr` outside of the switch.
mano-wii marked this conversation as resolved
Hans Goudey approved these changes 2024-04-15 18:26:45 +02:00
Germano Cavalcante added 2 commits 2024-04-15 22:44:30 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
70f2891190
Silence warnings | BLI_assert_unreachable
Clément Foucault approved these changes 2024-04-16 11:19:06 +02:00

@blender-bot build

@blender-bot build
Germano Cavalcante merged commit 157c4cfbc1 into main 2024-04-16 14:58:12 +02:00
Germano Cavalcante deleted branch draw_select_id_cleanup 2024-04-16 14:58:19 +02:00
Author
Member

Unfortunately I had to revert the commit because I failed to adjust the functions that generate bitmap with the original indexes:

  • DRW_select_buffer_bitmap_from_circle
  • DRW_select_buffer_bitmap_from_poly
  • DRW_select_buffer_bitmap_from_rect

Adapting these functions is more complicated than it seems, as it can cause performance penalties if the CPU has to be used to convert the buffer to original indices :\

Unfortunately I had to revert the commit because I failed to adjust the functions that generate bitmap with the original indexes: - `DRW_select_buffer_bitmap_from_circle` - `DRW_select_buffer_bitmap_from_poly` - `DRW_select_buffer_bitmap_from_rect` Adapting these functions is more complicated than it seems, as it can cause performance penalties if the CPU has to be used to convert the buffer to original indices :\\
Member

It still seems worth doing, since it changes the performance cost from every single redraw to only when selection happens.

It still seems worth doing, since it changes the performance cost from every single redraw to only when selection happens.
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
3 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#119977
No description provided.