| Instruction Set | ||||||||
| Name | Description | Instruction slots | Setup | Arithmetic | Texture | New | ||
| abs - ps | 绝对值 | 1 | x | x | ||||
| add - ps | 加法 | 1 | x | |||||
| cmp - ps | Compare source to 0 | 1 | x | |||||
| crs - ps | 叉积 | 2 | x | x | ||||
| dcl_samplerType (sm2, sm3 - ps asm) | 为采样器声明贴图维数 | 0 | x | x | ||||
| dcl - (sm2, sm3 - ps asm) | 声明顶点shader输出寄存器和像素shader输入寄存器之间的联合 | 0 | x | x | ||||
| def - ps | 定义常量 | 0 | x | |||||
| dp2add - ps | 2D点积之后加法运算 | 2 | x | x | ||||
| dp3 - ps | 3D点积 | 1 | x | |||||
| dp4 - ps | 4D点积 | 1 | x | |||||
| exp - ps | 全精度的2的x次方 | 1 | x | x | ||||
| frc - ps | 小数部分 | 1 | x | x | ||||
| log - ps | 全精度的 log?(x) | 1 | x | x | ||||
| lrp - ps | 线性插值 | 2 | x | |||||
| m3x2 - ps | 3x2 乘法 | 2 | x | x | ||||
| m3x3 - ps | 3x3 乘法 | 3 | x | x | ||||
| m3x4 - ps | 3x4 乘法 | 4 | x | x | ||||
| m4x3 - ps | 4x3 乘法 | 3 | x | x | ||||
| m4x4 - ps | 4x4 乘法 | 4 | x | x | ||||
| mad - ps | 乘法之后加法运算 | 1 | x | |||||
| max - ps | 最大值 | 1 | x | x | ||||
| min - ps | 最小值 | 1 | x | x | ||||
| mov - ps | 赋值 | 1 | x | |||||
| mul - ps | 乘法 | 1 | x | |||||
| nop - ps | 无运算 | 1 | x | |||||
| nrm - ps | 单位化 | 3 | x | x | ||||
| pow - ps | 幂运算 | 3 | x | x | ||||
| ps | 版本 | 0 | x | |||||
| rcp - ps | 倒数 | 1 | x | x | ||||
| rsq - ps | 平方根后倒数 | 1 | x | x | ||||
| sincos - ps | sin和cos | 8 | x | x | ||||
| sub - ps | 减法 | 1 | x | |||||
| texkill - ps | 中断像素渲染 | 1 | x | |||||
| texld - ps_2_0 and up | 采样一张贴图 | 1 | x | x | ||||
| texldb - ps | 根据w部分进行对贴图的level-of-detail bias采样 | 1 | x | x | ||||
| texldp - ps | 根据w部分进行对贴图的投影划分采样 | 1 | x | x | ||||
语法
crs dst, src0, src1
叉积
算法
dest.x = src0.y * src1.z - src0.z * src1.y;
dest.y = src0.z * src1.x - src0.x * src1.z;
dest.z = src0.x * src1.y - src0.y * src1.x;
语法
dcl_samplerType s#
声明一个像素shader采样器
· _2d
· _cube
· _volume
示例
dcl_cube t0.rgb; // Define a 3D texture map.
add r0, r0, t0; // Perturb texture coordinates.
texld r0, s0, r0; // Load r0 with a color sampled from stage0
// at perturbed texture coordinates r0.
// This is a dependent texture read.
语法
dp2add dst, src0, src1, src2.{x|y|z|w}
算法
dest = src0.r * src1.r + src0.g * src1.g + src2.replicate_swizzle
// The scalar result is replicated to the write mask components
语法
nrm dst, src
单位化一个3D向量
squareRootOfTheSum = (src0.x*src0.x + src0.y*src0.y +src0.z*src0.z)1/2;
算法
dest.x = src0.x * (1 / squareRootOfTheSum);
dest.y = src0.y * (1 / squareRootOfTheSum);
dest.z = src0.z * (1 / squareRootOfTheSum);
dest.w = src0.w * (1 / squareRootOfTheSum);
语法
sincos dst.{x|y|xy}, src0.{x|y|z|w}, src1, src2
sincos dst.{x|y|xy}, src0.{x|y|z|w}
算法
写入通道为.x
dest.x = cos(V)
dest.y is undefined when the instruction completes
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
写入通道为.y
dest.x is undefined when the instruction completes
dest.y = sin(V)
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
写入通道为.xy
dest.x = cos(V)
dest.y = sin(V)
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
写入通道为.x
dest.x = cos(V)
dest.y is undefined when the instruction completes
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
写入通道为.y
dest.x is undefined when the instruction completes
dest.y = sin(V)
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
写入通道为.xy
dest.x = cos(V)
dest.y = sin(V)
dest.z is undefined when the instruction completes
dest.w is not touched by the instruction
示例角度制转弧度制
def c0, pi, 0.5, 2*pi, 1/(2*pi)
mad r0.x, input_angle, c0.w, c0.y
frc r0.x, r0.x
mad r0.x, r0.x, c0.z, -c0.x
| Instruction Set | |||||||||
| Name | Description | Instruction slots | Setup | Arithmetic | Texture | Flow control | New | ||
| abs - ps | 绝对值 | 1 | x | ||||||
| add - ps | 加法运算 | 1 | x | ||||||
| break - ps | 跳出一个循环 | 1 | x | x | |||||
| break_comp - ps | 通过一个比较跳出循环 | 3 | x | x | |||||
| breakp - ps | 基于一个断言跳出循环 | 3 | x | x | |||||
| call - ps | 调用一个子程序 | 2 | x | x | |||||
| callnz bool - ps | 如果一个boolean寄存器不为0的话调用一个子程序 | 3 | x | x | |||||
| callnz pred - ps | 如果一个predicate寄存器不为0的话调用一个子程序 | 3 | x | x | |||||
| cmp - ps | 以0为比较赋值 | 1 | x | ||||||
| crs - ps | 叉积 | 2 | x | ||||||
| dcl_samplerType (sm2, sm3 - ps asm) | 为采样器声明贴图维数 | 0 | x | ||||||
| dcl - (sm2, sm3 - ps asm) | 声明顶点shader输出寄存器和像素shader输入寄存器之间的联合 | 0 | x | ||||||
| def - ps | 定义常量 | 0 | x | ||||||
| defb - ps | 定义一个 Boolean 常量 | 0 | x | x | |||||
| defi - ps | 定义一个integer 常量 | 0 | x | x | |||||
| dp2add - ps | 2D 点积之后加法运算 | 2 | x | ||||||
| dp3 - ps | 3D 点积 | 1 | x | ||||||
| dp4 - ps | 4D 点积 | 1 | x | ||||||
| dsx - ps | 改变x方向的比率 | 2 | x | x | |||||
| dsy - ps | 改变y方向的比率 | 2 | x | x | |||||
| else - ps | else块 | 1 | x | x | |||||
| endif - ps | if结束 | 1 | x | x | |||||
| endrep - ps | 循环结束 | 2 | x | x | |||||
| exp - ps | 全精度计算2的幂 | 1 | x | ||||||
| frc - ps | 小数部分 | 1 | x | ||||||
| if bool - ps | if块 | 3 | x | x | |||||
| if_comp - ps | 比较形式的if | 3 | x | x | |||||
| if pred - ps | 断言形式的if | 3 | x | x | |||||
| label - ps | 标签 | 0 | x | x | |||||
| log - ps | 全精度计算log?(x) | 1 | x | ||||||
| lrp - ps | 线性插值 | 2 | x | ||||||
| m3x2 - ps | 3x2 乘法 | 2 | x | ||||||
| m3x3 - ps | 3x3 乘法 | 3 | x | ||||||
| m3x4 - ps | 3x4 乘法 | 4 | x | ||||||
| m4x3 - ps | 4x3 乘法 | 3 | x | ||||||
| m4x4 - ps | 4x4 乘法 | 4 | x | ||||||
| mad - ps | 乘法之后加法运算 | 1 | x | ||||||
| max - ps | 最大值 | 1 | x | ||||||
| min - ps | 最小值 | 1 | x | ||||||
| mov - ps | 赋值 | 1 | x | ||||||
| mul - ps | 乘法 | 1 | x | ||||||
| nop - ps | 无运算 | 1 | x | ||||||
| nrm - ps | 单位化 | 3 | x | ||||||
| pow - ps | 幂运算 | 3 | x | ||||||
| ps | 版本 | 0 | x | ||||||
| rcp - ps | 倒数 | 1 | x | ||||||
| rep - ps | 循环 | 3 | x | x | |||||
| ret - ps | 子程序的结束 | 1 | x | x | |||||
| rsq - ps | 平方根的倒数 | 1 | x | ||||||
| setp_comp | 设置断言寄存器 | 1 | x | x | |||||
| sincos - ps | Sin和cos | 8 | x | ||||||
| sub - ps | 减法运算 | 1 | x | ||||||
| texkill - ps | 中断像素渲染 | See note 1 | x | ||||||
| texld - ps_2_0 and up | 采样一个贴图 | See note 2 | x | ||||||
| texldb - ps | 根据w部分进行对贴图的level-of-detail bias采样 | See note 3 | x | ||||||
| texldd - ps | 用户提供一个剃度值来采样贴图 | 3 | x | x | |||||
| texldp - ps | 根据w部分进行对贴图的投影划分采样 | See note 4 | x | ||||||
语法
endrep
示例
rep i2
add r0, r0, c0
endrep
if bool
示例
defb b3, true
if b3
// Instructions to run if b3 is nonzero
else
// Instructions to run otherwise
endif
语法
if_comp src0, src1
_comp为
|
Syntax |
Comparison |
|
_gt |
大于 |
|
_lt |
小于 |
|
_ge |
大于等于 |
|
_le |
小于等于 |
|
_eq |
等于 |
|
_ne |
不等于 |
示例
if_lt r3.x, r4.y
// Instructions to run if r3.x < r4.y
else
// Instructions to run otherwise
endif
语法
rep i#
循环
i#.x范围为[0, 255]
示例
rep i2
add r0, r0, c0
endrep
-----wolf96 2017/1/3
Asm Shader Reference --- Shader Model 2 part
原文:http://www.cnblogs.com/zhanlang96/p/6243732.html