I am trying to understand some shader code written in ARB. I am mostly using this to understand it. However the doc doesn't explain (or I missed it) how vector operands are transformed into scalars, for example in this expression

MAD.F32 R1.y, R2, R1, R1.w;

R2 and R1 are both 4 components vectors, but the swizzle is unspectified for R2 and the second R1. What is this instruction really doing? My hypothesis was that unspecified components were deduced using the result's component, thus the instruction would by equal to

MAD.F32 R1.y, R2.y, R1.y, R1.w;

but it doesn't seems to be correct.


1 Answer 1


Wow, NV assembly, a blast from the past! The semantics of this are that the calculation is done as if on a full 4-component vector, and then the destination register is masked so that the write only occurs to the selected component.

So this should be effectively like

vec4 temp = R2.xyzw * R1.xyzw + R1.wwww;
R1.y = temp.y;

(See NV_gpu_program4 spec, Section 2.X.4.3, "Program Destination Variable Update".)

But that agrees with the result being R2.y * R1.y + R1.w which you said doesn't seem to be correct, so I'm not sure what's going on.

  • 1
    $\begingroup$ I wasn't sure about the correctness, I compared the results I got to a glsl version (decompiled) of the shader I'm trying to understand, and the code didn't seem to match, so I tought maybe my hypothesis was wrong. But since it turns out to be correct, I'll go throught both versions again, I probably made a mistake reading it. Thanks you very much for your answer, this doc you've provided completes the other one on several points, it helps a lot. $\endgroup$
    – Aulaulz
    Sep 29, 2022 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.