Skip to content

Commit 965ef97

Browse files
committed
togl/togles: set D3DMATRIX alignment to 16
1 parent 657f59a commit 965ef97

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

public/mathlib/vmatrix.h

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ class alignas(16) VMatrix
114114

115115
const matrix3x4_t& As3x4() const;
116116
void CopyFrom3x4( const matrix3x4_t &m3x4 );
117-
void Set3x4( matrix3x4_t& matrix3x4 ) const;
117+
void Set3x4( const matrix3x4_t& matrix3x4 );
118118

119119
bool operator==( const VMatrix& src ) const {
120-
return !memcmp( src.m, m, sizeof(m) );
120+
return src.m[0][0] == m[0][0] && src.m[0][1] == m[0][1] && src.m[0][2] == m[0][2] && src.m[0][3] == m[0][3] &&
121+
src.m[1][0] == m[1][0] && src.m[1][1] == m[1][1] && src.m[1][2] == m[1][2] && src.m[1][3] == m[1][3] &&
122+
src.m[2][0] == m[2][0] && src.m[2][1] == m[2][1] && src.m[2][2] == m[2][2] && src.m[2][3] == m[2][3] &&
123+
src.m[3][0] == m[3][0] && src.m[3][1] == m[3][1] && src.m[3][2] == m[3][2] && src.m[3][3] == m[3][3];
121124
}
125+
122126
bool operator!=( const VMatrix& src ) const { return !( *this == src ); }
123127

124128
#ifndef VECTOR_NO_SLOW_OPERATIONS
@@ -512,14 +516,12 @@ inline void VMatrix::Init(
512516
//-----------------------------------------------------------------------------
513517
// Initialize from a 3x4
514518
//-----------------------------------------------------------------------------
515-
inline void VMatrix::Init( const matrix3x4_t& matrix3x4 )
519+
inline void VMatrix::Init( const matrix3x4_t& _m )
516520
{
517-
memcpy(m, matrix3x4.Base(), sizeof( matrix3x4_t ) );
518-
519-
m[3][0] = 0.0f;
520-
m[3][1] = 0.0f;
521-
m[3][2] = 0.0f;
522-
m[3][3] = 1.0f;
521+
m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3];
522+
m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3];
523+
m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3];
524+
m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f;
523525
}
524526

525527
//-----------------------------------------------------------------------------
@@ -837,14 +839,14 @@ inline const matrix3x4_t& VMatrix::As3x4() const
837839

838840
inline void VMatrix::CopyFrom3x4( const matrix3x4_t &m3x4 )
839841
{
840-
memcpy( m, m3x4.Base(), sizeof( matrix3x4_t ) );
841-
m[3][0] = m[3][1] = m[3][2] = 0;
842-
m[3][3] = 1;
843-
}
842+
Init(m3x4);
843+
}
844844

845-
inline void VMatrix::Set3x4( matrix3x4_t& matrix3x4 ) const
845+
inline void VMatrix::Set3x4( const matrix3x4_t& _m )
846846
{
847-
memcpy(matrix3x4.Base(), m, sizeof( matrix3x4_t ) );
847+
m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3];
848+
m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3];
849+
m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3];
848850
}
849851

850852
#ifndef VECTOR_NO_SLOW_OPERATIONS
@@ -1805,26 +1807,27 @@ inline void MatrixBuildScale( VMatrix &dst, const Vector& scale )
18051807
MatrixBuildScale( dst, scale.x, scale.y, scale.z );
18061808
}
18071809

1810+
// nillerusr: optimize this bruh later
18081811
inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar )
18091812
{
18101813
// FIXME: collapse all of this into one matrix after we figure out what all should be in here.
18111814
float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f );
18121815
float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f );
18131816

1814-
memset( dst.Base(), 0, sizeof( dst ) );
1815-
dst[0][0] = 2.0F * zNear / width;
1816-
dst[1][1] = 2.0F * zNear / height;
1817-
dst[2][2] = -zFar / ( zNear - zFar );
1818-
dst[3][2] = 1.0f;
1819-
dst[2][3] = zNear * zFar / ( zNear - zFar );
1817+
dst. Init(
1818+
2.0f * zNear / width, 0.f, 0.f, 0.f,
1819+
0.f, 2.0f * zNear / height, 0.f, 0.f,
1820+
0.f, 0.f, -zFar / ( zNear - zFar ), zNear * zFar / ( zNear - zFar ),
1821+
0.f, 0.f, 1.f, 0.f
1822+
);
18201823

18211824
// negate X and Y so that X points right, and Y points up.
18221825
VMatrix negateXY;
18231826
negateXY.Identity();
18241827
negateXY[0][0] = -1.0f;
18251828
negateXY[1][1] = -1.0f;
18261829
MatrixMultiply( negateXY, dst, dst );
1827-
1830+
18281831
VMatrix addW;
18291832
addW.Identity();
18301833
addW[0][3] = 1.0f;

public/togl/linuxwin/dxabstract_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
10421042
D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
10431043
} D3DSHADER_PARAM_REGISTER_TYPE;
10441044

1045-
struct D3DMATRIX
1045+
struct alignas(16) D3DMATRIX
10461046
{
10471047
union
10481048
{

public/togles/linuxwin/dxabstract_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
10421042
D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
10431043
} D3DSHADER_PARAM_REGISTER_TYPE;
10441044

1045-
struct D3DMATRIX
1045+
struct alignas(16) D3DMATRIX
10461046
{
10471047
union
10481048
{

0 commit comments

Comments
 (0)