Shader language

Metal Shading Language

Metal shaders use a special language called Metal Shading Language (probably called MSL?). Since it is a specialized language,

It is a separate language, but it is not brand new. It is a subset of C++14, and then did not much expansion. Compared with GLSL, especially those who are familiar with C++, it is much cooler to write. This language includes C++ template classes and template methods, macro replacement, macro replacement, etc., and can write more complex shaders in an object-oriented manner.

When using Metal, if it is used to render images, it is the same as in traditional OpenGL. It needs to provide vertex shader functions and fragment shader functions. If it is used for GPU operations, only the kernel function needs to be completed. In MSL, there is a big difference from OpenGL in memory/video memory and shader data exchange. Let's take a closer look below.

---- OpenGL

The OpenGL programming language is GLSL, which is what we call the shader language . GLSL is a shader language with C syntax style. Programs written with it have a main method for each object to call. But on this basis, many things suitable for graphics processing are added, such as vector and matrix operations. If we want graphics rendering, we must need a vertex shader and a simple fragment shader

----Vulkan
shader code must use bytecode format, not human-readable syntax such as GLSL and HLSL. This bytecode is SPIR-V, designed for Vulkan and OpenCL

Guess you like

Origin blog.csdn.net/u013321328/article/details/105506350