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