简体   繁体   中英

Kernel Functions in Metal

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

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM