redorav / hlslpp

Math library using HLSL syntax with multiplatform SIMD support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Matrix accessor operator

plekakis opened this issue · comments

Hey again and thank you for your hard work on this!
I do have another feature which would prove helpful when sharing codebase between HLSL and C++, that is matrix accessor operators, so it's conforming to how HLSL deals with it.

float4x4 m = { .... }
m[0][0] = 5;
m[0][1] = 2;
...
etc

Hi again @plekakis, thanks for the request! I have been toying around with the code and I think it can be implemented, with the following restrictions:

  • It will only be implemented for float4x4 and float3x3 matrices, which are the most common matrices anyway. float2x2 cannot be implemented because the physical layout of float2 doesn't match the physical layout of float2x2 (because a float2x2 is like a float4 internally). Other matrices have the same problems, for instance float4x2 and float2x4 have the same physical layout. They are probably rarely used and not worth the extra complexity.

  • For vectors, I cannot provide the same behavior as swizzling, so it will access the f32[] union and it's up to the compiler to generate the appropriate code. I'd expect a nice compiler to produce nice code if it's just initialization, for other operations I don't really know.

It won't be like hlsl other than in those limited cases, just due to the nature of SIMD and how the library has been designed. If this is acceptable I think I can have it in no time.

@plekakis Let me know if that works for you or if there's anything else you need

Closed via c275bcf

Unfortunately it looks like what I've done has upset gcc. I need to find an alternative

Fixed via 165fe75

I just noticed that GCC in AVX will be broken for the same reason. Since I don't test it I wasn't really aware. This is related to the swizzles. I wonder if there's anything else I can do. Unrelated to this bug but I'll leave a note.