xref: /aosp_15_r20/external/angle/src/libANGLE/validationES2.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // validationES2.h:
7*8975f5c5SAndroid Build Coastguard Worker //  Inlined validation functions for OpenGL ES 2.0 entry points.
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_VALIDATION_ES2_H_
10*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_VALIDATION_ES2_H_
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/ErrorStrings.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/validationES.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/validationES2_autogen.h"
15*8975f5c5SAndroid Build Coastguard Worker 
16*8975f5c5SAndroid Build Coastguard Worker namespace gl
17*8975f5c5SAndroid Build Coastguard Worker {
ValidateDrawArrays(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLint first,GLsizei count)18*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateDrawArrays(const Context *context,
19*8975f5c5SAndroid Build Coastguard Worker                                      angle::EntryPoint entryPoint,
20*8975f5c5SAndroid Build Coastguard Worker                                      PrimitiveMode mode,
21*8975f5c5SAndroid Build Coastguard Worker                                      GLint first,
22*8975f5c5SAndroid Build Coastguard Worker                                      GLsizei count)
23*8975f5c5SAndroid Build Coastguard Worker {
24*8975f5c5SAndroid Build Coastguard Worker     return ValidateDrawArraysCommon(context, entryPoint, mode, first, count, 1);
25*8975f5c5SAndroid Build Coastguard Worker }
26*8975f5c5SAndroid Build Coastguard Worker 
ValidateUniform2f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x,GLfloat y)27*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateUniform2f(const Context *context,
28*8975f5c5SAndroid Build Coastguard Worker                                     angle::EntryPoint entryPoint,
29*8975f5c5SAndroid Build Coastguard Worker                                     UniformLocation location,
30*8975f5c5SAndroid Build Coastguard Worker                                     GLfloat x,
31*8975f5c5SAndroid Build Coastguard Worker                                     GLfloat y)
32*8975f5c5SAndroid Build Coastguard Worker {
33*8975f5c5SAndroid Build Coastguard Worker     return ValidateUniform(context, entryPoint, GL_FLOAT_VEC2, location, 1);
34*8975f5c5SAndroid Build Coastguard Worker }
35*8975f5c5SAndroid Build Coastguard Worker 
ValidateBindBuffer(const Context * context,angle::EntryPoint entryPoint,BufferBinding target,BufferID buffer)36*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateBindBuffer(const Context *context,
37*8975f5c5SAndroid Build Coastguard Worker                                      angle::EntryPoint entryPoint,
38*8975f5c5SAndroid Build Coastguard Worker                                      BufferBinding target,
39*8975f5c5SAndroid Build Coastguard Worker                                      BufferID buffer)
40*8975f5c5SAndroid Build Coastguard Worker {
41*8975f5c5SAndroid Build Coastguard Worker     if (!context->isValidBufferBinding(target))
42*8975f5c5SAndroid Build Coastguard Worker     {
43*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kInvalidBufferTypes);
44*8975f5c5SAndroid Build Coastguard Worker         return false;
45*8975f5c5SAndroid Build Coastguard Worker     }
46*8975f5c5SAndroid Build Coastguard Worker 
47*8975f5c5SAndroid Build Coastguard Worker     if (!context->getState().isBindGeneratesResourceEnabled() &&
48*8975f5c5SAndroid Build Coastguard Worker         !context->isBufferGenerated(buffer))
49*8975f5c5SAndroid Build Coastguard Worker     {
50*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
51*8975f5c5SAndroid Build Coastguard Worker         return false;
52*8975f5c5SAndroid Build Coastguard Worker     }
53*8975f5c5SAndroid Build Coastguard Worker 
54*8975f5c5SAndroid Build Coastguard Worker     return true;
55*8975f5c5SAndroid Build Coastguard Worker }
56*8975f5c5SAndroid Build Coastguard Worker 
ValidateDrawElements(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices)57*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateDrawElements(const Context *context,
58*8975f5c5SAndroid Build Coastguard Worker                                        angle::EntryPoint entryPoint,
59*8975f5c5SAndroid Build Coastguard Worker                                        PrimitiveMode mode,
60*8975f5c5SAndroid Build Coastguard Worker                                        GLsizei count,
61*8975f5c5SAndroid Build Coastguard Worker                                        DrawElementsType type,
62*8975f5c5SAndroid Build Coastguard Worker                                        const void *indices)
63*8975f5c5SAndroid Build Coastguard Worker {
64*8975f5c5SAndroid Build Coastguard Worker     return ValidateDrawElementsCommon(context, entryPoint, mode, count, type, indices, 1);
65*8975f5c5SAndroid Build Coastguard Worker }
66*8975f5c5SAndroid Build Coastguard Worker 
ValidateVertexAttribPointer(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLint size,VertexAttribType type,GLboolean normalized,GLsizei stride,const void * ptr)67*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateVertexAttribPointer(const Context *context,
68*8975f5c5SAndroid Build Coastguard Worker                                               angle::EntryPoint entryPoint,
69*8975f5c5SAndroid Build Coastguard Worker                                               GLuint index,
70*8975f5c5SAndroid Build Coastguard Worker                                               GLint size,
71*8975f5c5SAndroid Build Coastguard Worker                                               VertexAttribType type,
72*8975f5c5SAndroid Build Coastguard Worker                                               GLboolean normalized,
73*8975f5c5SAndroid Build Coastguard Worker                                               GLsizei stride,
74*8975f5c5SAndroid Build Coastguard Worker                                               const void *ptr)
75*8975f5c5SAndroid Build Coastguard Worker {
76*8975f5c5SAndroid Build Coastguard Worker     if (!ValidateFloatVertexFormat(context, entryPoint, index, size, type))
77*8975f5c5SAndroid Build Coastguard Worker     {
78*8975f5c5SAndroid Build Coastguard Worker         return false;
79*8975f5c5SAndroid Build Coastguard Worker     }
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker     if (stride < 0)
82*8975f5c5SAndroid Build Coastguard Worker     {
83*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kNegativeStride);
84*8975f5c5SAndroid Build Coastguard Worker         return false;
85*8975f5c5SAndroid Build Coastguard Worker     }
86*8975f5c5SAndroid Build Coastguard Worker 
87*8975f5c5SAndroid Build Coastguard Worker     if (context->getClientVersion() >= ES_3_1)
88*8975f5c5SAndroid Build Coastguard Worker     {
89*8975f5c5SAndroid Build Coastguard Worker         const Caps &caps = context->getCaps();
90*8975f5c5SAndroid Build Coastguard Worker         if (stride > caps.maxVertexAttribStride)
91*8975f5c5SAndroid Build Coastguard Worker         {
92*8975f5c5SAndroid Build Coastguard Worker             ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribStride);
93*8975f5c5SAndroid Build Coastguard Worker             return false;
94*8975f5c5SAndroid Build Coastguard Worker         }
95*8975f5c5SAndroid Build Coastguard Worker 
96*8975f5c5SAndroid Build Coastguard Worker         if (index >= static_cast<GLuint>(caps.maxVertexAttribBindings))
97*8975f5c5SAndroid Build Coastguard Worker         {
98*8975f5c5SAndroid Build Coastguard Worker             ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribBindings);
99*8975f5c5SAndroid Build Coastguard Worker             return false;
100*8975f5c5SAndroid Build Coastguard Worker         }
101*8975f5c5SAndroid Build Coastguard Worker     }
102*8975f5c5SAndroid Build Coastguard Worker 
103*8975f5c5SAndroid Build Coastguard Worker     // [OpenGL ES 3.0.2] Section 2.8 page 24:
104*8975f5c5SAndroid Build Coastguard Worker     // An INVALID_OPERATION error is generated when a non-zero vertex array object
105*8975f5c5SAndroid Build Coastguard Worker     // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
106*8975f5c5SAndroid Build Coastguard Worker     // and the pointer argument is not NULL.
107*8975f5c5SAndroid Build Coastguard Worker     bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
108*8975f5c5SAndroid Build Coastguard Worker                              context->getState().getVertexArray()->id().value == 0;
109*8975f5c5SAndroid Build Coastguard Worker     if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
110*8975f5c5SAndroid Build Coastguard Worker         ptr != nullptr)
111*8975f5c5SAndroid Build Coastguard Worker     {
112*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kClientDataInVertexArray);
113*8975f5c5SAndroid Build Coastguard Worker         return false;
114*8975f5c5SAndroid Build Coastguard Worker     }
115*8975f5c5SAndroid Build Coastguard Worker 
116*8975f5c5SAndroid Build Coastguard Worker     if (context->isWebGL())
117*8975f5c5SAndroid Build Coastguard Worker     {
118*8975f5c5SAndroid Build Coastguard Worker         // WebGL 1.0 [Section 6.14] Fixed point support
119*8975f5c5SAndroid Build Coastguard Worker         // The WebGL API does not support the GL_FIXED data type.
120*8975f5c5SAndroid Build Coastguard Worker         if (type == VertexAttribType::Fixed)
121*8975f5c5SAndroid Build Coastguard Worker         {
122*8975f5c5SAndroid Build Coastguard Worker             ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kFixedNotInWebGL);
123*8975f5c5SAndroid Build Coastguard Worker             return false;
124*8975f5c5SAndroid Build Coastguard Worker         }
125*8975f5c5SAndroid Build Coastguard Worker 
126*8975f5c5SAndroid Build Coastguard Worker         if (!ValidateWebGLVertexAttribPointer(context, entryPoint, type, normalized, stride, ptr,
127*8975f5c5SAndroid Build Coastguard Worker                                               false))
128*8975f5c5SAndroid Build Coastguard Worker         {
129*8975f5c5SAndroid Build Coastguard Worker             return false;
130*8975f5c5SAndroid Build Coastguard Worker         }
131*8975f5c5SAndroid Build Coastguard Worker     }
132*8975f5c5SAndroid Build Coastguard Worker 
133*8975f5c5SAndroid Build Coastguard Worker     return true;
134*8975f5c5SAndroid Build Coastguard Worker }
135*8975f5c5SAndroid Build Coastguard Worker 
136*8975f5c5SAndroid Build Coastguard Worker void RecordBindTextureTypeError(const Context *context,
137*8975f5c5SAndroid Build Coastguard Worker                                 angle::EntryPoint entryPoint,
138*8975f5c5SAndroid Build Coastguard Worker                                 TextureType target);
139*8975f5c5SAndroid Build Coastguard Worker 
ValidateBindTexture(const Context * context,angle::EntryPoint entryPoint,TextureType target,TextureID texture)140*8975f5c5SAndroid Build Coastguard Worker ANGLE_INLINE bool ValidateBindTexture(const Context *context,
141*8975f5c5SAndroid Build Coastguard Worker                                       angle::EntryPoint entryPoint,
142*8975f5c5SAndroid Build Coastguard Worker                                       TextureType target,
143*8975f5c5SAndroid Build Coastguard Worker                                       TextureID texture)
144*8975f5c5SAndroid Build Coastguard Worker {
145*8975f5c5SAndroid Build Coastguard Worker     if (!context->getStateCache().isValidBindTextureType(target))
146*8975f5c5SAndroid Build Coastguard Worker     {
147*8975f5c5SAndroid Build Coastguard Worker         RecordBindTextureTypeError(context, entryPoint, target);
148*8975f5c5SAndroid Build Coastguard Worker         return false;
149*8975f5c5SAndroid Build Coastguard Worker     }
150*8975f5c5SAndroid Build Coastguard Worker 
151*8975f5c5SAndroid Build Coastguard Worker     if (texture.value == 0)
152*8975f5c5SAndroid Build Coastguard Worker     {
153*8975f5c5SAndroid Build Coastguard Worker         return true;
154*8975f5c5SAndroid Build Coastguard Worker     }
155*8975f5c5SAndroid Build Coastguard Worker 
156*8975f5c5SAndroid Build Coastguard Worker     Texture *textureObject = context->getTexture(texture);
157*8975f5c5SAndroid Build Coastguard Worker     if (textureObject && textureObject->getType() != target)
158*8975f5c5SAndroid Build Coastguard Worker     {
159*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERRORF(GL_INVALID_OPERATION, err::kTextureTargetMismatchWithLabel,
160*8975f5c5SAndroid Build Coastguard Worker                                 static_cast<uint8_t>(target),
161*8975f5c5SAndroid Build Coastguard Worker                                 static_cast<uint8_t>(textureObject->getType()),
162*8975f5c5SAndroid Build Coastguard Worker                                 textureObject->getLabel().c_str());
163*8975f5c5SAndroid Build Coastguard Worker         return false;
164*8975f5c5SAndroid Build Coastguard Worker     }
165*8975f5c5SAndroid Build Coastguard Worker 
166*8975f5c5SAndroid Build Coastguard Worker     if (!context->getState().isBindGeneratesResourceEnabled() &&
167*8975f5c5SAndroid Build Coastguard Worker         !context->isTextureGenerated(texture))
168*8975f5c5SAndroid Build Coastguard Worker     {
169*8975f5c5SAndroid Build Coastguard Worker         ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
170*8975f5c5SAndroid Build Coastguard Worker         return false;
171*8975f5c5SAndroid Build Coastguard Worker     }
172*8975f5c5SAndroid Build Coastguard Worker 
173*8975f5c5SAndroid Build Coastguard Worker     return true;
174*8975f5c5SAndroid Build Coastguard Worker }
175*8975f5c5SAndroid Build Coastguard Worker 
176*8975f5c5SAndroid Build Coastguard Worker // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
177*8975f5c5SAndroid Build Coastguard Worker bool ValidateES2TexImageParametersBase(const Context *context,
178*8975f5c5SAndroid Build Coastguard Worker                                        angle::EntryPoint entryPoint,
179*8975f5c5SAndroid Build Coastguard Worker                                        TextureTarget target,
180*8975f5c5SAndroid Build Coastguard Worker                                        GLint level,
181*8975f5c5SAndroid Build Coastguard Worker                                        GLenum internalformat,
182*8975f5c5SAndroid Build Coastguard Worker                                        bool isCompressed,
183*8975f5c5SAndroid Build Coastguard Worker                                        bool isSubImage,
184*8975f5c5SAndroid Build Coastguard Worker                                        GLint xoffset,
185*8975f5c5SAndroid Build Coastguard Worker                                        GLint yoffset,
186*8975f5c5SAndroid Build Coastguard Worker                                        GLsizei width,
187*8975f5c5SAndroid Build Coastguard Worker                                        GLsizei height,
188*8975f5c5SAndroid Build Coastguard Worker                                        GLint border,
189*8975f5c5SAndroid Build Coastguard Worker                                        GLenum format,
190*8975f5c5SAndroid Build Coastguard Worker                                        GLenum type,
191*8975f5c5SAndroid Build Coastguard Worker                                        GLsizei imageSize,
192*8975f5c5SAndroid Build Coastguard Worker                                        const void *pixels);
193*8975f5c5SAndroid Build Coastguard Worker 
194*8975f5c5SAndroid Build Coastguard Worker // Validation of TexStorage*2DEXT
195*8975f5c5SAndroid Build Coastguard Worker bool ValidateES2TexStorageParametersBase(const Context *context,
196*8975f5c5SAndroid Build Coastguard Worker                                          angle::EntryPoint entryPoint,
197*8975f5c5SAndroid Build Coastguard Worker                                          TextureType target,
198*8975f5c5SAndroid Build Coastguard Worker                                          GLsizei levels,
199*8975f5c5SAndroid Build Coastguard Worker                                          GLenum internalformat,
200*8975f5c5SAndroid Build Coastguard Worker                                          GLsizei width,
201*8975f5c5SAndroid Build Coastguard Worker                                          GLsizei height);
202*8975f5c5SAndroid Build Coastguard Worker 
203*8975f5c5SAndroid Build Coastguard Worker // Validation of [Push,Pop]DebugGroup
204*8975f5c5SAndroid Build Coastguard Worker bool ValidatePushDebugGroupBase(const Context *context,
205*8975f5c5SAndroid Build Coastguard Worker                                 angle::EntryPoint entryPoint,
206*8975f5c5SAndroid Build Coastguard Worker                                 GLenum source,
207*8975f5c5SAndroid Build Coastguard Worker                                 GLuint id,
208*8975f5c5SAndroid Build Coastguard Worker                                 GLsizei length,
209*8975f5c5SAndroid Build Coastguard Worker                                 const GLchar *message);
210*8975f5c5SAndroid Build Coastguard Worker bool ValidatePopDebugGroupBase(const Context *context, angle::EntryPoint entryPoint);
211*8975f5c5SAndroid Build Coastguard Worker 
212*8975f5c5SAndroid Build Coastguard Worker // Validation of ObjectLabel
213*8975f5c5SAndroid Build Coastguard Worker bool ValidateObjectLabelBase(const Context *context,
214*8975f5c5SAndroid Build Coastguard Worker                              angle::EntryPoint entryPoint,
215*8975f5c5SAndroid Build Coastguard Worker                              GLenum identifier,
216*8975f5c5SAndroid Build Coastguard Worker                              GLuint name,
217*8975f5c5SAndroid Build Coastguard Worker                              GLsizei length,
218*8975f5c5SAndroid Build Coastguard Worker                              const GLchar *label);
219*8975f5c5SAndroid Build Coastguard Worker 
220*8975f5c5SAndroid Build Coastguard Worker // Validation of GetObjectLabel
221*8975f5c5SAndroid Build Coastguard Worker bool ValidateGetObjectLabelBase(const Context *context,
222*8975f5c5SAndroid Build Coastguard Worker                                 angle::EntryPoint entryPoint,
223*8975f5c5SAndroid Build Coastguard Worker                                 GLenum identifier,
224*8975f5c5SAndroid Build Coastguard Worker                                 GLuint name,
225*8975f5c5SAndroid Build Coastguard Worker                                 GLsizei bufSize,
226*8975f5c5SAndroid Build Coastguard Worker                                 const GLsizei *length,
227*8975f5c5SAndroid Build Coastguard Worker                                 const GLchar *label);
228*8975f5c5SAndroid Build Coastguard Worker 
229*8975f5c5SAndroid Build Coastguard Worker // Validation of ObjectPtrLabel
230*8975f5c5SAndroid Build Coastguard Worker bool ValidateObjectPtrLabelBase(const Context *context,
231*8975f5c5SAndroid Build Coastguard Worker                                 angle::EntryPoint entryPoint,
232*8975f5c5SAndroid Build Coastguard Worker                                 const void *ptr,
233*8975f5c5SAndroid Build Coastguard Worker                                 GLsizei length,
234*8975f5c5SAndroid Build Coastguard Worker                                 const GLchar *label);
235*8975f5c5SAndroid Build Coastguard Worker 
236*8975f5c5SAndroid Build Coastguard Worker // Validation of GetObjectPtrLabel
237*8975f5c5SAndroid Build Coastguard Worker bool ValidateGetObjectPtrLabelBase(const Context *context,
238*8975f5c5SAndroid Build Coastguard Worker                                    angle::EntryPoint entryPoint,
239*8975f5c5SAndroid Build Coastguard Worker                                    const void *ptr,
240*8975f5c5SAndroid Build Coastguard Worker                                    GLsizei bufSize,
241*8975f5c5SAndroid Build Coastguard Worker                                    const GLsizei *length,
242*8975f5c5SAndroid Build Coastguard Worker                                    const GLchar *label);
243*8975f5c5SAndroid Build Coastguard Worker 
244*8975f5c5SAndroid Build Coastguard Worker }  // namespace gl
245*8975f5c5SAndroid Build Coastguard Worker 
246*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_VALIDATION_ES2_H_
247