没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
Metal Shading Language
Specification
Version 2.3
Developer
2020-06-20 Copyright © 2020 Apple Inc. All Rights Reserved.
Page 2 of 221
Contents
1 Introduction ............................................................................................... 8
1.1 Purpose of This Document ................................................................................................ 8
1.2 Organization of This Specification .................................................................................... 8
1.3 References ........................................................................................................................ 8
1.4 Metal and C++14 ............................................................................................................... 9
1.4.1 Overloading ................................................................................................................. 9
1.4.2 Templates ................................................................................................................... 9
1.4.3 Preprocessing Directives ............................................................................................ 9
1.4.4 Restrictions ................................................................................................................. 9
1.5 Compiler and Preprocessor ............................................................................................. 10
1.5.1 Preprocessor Compiler Options ................................................................................. 10
1.5.2 Preprocessor Definitions ............................................................................................ 10
1.5.3 Math Intrinsics Compiler Options ............................................................................... 11
1.5.4 Invariance Compiler Options ...................................................................................... 11
1.5.5 Compiler Options to Enable Modules ......................................................................... 12
1.5.6 Compiler Options Controlling the Language Version ................................................. 12
1.5.7 Compiler Options to Request or Suppress Warnings ................................................. 13
1.5.8 Target Conditionals .................................................................................................... 13
1.5.9 Dynamic Library Linker options .................................................................................. 14
1.6 Metal Coordinate Systems ............................................................................................... 14
2 Data Types ............................................................................................... 17
2.1 Scalar Data Types ............................................................................................................ 17
2.2 Vector Data Types ........................................................................................................... 19
2.2.1 Accessing Vector Components ................................................................................. 20
2.2.2 Vector Constructors .................................................................................................. 23
2.2.3 Packed Vector Types ................................................................................................ 24
2.3 Matrix Data Types ........................................................................................................... 26
2.3.1 Accessing Matrix Components ................................................................................. 27
2.3.2 Matrix Constructors .................................................................................................. 28
2.4 Alignment of Data Types ................................................................................................. 29
2.5 Atomic Data Types .......................................................................................................... 29
2.6 Pixel Data Types ............................................................................................................. 29
2.7 Buffers .............................................................................................................................. 31
2.8 Textures .......................................................................................................................... 32
2.8.1 Texture Buffers ......................................................................................................... 33
2.9 Samplers ......................................................................................................................... 34
2.10 Imageblocks .................................................................................................................... 37
2.11 Aggregate Types ............................................................................................................. 39
2.11.1 Arrays of Textures, Texture Buffers, and Samplers .................................................. 39
2020-06-20 Copyright © 2020 Apple Inc. All Rights Reserved.
Page 3 of 221
2.11.1.1 Array Element Access with its Operator .............................................................. 40
2.11.1.2 Array Capacity ..................................................................................................... 40
2.11.1.3 Constructors for Templated Arrays ..................................................................... 40
2.11.2 Structures of Buffers, Textures, and Samplers ......................................................... 42
2.12 Argument Buffers ............................................................................................................ 43
2.12.1 Tier 2 Hardware Support for Argument Buffers ........................................................ 45
2.13 Uniform Type .................................................................................................................. 46
2.13.1 The Need for a Uniform Type .................................................................................... 46
2.13.2 Behavior of the Uniform Type ................................................................................... 48
2.13.3 Uniform Control Flow ................................................................................................ 49
2.14 Visible Function Table ..................................................................................................... 49
2.15 Function Group Attribute ................................................................................................ 50
2.16 Ray Tracing Intersection Tags ........................................................................................ 50
2.17 Type Conversions and Re-interpreting Data .................................................................. 52
2.18 Implicit Type Conversions ............................................................................................... 53
3 Operators ................................................................................................ 54
3.1 Scalar and Vector Operators ........................................................................................... 54
3.2 Matrix Operators ............................................................................................................. 57
4 Address Spaces ....................................................................................... 60
4.1 device Address Space .................................................................................................... 60
4.2 constant Address Space .................................................................................................. 61
4.3 thread Address Space ..................................................................................................... 62
4.4 threadgroup Address Space ........................................................................................... 62
4.4.1 SIMD-groups and Quad-groups ............................................................................... 63
4.5 threadgroup_imageblock Address Space ....................................................................... 63
4.6 ray_data Address Space ................................................................................................. 64
5 Function and Variable Declarations .......................................................... 65
5.1 Functions ......................................................................................................................... 65
5.1.1 Vertex Functions ....................................................................................................... 65
5.1.1.1 Post-Tessellation Vertex Functions .................................................................... 66
5.1.1.2 Patch Type and Number of Control Points Per-Patch ........................................ 66
5.1.2 Fragment Functions .................................................................................................. 67
5.1.3 Compute Functions (Kernels) ................................................................................... 68
5.1.4 Visible Functions ....................................................................................................... 68
5.1.5 Intersection Functions ............................................................................................... 68
5.1.6 Tile Functions ............................................................................................................ 69
5.1.7 Host Name Attribute ................................................................................................. 70
5.1.8 Templated Vertex, Fragment, and Kernel functions ................................................. 70
5.2 Function Arguments and Variables .................................................................................. 71
5.2.1 Locating Buffer, Texture, and Sampler Arguments ................................................... 72
5.2.1.1 Vertex Function Example with Resources and Outputs to Device Memory ........ 73
2020-06-20 Copyright © 2020 Apple Inc. All Rights Reserved.
Page 4 of 221
5.2.1.2 Raster Order Groups ........................................................................................... 74
5.2.2 Attributes to Locate Per-Vertex Inputs ..................................................................... 75
5.2.3 Attributes for Built-in Variables ................................................................................. 78
5.2.3.1 Vertex Function Input Attributes ......................................................................... 78
5.2.3.2 Post-Tessellation Vertex Function Input Attributes ............................................ 80
5.2.3.3 Vertex Function Output Attributes ...................................................................... 80
5.2.3.4 Fragment Function Input Attributes .................................................................... 83
5.2.3.5 Fragment Function Output Attributes ................................................................. 88
5.2.3.6 Kernel Function Input Attributes ......................................................................... 90
5.2.3.7 Intersection Function Input Attributes ................................................................. 94
5.2.3.8 Intersection Function Output Attributes .............................................................. 96
5.2.4 Input Assembly Attribute ........................................................................................... 97
5.2.4.1 Vertex Function Output Example ........................................................................ 98
5.2.4.2 Fragment Function Input Example ...................................................................... 99
5.2.4.3 Kernel Function Per-Thread Input Example ...................................................... 100
5.3 Storage Class Specifiers ................................................................................................ 101
5.4 Sampling and Interpolation Attributes ........................................................................... 102
5.5 Per-Fragment Function versus Per-Sample Function ................................................... 103
5.6 Imageblock Attributes ................................................................................................... 103
5.6.1 Matching Data Members of Master and View Imageblocks .................................... 104
5.6.2 Imageblocks and Raster Order Groups ................................................................... 108
5.6.3 Imageblock Layouts for Fragment Functions .......................................................... 109
5.6.3.1 Implicit Imageblock Layout for Fragment Functions ......................................... 109
5.6.3.2 Explicit Imageblock Layout for Fragment Functions .......................................... 110
5.6.4 Imageblock Layouts in Kernel Functions ................................................................... 111
5.6.5 Aliasing Explicit and Implicit Imageblocks ................................................................ 112
5.6.6 Imageblocks and Function Constants ...................................................................... 113
5.7 Graphics Function – Signature Matching ....................................................................... 113
5.7.1 Vertex – Fragment Signature Matching .................................................................... 114
5.8 Program Scope Function Constants .............................................................................. 118
5.8.1 Specifying Program Scope Function Constants ...................................................... 119
5.8.1.1 Function Constants to Control Code Paths to Compile ..................................... 120
5.8.1.2 Function Constants when Declaring the Arguments of Functions ..................... 121
5.8.1.3 Function Constants for Elements of an Input Assembly Structure .................... 123
5.8.1.4 Function Constants for Resource Bindings ........................................................ 124
5.8.1.5 Function Constants for Color Attachments and Raster Order Groups ............... 125
5.8.1.6 Function Constants with Elements of a Structure .............................................. 125
5.9 Per-Primitive Viewport and Scissor Rectangle Index Selection ..................................... 126
5.10 Additional Restrictions ................................................................................................... 126
6 Metal Standard Library ............................................................................ 128
6.1 Namespace and Header Files ........................................................................................ 128
6.2 Common Functions ........................................................................................................ 128
2020-06-20 Copyright © 2020 Apple Inc. All Rights Reserved.
Page 5 of 221
6.3 Integer Functions ........................................................................................................... 129
6.4 Relational Functions ....................................................................................................... 131
6.5 Math Functions .............................................................................................................. 132
6.6 Matrix Functions ............................................................................................................. 137
6.7 Geometric Functions ..................................................................................................... 138
6.8 Compute Functions ....................................................................................................... 139
6.8.1 Threadgroup and SIMD-group Synchronization Functions .................................... 139
6.8.2 SIMD-group Functions ............................................................................................ 140
6.8.3 Quad-group Functions ............................................................................................. 147
6.9 Graphics Functions ........................................................................................................ 152
6.9.1 Fragment Functions ................................................................................................. 152
6.9.1.1 Fragment Functions – Derivatives ...................................................................... 152
6.9.1.2 Fragment Functions – Samples .......................................................................... 153
6.9.1.3 Fragment Functions – Flow Control ................................................................... 153
6.10 Texture Functions ......................................................................................................... 154
6.10.1 1D Texture ................................................................................................................ 157
6.10.2 1D Texture Array ..................................................................................................... 158
6.10.3 2D Texture .............................................................................................................. 158
6.10.3.1 2D Texture Sampling Example .......................................................................... 160
6.10.4 2D Texture Array ...................................................................................................... 161
6.10.5 3D Texture .............................................................................................................. 163
6.10.6 Cube Texture ........................................................................................................... 164
6.10.7 Cube Texture Array ................................................................................................. 166
6.10.8 2D Multisampled Texture ........................................................................................ 168
6.10.9 2D Multisampled Texture Array .............................................................................. 169
6.10.10 2D Depth Texture .................................................................................................... 169
6.10.11 2D Depth Texture Array ........................................................................................... 172
6.10.12 2D Multisampled Depth Texture .............................................................................. 174
6.10.13 2D Multisampled Depth Texture Array ..................................................................... 174
6.10.14 Cube Depth Texture ................................................................................................. 175
6.10.15 Cube Depth Texture Array ....................................................................................... 177
6.10.16 Texture Buffer Functions ......................................................................................... 180
6.10.17 Texture Synchronization Functions ........................................................................ 180
6.10.18 Null Texture Functions ............................................................................................. 181
6.11 Imageblock Functions .................................................................................................... 182
6.11.1 Functions for Imageblocks with Implicit Layout ....................................................... 182
6.11.2 Functions for Imageblocks with Explicit Layout ...................................................... 184
6.11.3 Writing an Imageblock Slice to a Region in a Texture ............................................. 185
6.12 Pack and Unpack Functions .......................................................................................... 188
6.12.1 Unpack and Convert Integers to a Floating-Point Vector ....................................... 188
6.12.2 Convert Floating-Point Vector to Integers, then Pack the Integers ........................ 189
6.13 Atomic Functions .......................................................................................................... 190
剩余220页未读,继续阅读
滑了丝的螺丝钉
- 粉丝: 5999
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0