Search code examples
unity-game-enginegraphics3dglslhlsl

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


the code below generated from intel GPA tool and i have been studying these HLSL code and i have trouble understanding in what is l register used in the code and what values it holds? how do we know the values in registers what values they are using?

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

we can see l is being used many times in above code with different values in brackets like

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

and

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

i know about and operation but how l getting these values and what could be the final output i'm very new to this please pardon if it seams very dumb thanks in advance


Solution

  • Reading shader bytecode is really not an easy task, for such a complex shader it needs a little patience. To get a deeper understanding I'll recommend to read the documentation, so you can easily lookup operators or registers.

    To your questions:

    • v1 stands for a input color register (docs), as there are to components xy and a texture is declared I would assume that it is describing some kind of texture coordinate passed to the shader
    • l(...) seems to be a short form for a constant, I didn't find any documentation on this, but it is most probably an inline constant so 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) is a bit special to understand. It and's the registers componentwise, two lines above there is a lt, which means that now in r0.x is a boolean in the form 0xFFFFFFFF (true) or 0x00000000(false). By an and with 0x3f800000 (which is the floating point representation of 1.0), it essentially transforms the boolean to a float either 1.0 or 0.0. So the output of the shader is 1.0 or 0.0 in each channel regarding the boolean value of r0.