Metal backend fails to compile simple shaders #106304

Closed
opened 2023-03-30 13:05:00 +02:00 by stephen leger · 4 comments
Member

System Information
Operating system: MacOs - Metal backend
Graphics card: M1

Blender Version
Broken: 3.5
Worked: ?

Short description of error
Simple shader compilation fails under metal backend. The same does work using opengl backend on same computer.

Exact steps for others to reproduce the error
Start blender on M1, run the code in the console, lead to "shader compilation error".

import gpu

line_vertSrc = '''
uniform mat4 ModelViewProjectionMatrix;

in vec2 pos;

void main()
{
    gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
}

'''

line_fragSrc = '''
uniform vec4 color;

out vec4 fragColor;

void main()
{
    fragColor = blender_srgb_to_framebuffer_space(color);
}
'''


_format = gpu.types.GPUVertFormat()
_pos_id = _format.attr_add(
    id="pos",
    comp_type="F32",
    len=2,
    fetch_mode="FLOAT")
shader = gpu.types.GPUShader(line_vertSrc, line_fragSrc)
unif_color = shader.uniform_from_name("color")

**System Information** Operating system: MacOs - Metal backend Graphics card: M1 **Blender Version** Broken: 3.5 Worked: ? **Short description of error** Simple shader compilation fails under metal backend. The same does work using opengl backend on same computer. **Exact steps for others to reproduce the error** Start blender on M1, run the code in the console, lead to "shader compilation error". ``` import gpu line_vertSrc = ''' uniform mat4 ModelViewProjectionMatrix; in vec2 pos; void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); } ''' line_fragSrc = ''' uniform vec4 color; out vec4 fragColor; void main() { fragColor = blender_srgb_to_framebuffer_space(color); } ''' _format = gpu.types.GPUVertFormat() _pos_id = _format.attr_add( id="pos", comp_type="F32", len=2, fetch_mode="FLOAT") shader = gpu.types.GPUShader(line_vertSrc, line_fragSrc) unif_color = shader.uniform_from_name("color") ```
stephen leger added the
Priority
Normal
Status
Needs Triage
Type
Report
labels 2023-03-30 13:05:01 +02:00
Member

@mano-wii , can you check?

@mano-wii , can you check?
Pratik Borhade added the
Platform
macOS
Interest
Metal
labels 2023-03-31 07:11:27 +02:00

Believe this is a consequence of using the old shader creation API in python.
Metal requires Create-info for generating the shader resource binding points, so rather than using in vec2 pos directly, this should be specified with bpy.types.GPUShaderCreateInfo.

See: https://docs.blender.org/api/current/gpu.shader.html

I believe this older usage of the API had been deprecated?

Believe this is a consequence of using the old shader creation API in python. Metal requires Create-info for generating the shader resource binding points, so rather than using `in vec2 pos` directly, this should be specified with `bpy.types.GPUShaderCreateInfo`. See: https://docs.blender.org/api/current/gpu.shader.html I believe this older usage of the API had been deprecated?
Richard Antalik added
Module
EEVEE & Viewport
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-03-31 19:03:09 +02:00

In fact the use of the old API should be deprecated.

We can see examples of the new one at:
https://docs.blender.org/api/current/gpu.html#triangle-with-custom-shader

I feel like we need to do a task about this.
The closest I found was this one: #105644

In fact the use of the old API should be deprecated. We can see examples of the new one at: https://docs.blender.org/api/current/gpu.html#triangle-with-custom-shader I feel like we need to do a task about this. The closest I found was this one: #105644

I am closing this report as it is an issue that needs to be handled differently than a bug.

I am closing this report as it is an issue that needs to be handled differently than a bug.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-03-31 22:59:00 +02:00
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
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#106304
No description provided.