Hey @warrenm, I was playing around with MPS from your tutorial http://metalbyexample.com/metal-performance-shaders-in-swift/ … now I want to try and chain some filters, Sobel and Resize for example but I'm not sure where to start. Any tips?
All of this goes out the window if you’re using MTLHeap, where accesses are noted less granularly, but I suspect that for now you’re not using heaps?
-
-
Nope, not using heaps. The part where I'm kind of stranded is the source and destination textures when I encode the filters, how to make sure these are the right size and set up in the correct way in general.
-
to explain the situation. Im getting some source image at a 320 x 480 resolution and apply the sobel filter for now. But the result in my mtk view is a tiny rectangle at the top right because of this resolution and so I want to resize the texture before applying the sober filter.
-
Oh, you want to upsample from the source first? In that case, MPSImageScale up to the desired size (yes, you have to compute the dest size manually); at worst use Lanczos (you probably don’t need it); then feed that to your Sobel.
-
Sorry if this is obtuse; I really should write a new article about all of this

-
Ah I didn't even know sobel is only applied to 1:1 aspect images, I'm using it on something 320 x 240. But yes that's exactly what I'm trying to do. So the thing to do is have one intermediate texture of the same size as my drawable?
-
So I can encode the resize with the image as source and intermediate texture as destination, and the sobel filter with the intermediate as source and drawable as destination. Is that correct?
-
Bingo, yes. Just make sure the drawable is coming from a layer/view whose framebufferOnly property is set to false.
End of conversation
New conversation -
-
-
Sorry for reviving the ancient thread, but I’m looking for a way to chain MPS kernels on heap sub-allocated resources. Any hints?
-
The key thing to remember is that you’re responsible for tracking dependencies between resources that might alias. I seem to recall another tweet from you that mentioned fences; are you using them? Have you consulted this sample? https://developer.apple.com/documentation/metal/resource_objects/image_filter_graph_with_heaps_and_fences …
-
Yeah, the problem is that MPS kernels don’t provide you with MPSComputeComandEncoder, but instead encode themselves into command buffer. That’s why I’m lost at how to ensure chaining order on heap sub-allocated resources. Is there a way to feed MPS a fence to use?
-
Sorry, that wasn’t the sample I intended. I think what you want are MTLEvents, which are command buffer-level objects that allow more flexible specification of sync boundaries for heap-allocated and non-tracked resources: https://developer.apple.com/documentation/metal/advanced_command_setup/image_filter_graph_with_heaps_and_events …
-
Oh I see, so I can encode MTLEvents in between MPS kernels so that they are chained in a serial order. Do you think it will introduce comparable overhead as device-memory resources with automatic hazard tracking?
-
Difficult to say. On the one hand, by going manual, you’re reducing the work done by the framework/driver. On the other, it might be tricky to place events and order work optimally. Best to ask a profiler.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.