xref: /aosp_15_r20/external/deqp/framework/referencerenderer/rrVertexAttrib.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _RRVERTEXATTRIB_HPP
2*35238bceSAndroid Build Coastguard Worker #define _RRVERTEXATTRIB_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Reference Renderer
5*35238bceSAndroid Build Coastguard Worker  * -----------------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Vertex attribute fetch.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "rrDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "rrGenericVector.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
29*35238bceSAndroid Build Coastguard Worker 
30*35238bceSAndroid Build Coastguard Worker namespace rr
31*35238bceSAndroid Build Coastguard Worker {
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker enum VertexAttribType
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker     // Can only be read as floats
36*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_FLOAT = 0,
37*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_HALF,
38*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_FIXED,
39*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_DOUBLE,
40*35238bceSAndroid Build Coastguard Worker 
41*35238bceSAndroid Build Coastguard Worker     // Can only be read as floats, will be normalized
42*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM8,
43*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM16,
44*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM32,
45*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV, //!< Packed format, only size = 4 is allowed
46*35238bceSAndroid Build Coastguard Worker 
47*35238bceSAndroid Build Coastguard Worker     // Clamped formats, GLES3-style conversion: max{c / (2^(b-1) - 1), -1 }
48*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM8_CLAMP,
49*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM16_CLAMP,
50*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM32_CLAMP,
51*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP, //!< Packed format, only size = 4 is allowed
52*35238bceSAndroid Build Coastguard Worker 
53*35238bceSAndroid Build Coastguard Worker     // Scaled formats, GLES2-style conversion: (2c + 1) / (2^b - 1)
54*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM8_SCALE,
55*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM16_SCALE,
56*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM32_SCALE,
57*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE, //!< Packed format, only size = 4 is allowed
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker     // can only be read as float, will not be normalized
60*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UINT8,
61*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UINT16,
62*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UINT32,
63*35238bceSAndroid Build Coastguard Worker 
64*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_INT8,
65*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_INT16,
66*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_INT32,
67*35238bceSAndroid Build Coastguard Worker 
68*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UINT_2_10_10_10_REV, //!< Packed format, only size = 4 is allowed
69*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_INT_2_10_10_10_REV,  //!< Packed format, only size = 4 is allowed
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker     // can only be read as integers
72*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_UINT8,
73*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_UINT16,
74*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_UINT32,
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_INT8,
77*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_INT16,
78*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_PURE_INT32,
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     // reordered formats of GL_ARB_vertex_array_bgra
81*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM8_BGRA,
82*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_UNORM_2_10_10_10_REV_BGRA,
83*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_CLAMP_BGRA,
84*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_NONPURE_SNORM_2_10_10_10_REV_SCALE_BGRA,
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker     // can be read as anything
87*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_DONT_CARE, //!< Do not enforce type checking when reading GENERIC attribute. Used for current client side attributes.
88*35238bceSAndroid Build Coastguard Worker 
89*35238bceSAndroid Build Coastguard Worker     VERTEXATTRIBTYPE_LAST
90*35238bceSAndroid Build Coastguard Worker };
91*35238bceSAndroid Build Coastguard Worker 
92*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
93*35238bceSAndroid Build Coastguard Worker  * \brief Vertex attribute slot
94*35238bceSAndroid Build Coastguard Worker  *
95*35238bceSAndroid Build Coastguard Worker  * Vertex attribute type specifies component type for attribute and it
96*35238bceSAndroid Build Coastguard Worker  * includes signed & normalized bits as well.
97*35238bceSAndroid Build Coastguard Worker  *
98*35238bceSAndroid Build Coastguard Worker  * Attribute size specifies how many components there are per vertex.
99*35238bceSAndroid Build Coastguard Worker  * If size is 0, no components are fetched, ie. vertex attribute slot
100*35238bceSAndroid Build Coastguard Worker  * is disabled.
101*35238bceSAndroid Build Coastguard Worker  *
102*35238bceSAndroid Build Coastguard Worker  * Divisor specifies the rate at which vertex attribute advances. If it is
103*35238bceSAndroid Build Coastguard Worker  * zero, attribute is advanced per vertex. If divisor is non-zero, attribute
104*35238bceSAndroid Build Coastguard Worker  * advances once per instanceDivisor instances.
105*35238bceSAndroid Build Coastguard Worker  *
106*35238bceSAndroid Build Coastguard Worker  * Pointer is used if not null, otherwise generic attribute is used instead
107*35238bceSAndroid Build Coastguard Worker  * and in such case only DONT_CARE is valid attribute type.
108*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
109*35238bceSAndroid Build Coastguard Worker struct VertexAttrib
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker     VertexAttribType type; //!< Attribute component type.
112*35238bceSAndroid Build Coastguard Worker     int size;              //!< Number of components, valid range is [0,4].
113*35238bceSAndroid Build Coastguard Worker     int stride; //!< Number of bytes two consecutive elements differ by. Zero works as in GL. Valid range is [0, inf).
114*35238bceSAndroid Build Coastguard Worker     int instanceDivisor; //!< Vertex attribute divisor.
115*35238bceSAndroid Build Coastguard Worker     const void *pointer; //!< Data pointer.
116*35238bceSAndroid Build Coastguard Worker     GenericVec4 generic; //!< Generic attribute, used if pointer is null.
117*35238bceSAndroid Build Coastguard Worker 
VertexAttribrr::VertexAttrib118*35238bceSAndroid Build Coastguard Worker     VertexAttrib(void) : type(VERTEXATTRIBTYPE_FLOAT), size(0), stride(0), instanceDivisor(0), pointer(DE_NULL)
119*35238bceSAndroid Build Coastguard Worker     {
120*35238bceSAndroid Build Coastguard Worker     }
121*35238bceSAndroid Build Coastguard Worker 
VertexAttribrr::VertexAttrib122*35238bceSAndroid Build Coastguard Worker     VertexAttrib(VertexAttribType type_, int size_, int stride_, int instanceDivisor_, const void *pointer_)
123*35238bceSAndroid Build Coastguard Worker         : type(type_)
124*35238bceSAndroid Build Coastguard Worker         , size(size_)
125*35238bceSAndroid Build Coastguard Worker         , stride(stride_)
126*35238bceSAndroid Build Coastguard Worker         , instanceDivisor(instanceDivisor_)
127*35238bceSAndroid Build Coastguard Worker         , pointer(pointer_)
128*35238bceSAndroid Build Coastguard Worker     {
129*35238bceSAndroid Build Coastguard Worker     }
130*35238bceSAndroid Build Coastguard Worker 
131*35238bceSAndroid Build Coastguard Worker     template <typename ScalarType>
VertexAttribrr::VertexAttrib132*35238bceSAndroid Build Coastguard Worker     explicit VertexAttrib(const tcu::Vector<ScalarType, 4> &generic_)
133*35238bceSAndroid Build Coastguard Worker         : type(VERTEXATTRIBTYPE_DONT_CARE)
134*35238bceSAndroid Build Coastguard Worker         , size(0)
135*35238bceSAndroid Build Coastguard Worker         , stride(0)
136*35238bceSAndroid Build Coastguard Worker         , instanceDivisor(0)
137*35238bceSAndroid Build Coastguard Worker         , pointer(DE_NULL)
138*35238bceSAndroid Build Coastguard Worker         , generic(generic_)
139*35238bceSAndroid Build Coastguard Worker     {
140*35238bceSAndroid Build Coastguard Worker     }
141*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE;
142*35238bceSAndroid Build Coastguard Worker 
143*35238bceSAndroid Build Coastguard Worker bool isValidVertexAttrib(const VertexAttrib &vertexAttrib);
144*35238bceSAndroid Build Coastguard Worker // \todo [2013-04-01 pyry] Queries: isReadFloatValid(), isReadIntValid() ...
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker void readVertexAttrib(tcu::Vec4 &dst, const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
147*35238bceSAndroid Build Coastguard Worker                       const int baseInstanceNdx = 0);
148*35238bceSAndroid Build Coastguard Worker void readVertexAttrib(tcu::IVec4 &dst, const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
149*35238bceSAndroid Build Coastguard Worker                       const int baseInstanceNdx = 0);
150*35238bceSAndroid Build Coastguard Worker void readVertexAttrib(tcu::UVec4 &dst, const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
151*35238bceSAndroid Build Coastguard Worker                       const int baseInstanceNdx = 0);
152*35238bceSAndroid Build Coastguard Worker 
153*35238bceSAndroid Build Coastguard Worker // Helpers that return by value (trivial for compiler to optimize).
154*35238bceSAndroid Build Coastguard Worker 
readVertexAttribFloat(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx,const int baseInstanceNdx=0)155*35238bceSAndroid Build Coastguard Worker inline tcu::Vec4 readVertexAttribFloat(const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
156*35238bceSAndroid Build Coastguard Worker                                        const int baseInstanceNdx = 0)
157*35238bceSAndroid Build Coastguard Worker {
158*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 v;
159*35238bceSAndroid Build Coastguard Worker     readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx, baseInstanceNdx);
160*35238bceSAndroid Build Coastguard Worker     return v;
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker 
readVertexAttribInt(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx,const int baseInstanceNdx=0)163*35238bceSAndroid Build Coastguard Worker inline tcu::IVec4 readVertexAttribInt(const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
164*35238bceSAndroid Build Coastguard Worker                                       const int baseInstanceNdx = 0)
165*35238bceSAndroid Build Coastguard Worker {
166*35238bceSAndroid Build Coastguard Worker     tcu::IVec4 v;
167*35238bceSAndroid Build Coastguard Worker     readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx, baseInstanceNdx);
168*35238bceSAndroid Build Coastguard Worker     return v;
169*35238bceSAndroid Build Coastguard Worker }
170*35238bceSAndroid Build Coastguard Worker 
readVertexAttribUint(const VertexAttrib & vertexAttrib,const int instanceNdx,const int vertexNdx,const int baseInstanceNdx=0)171*35238bceSAndroid Build Coastguard Worker inline tcu::UVec4 readVertexAttribUint(const VertexAttrib &vertexAttrib, const int instanceNdx, const int vertexNdx,
172*35238bceSAndroid Build Coastguard Worker                                        const int baseInstanceNdx = 0)
173*35238bceSAndroid Build Coastguard Worker {
174*35238bceSAndroid Build Coastguard Worker     tcu::UVec4 v;
175*35238bceSAndroid Build Coastguard Worker     readVertexAttrib(v, vertexAttrib, instanceNdx, vertexNdx, baseInstanceNdx);
176*35238bceSAndroid Build Coastguard Worker     return v;
177*35238bceSAndroid Build Coastguard Worker }
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker } // namespace rr
180*35238bceSAndroid Build Coastguard Worker 
181*35238bceSAndroid Build Coastguard Worker #endif // _RRVERTEXATTRIB_HPP
182