UV islands display issue - macOS Metal #126542

Closed
opened 2024-08-20 11:16:05 +02:00 by thibault-ging · 12 comments

Operating system: Mac Studio (Sonoma 14.5)
Graphics card: Apple M1 Max

Broken: 4.2.0
Broken: 4.3.0 alpha (baa20eb289)
Worked:

When selecting part of a big mesh, in the UV editor faces appear light orange but visuals of edges are everywhere on the screen, can't precisely work that way.
Everything working as usual though; created UV vertices, edges and faces can be manipulated. Just a visual pain because I can not see them well under all that UV web.
Only on certains meshes, so I assume it might be an issue with big meshes only (I work for WebGL devs so 40k triangles is quite a large mesh in my case).

Exact steps for others to reproduce the error
Select part of the mesh (already selected when opening the .blend file).

Operating system: Mac Studio (Sonoma 14.5) Graphics card: Apple M1 Max Broken: 4.2.0 Broken: 4.3.0 alpha (baa20eb28976) Worked: When selecting part of a big mesh, in the UV editor faces appear light orange but visuals of edges are everywhere on the screen, can't precisely work that way. Everything working as usual though; created UV vertices, edges and faces can be manipulated. Just a visual pain because I can not see them well under all that UV web. Only on certains meshes, so I assume it might be an issue with big meshes only (I work for WebGL devs so 40k triangles is quite a large mesh in my case). **Exact steps for others to reproduce the error** Select part of the mesh (already selected when opening the .blend file).
thibault-ging added the
Severity
Normal
Type
Bug
Status
Needs Triage
labels 2024-08-20 11:16:06 +02:00
Author

Has been like this for a long time (for all I can remember since I started working on this machine 1 year ago).

Has been like this for a long time (for all I can remember since I started working on this machine 1 year ago).
Member

I can confirm this issue in Blender 4.2.0 with a M1 Pro. Can't on a Windows computer. It's likely to be a Metal issue.

I don't currently know the steps to reproduce this issue from scratch. @thibault-ging Can you provide steps to reproduce this issue from a new file?

I will set to high severity as it's a bad issue.

I can confirm this issue in Blender 4.2.0 with a M1 Pro. Can't on a Windows computer. It's likely to be a Metal issue. I don't currently know the steps to reproduce this issue from scratch. @thibault-ging Can you provide steps to reproduce this issue from a new file? I will set to high severity as it's a bad issue.
Author

I figured, Blender seems to have multiple issues on Mac that I don't get on my pc at home.

I tried recreating it from a new file with Susans but have not succeeded. When I append the mesh from my project file into a new .blend the issue is visible though.

Thanks for taking the time.

I figured, Blender seems to have multiple issues on Mac that I don't get on my pc at home. I tried recreating it from a new file with Susans but have not succeeded. When I append the mesh from my project file into a new .blend the issue is visible though. Thanks for taking the time.
Alaska changed title from uv islands display issue to UV islands display issue - macOS Metal 2024-08-21 11:59:25 +02:00
Clément Foucault added the
Interest
Overlay
label 2024-08-23 09:57:24 +02:00
Clément Foucault self-assigned this 2024-09-05 13:15:11 +02:00

The root cause of the problem is that the Metal vertex fetch path does not consider the base index from the original render command. And this is used when the index buffer range of vertices is less than SHORT_MAX and not starting from 0.

The new Primitive Expansion API (which goal is to replace the Metal vertex fetch path) does the proper thing and is supposed to be used for UV drawing for the Overlay Next project #102179.

I will not take time to fix the Metal Vertex Fetch path and focus on the new implementation which should be default at the start of 4.4. However, it would be nice to fix for 4.2 and 4.3. So I will leave that to Apple to fix it.

The root cause of the problem is that the Metal vertex fetch path does not consider the base index from the original render command. And this is used when the index buffer range of vertices is less than SHORT_MAX and not starting from 0. The new Primitive Expansion API (which goal is to replace the Metal vertex fetch path) does the proper thing and is supposed to be used for UV drawing for the Overlay Next project #102179. I will not take time to fix the Metal Vertex Fetch path and focus on the new implementation which should be default at the start of 4.4. However, it would be nice to fix for 4.2 and 4.3. So I will leave that to Apple to fix it.
Clément Foucault added
Severity
Normal
and removed
Severity
High
labels 2024-09-09 17:11:51 +02:00

@James-McCarthy-4 This is the issue I was mentioning in the meeting today. I am not sure how hard is it to fix for 4.2 / 4.3.

But it will definitely be fixed in 4.4 after replacing the Overlay engine by Overlay next.

@James-McCarthy-4 This is the issue I was mentioning in the meeting today. I am not sure how hard is it to fix for 4.2 / 4.3. But it will definitely be fixed in 4.4 after replacing the Overlay engine by Overlay next.
Clément Foucault removed their assignment 2024-09-16 12:50:06 +02:00

@fclem Just to be clear when you say 'base-index' do you mean the indexBufferOffset in the draw command? And you're saying it's not being taken into account when you read the vertex_id in the shader?

@fclem Just to be clear when you say 'base-index' do you mean the _indexBufferOffset_ in the draw command? And you're saying it's not being taken into account when you read the [[ vertex_id ]] in the shader?

@James-McCarthy-4 Yes it is indexBufferOffset but in vertex, not in bytes. See gpu::IndexBuf::index_start_.

It is not taken into account inside the RESOLVE_VERTEX macro of the vertex fetch API.

#  define RESOLVE_VERTEX(v_id) \
    ((UNIFORM_SSBO_USES_INDEXED_RENDERING_STR > 0) ? \
         ((UNIFORM_SSBO_INDEX_MODE_U16_STR > 0) ? MTL_INDEX_DATA_U16[v_id] : \
                                                  MTL_INDEX_DATA_U32[v_id]) : \
         v_id)

It should be MTL_INDEX_DATA_U16[v_id] + index_start_. I guess it just needs to be passed as uniform.

@James-McCarthy-4 Yes it is `indexBufferOffset` but in vertex, not in bytes. See `gpu::IndexBuf::index_start_`. It is not taken into account inside the RESOLVE_VERTEX macro of the vertex fetch API. ``` # define RESOLVE_VERTEX(v_id) \ ((UNIFORM_SSBO_USES_INDEXED_RENDERING_STR > 0) ? \ ((UNIFORM_SSBO_INDEX_MODE_U16_STR > 0) ? MTL_INDEX_DATA_U16[v_id] : \ MTL_INDEX_DATA_U32[v_id]) : \ v_id) ``` It should be `MTL_INDEX_DATA_U16[v_id] + index_start_`. I guess it just needs to be passed as uniform.

@fclem Hi Clement, indexBufferOffset is just to used to shift the base of the provided index buffer. It's not something that should be added on to an index, the HW uses it when calculating the value of vertex_id to pass into a shader.

i.e. For 32bit indicies.
vertex_id = index_buffer[ vertex_index + (indexBaseOffset / 4)]

So possibly the issue lies somewhere else - unless I'm missing something.

@fclem Hi Clement, indexBufferOffset is just to used to shift the base of the provided index buffer. It's not something that should be added on to an index, the HW uses it when calculating the value of vertex_id to pass into a shader. i.e. For 32bit indicies. vertex_id = index_buffer[ vertex_index + (indexBaseOffset / 4)] So possibly the issue lies somewhere else - unless I'm missing something.

@fclem IIRC the behaviour for GL and Metal differs for values given for baseVertex maybe that's the issue?

@fclem IIRC the behaviour for GL and Metal differs for values given for _baseVertex_ maybe that's the issue?

@James-McCarthy-4 My bad. You are right. It is in fact index_base_ (or baseVertex) that should be added to the index value from the index buffer.

I believe the indexBufferOffset is already taken into account when binding the IBO as Storage buffer.

I am pretty sure the behavior of GL and Metal regarding baseVertex is exactly the same since we feed the same value for MTLDrawList::append and GLDrawList::append. But the Metal Vertex Fetch API does not honor this specific offset (which IIRC is only used for 16bit indices).

@James-McCarthy-4 My bad. You are right. It is in fact `index_base_` (or `baseVertex`) that should be added to the index value from the index buffer. I believe the `indexBufferOffset` is already taken into account when binding the IBO as Storage buffer. I am pretty sure the behavior of GL and Metal regarding `baseVertex` is exactly the same since we feed the same value for `MTLDrawList::append` and `GLDrawList::append`. But the Metal Vertex Fetch API does not honor this specific offset (which IIRC is only used for 16bit indices).

@fclem You're correct - I was thinking of gl_baseVertex which has no equivalent in Metal but I don't think that has any relevance here.

" But the Metal Vertex Fetch API does not honor this specific offset (which IIRC is only used for 16bit indices)."
vertex_id does include the baseVertex according to the Metal Language spec:
vertex_id - ushort or uint - The per-vertex identifier, which includes the base vertex value if one is specified.

(There's a good summary here of the differences between the APIs here: https://github.com/gpuweb/gpuweb/issues/901)

I'm still not sure if we're looking at a compiler/drive bug or a Blender bug. I'll have a look through the Metal draw code.

@fclem You're correct - I was thinking of gl_baseVertex which has no equivalent in Metal but I don't think that has any relevance here. " But the Metal Vertex Fetch API does not honor this specific offset (which IIRC is only used for 16bit indices)." vertex_id does include the baseVertex according to the Metal Language spec: _vertex_id - ushort or uint - The per-vertex identifier, which includes the base vertex value if one is specified._ (There's a good summary here of the differences between the APIs here: https://github.com/gpuweb/gpuweb/issues/901) I'm still not sure if we're looking at a compiler/drive bug or a Blender bug. I'll have a look through the Metal draw code.

@James-McCarthy-4

I am looking at a Blender Metal Backend bug (so in our codebase). The SSBO Vertex Fetch API was introduced by Michael PW to be able to workaround Metal's lack of geometry shader.

See the part after /* SSBO Vertex Fetch Mode. */ inside source/blender/gpu/shaders/metal/mtl_shader_defines.msl.

When this API is used (e.g. inside overlay_edit_uv_edges_vert_no_geom.glsl), the vertex_id does not represent the indices inside index buffer as the drawcall just emits X number of primitive (the max number of primitive you would expect after geometry shader expansion). The shader then use vertex_fetch_attribute function to load the index buffer value for a specific input vertex using manual IBO indirection. This indirection is the source of the bug.

You can find all code (that I found) related to this API in this PR #127660.

@James-McCarthy-4 I am looking at a Blender Metal Backend bug (so in our codebase). The SSBO Vertex Fetch API was introduced by Michael PW to be able to workaround Metal's lack of geometry shader. See the part after `/* SSBO Vertex Fetch Mode. */` inside `source/blender/gpu/shaders/metal/mtl_shader_defines.msl`. When this API is used (e.g. inside `overlay_edit_uv_edges_vert_no_geom.glsl`), the `vertex_id` does not represent the indices inside index buffer as the drawcall just emits X number of primitive (the max number of primitive you would expect after geometry shader expansion). The shader then use `vertex_fetch_attribute` function to load the index buffer value for a specific input vertex using manual IBO indirection. This indirection is the source of the bug. You can find all code (that I found) related to this API in this PR #127660.
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-09-25 15:22:50 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#126542
No description provided.