没有合适的资源?快使用搜索试试~ 我知道了~
首页Metal_Shading_Language_Guide翻译.pdf
资源详情
资源评论
资源推荐

Metal Shading Language Guide
Metal着色语言指南
Introduction
The Metal shading language is a unified programming language for writing both graphics and compute kernel functions that
are used by apps written with the Metal framework.
The Metal shading language is designed to work together with the Metal framework, which manages the execution, and
optionally the compilation, of the Metal shading language code. The Metal shading language uses clang and LLVM so
developers get a compiler that delivers close to the metal performance for code executing on the GPU.
Metal着色语言是一个用来编写3d图形渲染逻辑 和 并行计算核心逻辑的编程语言,编写Metal框架的app需要使用
Metal着色语言程序。
Metal着色语言和Metal框架配合使用,Metal框架管理Metal着色语言的运行和可选编译选项。Metal着色语言使用clang
和 LLVM,编译器对于在GPU上的代码执行效率有更好的控制。
At a Glance
This document describes the Metal unified graphics and compute shading language. The Metal shading language is a C++
based programming language that developers can use to write code that is executed on the GPU for graphics and
general-purpose data-parallel computations. Since the Metal shading language is based on C++, developers will find it
familiar and easy to use. With the Metal shading language, both graphics and compute programs can be written with a single,
unified language, which allows tighter integration between the two.
本文描述了Metal着色语言的使用(图形渲染和并行计算)。Metal着色语言基于C++设计,开发者可以用它来编写在
GPU上执行的图形渲染逻辑代码和通用并行计算逻辑代码。因为是基于C++设计,开发者会发现它熟悉便于使用。使
用Metal着色语言,图形渲染和并行计算可以使用同一种语言,这就允许把两种任务结合在一起完成。
How to Use This Document
Developers who are writing code with the Metal framework will want to read this document, because they will need to use
the Metal shading language to write graphics and compute programs to be executed on the GPU. This document is organized
into the following chapters:
! Metal and C++11 (page 8) covers the similarities and differences between the Metal shading language and C++11.
! Metal Data Types (page 10) lists the Metal shading language data types, including types that represent vectors, matrices,
buffers, textures, and samplers. It also discusses type alignment and type conversion.
! Operators (page 30) lists the Metal shading language operators.!
! Functions, Variables, and Qualifiers (page 36) details how functions and variables are declared, sometimes with qualifiers
that restrict how they are used.
! !Metal Standard Library (page 62) defines a collection of built-in Metal shading language functions.
! Compiler Options (page 93) details the options for the Metal shading language compiler, including pre-processor
directives, options for math intrinsics, and options that control optimization.
! Numerical Compliance (page 95) describes requirements for representing floating-point numbers, including accuracy in
mathematical operations.
使用Metal框架的开发者应该阅读本文,因为他们需要使用Metal着色语言编写运行在GPU上的图形渲染和并行计算逻
辑。本文包含如下的章节:
! Metal and C++11, 描述Metal着色语言和它的基础C++11的异同。

! Metal数据类型, 列举Metal着色语言的数据类型,包括表示向量,矩阵,缓存,纹理,采样器等等,还描
述了类型对齐和类型转换。
! 运算符, 列举Metal着色语言操作运算符。
! 方法、变量、修饰符, 详细描述了方法变量如何声明,已经如何使用修饰符修饰,表示使用时的限制。
! Metal标准库, 描述了一些Metal着色语言内建的方法如何使用。
! 编译选项 描述了Metal着色语言编译器的可选项,包括预编译指令,数学内联计算函数选项和其他
优化控制选项。
! 数值规则, 描述了表示浮点数的要求,包括数学运算的精度。
See Also
C++11!
Stroustrup, Bjarne. The C++ Programming Language. Harlow: Addison-Wesley, 2013.
Metal Framework
! The 《Metal Programming Guide
》
provides a detailed introduction to writing apps with the Metal framework. 详细介
绍如何使用Metal框架编写app
The 《Metal Framework Reference
》
details individual classes in the Metal framework. 详细描述每一个Metal框架中
的类。

Metal and C++11
The Metal shading language is based on the C++11 Specification (a.k.a., the ISO/IEC JTC1/SC22/WG21 N3290 Language
Specification) with specific extensions and restrictions. Please refer to the C++11 Specification for a detailed description of
the language grammar. This section and its subsections describe modifications and restrictions to the C++11 language
supported in the Metal shading language. For more information about Metal shading language pre-processing directives and
compiler options, see Compiler Options (page 93) of this document.
Metal着色语言是基于C++ 11标准设计的,它在C++基础上多了一些扩展和限制。下面的内容就是在描述Metal着色语
言相比C++11的修改和限制。Metal着色语言的预编指令和编译器选项后面的章节有描述。
Overloading 重载
The Metal shading language supports overloading as defined by section 13 of the C++11 Specification . The function
overloading rules are extended to include the address space qualifier of an argument. The Metal shading language graphics
and kernel functions cannot be overloaded. (For definition of graphics and kernel functions, see Function Qualifiers (page
36).)
Metal着色语言支持的重载如同C++11标准的section 13所述,方 法 重 载 规 则 有 扩 展 ,可 以 包 括 参 数 的 地 址 空 间 描 述 符 。
Metal着色语言中的标识为图形渲染入口函数或是并行计算入口函数的不可以被重载。(如何标识函数为图形渲染入
口函数 或 并行计算入口函数,参见后面的章节)。
Templates 模板
The Metal shading language supports templates as defined by section 14 of the C++11 Specification .
Metal着色语言支持的模板如同C++11标准的section 14所述
Preprocessing Directives
预编译指令
The Metal shading language supports the pre-processing directives defined by section 16 of the C++11 Specification .
Metal着色语言支持的预编译指令如同C++11标准的section 16所述
Restrictions 限制
The following C++11 features are not available in the Metal shading language (section numbers in this list refer to the
C++11 Specification ):
如下的C++11特性在Metal着色语言中不支持:
! lambda expressions (section 5.1.2) lambda表达式
! !recursive function calls (section 5.2.2, item 9) 递归函数调用
! dynamic_cast operator (section 5.2.7)! 动态转换操作符
! type identification (section 5.2.8)! 类型识别
! new and delete operators (sections 5.3.4 and 5.3.5) 对象创建(new)和销毁(delete)操作符
! noexcept operator (section 5.3.7) 操作符 noexcept
! !goto statement (section 6.6) goto跳转
! !register, thread_local storage qualifiers (section 7.1.1) 变量存储修饰符register 和 thread_local
! virtual function qualifier (section 7.1.2)! 虚函数修饰符
! derived classes (sections 10 and 11)! 派生类
! exception handling (section 15) 异常处理
The C++ standard library must not be used in the Metal shading language code. Instead of the C++ standard library, Metal
has its own standard library that is described in Metal Standard Library (page 62).
C++标准库不可以在Metal着色语言中使用,Metal着色语言使用自己的标准库,后面专门有一个章节描述。
The Metal shading language restricts the use of pointers: Metal着色语言中对于指针的使用的限制

! Arguments to Metal graphics and kernel functions that are pointers declared in a program must be declared with the
Metal device, threadgroup, or constant address space qualifier. (See Address Space Qualifiers for Variables and
Arguments (page 37) for more about address space qualifiers.)
Metal图形和并行计算函数用到的入参如果是指针必须使用地址空间修饰符(device, threadgroup, constant)。
! Function pointers are not supported.
不支持函数指针。
A Metal function cannot be called main.
Metal函数名不能叫main。
Metal Pixel Coordinate System
Metal像素坐标系统
In Metal, the origin of the pixel coordinate system of a texture or a framebuffer attachment is defined at the top left corner.
在Metal中,纹理 或是 帧缓存attachment 中的像素 使用的坐标系统的原点定义在左上角。

Metal Data Types
Metal数据类型
This chapter details the Metal shading language data types, including types that represent vectors and matrices. Atomic data
types, buffers, textures, samplers, arrays, and user-defined structs are also discussed. Type alignment and type conversion are
also described.
本章详述Metal着色语言的数据类型,包括表示向量和矩阵的类型,原子数据类型,缓存,纹理,采样器,数组,已
经用户自定义结构体。还会描述类型对齐和类型转换。
Scalar Data Types
标量数据类型
Metal supports the scalar types listed in Table 2-1 (page 10). Metal does not support the double, long, unsigned long,
long long, unsigned long long, and long double data types.
Metal支持如表2-1列举的标量数据类型,Metal不支持这些数据类型:double, long, unsigned long, long long,
unsigned long long, long double。
Table 2-1 Metal scalar data types
Type
Description
bool
A conditional data type that has the value of either true or false. The value true expands to the
integer constant 1, and the value false expands to the integer constant 0.
布尔数据类型,取值有true或false,true可以扩展为整数常量1,false可以扩展为整数常量0
char
A signed two’s complement 8-bit integer.
有符号8-bit整数
unsigned char
uchar
An unsigned 8-bit integer.
无符号8-bit整数
short
A signed two’s complement 16-bit integer.
有符号16-bit整数
unsigned short
ushort
An unsigned 16-bit integer.
无符号16-bit整数
int
A signed two’s complement 32-bit integer.
有符号32-bit整数
unsigned int
uint
An unsigned 32-bit integer.
无符号32-bit整数
half
A 16-bit floating-point. The half data type must conform to the IEEE 754 binary16 storage format.
一个16-bit浮点数,符合IEEE754的16位二进制浮点数存储格式规范
float
A 32-bit floating-point. The float data type must conform to the IEEE 754 single precision storage
format.
一个32-bit浮点数,符合IEEE754的单精度浮点数存储格式规范
size_t
An unsigned integer type of the result of the sizeof operator. This is a 64-bit unsigned integer.
64-bit无符号整数,表示sizeof操作符的结果,
剩余78页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1