Metal: Storage buffer and explicit bind location support #107175

Merged
Clément Foucault merged 4 commits from Jason-Fielder/blender:MetalSSBO_Support_Apr20 into main 2023-05-03 11:46:36 +02:00
Member

Adds support for Storage buffers, including changes to the resource
binding model to ensure explicit resource bind locations are supported
for all resource types.

Storage buffer support also includes required changes for shader
source generation and SSBO wrapper support for other resource
types such as GPUVertBuf, GPUIndexBuf and GPUUniformBuf.

Authored by Apple: Michael Parkin-White

Adds support for Storage buffers, including changes to the resource binding model to ensure explicit resource bind locations are supported for all resource types. Storage buffer support also includes required changes for shader source generation and SSBO wrapper support for other resource types such as GPUVertBuf, GPUIndexBuf and GPUUniformBuf. Authored by Apple: Michael Parkin-White
Jason Fielder added 1 commit 2023-04-20 15:54:58 +02:00
3b9da30474 Metal: Storage buffer and explicit bind location support
Adds support for Storage buffers, including changes to the resource
binding model to ensure explicit resource bind locations are supported
for all resource types.

Storage buffer support also includes required changes for shader
source generation and SSBO wrapper support for other resource
types such as GPUVertBuf, GPUIndexBuf and GPUUniformBuf.

Authored by Apple: Michael Parkin-White
Jason Fielder requested review from Jeroen Bakker 2023-04-20 15:55:05 +02:00
Jason Fielder requested review from Clément Foucault 2023-04-20 15:55:10 +02:00
Jason Fielder added this to the EEVEE & Viewport project 2023-04-20 15:55:15 +02:00
Jason Fielder added the
Interest
EEVEE & Viewport
Interest
Metal
labels 2023-04-20 15:55:24 +02:00
Jeroen Bakker requested changes 2023-05-01 09:00:16 +02:00
Jeroen Bakker left a comment
Member

I tried to run the test cases for storage_buffers.

bin/tests/blender_test "--gtest_filter=GPUMetalTest.storage*"
the clearing ones fail. But can be a missing barrier inside the test case itself.

I did a quick pass over the code, as this is my first big PR on the Metal backend I might need to do some more in order to understand the choices.

I tried to run the test cases for storage_buffers. `bin/tests/blender_test "--gtest_filter=GPUMetalTest.storage*"` the clearing ones fail. But can be a missing barrier inside the test case itself. I did a quick pass over the code, as this is my first big PR on the Metal backend I might need to do some more in order to understand the choices.
@ -463,0 +469,4 @@
if (ctx) {
ctx->compute_dispatch_indirect(indirect_buf);
}
}
Member

Indentation isn't correct.

Indentation isn't correct.
@ -883,0 +894,4 @@
MTLContext *ctx = reinterpret_cast<MTLContext *>(GPU_context_active_get());
id<MTLRenderCommandEncoder> rec = this->bind(0);
if (rec == nil) {
printf("Failed to open Render Command encoder for DRAW INDIRECT\n");
Member

We should go over the printf statements and replace them with CLog in a separate PR. Although these prints should not be visible to end users, using CLog gives more control to the developer and provides a priority/severity of the message what will help developers who aren't familiar with the Metal backend/GPU back-end.

We also have the MTL_LOG_* macros.

We should go over the printf statements and replace them with CLog in a separate PR. Although these prints should not be visible to end users, using CLog gives more control to the developer and provides a priority/severity of the message what will help developers who aren't familiar with the Metal backend/GPU back-end. We also have the `MTL_LOG_*` macros.
@ -2012,1 +2118,4 @@
/* Early fragment tests. */
if(uses_early_fragment_test) {
out << "[[early_fragment_tests]]" << std::endl;
Member

indentation

indentation
Clément Foucault reviewed 2023-05-02 10:23:19 +02:00
@ -883,0 +919,4 @@
id<MTLBuffer> mtl_indirect_buf = mtlssbo->get_metal_buffer();
BLI_assert(mtl_indirect_buf != nil);
if (mtl_indirect_buf == nil) {
printf("Metal Indirect Draw Storage Buffer is nil.\n");

Redundant with the MTL_LOG_WARNING bellow.

Redundant with the MTL_LOG_WARNING bellow.
Clément Foucault requested changes 2023-05-02 16:24:49 +02:00
Clément Foucault left a comment
Member

I think the patch is good to go after the few cosmetic comments are addressed.

I think the patch is good to go after the few cosmetic comments are addressed.
@ -883,0 +910,4 @@
MTLPrimitiveType mtl_prim_type = gpu_prim_type_to_metal(this->prim_type);
if (mtl_needs_topology_emulation(this->prim_type)) {
printf("Metal Topology emulation unsupported for draw indirect.\n");

I usually use BLI_assert_msg() for unsupported features. That makes it harder to overlook.

I usually use `BLI_assert_msg()` for unsupported features. That makes it harder to overlook.
@ -272,0 +298,4 @@
for (int i = 0; i < MTL_MAX_BUFFER_BINDINGS; i++) {
if (this->pipeline_state.ssbo_bindings[i].bound &&
this->pipeline_state.ssbo_bindings[i].ssbo != nullptr) {
GPUStorageBuf *ssbo = wrap(

Why does it need to be casted and wrapped? just call this->pipeline_state.ssbo_bindings[i].ssbo.unbind() should work.

Why does it need to be casted and wrapped? just call `this->pipeline_state.ssbo_bindings[i].ssbo.unbind()` should work.
@ -1192,0 +1247,4 @@
/* Bind Global GPUStorageBuf's */
/* Iterate through expected SSBOs in the shader interface, and check if the globally bound ones
* match. This is used to support the gpu_uniformbuffer module, where the uniform data is global,

Not sure what gpu_uniformbuffer refers to.

Not sure what `gpu_uniformbuffer` refers to.
@ -1192,0 +1263,4 @@
if (this->pipeline_state.ssbo_bindings[ssbo_location].bound) {
/* Fetch UBO global-binding properties from slot. */

UBO > SSBO

UBO > SSBO
@ -1923,0 +2153,4 @@
void MTLContext::compute_dispatch_indirect(StorageBuf *indirect_buf)
{
/* Ensure all resources required by upcoming compute submission are correctly bound. */
if (this->ensure_compute_pipeline_state()) {

Early out instead of indenting codeblock.

Early out instead of indenting codeblock.
@ -2003,3 +2286,4 @@
{
BLI_assert(mtl_texture);
MTLTextureBinding(

Confusing syntax.

Confusing syntax.

I think I understand it. Will leave it as is for now since it is also used in other places. And I currently don't know a better way.

I think I understand it. Will leave it as is for now since it is also used in other places. And I currently don't know a better way.
@ -990,0 +992,4 @@
* and an additional space for the push constant block.
* If the shader does not have any uniform blocks, then we can place directly after the push
* constant block. As we do not need an extra spot for the UBO at index '0'. */
int MTL_storage_buffer_base_index = MTL_uniform_buffer_base_index + 1 +

naming convention: Dont use uppercase prefixes for local variable.

naming convention: Dont use uppercase prefixes for local variable.

This convention is also used throughout the module. So I would leave that to a cleanup commit.

This convention is also used throughout the module. So I would leave that to a cleanup commit.
@ -713,0 +716,4 @@
const char *memory_scope = ((writeable) ? "device " : "constant ");
if (array_offset == -1) {
/* Create local class member as device pointer reference to bound SSBO.
* Given usage within a shader follows ssbo_name.ubo_element syntax, we can

ssbo_name.ubo_element > ssbo_name.ssbo_element

ssbo_name.ubo_element > ssbo_name.ssbo_element
fclem marked this conversation as resolved
@ -1769,4 +1814,3 @@
}
BLI_assert(used_slot >= 0 && used_slot < MTL_MAX_TEXTURE_SLOTS);
/* Writeable image targets only assigned to Fragment and compute shaders. */

I don't think we need vertex shaders to write to image targets, but is that a limitation of Metal? Would be preferable to put asserts in other backends.

I don't think we need vertex shaders to write to image targets, but is that a limitation of Metal? Would be preferable to put asserts in other backends.
@ -7,0 +228,4 @@
void MTLStorageBuf::copy_sub(VertBuf *src_, uint dst_offset, uint src_offset, uint copy_size)
{
/* TODO(Metal): Support Copy sub operation. */
MTL_LOG_WARNING("TLStorageBuf::copy_sub not yet supported.\n");

"TLStorageBuf" > "TLStorageBuf"

"TLStorageBuf" > "TLStorageBuf"
Clément Foucault added 3 commits 2023-05-03 11:00:39 +02:00
d3f983ac78 Merge branch 'main' into MetalSSBO_Support_Apr20
# Conflicts:
#	source/blender/gpu/metal/mtl_context.mm
buildbot/vexp-code-patch-coordinator Build done. Details
fc721a398a
Address reviewers comments

@blender-bot build macos

@blender-bot build macos
Clément Foucault approved these changes 2023-05-03 11:17:07 +02:00
Clément Foucault merged commit 88ace032a6 into main 2023-05-03 11:46:36 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:42 +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 Assignees
3 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#107175
No description provided.