Metal语言规范

2020-09-13  本文已影响0人  ugpass
Metal Shading Language
Metal 和 C++ 11.0的异同

1.Lambda表达式
2.递归函数调用
3.动态转换操作符
4.类型识别
5.对象创建 new和销毁 delete操作符
6.操作符noexcept,告诉编译器函数内部不会发生异常
7.goto跳转
8.变量存储修饰符register和thread_local
9.虚函数修饰符
10.派生类
11.异常处理
12.C++标准函数在Metal中不可使用

  1. 函数参数如果是指针必须使用地址空间修饰符(device, threadgroup, constant)
    2.不支持指针函数
    3.函数名中不能出现main
Metal 标量数据类型
函数修饰符

note:使用kernel修饰的函数返回值必须是void

note:不能在被函数修饰符修饰的函数中,调用其他被函数修饰符修饰的函数,这会导致编译失败

纹理Textures类型

enum class access { sample, read, write };

texture1d<T, access a = access::sample>
texture1d<T, access a = access::sample>
texture1d<T, access a = access::sample>

T指从纹理中读取数据的数据类型,可以是 half/float/short/int等

采样器类型Samplers

采样器类型决定了如何对一个纹理进行采样,在Metal框架中有一个对应着色器语言的采样器对象MTLSamplerState,这个对象作为图形着色器渲染函数或并行计算函数的参数传入。

enum class coord { normalized, pixel }
从纹理中采样时,纹理坐标是否需要归一化

enum class filter { nearest, linear }
纹理采样过滤方式,放大/缩小过滤方式

enum class min_filter { normalized, pixel }
设置纹理采样的缩小过滤方式

enum class mag_filter { normalized, pixel }
设置纹理采样的放大过滤方式

enum class s_address { clamp_to_zero, clamp_to_edge, repeat, mirrored_repeat }
enum class t_address { clamp_to_zero, clamp_to_edge, repeat, mirrored_repeat }
enum class r_address { clamp_to_zero, clamp_to_edge, repeat, mirrored_repeat }
设置纹理s,t,r坐标的寻址模式

enum class address { clamp_to_zero, clamp_to_edge, repeat, mirrored_repeat }
设置所有的纹理坐标的寻址模式

enum class mip_filter { none, nearest, linear }
设置纹理采样的mipMap过滤模式,如果是none,那么只有一层纹理生效

note:在Metal中初始化的采样器必须使用constexpr修饰符修饰

例:
constexpr sampler s(coord::pixel, address::clamp_to_zero, filter::linear);
上一篇 下一篇

猜你喜欢

热点阅读