Reputation: 841
I am new to Metal. In which instances we use kernel statements in Shaders. What are the advantage of using that rather than normal vertex and fragment shaders
kernel void shadowShader
Upvotes: 1
Views: 1166
Reputation: 1475
A compute or kernel shader is a general purpose computation pipeline. It is often used in image processing tasks. That is usually what comes up when you search with Google. But a kernel program can be used to do anything with the data you supply. The compute pipeline is separate from the rendering pipeline. You can see it is a GPU parallel way of doing computations. A compute pipeline can write back to device memory in an MTLBuffer
you provide or a texture. And you can use that output in your rendering pipeline.
Upvotes: 3
Reputation: 7892
A fragment shader is called once for every pixel in the output image. A kernel shader is called however many times you want to, so one kernel shader could work on multiple pixels, for example -- or not on pixels at all. It's just more flexible, and possibly more performant for certain problems (because compute threads can work together using threadgroup memory).
Upvotes: 2