Sign in to follow this  
yadango

HLSL Assembly Question

Recommended Posts

Hello,
I'm trying to learn HLSL assembly, using MSDN as a guide and a book or two. Most swizzle examples given are kind of simple and I saw some code that looked like this and wondered what the equivalent statements were.
[source]mova a0.w, r4.x
mul r4.yzw, v0.y, c0[a0.w].xxyz
[/source]
is the equivalent expression
[source]a0.w = r4.x
r4.y = v0.y * c0[a0.w].x
r4.z = v0.y * c0[a0.w].x
r4.w = v0.y * c0[a0.w].y[/source]
or this?
[source]a0.w = r4.x
r4.y = v0.y * c0[a0.w].x
r4.z = v0.y * c0[a0.w].x
r4.w = v0.y * c0[a0.w].y
r4.w = v0.y * c0[a0.w].z[/source]
Thanks!

Share this post


Link to post
Share on other sites
I'm not sure.. but I would guess neither.. and that r4.yzw = v0.y * c0[a0.w].xyz
The docs [url="http://msdn.microsoft.com/en-us/library/windows/desktop/hh447193(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/hh447193(v=vs.85).aspx[/url] says the destination register has a writemask.. which is not the same as a swizzle. I interpret it as that the calculation is done on 4 components and the components of the result is written to the destination register or skipped depending on the mask..
That is, xxyz * v0.y is calculated to a temporary result xyzw, and the x is skipped on write to destination since it's not in the mask.

Share this post


Link to post
Share on other sites
so maybe something like this? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] that's why the mask has to be in order...

[source lang="cpp"]// mova a0.w, r4.x
temp.x = r4.x
temp.y = r4.x
temp.z = r4.x
temp.w = r4.x
a0.x = unchanged
a0.y = unchanged
a0.z = unchanged
a0.w = temp.w

// mul r4.yzw, v0.y, c0[a0.w].xxyz
temp1.x = v0.y
temp1.y = v0.y
temp1.z = v0.y
temp1.w = v0.y
temp2.x = c0[a0.w].x
temp2.y = c0[a0.w].x
temp2.z = c0[a0.w].y
temp2.w = c0[a0.w].z
r4.x = unchanged
r4.y = temp1.y * temp2.y
r4.z = temp1.z * temp2.z
r4.w = temp1.w * temp2.w[/source] Edited by yadango

Share this post


Link to post
Share on other sites
The internal steps will differ from platform to platform, HLSL ASM is an intermediate format, but the end result is most likely like that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this