PDA

View Full Version : Effects in DX10, matrix transposes and HLSL


Hawkwind
01-30-2008, 12:21 AM
I'm a bit of a die-hard for assembler shaders, and used to transposing matrices before I pass them via shader constants to the shader.

HOWEVER, with DX10 I am finally biting the bullet and using effects and HLSL.

Now the effects (.fx files) which I have, require the passing of transform matrices to the effect via the effect variables. That's fine, but they don't
require me to transpose them first. Does this mean that the effect is wasting time by doing this transform ? I have usually maintained copies of transforms 'ready transposed' in my code when using shader 3, but it now seems that by using effects there will be an undesirable preprocessing ( albeit small) each time I set the effect variables ?

Am I missing something here ?

Cheers

Goz
01-30-2008, 01:22 PM
Surely HLSL can, simply, optimise that behind your back ... so instead of using 4 dp4s for a matrix-vector mulitply it can use 4 madds instead?

Goz
01-30-2008, 01:43 PM
Just in case you don't know you can do a matrix vector multiply with an un-transposed matrix as follows ...

mul r0, c0, r1.x
mad r0, c1, r1.y, r0
mad r0, c2, r1.z, r0
mad r0, c3, r1.w, r0

This sorta thing gets abstracted from you with HLSL doesn't it?

.oisyn
01-30-2008, 02:32 PM
Sure, if I remember it correctly it all depends on whether you use column vectors (m * v) or row vectors (v * m)

Hawkwind
01-31-2008, 12:27 AM
Thanks - Goz: I didn't know this trick, pretty neat though. I assumed that the matrix had to be transposed, I'll try it out with some old asm shaders. I guess that HLSL will be doing something similar. I just assumed that the m4x4 macro was the only sensible way....
Cheers