Blender 3.5 issues migrating code from bgl to gpu on Mac M1 Metal backend #107332
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#107332
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've met some issues migrating shader code from bgl to gpu.
Migrating it on windows and linux worked fine - I either simply replaced all built-in line shaders I was using with "3D_POLYLINE_UNIFORM_COLOR" or rewrote all custom shaders having the same polyline principle in mind (basically creating a two triangles through geo shader for each line to support smoothing).
Migrating on Mac didn't worked that well:
When shader doesn't compile on Mac you do get
Exception: Shader Compile Error, see console for more details
but can't see any details in console besides that. I got more info providing--debug-gpu
command line argument but it gives me too much info. Shouldn't it provide compile errors message even without debug mode?Running script
simple_shader.py
(attached below) either gives me this error if I run it without geometry shader partor if I run it with geometry shader (uncommenting
geocode=polyline_geom_glsl
)Is it expected that I cannot create shader with just
gpu.types.GPUShader
on Metal or it's a bug?Since it's saying that it cannot find "create-info" I've tried to write shader with
gpu.types.GPUShaderCreateInfo
andgpu.shader.create_from_info
(attached examplecreate_info.py
below) and it actually worked on Mac.But what do I do about the geometry shader - is there some workaround or gpu geometry shaders are not supported at all? Still need geometry shader to either create custom things in shader or to just perfom line smoothing using polyline method.
Line created with create-info method is still a bit different on Mac from what I've got in Windows - on Mac it appear less thick (tried to change it with
gpu.state.line_width_set
but it had no effect).simple_shader.py:
create_info.py
Thanks for the report, but this is the same issue described in #106304.
Unfortunately we cannot use the same GLSL code (for OpenGL), in the Metal or the future Vulkan backend.
Therefore a new API was implemented. You can see examples of it at:
https://docs.blender.org/api/current/gpu.html#triangle-with-custom-shader
Try adapting your shader to use gpu.shader.create_from_info.
It is planned to improve the documentation and add deprecated messages to avoid further confusion.
@mano-wii but is there any way to implement geometry shaders on Metal now or it is still in development?
At the moment
GPUShaderCreateInfo
doesn't support geometry shadersWithout geometry shaders there is currently no way to implement smoothed line shaders or something more complex on Metal :\
To also comment on Geometry shader support, Metal does not have this.
However, there is an option supported by the Metal backend which allows random-access reading of the vertex shader data, allowing you to use information from other/neighbouring vertices within a vertex shader.
This is planned to be a common API, lifted to the high-level such that it can be used for all APIs, and is not recommend for use at the moment, however, if functionality is essential, a similar approach to
source/blender/gpu/shaders/gpu_shader_3D_polyline_vert_no_geom.glsl
can be used for wideline rendering.Adding
#pragma USE_SSBO_VERTEX_FETCH(TriangleList, 6)
in your vertex shader will inform the backend to issue a differing output primitive type, with a set vertex count per input primitive.i.e. in this case, if your source data is a line shader, then having the settings as above will issue a vertex shader invocation outputting two triangles (6 vertices using triangleList primitive type) for each input line.
vertex_fetch_attribute(vertex_index, attribute_name, data type)
can then be used to read the value.Again, I do not recommend that you use this, but it is an option if required.