While developing my Metal application I noticed that making a draw call is a lot slower than using a tile shader. In particular, when operating on a 4k resolution texture it takes about 3ms to complete a draw call while the tile shader takes about 150ns. I was wondering, is a tile shader the preferred approach for drawing with Metal now? Or is there any particular reason why a typical draw call should be used.
Replies
Can you provide some more info about what you are doing in your draw call? I could see the tile shader being faster if you have multiple render passes that use that texture, since each render pass is likely reading and writing the texture back to system memory. With the tile shader, you are probably saving on those read and write operations.
-
The draw call will sample 1-2 textures at any given time and write back to two different color attachments. There are also a good amount of if-statements in the fragment shader. The tile shader, at the moment, runs immediately after the draw call and uses one of the color attachments from the draw call to change the color of the pixel. There is defintely more work being done by the draw call approach, but I'm wondering if it can be sped up by using a tile shader to display the content instead.
-
Can you share the code for your fragment and tile shaders? It’s possible that your fragment shader is just doing more work than the tile shader. Also, your if statements might be causing a lot of thread divergence which is slowing down your shader. Maybe take a look at function specialization/function constants to see if you can remove some of those if statements on some of your draw calls.
-
The code is pretty detailed and might not make sense on its own. Nonetheless it contains about 7 if-statements where a few of the conditions sample other textures. What is function specialization? I've heard of function constants but am not entirely sure I understand them completely. Wouldn't function constants just be more if-statements?