AGAL基本知识(What is AGAL)

Adobe的汇编GPU语言是AGAL,相对的高级语言是PixelBender 3D,学习AGAL有助于更好的理解GPU的工作模式。

以下是Adobe给出的指令集:

 

AGAL的基本语法:

<opcode> <destination>, <source 1>, <source 2 or sampler>

Registers:

所有的Register都是128位的。可以看成4个Components,每个Component都可以用<register>.<x|y|z|w> 或者<register>.<r|g|b|a>来表示。自己根据实际语言区分坐标和颜色。

6种类型register

1. Attribute registers

These registers reference the Vertex Attribute data of the VertexBuffer that is the input of the Vertex Shader. Therefore, they are only available in Vertex Shaders.

This is the main data stream that the Vertex Shader is responsible for processing. Each vertex attribute in the VertexBuffer has its own attribute register.

In order to assign a VertexBuffer attribute to a specific attribute register, use the function Context3D:setVertexBufferAt() , with the proper index.

Then from the Shader, access the attribute register with the syntax: va<n> , where <n> is the index number of the attribute register.

There are a total of attribute registers available to Vertex Shaders.

2. Constant registers

These registers serve the purpose of passing parameters from ActionScript to the Shaders. This is performed with the Context3D::setProgramConstants() family of functions.

These registers are accessed from the Shader with the syntax: vc<n> for Vertex Shaders and fc<n> for Pixel Shaders, where <n> is the index number of the constant register.

There are 128 constant registers available to Vertex Shaders, and 28 constant registers for Pixel Shaders.

3. Temporary registers

These registers are available to Shaders, and they are used for temporary calculations. Since AGAL doesn’t use variables, you’ll use temporary registers to store data throughout your code.

Temporary registers are accessed with the syntax vt<n> (Vertex Shaders) and ft<n> (Pixel Shaders) where <n> is the register number.

There are 8 temporary registers available for Vertex Shaders, and 8 for Pixel Shaders.

4. Output registers

The output registers are used by Vertex and Pixel Shaders to store the output of their calculations. For Vertex Shaders, this output is the position of the vertex. For Pixel Shaders it is the color of the pixel.

These registers are accessed with the syntax op for Vertex Shaders, and oc for Pixel Shaders.

There is obviously only one output register for Vertex and for Pixel Shaders.

5. Varying Registers

These registers are used to pass data from Vertex Shaders to Pixel Shaders. The data that is passed is properly interpolated by the GPU, so that the Pixel Shader receives the correct value for the pixel that is being processed.

Typical data that gets passed in this way is the vertex color or the UV coordinates for texturing.

These registers can be accessed with the syntax v<n> , where <n> is the register number.

There are 8 varying registers available.

6. Texture sampler registers

Texture Sampler registers are used to pick color values from textures, based on UV coordinates.

The texture to be used is specified through ActionScript with the call Context3D::setTextureAt().

The syntax for using texture samplers is: fs<n> <flags> , where <n> is the sampler index, and <flags> is a set of one or more flags that specifies how the sampling should be made.

<flags> is a comma separated set of strings, that defines:

  • texture dimension. Options: 2d, cube
  • mip mapping. Options: nomip (or mipnone , they are the same) , mipnearest, miplinear
  • texture filtering. Options: nearest, linear
  • texture repeat. Options: repeat, wrap, clamp

For example, a standard 2D texture without MIP mapping and linear filtering could be sampled into temporary register ft1 , with the following line:

tex ft1, v0, fs0 <2d,linear,nomip>

In the example above, the varying register v0 holds the interpolated texture UVs.

By Lu Jun

80后男,就职于软件行业。习于F*** GFW。人生48%时间陪同电子设备和互联网,美剧迷,高清视频狂热者,游戏菜鸟,长期谷粉,临时果粉,略知摄影。

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.