xref: /aosp_15_r20/external/deqp/framework/referencerenderer/rrGenericVector.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _RRGENERICVECTOR_HPP
2 #define _RRGENERICVECTOR_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Reference Renderer
5  * -----------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Generic vetor
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rrDefs.hpp"
27 #include "tcuVector.hpp"
28 
29 namespace rr
30 {
31 
32 enum GenericVecType
33 {
34     GENERICVECTYPE_FLOAT = 0,
35     GENERICVECTYPE_UINT32,
36     GENERICVECTYPE_INT32,
37 
38     GENERICVECTYPE_LAST
39 };
40 
41 /*--------------------------------------------------------------------*//*!
42  * \brief Generic vertex attrib
43  *
44  * Generic vertex attributes hold 4 32-bit scalar values that can be accessed
45  * as floating-point or integer values.
46  *
47  * Aliasing rules must be adhered when accessing data (ie. writing as float
48  * and reading as int has undefined result).
49  *//*--------------------------------------------------------------------*/
50 class GenericVec4
51 {
52 private:
53     union
54     {
55         uint32_t uData[4];
56         int32_t iData[4];
57         float fData[4];
58     } v;
59 
60 public:
GenericVec4(void)61     inline GenericVec4(void)
62     {
63         v.iData[0] = 0;
64         v.iData[1] = 0;
65         v.iData[2] = 0;
66         v.iData[3] = 0;
67     }
68 
69     template <typename ScalarType>
GenericVec4(const tcu::Vector<ScalarType,4> & value)70     explicit GenericVec4(const tcu::Vector<ScalarType, 4> &value)
71     {
72         *this = value;
73     }
74 
GenericVec4(const GenericVec4 & other)75     inline GenericVec4(const GenericVec4 &other)
76     {
77         v.iData[0] = other.v.iData[0];
78         v.iData[1] = other.v.iData[1];
79         v.iData[2] = other.v.iData[2];
80         v.iData[3] = other.v.iData[3];
81     }
82 
operator =(const GenericVec4 & value)83     GenericVec4 &operator=(const GenericVec4 &value)
84     {
85         v.iData[0] = value.v.iData[0];
86         v.iData[1] = value.v.iData[1];
87         v.iData[2] = value.v.iData[2];
88         v.iData[3] = value.v.iData[3];
89         return *this;
90     }
91 
92     template <typename ScalarType>
operator =(const tcu::Vector<ScalarType,4> & value)93     GenericVec4 &operator=(const tcu::Vector<ScalarType, 4> &value)
94     {
95         getAccess<ScalarType>()[0] = value[0];
96         getAccess<ScalarType>()[1] = value[1];
97         getAccess<ScalarType>()[2] = value[2];
98         getAccess<ScalarType>()[3] = value[3];
99         return *this;
100     }
101 
102     template <typename ScalarType>
get(void) const103     inline tcu::Vector<ScalarType, 4> get(void) const
104     {
105         return tcu::Vector<ScalarType, 4>(getAccess<ScalarType>()[0], getAccess<ScalarType>()[1],
106                                           getAccess<ScalarType>()[2], getAccess<ScalarType>()[3]);
107     }
108 
109     template <typename ScalarType>
110     inline ScalarType *getAccess();
111 
112     template <typename ScalarType>
113     inline const ScalarType *getAccess() const;
114 } DE_WARN_UNUSED_TYPE;
115 
116 template <>
getAccess()117 inline float *GenericVec4::getAccess<float>()
118 {
119     return v.fData;
120 }
121 
122 template <>
getAccess() const123 inline const float *GenericVec4::getAccess<float>() const
124 {
125     return v.fData;
126 }
127 
128 template <>
getAccess()129 inline uint32_t *GenericVec4::getAccess<uint32_t>()
130 {
131     return v.uData;
132 }
133 
134 template <>
getAccess() const135 inline const uint32_t *GenericVec4::getAccess<uint32_t>() const
136 {
137     return v.uData;
138 }
139 
140 template <>
getAccess()141 inline int32_t *GenericVec4::getAccess<int32_t>()
142 {
143     return v.iData;
144 }
145 
146 template <>
getAccess() const147 inline const int32_t *GenericVec4::getAccess<int32_t>() const
148 {
149     return v.iData;
150 }
151 
152 } // namespace rr
153 
154 #endif // _RRGENERICVECTOR_HPP
155