-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metal: Performance improvements and bug fixes #98212
Metal: Performance improvements and bug fixes #98212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments
@@ -58,7 +58,7 @@ | |||
|
|||
void MDCommandBuffer::begin() { | |||
DEV_ASSERT(commandBuffer == nil); | |||
commandBuffer = queue.commandBuffer; | |||
commandBuffer = queue.commandBufferWithUnretainedReferences; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Metal driver maintains references to the Metal resources, so there is no need for the command buffer to perform add ref and release calls.
primary.arrayLength = 1; | ||
for (uint32_t const &a : a_type.array) { | ||
primary.arrayLength *= a; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix to support arrays of samplers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love to see that performance improvement!
drivers/metal/metal_objects.h
Outdated
@@ -271,8 +288,14 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDCommandBuffer { | |||
blend_constants.reset(); | |||
vertex_buffers.clear(); | |||
vertex_offsets.clear(); | |||
// keep the keys, as they are likely to be used again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// keep the keys, as they are likely to be used again | |
// Keep the keys, as they are likely to be used again. |
drivers/metal/metal_objects.h
Outdated
_FORCE_INLINE_ void reset() { | ||
pipeline = nil; | ||
encoder = nil; | ||
// keep the keys, as they are likely to be used again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// keep the keys, as they are likely to be used again | |
// Keep the keys, as they are likely to be used again. |
drivers/metal/metal_objects.mm
Outdated
if (resources == nullptr) { | ||
resources = &p_dst.insert(keyval.key, ResourceVector())->value; | ||
} | ||
// reserve space for the new resources, assuming they are all added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// reserve space for the new resources, assuming they are all added | |
// Reserve space for the new resources, assuming they are all added. |
drivers/metal/metal_objects.mm
Outdated
uint32_t i = 0, j = 0; | ||
__unsafe_unretained id<MTLResource> *resources_ptr = resources->ptr(); | ||
const __unsafe_unretained id<MTLResource> *keyval_ptr = keyval.value.ptr(); | ||
// 2-way merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 2-way merge | |
// 2-way merge. |
drivers/metal/metal_objects.mm
Outdated
return; | ||
} | ||
|
||
// bind all resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// bind all resources | |
// Bind all resources. |
drivers/metal/metal_objects.mm
Outdated
return; | ||
} | ||
|
||
// bind all resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// bind all resources | |
// Bind all resources. |
10b9041
to
83ac274
Compare
@AThousandShips thanks for the feedback – all those changes are in |
Thanks! |
This PR includes general improvements to the Metal rendering driver.
MTLRenderCommandEncoder
includes a large number ofid<MTLResources>
by removing redundantuseResource:
calls when binding the same resources over multiple draw callsdrawcalltest
project that alternates between 2D rect and line canvas items