-
Notifications
You must be signed in to change notification settings - Fork 239
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
Most efficient way to encode arguments #355
Comments
I think you are doing pretty well under the current framework limitation. You can do a little "hack" if you want, using Examples of implementing MetalPetal/MetalPetalExamples/Shared/BouncingBallsView.swift Lines 16 to 23 in f9b7889
MetalPetal/Frameworks/MetalPetal/MTIVertex.m Lines 233 to 240 in f9b7889
Examples of using MetalPetal/MetalPetalExamples/Shared/BouncingBallsView.swift Lines 56 to 57 in f9b7889
The 3x buffers only create once. It's a one-time cost, using a contiguous buffer won't help much.
Have you measured the performance of this part? This should be super fast. The cache uses the object address directly for the key hashing and object comparison, also, the hash table is very small (you usually only have one MTLDevice).
As I mentioned earlier. The cache uses the object's pointer/address, so it does not have any counter-affects on the triple buffering. For further improvements on filter argument encoding, I'm thinking about adding APIs to register custom argument encoders. I'll let you know when I have some designs to discuss. |
Interesting! I'll definitely try that, although it does feel like quite a workaround.
True, thanks for confirming.
Fair point; I haven't. If the cache uses object addresses I agree with you, this shouldn't be a problem for speed or accuracy. Thanks for explaining!
Definitely do! Maybe MTIRenderPipelineKernel(encoding: @escaping ((MTLRenderCommandEncoder) -> Void), dimensions: MTITextureDimensions, pixelFormat: MTLPixelFormat = .unspecified) and matching I also wanted to ask about texture usage. If I regenerate the same image (but with different parameters) every frame, how can I do so in the most performant way possible? Doing it manually I would reuse a single texture (assuming dimensions are the same) but with a |
MetalPetal uses a texture pool internally. It allocates and resues textures from the pool. (You can call So it does not create a new texture for each frame. MetalPetal uses |
Checklist
I have an app that implements realtime Metal rendering pipelines @ 60 FPS. My arguments (filter, render, shader pipelines) won't change for 99.9% of the time, so it seems that the best method of storage & encoding is via a Metal buffer. We also make use of triple buffering for our rendering, creating MTLBuffers of 3x the size of the parameters (with proper alignment).
I'm trying to replace parts of it with MetalPetal, but I'm confused as to what is the best way to encode arguments. I've been trying to use MTIDataBuffer in the following way:
While this works, it creates 3x buffers instead of a contiguous buffer (worse performance?). It also incurs a bit of performance hit due to the fact that the argument encoder is looking up buffers in a cache every time. I'm also concerned whether this fact counter-affects the triple buffering and may reuse the same single MTLBuffer under the hood?
If I am OK with managing my MTLBuffers manually, how can I use them in conjunction with MetalPetal? Is there a better way to optimise resource usage?
The text was updated successfully, but these errors were encountered: