Metal: Support for Storage Buffers. #104870

Closed
Thomas Dinges wants to merge 1 commits from (deleted):metal-ssbo into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Adds support for SSBOs to the Metal backend. Also includes small compilation fixes for EEVEE Next shaders which are now compiled under build time testing.

One requirement being explicit address space tagging on reference types pased into functions which write to SSBOs, if an SSBO buffer reference is passed. Previously, all reference types were treated as being within thread address space.

For testing and stability, storage buffer feature flag remains disabled on macOS, however, this can now be toggled in mtl_backend for testing of future work.

Authored by Apple: Michael Parkin-White

Ref #96261

Adds support for SSBOs to the Metal backend. Also includes small compilation fixes for EEVEE Next shaders which are now compiled under build time testing. One requirement being explicit address space tagging on reference types pased into functions which write to SSBOs, if an SSBO buffer reference is passed. Previously, all reference types were treated as being within thread address space. For testing and stability, storage buffer feature flag remains disabled on macOS, however, this can now be toggled in mtl_backend for testing of future work. Authored by Apple: Michael Parkin-White Ref #96261
Thomas Dinges added this to the 3.6 LTS milestone 2023-02-17 12:49:45 +01:00
Clément Foucault was assigned by Thomas Dinges 2023-02-17 12:49:45 +01:00
Thomas Dinges added 1 commit 2023-02-17 12:49:58 +01:00
49bd2fe155 Metal: Support for Storage Buffers.
Adds support for SSBOs to the Metal backend. Also includes small compilation fixes for EEVEE Next shaders which are now compiled under build time testing.

One requirement being explicit address space tagging on reference types pased into functions which write to SSBOs, if an SSBO buffer reference is passed. Previously, all reference types were treated as being within thread address space.

For testing and stability, storage buffer feature flag remains disabled on macOS, however, this can now be toggled in mtl_backend for testing of future work.

Authored by Apple: Michael Parkin-White

Ref #96261
Thomas Dinges requested review from Clément Foucault 2023-02-17 12:50:11 +01:00
Clément Foucault was unassigned by Thomas Dinges 2023-02-17 12:50:23 +01:00
Brecht Van Lommel added this to the EEVEE & Viewport project 2023-02-20 10:40:03 +01:00
Clément Foucault requested changes 2023-02-27 16:15:34 +01:00
Clément Foucault left a comment
Member

Very minor touch ups required.

Very minor touch ups required.
@ -37,3 +37,3 @@
BLI_INLINE eParticleRefineShaderType drw_hair_shader_type_get()
{
if (GPU_compute_shader_support() && GPU_shader_storage_buffer_objects_support()) {
/* NOTE: Hair refine is faster using transform feedback via vertex processing pipeline with Metal

I just created #105241 to keep track of this.

I just created #105241 to keep track of this.
@ -74,3 +71,1 @@
out vec4 top,
out vec4 near,
out vec4 far)
DEVICE_OUT(vec4, left),

I would prefer have a return struct instead of this (maybe ProjectionPlanes). This is more refactor I would very much avoid these types of defines.

I would prefer have a return struct instead of this (maybe `ProjectionPlanes`). This is more refactor I would very much avoid these types of defines.
@ -90,3 +90,3 @@
}
void frustum_culling_planes_calc(mat4 winmat, mat4 viewmat, out vec4 planes[6])
void frustum_culling_planes_calc(mat4 winmat, mat4 viewmat, DEVICE_OUT_ARRAY(vec4, planes, 6))

Same here

Same here
@ -101,3 +101,3 @@
}
vec4 frustum_culling_sphere_calc(vec4 corners[8])
vec4 frustum_culling_sphere_calc(device vec4 corners[8])

Same here. You can use struct Box for that matter.

Same here. You can use `struct Box` for that matter.
@ -22,0 +23,4 @@
* - Argument buffer for bindless resources (e.g. samplers)
* - Transform feedback buffer
* - Default push constant block
* Along with up to 6+1 buffers for vertex data, and index data. */

We also require an additional 3 core buffers for:

Does this mean they are also counting towards the limit of MTL_MAX_BUFFER_BINDINGS ?

> We also require an additional 3 core buffers for: Does this mean they are also counting towards the limit of `MTL_MAX_BUFFER_BINDINGS` ?
@ -1180,0 +1226,4 @@
BLI_assert(ssbo_size > 0);
}
else {
MTL_LOG_INFO(

Should be MTL_LOG_ERROR. This should mandatory. Same for UBOs.

Should be `MTL_LOG_ERROR`. This should mandatory. Same for UBOs.
@ -108,0 +116,4 @@
* Default Push constant block for uniforms <-- MTL_uniform_buffer_base_index
* Uniform buffers <-- MTL_uniform_buffer_base_index+1
* Storage buffers <-- MTL_storage_buffer_base_index
* Samplers/argument buffer table <-- last buffer + 1

Why not put all reserved ones first? This would simplify this mapping.

Why not put all reserved ones first? This would simplify this mapping.
@ -1125,0 +1156,4 @@
template<typename T> T findMSB(T x)
{
/* clz returns the number of leading zeroes. To fetch the index of the LSB, we can also use this

The comment need to be reworked. It mention LSB.

The comment need to be reworked. It mention LSB.
@ -1125,0 +1158,4 @@
{
/* clz returns the number of leading zeroes. To fetch the index of the LSB, we can also use this
* value as index when offset by 1. however need to filter out the case where the input value is
* zero to match GLSL functionality. 000000010*/

Nice 000000010 you got here.

Nice `000000010` you got here.
@ -1125,0 +1159,4 @@
/* clz returns the number of leading zeroes. To fetch the index of the LSB, we can also use this
* value as index when offset by 1. however need to filter out the case where the input value is
* zero to match GLSL functionality. 000000010*/
return (x == T(0)) ? T(-1) : (clz(T(0)) - clz(x) - T(1));

I think the 0 case here already handled by the logic:
clz(0) - clz(0) - 1 = -1
Also can we make sure that clz(T(0)) - T(1) is compiled time constant folded? Or it can be replaced by sizeof(T) * -8 - 1.

I think the 0 case here already handled by the logic: `clz(0) - clz(0) - 1 = -1` Also can we make sure that `clz(T(0)) - T(1)` is compiled time constant folded? Or it can be replaced by `sizeof(T) * -8 - 1`.
@ -16,2 +16,4 @@
#define depth2DArrayShadow sampler2DArrayShadow
/* Memory scope and pass by reference types.
* NOTE: These are required by Metal, but are not required in all cases by GLSL. */

Not sure why this is here. Any GLSL code targeted at Metal should be using #ifdef GPU_METAL.
Like mentioned in the GLSL files, I would really like to avoid these.

Not sure why this is here. Any GLSL code targeted at Metal should be using `#ifdef GPU_METAL`. Like mentioned in the GLSL files, I would really like to avoid these.
Jason Fielder closed this pull request 2023-04-20 15:56:24 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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 Assignees
2 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#104870
No description provided.