Metal Backend causes UV editing to glitch out, crash Blender #112190

Open
opened 2023-09-09 23:52:33 +02:00 by Tom Oliver · 17 comments

System Information
Operating system: macOS-13.5.2-arm64-arm-64bit 64 Bits
Graphics card: Metal API Apple M1 1.2

Blender Version
Broken: version: 3.5.1, 3.6.3, 4.0 alpha
Worked: (newest version of Blender that worked as expected)

Short description of error
Trying to do UV editing with the Metal backend causes unexpected UI behavior. Islands will glitch out, disappear, randomly stretch and contort, or Blender will crash entirely. It makes Metal useless for work and requires a switch to OpenGL to have expected performance. This happens on my M1 Air, M1 Pro MacBook Pro, and M1 Max Mac Studio. They all had to be switched back to OpenGL.


Exact steps for others to reproduce the error

  • Open the included Blender file with Metal backend
  • Make sure the 3D viewport has either Material Preview or Rendered View enabled.
  • Start UV editing on the Azumi object (go to Object Mode > Select the Azumi object > go to UV Editing Workspace)
  • Zoom, pan, scale, rotate...

It'll happen eventually.

EDIT: This issue seems to stem from having multiple UV Maps on the model somehow. If the additional UV Maps are removed, the issue stops occurring.

EDIT 2: Further digging seems to show that it specifically has to do with the texture atlas expression swapping using the UV Map and Mapping Nodes in the "Colors.001" material. Clearing the field in the UV Map node also immediately resolves the issue.

I've attached two screen recordings of some of the behavior, as well as the error log when Blender crashed, and the file I'm working with.

EDIT 3: Uploaded a simple test file with just a cube using the same material setup as my character file. It exhibits the exact same behavior.

**System Information** Operating system: macOS-13.5.2-arm64-arm-64bit 64 Bits Graphics card: Metal API Apple M1 1.2 **Blender Version** Broken: version: 3.5.1, 3.6.3, 4.0 alpha Worked: (newest version of Blender that worked as expected) **Short description of error** Trying to do UV editing with the Metal backend causes unexpected UI behavior. Islands will glitch out, disappear, randomly stretch and contort, or Blender will crash entirely. It makes Metal useless for work and requires a switch to OpenGL to have expected performance. This happens on my M1 Air, M1 Pro MacBook Pro, and M1 Max Mac Studio. They all had to be switched back to OpenGL. <video src="/attachments/7afa9664-0eda-4c05-ac82-29ef324de2fd" title="error.mov" controls></video> <video src="/attachments/f930dab3-0ad4-4215-adca-c4235f40df94" title="Screen Recording 2023-09-09 at 5.50.49 PM.mov" controls></video> **Exact steps for others to reproduce the error** - Open the included Blender file with Metal backend - Make sure the 3D viewport has either Material Preview or Rendered View enabled. - Start UV editing on the `Azumi` object (go to Object Mode > Select the Azumi object > go to UV Editing Workspace) - Zoom, pan, scale, rotate... It'll happen eventually. EDIT: This issue seems to stem from having multiple UV Maps on the model somehow. If the additional UV Maps are removed, the issue stops occurring. EDIT 2: Further digging seems to show that it specifically has to do with the texture atlas expression swapping using the UV Map and Mapping Nodes in the "Colors.001" material. Clearing the field in the UV Map node also immediately resolves the issue. I've attached two screen recordings of some of the behavior, as well as the error log when Blender crashed, and the file I'm working with. EDIT 3: Uploaded a simple test file with just a cube using the same material setup as my character file. It exhibits the exact same behavior.
Tom Oliver added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-09-09 23:52:34 +02:00
Member

Hi, thanks for the report. Any improvements in fresh 3.6.3/4.0 build?: https://builder.blender.org/download/daily/
3.5 is now archived

Hi, thanks for the report. Any improvements in fresh 3.6.3/4.0 build?: https://builder.blender.org/download/daily/ 3.5 is now archived
Pratik Borhade added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-09-11 08:15:43 +02:00
Author

Hey. It still happens in 3.6. Haven't tried 4.0 yet. But I'll give it a shot and get back to you

Hey. It still happens in 3.6. Haven't tried 4.0 yet. But I'll give it a shot and get back to you
Author

Yep. Still happens in 4.0. Same glitch and then Blender crashed. Error log is attached.

Couldn't test if OpenGL was still okay since it looks like OpenGL was removed in 4.0, or was at least moved.

Yep. Still happens in 4.0. Same glitch and then Blender crashed. Error log is attached. Couldn't test if OpenGL was still okay since it looks like OpenGL was removed in 4.0, or was at least moved.
Member

Thanks. @mano-wii , can you verify on Mac M1?
OpenGL support is removed in 4.0 for Mac because some newer feature requires 4.3 GL version :)

Thanks. @mano-wii , can you verify on Mac M1? OpenGL support is removed in 4.0 for Mac because some newer feature requires 4.3 GL version :)
Pratik Borhade added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2023-09-11 08:37:10 +02:00

Based on the video, I edited the description to include clearer steps.
But I still can't replicate the problem. Whether in Blender 3.5 or Blender 4.0

@tommyoliversays, could you please clarify a few things:

  • Does the problem also happen when textures are not available? (the attached file does not have the textures).
  • Are there any specific actions to perform for the issue to happen?
System Information
  • Operating system: macOS-13.5.1-x86_64-i386-64bit 64 Bits
  • Graphics card: Metal API Apple M1 1.2
Based on the video, I edited the description to include clearer steps. But I still can't replicate the problem. Whether in Blender 3.5 or Blender 4.0 @tommyoliversays, could you please clarify a few things: - Does the problem also happen when textures are not available? (the attached file does not have the textures). - Are there any specific actions to perform for the issue to happen? <details> <summary>System Information</summary> <ul> <li>Operating system: macOS-13.5.1-x86_64-i386-64bit 64 Bits</li> <li>Graphics card: Metal API Apple M1 1.2</li> </ul> </details>
Germano Cavalcante added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-09-11 16:12:28 +02:00
Author

Based on the video, I edited the description to include clearer steps.
But I still can't replicate the problem. Whether in Blender 3.5 or Blender 4.0

@tommyoliversays, could you please clarify a few things:

  • Does the problem also happen when textures are not available? (the attached file does not have the textures).
  • Are there any specific actions to perform for the issue happen?
System Information
  • Operating system: macOS-13.5.1-x86_64-i386-64bit 64 Bits
  • Graphics card: Metal API Apple M1 1.2

My apologizes. I thought the textures were packed. I've uploaded the file again with the packed textures.

However, in doing more tests, I've been able to narrow down that the issue only occurs when the 3D viewport in in Material Preview or Rendering Preview. Wireframe and Solid don't seem to have the issue, or at least less frequently that I can't easily reproduce it. I'll edit the description to reflect this as well.

> Based on the video, I edited the description to include clearer steps. > But I still can't replicate the problem. Whether in Blender 3.5 or Blender 4.0 > > @tommyoliversays, could you please clarify a few things: > - Does the problem also happen when textures are not available? (the attached file does not have the textures). > - Are there any specific actions to perform for the issue happen? > > <details> > <summary>System Information</summary> > <ul> > <li>Operating system: macOS-13.5.1-x86_64-i386-64bit 64 Bits</li> > <li>Graphics card: Metal API Apple M1 1.2</li> > </ul> > </details> My apologizes. I thought the textures were packed. I've uploaded the file again with the packed textures. However, in doing more tests, I've been able to narrow down that the issue only occurs when the 3D viewport in in Material Preview or Rendering Preview. Wireframe and Solid don't seem to have the issue, or at least less frequently that I can't easily reproduce it. I'll edit the description to reflect this as well.
Author

Okay. More info. It has something to do with the additional UV Maps. If you remove them and just leave the base UV Map, this issue is immediately resolved.

Okay. More info. It has something to do with the additional UV Maps. If you remove them and just leave the base UV Map, this issue is immediately resolved.

There are still bunch of textures missing. I wasn't able to reproduce crash on intel Mac, but I was able to reproduce "glitching" as in your second video.
I suspect these are 2 different bugs, so it would be best to split this report and make new one for crash perhaps.

There are still bunch of textures missing. I wasn't able to reproduce crash on intel Mac, but I was able to reproduce "glitching" as in your second video. I suspect these are 2 different bugs, so it would be best to split this report and make new one for crash perhaps.

I can also confirm the glitch.
I think we can confirm for now because of the glitch.
But the crash actually needs more details.

I can also confirm the glitch. I think we can confirm for now because of the glitch. But the crash actually needs more details.
Author

There are still bunch of textures missing. I wasn't able to reproduce crash on intel Mac, but I was able to reproduce "glitching" as in your second video.
I suspect these are 2 different bugs, so it would be best to split this report and make new one for crash perhaps.

I just updated the file again, again making sure to pack the images (as well as try and clear out some redundant materials, been working in this file for a while). It should be good now.

Further messing around seems to show that the UV glitch error specifically has to do with the texture atlas expression swap using the UV Map and Mapping Nodes in the "Colors.001" material. Clearing the field in the UV Map node here also immediately resolves the issue.

> There are still bunch of textures missing. I wasn't able to reproduce crash on intel Mac, but I was able to reproduce "glitching" as in your second video. > I suspect these are 2 different bugs, so it would be best to split this report and make new one for crash perhaps. I just updated the file again, again making sure to pack the images (as well as try and clear out some redundant materials, been working in this file for a while). It should be good now. Further messing around seems to show that the UV glitch error specifically has to do with the texture atlas expression swap using the UV Map and Mapping Nodes in the "Colors.001" material. Clearing the field in the UV Map node here also immediately resolves the issue.

@tommyoliversays If you understand the cause of the issue, can you perhaps simplify the file as much as possible?

@tommyoliversays If you understand the cause of the issue, can you perhaps simplify the file as much as possible?
Author

@tommyoliversays If you understand the cause of the issue, can you perhaps simplify the file as much as possible?

Sure. Here is a simple file with the same material setup that exhibits the same issue. I'll also add it to the main post.

Edit: also added the texture files separately. I've been packing them but the files sometimes don't work

> @tommyoliversays If you understand the cause of the issue, can you perhaps simplify the file as much as possible? Sure. Here is a simple file with the same material setup that exhibits the same issue. I'll also add it to the main post. _Edit: also added the texture files separately. I've been packing them but the files sometimes don't work_
Germano Cavalcante added the
Interest
UV Editing
label 2023-09-18 16:31:04 +02:00
Author

Just figured I'd chime back in and say that the issue is still present in 4.0.2

Just figured I'd chime back in and say that the issue is still present in 4.0.2

So while this is only crashing in the Metal backend, it looks like it is caused by one of the vertex buffers having the GPU_VERTBUF_INVALID flag., and thus attempts to allocate it while containing no data.

It looks like this is an unexpected scenario. In this case, the OpenGL backend allocates an empty buffer. The error would be avoided by binding an empty buffer in Metal too however, but this feels like it would cause issues on read.

It feels like this problem lies higher up. Being unfamiliar with UV editing, my guess is that this is because the GPUBatch being drawn for UV editing has two vertex buffers bound, one for each UV layer, however, only one of these layers is displayed at a time in the editor.

So while this is only crashing in the Metal backend, it looks like it is caused by one of the vertex buffers having the `GPU_VERTBUF_INVALID` flag., and thus attempts to allocate it while containing no data. It looks like this is an unexpected scenario. In this case, the OpenGL backend allocates an empty buffer. The error would be avoided by binding an empty buffer in Metal too however, but this feels like it would cause issues on read. It feels like this problem lies higher up. Being unfamiliar with UV editing, my guess is that this is because the GPUBatch being drawn for UV editing has two vertex buffers bound, one for each UV layer, however, only one of these layers is displayed at a time in the editor.

Adding a guard around the asserting code (asserts on VertBuf::size_used_get) removes the crash, but for whatever reason in the provided test file, when the equivalent invalid binding is hit, defaulting to binding an invalid buffer results in erroneous display:

  if (flag & GPU_VERTBUF_DATA_DIRTY || flag & GPU_VERTBUF_INIT) {
    required_size_raw = sizeof(uchar) * this->size_used_get();
  }

Deleting the original UV maps and adding two new ones however appears okay, so not sure where this bad data/state is coming from in the first place.

Adding a guard around the asserting code (asserts on VertBuf::size_used_get) removes the crash, but for whatever reason in the provided test file, when the equivalent invalid binding is hit, defaulting to binding an invalid buffer results in erroneous display: ``` if (flag & GPU_VERTBUF_DATA_DIRTY || flag & GPU_VERTBUF_INIT) { required_size_raw = sizeof(uchar) * this->size_used_get(); } ``` Deleting the original UV maps and adding two new ones however appears okay, so not sure where this bad data/state is coming from in the first place.

This may be one that @Jeroen-Bakker has a better idea about.

FYI far easier to reproduce if disabling VAO caching in Metal, as this will assert very consistently when editing UVs if the GPUVertBuf is in invalid state at draw time:

Can comment out lines 714-718 in source/blender/gpu/metal/mtl_batch.mm:

if (!this->vao_cache.insert(pair)) {
      printf(
          "[Performance Warning] cache is full (Size: %d), vertex descriptor will not be cached\n",
          GPU_VAO_STATIC_LEN);
    }

Meaning vertex attribute fetching happens each time. After some time of editing UVs, you will get a situation where this fails, and the offending VBO has GPU_VERTBUF_INVALID as its state, and usually nonsense data.

Other investigations seem that at the time the mesh batch cache fetching is complete, the status is always valid. Not sure where this is getting stomped, whether an issue with some other part of the code stomping the pointer, or if it is prematurely cleared.

This may be one that @Jeroen-Bakker has a better idea about. FYI far easier to reproduce if disabling VAO caching in Metal, as this will assert very consistently when editing UVs if the GPUVertBuf is in invalid state at draw time: Can comment out lines 714-718 in `source/blender/gpu/metal/mtl_batch.mm`: ``` if (!this->vao_cache.insert(pair)) { printf( "[Performance Warning] cache is full (Size: %d), vertex descriptor will not be cached\n", GPU_VAO_STATIC_LEN); } ``` Meaning vertex attribute fetching happens each time. After some time of editing UVs, you will get a situation where this fails, and the offending VBO has GPU_VERTBUF_INVALID as its state, and usually nonsense data. Other investigations seem that at the time the mesh batch cache fetching is complete, the status is always valid. Not sure where this is getting stomped, whether an issue with some other part of the code stomping the pointer, or if it is prematurely cleared.
Jeroen Bakker was assigned by Jason Fielder 2024-01-11 12:53:58 +01:00

Hi all !

Regarding mention of #119340 I am not sure it is the same bug because the latter is far more simpler to reproduce and does not depend on texture or material.

Simple test to reproduce:

  • open blender with metal backend
  • select cube
  • edit mode
  • subdivide w/ count = 10 >>> the bug occurs only when the # of faces reaches 64
  • create new UV and select it
  • in UV editor select faces and move them around

If you reopen blender with OpenGL backend the bug is not there.

Hope that helps !
Cheers !

Hi all ! Regarding mention of #119340 I am not sure it is the same bug because the latter is far more simpler to reproduce and does not depend on texture or material. Simple test to reproduce: - open blender with metal backend - select cube - edit mode - subdivide w/ count = 10 >>> the bug occurs only when **the # of faces reaches 64** - create new UV and select it - in UV editor select faces and move them around If you reopen blender with OpenGL backend the bug is not there. Hope that helps ! Cheers !
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#112190
No description provided.