Blender V5.3
gpu_shader_cxx_matrix.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
15
16/* Some compilers complain about lack of return values. Keep it short. */
17#define RET \
18 { \
19 return {}; \
20 }
21
22/* -------------------------------------------------------------------- */
25
26template<int C, int R> struct MatBase {};
27
28template<int C, int R> struct MatOp {
32
33 const ColT &operator[](int) const
34 {
35 return *reinterpret_cast<const ColT *>(this);
36 }
38 {
39 return *reinterpret_cast<ColT *>(this);
40 }
41 const ColT &operator[](uint) const
42 {
43 return *reinterpret_cast<const ColT *>(this);
44 }
46 {
47 return *reinterpret_cast<ColT *>(this);
48 }
49
51 MatT operator-() RET;
52
53 MatT operator*(MatT) const RET;
54
55 friend RowT operator*(ColT, MatT) RET;
56 friend ColT operator*(MatT, RowT) RET;
57 friend MatT operator*(MatT, float) RET;
58 friend MatT operator*(float, MatT) RET;
59};
60
61template<int R> struct MatBase<2, R> : MatOp<2, R> {
62 using T = float;
65
66 MatBase() = default;
67 explicit MatBase(T) {}
68 explicit MatBase(T, T, T, T) {}
69 explicit MatBase(ColT, ColT) {}
70 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
71};
72
73template<int R> struct MatBase<3, R> : MatOp<3, R> {
74 using T = float;
76 ColT x, y, z;
77
78 MatBase() = default;
79 explicit MatBase(T) {}
80 explicit MatBase(T, T, T, T, T, T, T, T, T) {}
81 explicit MatBase(ColT, ColT, ColT) {}
82 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
83};
84
85template<int R> struct MatBase<4, R> : MatOp<4, R> {
86 using T = float;
88 ColT x, y, z, w;
89
90 MatBase() = default;
91 explicit MatBase(T) {}
92 explicit MatBase(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) {}
93 explicit MatBase(ColT, ColT, ColT, ColT) {}
94 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
95};
96
106
107/* Matrix reshaping functions. */
108#define RESHAPE(mat_to, mat_from, ...) \
109 mat_to to_##mat_to(mat_from m) \
110 { \
111 return mat_to(__VA_ARGS__); \
112 }
113
114/* clang-format off */
115RESHAPE(float2x2, float3x3, m[0].xy, m[1].xy)
116RESHAPE(float2x2, float4x4, m[0].xy, m[1].xy)
117RESHAPE(float3x3, float4x4, m[0].xyz, m[1].xyz, m[2].xyz)
118RESHAPE(float3x3, float2x2, m[0].x, m[0].y, 0, m[1].x, m[1].y, 0, 0, 0, 1)
119RESHAPE(float4x4, float2x2, m[0].x, m[0].y, 0, 0, m[1].x, m[1].y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
120RESHAPE(float4x4, float3x3, m[0].x, m[0].y, m[0].z, 0, m[1].x, m[1].y, m[1].z, 0, m[2].x, m[2].y, m[2].z, 0, 0, 0, 0, 1)
121/* clang-format on */
122/* TODO(fclem): Remove. Use Transform instead. */
123RESHAPE(float3x3, float3x4, m[0].xyz, m[1].xyz, m[2].xyz)
124#undef RESHAPE
125
127
128#undef RET
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
MatBase< 3, 4 > float3x4
#define RESHAPE(mat_to, mat_from,...)
MatBase< 2, 4 > float2x4
MatBase< 3, 2 > float3x2
MatBase< 2, 2 > float2x2
MatBase< 4, 4 > float4x4
MatBase< 2, 3 > float2x3
MatBase< 4, 3 > float4x3
MatBase< 4, 2 > float4x2
#define RET
#define R
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
MatBase(const MatBase< OtherC, OtherR > &)
VecBase< float, R > ColT
MatBase()=default
VecBase< float, R > ColT
MatBase()=default
MatBase(T, T, T, T, T, T, T, T, T)
MatBase(ColT, ColT, ColT)
MatBase(const MatBase< OtherC, OtherR > &)
MatBase(ColT, ColT, ColT, ColT)
VecBase< float, R > ColT
MatBase(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)
MatBase(const MatBase< OtherC, OtherR > &)
MatBase()=default
ColT & operator[](int)
ColT & operator[](uint)
const ColT & operator[](uint) const
VecBase< float, C > RowT
MatBase< C, R > MatT
VecBase< float, R > ColT
const ColT & operator[](int) const
MatT operator+() RET