Skip to content

Add XMMatrixInverseTranspose for optimal normal vector transformation - #336

Open
RohithPariki wants to merge 1 commit into
microsoft:mainfrom
RohithPariki:feature/matrix-inverse-transpose
Open

Add XMMatrixInverseTranspose for optimal normal vector transformation#336
RohithPariki wants to merge 1 commit into
microsoft:mainfrom
RohithPariki:feature/matrix-inverse-transpose

Conversation

@RohithPariki

Copy link
Copy Markdown

Fixes #9

Description

This PR introduces XMMatrixInverseTranspose, computing (M^-1)^T in a single pass. This is a common operation used for transforming surface normals, where developers previously had to chain XMMatrixTranspose(XMMatrixInverse(nullptr, M)).

Optimization Insight:
The standard XMMatrixInverse internally transposes the matrix first (MT = M^T) and then computes the cofactors of MT to produce adj(M^T) = adj(M)^T. Since the caller ultimately requests the transpose of the inverse, that final transpose cancels out the internal one.

XMMatrixInverseTranspose simply runs the cofactor algorithm directly on M (skipping the initial transpose block entirely) to produce adj(M) / det(M).

Savings:

  • Eliminates ~12 redundant _mm_shuffle_ps instructions on the _XM_SSE_INTRINSICS_ path.
  • Removes the initial matrix transpose on the scalar and NEON paths.

Verification

All paths (Scalar, NEON, and SSE) were successfully implemented and verified against chained calls (Transpose(Inverse(M))) for:

  • Identity Matrices
  • Pure Rotation Matrices (invT(R) == R)
  • Scaling Matrices
  • Arbitrary non-degenerate matrices (ensuring matrix values and determinant outputs match perfectly)
    i can share the test code , if needed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add XMMatrixInverseTranspose

1 participant