Metal: Storage buffer and explicit bind location support #107175
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#107175
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Jason-Fielder/blender:MetalSSBO_Support_Apr20"
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?
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
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);
}
}
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");
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;
indentation
@ -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.
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.@ -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.@ -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.@ -1192,0 +1263,4 @@
if (this->pipeline_state.ssbo_bindings[ssbo_location].bound) {
/* Fetch UBO global-binding properties from slot. */
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.
@ -2003,3 +2286,4 @@
{
BLI_assert(mtl_texture);
MTLTextureBinding(
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.
@ -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.
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
@ -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.
@ -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"
@blender-bot build macos