Metal Shading Language

2019-07-10  本文已影响0人  zhongxiaoyue

介绍

Metal 与 C++ 11.0

Metal 这门语言是基于C++ 11.0标准设计的.它在C++基础是多了⼀些拓展和限制.下面我们可以简单介绍Metal着⾊语言与C++11.0 相⽐之下的修改和限制.

Metal Restrictions 限制
如下的C++11.0的特性在Metal 着⾊语言中是不⽀持的.

C++的标准库不可以在Metal 着色语言中使用
Metal 着色语言是有对于指针的使用限制. Metal图形和并行计算函数用到的入参如果是指针使用地址空间修饰符 (device ,threadgroup ,constant)
不支持函数指针
Metal函数名不能命名为Main函数

Metal 数据类型

缓存buffer

在Metal 中实现缓存靠的是一个指针.它指向一个在Device 或者 constant 地址空间中的内建或是开发者自定义的数据块.缓存可以被定在程序域域中,或是当做函数的参数传递.

属性修饰符

属性修饰符目的:

  1. 变量与参数的地址空间修饰符

Metal 着色语言使用"地址空间修饰符号",来表示一个函数变量或是参数 被分于那块内存区域. 下面这些修饰符描述了不相交叠地址空间:

  1. 函数参数和变量

图形绘制或是并行计算着色函数的输入/输出都需要通过参数传递(除了常量地址空间变量和程序域中定义的采样器以外).参数可以是如下之一:

  1. 用于寻址缓存,纹理,采样器属性修饰符

为每个参数,指定一个属性修饰符. 指定明确的缓冲,纹理位置.

纹理Textures

enum class access {sample,read,write};
texture1d<T,access a = access::sample>
texture1d_array<T,access a = access::sample>

texture2d<T,access a = access::sample>
texture2d_array<T,access a = access::sample>

texture3d<T,access a = access::sample>
texturecube<T,access a = access::sample>
texture2d_ms<T,access a = access::read>
enum class depth_forma {depth_float};
depth2d<T,access a = depth_format::depth_float>
depth2d_array<T,access a = access::sample,depth_format d = depth_format::depth_float>
depthcube<T,access a = access::sample,depth_format d = depth_format::depth_float>
depth2d_ms<T,access a = access::read,depth_format d = depth_format::depth_float>

采样器 Samplers

上一篇 下一篇

猜你喜欢

热点阅读