Skip to main content
GameDev.net gamedev.net
🔒 Locked

HLSL Assembly Question

Started by yadango Aug 3, 2012 at 10:01 AM 4 replies 2.2k views
Original Post
yadango
yadango
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!
Digitalfragment
Digitalfragment
The first. the z in c0[a0.w].xxyz would get dropped as it doesn't have a corresponding output in r4.yzw
yadango
yadango
Cool, thanks, makes sense now! The repeat rule only applies to the source register and not the dest.
Erik Rufelt
Erik Rufelt
I'm not sure.. but I would guess neither.. and that r4.yzw = v0.y * c0[a0.w].xyz
The docs http://msdn.microsoft.com/en-us/library/windows/desktop/hh447193(v=vs.85).aspx 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.
yadango
yadango
so maybe something like this? smile.png 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]
Erik Rufelt
Erik Rufelt
The internal steps will differ from platform to platform, HLSL ASM is an intermediate format, but the end result is most likely like that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.