l 和 v1 是什么,它有什么类型的值?

What is l and v1 and what type of values it holds?

以下代码由英特尔 GPA 工具生成 我一直在研究这些 HLSL 代码,但我很难理解代码中使用的寄存器是什么以及它具有什么值? 我们怎么知道寄存器中的值他们正在使用什么值?

dcl_constantbuffer CB2[16], immediateIndexed
dcl_constantbuffer CB12[13], immediateIndexed
dcl_sampler s6, mode_default
dcl_resource_texture2d (float,float,float,float) t6
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 6
mov r0.x, cb2[15].z
mov r0.yw, l(0,0,0,0)
add r0.xy, r0.xyxx, v1.xyxx
mad r1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
sample_l r2.xyzw, r0.xyxx, t6.xyzw, s6, l(0.000000)
mul r1.xy, r1.xyxx, cb12[0].xyxx
mov r1.z, l(1.000000)
mul r1.xyz, r2.xxxx, r1.xyzx
mov r0.z, -cb2[15].z
add r0.xy, r0.zwzz, v1.xyxx
mad r0.zw, r0.xxxy, l(0.000000, 0.000000, 2.000000, -2.000000), l(0.000000, 0.000000, -1.000000, 1.000000)
sample_l r2.xyzw, r0.xyxx, t6.xyzw, s6, l(0.000000)
mul r0.xy, r0.zwzz, cb12[0].xyxx
mov r0.z, l(1.000000)
mul r0.xyz, r2.xxxx, r0.xyzx
mad r2.xy, v1.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
mul r2.xy, r2.xyxx, cb12[0].xyxx
sample_l r3.xyzw, v1.xyxx, t6.xyzw, s6, l(0.000000)
mov r2.z, l(1.000000)
mad r3.yzw, r2.xxyz, r3.xxxx, -r0.xxyz
dp3 r0.w, r3.yzwy, r3.yzwy
sqrt r0.w, r0.w
mad r3.yzw, r2.xxyz, r3.xxxx, -r1.xxyz
dp3 r1.w, r3.yzwy, r3.yzwy
sqrt r1.w, r1.w
lt r0.w, r0.w, r1.w
movc r0.xyz, r0.wwww, r0.xyzx, r1.xyzx
mad r0.xyz, -r2.xyzx, r3.xxxx, r0.xyzx
dp3 r0.x, r0.xyzx, r0.xyzx
sqrt r0.x, r0.x
mov r1.y, cb2[15].w
mov r1.xz, l(0,0,0,0)
add r0.yz, r1.xxyx, v1.xxyx
mad r1.xy, r0.yzyy, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
sample_l r4.xyzw, r0.yzyy, t6.xyzw, s6, l(0.000000)
mul r5.xy, r1.xyxx, cb12[0].xyxx
mov r5.z, l(1.000000)
mul r0.yzw, r4.xxxx, r5.xxyz
mad r3.yzw, r2.xxyz, r3.xxxx, -r0.yyzw
dp3 r1.x, r3.yzwy, r3.yzwy
sqrt r1.x, r1.x
mov r1.w, -cb2[15].w
add r1.yz, r1.zzwz, v1.xxyx
mad r3.yz, r1.yyzy, l(0.000000, 2.000000, -2.000000, 0.000000), l(0.000000, -1.000000, 1.000000, 0.000000)
sample_l r4.xyzw, r1.yzyy, t6.xyzw, s6, l(0.000000)
mul r5.xy, r3.yzyy, cb12[0].xyxx
mov r5.z, l(1.000000)
mul r1.yzw, r4.xxxx, r5.xxyz
mad r3.yzw, r2.xxyz, r3.xxxx, -r1.yyzw
dp3 r2.w, r3.yzwy, r3.yzwy
sqrt r2.w, r2.w
lt r1.x, r1.x, r2.w
movc r0.yzw, r1.xxxx, r0.yyzw, r1.yyzw
mad r0.yzw, -r2.xxyz, r3.xxxx, r0.yyzw
dp3 r0.y, r0.yzwy, r0.yzwy
sqrt r0.y, r0.y
lt r0.xy, r0.xyxx, cb12[12].wwww
and r0.x, r0.y, r0.x
and o0.xyzw, r0.xxxx, l(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000)
ret

我们可以看到 l 在上面的代码中被多次使用,括号中的值不同,例如

mad r1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)

and o0.xyzw, r0.xxxx, l(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000)

我知道和操作但是我如何获得这些值以及最终输出可能是什么 我对此很陌生,请原谅,如果接缝非常愚蠢,请提前致谢

阅读着色器字节码确实不是一件容易的事,对于如此复杂的着色器需要一点耐心。为了更深入地了解,我建议阅读 documentation,这样您就可以轻松查找运算符或寄存器。

针对您的问题:

  • v1 代表一个输入颜色寄存器(docs),因为有组件 xy 并且声明了一个纹理我假设它描述了传递给着色器
  • l(...) 似乎是常量的缩写形式,我没有找到任何关于此的文档,但它很可能是一个内联常量所以 mad r1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000) => r1.xy = r0.xy * float2(2,-2) + float2(-1, 1)
  • and o0.xyzw, r0.xxxx, l(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000)理解起来有点特殊。它是寄存器组件,上面两行有一个 lt,这意味着现在 r0.x 是一个形式为 0xFFFFFFFF (true) 或 0x00000000(false ).通过 and with 0x3f800000(这是 1.0 的浮点表示),它实质上将布尔值转换为 1.0 或 0.0 的浮点数。因此着色器的输出在每个通道中关于 r0.
  • 的布尔值是 1.0 或 0.0