1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // validationESEXT.cpp: Validation functions for OpenGL ES extension entry points.
7 
8 #include "libANGLE/validationESEXT_autogen.h"
9 
10 #include "libANGLE/Context.h"
11 #include "libANGLE/ErrorStrings.h"
12 #include "libANGLE/MemoryObject.h"
13 #include "libANGLE/validationES.h"
14 #include "libANGLE/validationES2.h"
15 #include "libANGLE/validationES32.h"
16 
17 namespace gl
18 {
19 using namespace err;
20 
21 namespace
22 {
23 template <typename ObjectT>
ValidateGetImageFormatAndType(const Context * context,ObjectT * obj,GLenum format,GLenum type)24 bool ValidateGetImageFormatAndType(const Context *context, ObjectT *obj, GLenum format, GLenum type)
25 {
26     GLenum implFormat = obj->getImplementationColorReadFormat(context);
27     if (!ValidES3Format(format) && (format != implFormat || format == GL_NONE))
28     {
29         context->validationError(GL_INVALID_ENUM, kInvalidFormat);
30         return false;
31     }
32 
33     GLenum implType = obj->getImplementationColorReadType(context);
34     if (!ValidES3Type(type) && (type != implType || type == GL_NONE))
35     {
36         context->validationError(GL_INVALID_ENUM, kInvalidType);
37         return false;
38     }
39 
40     // Format/type combinations are not yet validated.
41 
42     return true;
43 }
44 
IsValidImageLayout(ImageLayout layout)45 bool IsValidImageLayout(ImageLayout layout)
46 {
47     switch (layout)
48     {
49         case ImageLayout::Undefined:
50         case ImageLayout::General:
51         case ImageLayout::ColorAttachment:
52         case ImageLayout::DepthStencilAttachment:
53         case ImageLayout::DepthStencilReadOnlyAttachment:
54         case ImageLayout::ShaderReadOnly:
55         case ImageLayout::TransferSrc:
56         case ImageLayout::TransferDst:
57         case ImageLayout::DepthReadOnlyStencilAttachment:
58         case ImageLayout::DepthAttachmentStencilReadOnly:
59             return true;
60 
61         default:
62             return false;
63     }
64 }
65 
IsValidMemoryObjectParamater(const Context * context,GLenum pname)66 bool IsValidMemoryObjectParamater(const Context *context, GLenum pname)
67 {
68     switch (pname)
69     {
70         case GL_DEDICATED_MEMORY_OBJECT_EXT:
71             return true;
72 
73         default:
74             return false;
75     }
76 }
77 
78 }  // namespace
79 
ValidateGetTexImageANGLE(const Context * context,TextureTarget target,GLint level,GLenum format,GLenum type,const void * pixels)80 bool ValidateGetTexImageANGLE(const Context *context,
81                               TextureTarget target,
82                               GLint level,
83                               GLenum format,
84                               GLenum type,
85                               const void *pixels)
86 {
87     if (!context->getExtensions().getImageANGLE)
88     {
89         context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
90         return false;
91     }
92 
93     if (!ValidTexture2DDestinationTarget(context, target) &&
94         !ValidTexture3DDestinationTarget(context, target))
95     {
96         context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
97         return false;
98     }
99 
100     if (level < 0)
101     {
102         context->validationError(GL_INVALID_VALUE, kNegativeLevel);
103         return false;
104     }
105 
106     TextureType textureType = TextureTargetToType(target);
107     if (!ValidMipLevel(context, textureType, level))
108     {
109         context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
110         return false;
111     }
112 
113     Texture *texture = context->getTextureByTarget(target);
114 
115     if (!ValidateGetImageFormatAndType(context, texture, format, type))
116     {
117         return false;
118     }
119 
120     GLsizei width  = static_cast<GLsizei>(texture->getWidth(target, level));
121     GLsizei height = static_cast<GLsizei>(texture->getHeight(target, level));
122     if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
123     {
124         return false;
125     }
126 
127     return true;
128 }
129 
ValidateGetRenderbufferImageANGLE(const Context * context,GLenum target,GLenum format,GLenum type,const void * pixels)130 bool ValidateGetRenderbufferImageANGLE(const Context *context,
131                                        GLenum target,
132                                        GLenum format,
133                                        GLenum type,
134                                        const void *pixels)
135 {
136     if (!context->getExtensions().getImageANGLE)
137     {
138         context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
139         return false;
140     }
141 
142     if (target != GL_RENDERBUFFER)
143     {
144         context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
145         return false;
146     }
147 
148     Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
149 
150     if (!ValidateGetImageFormatAndType(context, renderbuffer, format, type))
151     {
152         return false;
153     }
154 
155     GLsizei width  = renderbuffer->getWidth();
156     GLsizei height = renderbuffer->getHeight();
157     if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
158     {
159         return false;
160     }
161 
162     return true;
163 }
164 
ValidateDrawElementsBaseVertexEXT(const Context * context,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices,GLint basevertex)165 bool ValidateDrawElementsBaseVertexEXT(const Context *context,
166                                        PrimitiveMode mode,
167                                        GLsizei count,
168                                        DrawElementsType type,
169                                        const void *indices,
170                                        GLint basevertex)
171 {
172     if (!context->getExtensions().drawElementsBaseVertexAny())
173     {
174         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
175         return false;
176     }
177 
178     return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
179 }
180 
ValidateDrawElementsInstancedBaseVertexEXT(const Context * context,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices,GLsizei instancecount,GLint basevertex)181 bool ValidateDrawElementsInstancedBaseVertexEXT(const Context *context,
182                                                 PrimitiveMode mode,
183                                                 GLsizei count,
184                                                 DrawElementsType type,
185                                                 const void *indices,
186                                                 GLsizei instancecount,
187                                                 GLint basevertex)
188 {
189     if (!context->getExtensions().drawElementsBaseVertexAny())
190     {
191         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
192         return false;
193     }
194 
195     return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
196 }
197 
ValidateDrawRangeElementsBaseVertexEXT(const Context * context,PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,DrawElementsType type,const void * indices,GLint basevertex)198 bool ValidateDrawRangeElementsBaseVertexEXT(const Context *context,
199                                             PrimitiveMode mode,
200                                             GLuint start,
201                                             GLuint end,
202                                             GLsizei count,
203                                             DrawElementsType type,
204                                             const void *indices,
205                                             GLint basevertex)
206 {
207     if (!context->getExtensions().drawElementsBaseVertexAny())
208     {
209         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
210         return false;
211     }
212 
213     if (end < start)
214     {
215         context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
216         return false;
217     }
218 
219     if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
220     {
221         return false;
222     }
223 
224     // Skip range checks for no-op calls.
225     if (count <= 0)
226     {
227         return true;
228     }
229 
230     // Note that resolving the index range is a bit slow. We should probably optimize this.
231     IndexRange indexRange;
232     ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
233                                                                              indices, &indexRange));
234 
235     if (indexRange.end > end || indexRange.start < start)
236     {
237         // GL spec says that behavior in this case is undefined - generating an error is fine.
238         context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
239         return false;
240     }
241     return true;
242 }
243 
ValidateMultiDrawElementsBaseVertexEXT(const Context * context,PrimitiveMode mode,const GLsizei * count,DrawElementsType type,const void * const * indices,GLsizei drawcount,const GLint * basevertex)244 bool ValidateMultiDrawElementsBaseVertexEXT(const Context *context,
245                                             PrimitiveMode mode,
246                                             const GLsizei *count,
247                                             DrawElementsType type,
248                                             const void *const *indices,
249                                             GLsizei drawcount,
250                                             const GLint *basevertex)
251 {
252     return true;
253 }
254 
ValidateDrawElementsBaseVertexOES(const Context * context,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices,GLint basevertex)255 bool ValidateDrawElementsBaseVertexOES(const Context *context,
256                                        PrimitiveMode mode,
257                                        GLsizei count,
258                                        DrawElementsType type,
259                                        const void *indices,
260                                        GLint basevertex)
261 {
262     if (!context->getExtensions().drawElementsBaseVertexAny())
263     {
264         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
265         return false;
266     }
267 
268     return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
269 }
270 
ValidateDrawElementsInstancedBaseVertexOES(const Context * context,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices,GLsizei instancecount,GLint basevertex)271 bool ValidateDrawElementsInstancedBaseVertexOES(const Context *context,
272                                                 PrimitiveMode mode,
273                                                 GLsizei count,
274                                                 DrawElementsType type,
275                                                 const void *indices,
276                                                 GLsizei instancecount,
277                                                 GLint basevertex)
278 {
279     if (!context->getExtensions().drawElementsBaseVertexAny())
280     {
281         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
282         return false;
283     }
284 
285     return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
286 }
287 
ValidateDrawRangeElementsBaseVertexOES(const Context * context,PrimitiveMode mode,GLuint start,GLuint end,GLsizei count,DrawElementsType type,const void * indices,GLint basevertex)288 bool ValidateDrawRangeElementsBaseVertexOES(const Context *context,
289                                             PrimitiveMode mode,
290                                             GLuint start,
291                                             GLuint end,
292                                             GLsizei count,
293                                             DrawElementsType type,
294                                             const void *indices,
295                                             GLint basevertex)
296 {
297     if (!context->getExtensions().drawElementsBaseVertexAny())
298     {
299         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
300         return false;
301     }
302 
303     if (end < start)
304     {
305         context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
306         return false;
307     }
308 
309     if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
310     {
311         return false;
312     }
313 
314     // Skip range checks for no-op calls.
315     if (count <= 0)
316     {
317         return true;
318     }
319 
320     // Note that resolving the index range is a bit slow. We should probably optimize this.
321     IndexRange indexRange;
322     ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
323                                                                              indices, &indexRange));
324 
325     if (indexRange.end > end || indexRange.start < start)
326     {
327         // GL spec says that behavior in this case is undefined - generating an error is fine.
328         context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
329         return false;
330     }
331     return true;
332 }
333 
ValidateBlendEquationSeparateiEXT(const Context * context,GLuint buf,GLenum modeRGB,GLenum modeAlpha)334 bool ValidateBlendEquationSeparateiEXT(const Context *context,
335                                        GLuint buf,
336                                        GLenum modeRGB,
337                                        GLenum modeAlpha)
338 {
339     if (!context->getExtensions().drawBuffersIndexedEXT)
340     {
341         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
342         return false;
343     }
344 
345     return ValidateBlendEquationSeparatei(context, buf, modeRGB, modeAlpha);
346 }
347 
ValidateBlendEquationiEXT(const Context * context,GLuint buf,GLenum mode)348 bool ValidateBlendEquationiEXT(const Context *context, GLuint buf, GLenum mode)
349 {
350     if (!context->getExtensions().drawBuffersIndexedEXT)
351     {
352         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
353         return false;
354     }
355 
356     return ValidateBlendEquationi(context, buf, mode);
357 }
358 
ValidateBlendFuncSeparateiEXT(const Context * context,GLuint buf,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)359 bool ValidateBlendFuncSeparateiEXT(const Context *context,
360                                    GLuint buf,
361                                    GLenum srcRGB,
362                                    GLenum dstRGB,
363                                    GLenum srcAlpha,
364                                    GLenum dstAlpha)
365 {
366     if (!context->getExtensions().drawBuffersIndexedEXT)
367     {
368         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
369         return false;
370     }
371 
372     return ValidateBlendFuncSeparatei(context, buf, srcRGB, dstRGB, srcAlpha, dstAlpha);
373 }
374 
ValidateBlendFunciEXT(const Context * context,GLuint buf,GLenum src,GLenum dst)375 bool ValidateBlendFunciEXT(const Context *context, GLuint buf, GLenum src, GLenum dst)
376 {
377     if (!context->getExtensions().drawBuffersIndexedEXT)
378     {
379         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
380         return false;
381     }
382 
383     return ValidateBlendFunci(context, buf, src, dst);
384 }
385 
ValidateColorMaskiEXT(const Context * context,GLuint index,GLboolean r,GLboolean g,GLboolean b,GLboolean a)386 bool ValidateColorMaskiEXT(const Context *context,
387                            GLuint index,
388                            GLboolean r,
389                            GLboolean g,
390                            GLboolean b,
391                            GLboolean a)
392 {
393     if (!context->getExtensions().drawBuffersIndexedEXT)
394     {
395         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
396         return false;
397     }
398 
399     return ValidateColorMaski(context, index, r, g, b, a);
400 }
401 
ValidateDisableiEXT(const Context * context,GLenum target,GLuint index)402 bool ValidateDisableiEXT(const Context *context, GLenum target, GLuint index)
403 {
404     if (!context->getExtensions().drawBuffersIndexedEXT)
405     {
406         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
407         return false;
408     }
409 
410     return ValidateDisablei(context, target, index);
411 }
412 
ValidateEnableiEXT(const Context * context,GLenum target,GLuint index)413 bool ValidateEnableiEXT(const Context *context, GLenum target, GLuint index)
414 {
415     if (!context->getExtensions().drawBuffersIndexedEXT)
416     {
417         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
418         return false;
419     }
420 
421     return ValidateEnablei(context, target, index);
422 }
423 
ValidateIsEnablediEXT(const Context * context,GLenum target,GLuint index)424 bool ValidateIsEnablediEXT(const Context *context, GLenum target, GLuint index)
425 {
426     if (!context->getExtensions().drawBuffersIndexedEXT)
427     {
428         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
429         return false;
430     }
431 
432     return ValidateIsEnabledi(context, target, index);
433 }
434 
ValidateBlendEquationSeparateiOES(const Context * context,GLuint buf,GLenum modeRGB,GLenum modeAlpha)435 bool ValidateBlendEquationSeparateiOES(const Context *context,
436                                        GLuint buf,
437                                        GLenum modeRGB,
438                                        GLenum modeAlpha)
439 {
440     if (!context->getExtensions().drawBuffersIndexedOES)
441     {
442         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
443         return false;
444     }
445 
446     return ValidateBlendEquationSeparatei(context, buf, modeRGB, modeAlpha);
447 }
448 
ValidateBlendEquationiOES(const Context * context,GLuint buf,GLenum mode)449 bool ValidateBlendEquationiOES(const Context *context, GLuint buf, GLenum mode)
450 {
451     if (!context->getExtensions().drawBuffersIndexedOES)
452     {
453         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
454         return false;
455     }
456 
457     return ValidateBlendEquationi(context, buf, mode);
458 }
459 
ValidateBlendFuncSeparateiOES(const Context * context,GLuint buf,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)460 bool ValidateBlendFuncSeparateiOES(const Context *context,
461                                    GLuint buf,
462                                    GLenum srcRGB,
463                                    GLenum dstRGB,
464                                    GLenum srcAlpha,
465                                    GLenum dstAlpha)
466 {
467     if (!context->getExtensions().drawBuffersIndexedOES)
468     {
469         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
470         return false;
471     }
472 
473     return ValidateBlendFuncSeparatei(context, buf, srcRGB, dstRGB, srcAlpha, dstAlpha);
474 }
475 
ValidateBlendFunciOES(const Context * context,GLuint buf,GLenum src,GLenum dst)476 bool ValidateBlendFunciOES(const Context *context, GLuint buf, GLenum src, GLenum dst)
477 {
478     if (!context->getExtensions().drawBuffersIndexedOES)
479     {
480         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
481         return false;
482     }
483 
484     return ValidateBlendFunci(context, buf, src, dst);
485 }
486 
ValidateColorMaskiOES(const Context * context,GLuint index,GLboolean r,GLboolean g,GLboolean b,GLboolean a)487 bool ValidateColorMaskiOES(const Context *context,
488                            GLuint index,
489                            GLboolean r,
490                            GLboolean g,
491                            GLboolean b,
492                            GLboolean a)
493 {
494     if (!context->getExtensions().drawBuffersIndexedOES)
495     {
496         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
497         return false;
498     }
499 
500     return ValidateColorMaski(context, index, r, g, b, a);
501 }
502 
ValidateDisableiOES(const Context * context,GLenum target,GLuint index)503 bool ValidateDisableiOES(const Context *context, GLenum target, GLuint index)
504 {
505     if (!context->getExtensions().drawBuffersIndexedOES)
506     {
507         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
508         return false;
509     }
510 
511     return ValidateDisablei(context, target, index);
512 }
513 
ValidateEnableiOES(const Context * context,GLenum target,GLuint index)514 bool ValidateEnableiOES(const Context *context, GLenum target, GLuint index)
515 {
516     if (!context->getExtensions().drawBuffersIndexedOES)
517     {
518         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
519         return false;
520     }
521 
522     return ValidateEnablei(context, target, index);
523 }
524 
ValidateIsEnablediOES(const Context * context,GLenum target,GLuint index)525 bool ValidateIsEnablediOES(const Context *context, GLenum target, GLuint index)
526 {
527     if (!context->getExtensions().drawBuffersIndexedOES)
528     {
529         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
530         return false;
531     }
532 
533     return ValidateIsEnabledi(context, target, index);
534 }
535 
ValidateGetInteger64vEXT(const Context * context,GLenum pname,const GLint64 * data)536 bool ValidateGetInteger64vEXT(const Context *context, GLenum pname, const GLint64 *data)
537 {
538     if (!context->getExtensions().disjointTimerQuery)
539     {
540         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
541         return false;
542     }
543 
544     GLenum nativeType      = GL_NONE;
545     unsigned int numParams = 0;
546     if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
547     {
548         return false;
549     }
550 
551     return true;
552 }
553 
ValidateCopyImageSubDataEXT(const Context * context,GLuint srcName,GLenum srcTarget,GLint srcLevel,GLint srcX,GLint srcY,GLint srcZ,GLuint dstName,GLenum dstTarget,GLint dstLevel,GLint dstX,GLint dstY,GLint dstZ,GLsizei srcWidth,GLsizei srcHeight,GLsizei srcDepth)554 bool ValidateCopyImageSubDataEXT(const Context *context,
555                                  GLuint srcName,
556                                  GLenum srcTarget,
557                                  GLint srcLevel,
558                                  GLint srcX,
559                                  GLint srcY,
560                                  GLint srcZ,
561                                  GLuint dstName,
562                                  GLenum dstTarget,
563                                  GLint dstLevel,
564                                  GLint dstX,
565                                  GLint dstY,
566                                  GLint dstZ,
567                                  GLsizei srcWidth,
568                                  GLsizei srcHeight,
569                                  GLsizei srcDepth)
570 {
571     if (!context->getExtensions().copyImageEXT)
572     {
573         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
574         return false;
575     }
576 
577     return ValidateCopyImageSubDataBase(context, srcName, srcTarget, srcLevel, srcX, srcY, srcZ,
578                                         dstName, dstTarget, dstLevel, dstX, dstY, dstZ, srcWidth,
579                                         srcHeight, srcDepth);
580 }
581 
ValidateCopyImageSubDataOES(const Context * context,GLuint srcName,GLenum srcTarget,GLint srcLevel,GLint srcX,GLint srcY,GLint srcZ,GLuint dstName,GLenum dstTarget,GLint dstLevel,GLint dstX,GLint dstY,GLint dstZ,GLsizei srcWidth,GLsizei srcHeight,GLsizei srcDepth)582 bool ValidateCopyImageSubDataOES(const Context *context,
583                                  GLuint srcName,
584                                  GLenum srcTarget,
585                                  GLint srcLevel,
586                                  GLint srcX,
587                                  GLint srcY,
588                                  GLint srcZ,
589                                  GLuint dstName,
590                                  GLenum dstTarget,
591                                  GLint dstLevel,
592                                  GLint dstX,
593                                  GLint dstY,
594                                  GLint dstZ,
595                                  GLsizei srcWidth,
596                                  GLsizei srcHeight,
597                                  GLsizei srcDepth)
598 {
599     if (!context->getExtensions().copyImageEXT)
600     {
601         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
602         return false;
603     }
604 
605     return ValidateCopyImageSubDataBase(context, srcName, srcTarget, srcLevel, srcX, srcY, srcZ,
606                                         dstName, dstTarget, dstLevel, dstX, dstY, dstZ, srcWidth,
607                                         srcHeight, srcDepth);
608 }
609 
ValidateBufferStorageMemEXT(const Context * context,TextureType target,GLsizeiptr size,MemoryObjectID memory,GLuint64 offset)610 bool ValidateBufferStorageMemEXT(const Context *context,
611                                  TextureType target,
612                                  GLsizeiptr size,
613                                  MemoryObjectID memory,
614                                  GLuint64 offset)
615 {
616     if (!context->getExtensions().memoryObject)
617     {
618         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
619         return false;
620     }
621 
622     UNIMPLEMENTED();
623     return false;
624 }
625 
ValidateCreateMemoryObjectsEXT(const Context * context,GLsizei n,const MemoryObjectID * memoryObjects)626 bool ValidateCreateMemoryObjectsEXT(const Context *context,
627                                     GLsizei n,
628                                     const MemoryObjectID *memoryObjects)
629 {
630     if (!context->getExtensions().memoryObject)
631     {
632         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
633         return false;
634     }
635 
636     return ValidateGenOrDelete(context, n);
637 }
638 
ValidateDeleteMemoryObjectsEXT(const Context * context,GLsizei n,const MemoryObjectID * memoryObjects)639 bool ValidateDeleteMemoryObjectsEXT(const Context *context,
640                                     GLsizei n,
641                                     const MemoryObjectID *memoryObjects)
642 {
643     if (!context->getExtensions().memoryObject)
644     {
645         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
646         return false;
647     }
648 
649     return ValidateGenOrDelete(context, n);
650 }
651 
ValidateGetMemoryObjectParameterivEXT(const Context * context,MemoryObjectID memoryObject,GLenum pname,const GLint * params)652 bool ValidateGetMemoryObjectParameterivEXT(const Context *context,
653                                            MemoryObjectID memoryObject,
654                                            GLenum pname,
655                                            const GLint *params)
656 {
657     if (!context->getExtensions().memoryObject)
658     {
659         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
660         return false;
661     }
662 
663     const MemoryObject *memory = context->getMemoryObject(memoryObject);
664     if (memory == nullptr)
665     {
666         context->validationError(GL_INVALID_VALUE, kInvalidMemoryObject);
667     }
668 
669     if (!IsValidMemoryObjectParamater(context, pname))
670     {
671         context->validationError(GL_INVALID_ENUM, kInvalidMemoryObjectParameter);
672         return false;
673     }
674 
675     return true;
676 }
677 
ValidateGetUnsignedBytevEXT(const Context * context,GLenum pname,const GLubyte * data)678 bool ValidateGetUnsignedBytevEXT(const Context *context, GLenum pname, const GLubyte *data)
679 {
680     if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
681     {
682         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
683         return false;
684     }
685 
686     UNIMPLEMENTED();
687     return false;
688 }
689 
ValidateGetUnsignedBytei_vEXT(const Context * context,GLenum target,GLuint index,const GLubyte * data)690 bool ValidateGetUnsignedBytei_vEXT(const Context *context,
691                                    GLenum target,
692                                    GLuint index,
693                                    const GLubyte *data)
694 {
695     if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore)
696     {
697         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
698         return false;
699     }
700 
701     UNIMPLEMENTED();
702     return false;
703 }
704 
ValidateIsMemoryObjectEXT(const Context * context,MemoryObjectID memoryObject)705 bool ValidateIsMemoryObjectEXT(const Context *context, MemoryObjectID memoryObject)
706 {
707     if (!context->getExtensions().memoryObject)
708     {
709         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
710         return false;
711     }
712 
713     return true;
714 }
715 
ValidateMemoryObjectParameterivEXT(const Context * context,MemoryObjectID memoryObject,GLenum pname,const GLint * params)716 bool ValidateMemoryObjectParameterivEXT(const Context *context,
717                                         MemoryObjectID memoryObject,
718                                         GLenum pname,
719                                         const GLint *params)
720 {
721     if (!context->getExtensions().memoryObject)
722     {
723         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
724         return false;
725     }
726 
727     const MemoryObject *memory = context->getMemoryObject(memoryObject);
728     if (memory == nullptr)
729     {
730         context->validationError(GL_INVALID_VALUE, kInvalidMemoryObject);
731         return false;
732     }
733 
734     if (memory->isImmutable())
735     {
736         context->validationError(GL_INVALID_OPERATION, kImmutableMemoryObject);
737         return false;
738     }
739 
740     if (!IsValidMemoryObjectParamater(context, pname))
741     {
742         context->validationError(GL_INVALID_ENUM, kInvalidMemoryObjectParameter);
743         return false;
744     }
745 
746     return true;
747 }
748 
ValidateTexStorageMem2DEXT(const Context * context,TextureType target,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,MemoryObjectID memory,GLuint64 offset)749 bool ValidateTexStorageMem2DEXT(const Context *context,
750                                 TextureType target,
751                                 GLsizei levels,
752                                 GLenum internalFormat,
753                                 GLsizei width,
754                                 GLsizei height,
755                                 MemoryObjectID memory,
756                                 GLuint64 offset)
757 {
758     if (!context->getExtensions().memoryObject)
759     {
760         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
761         return false;
762     }
763 
764     if (context->getClientMajorVersion() < 3)
765     {
766         return ValidateES2TexStorageParametersBase(context, target, levels, internalFormat, width,
767                                                    height);
768     }
769 
770     ASSERT(context->getClientMajorVersion() >= 3);
771     return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height,
772                                              1);
773 }
774 
ValidateTexStorageMem3DEXT(const Context * context,TextureType target,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,MemoryObjectID memory,GLuint64 offset)775 bool ValidateTexStorageMem3DEXT(const Context *context,
776                                 TextureType target,
777                                 GLsizei levels,
778                                 GLenum internalFormat,
779                                 GLsizei width,
780                                 GLsizei height,
781                                 GLsizei depth,
782                                 MemoryObjectID memory,
783                                 GLuint64 offset)
784 {
785     if (!context->getExtensions().memoryObject)
786     {
787         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
788         return false;
789     }
790 
791     UNIMPLEMENTED();
792     return false;
793 }
794 
ValidateImportMemoryFdEXT(const Context * context,MemoryObjectID memory,GLuint64 size,HandleType handleType,GLint fd)795 bool ValidateImportMemoryFdEXT(const Context *context,
796                                MemoryObjectID memory,
797                                GLuint64 size,
798                                HandleType handleType,
799                                GLint fd)
800 {
801     if (!context->getExtensions().memoryObjectFd)
802     {
803         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
804         return false;
805     }
806 
807     switch (handleType)
808     {
809         case HandleType::OpaqueFd:
810             break;
811         default:
812             context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
813             return false;
814     }
815 
816     return true;
817 }
818 
ValidateImportMemoryZirconHandleANGLE(const Context * context,MemoryObjectID memory,GLuint64 size,HandleType handleType,GLuint handle)819 bool ValidateImportMemoryZirconHandleANGLE(const Context *context,
820                                            MemoryObjectID memory,
821                                            GLuint64 size,
822                                            HandleType handleType,
823                                            GLuint handle)
824 {
825     if (!context->getExtensions().memoryObjectFuchsiaANGLE)
826     {
827         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
828         return false;
829     }
830 
831     switch (handleType)
832     {
833         case HandleType::ZirconVmo:
834             break;
835         default:
836             context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
837             return false;
838     }
839 
840     return true;
841 }
842 
ValidateDeleteSemaphoresEXT(const Context * context,GLsizei n,const SemaphoreID * semaphores)843 bool ValidateDeleteSemaphoresEXT(const Context *context, GLsizei n, const SemaphoreID *semaphores)
844 {
845     if (!context->getExtensions().semaphore)
846     {
847         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
848         return false;
849     }
850 
851     return ValidateGenOrDelete(context, n);
852 }
853 
ValidateGenSemaphoresEXT(const Context * context,GLsizei n,const SemaphoreID * semaphores)854 bool ValidateGenSemaphoresEXT(const Context *context, GLsizei n, const SemaphoreID *semaphores)
855 {
856     if (!context->getExtensions().semaphore)
857     {
858         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
859         return false;
860     }
861 
862     return ValidateGenOrDelete(context, n);
863 }
864 
ValidateGetSemaphoreParameterui64vEXT(const Context * context,SemaphoreID semaphore,GLenum pname,const GLuint64 * params)865 bool ValidateGetSemaphoreParameterui64vEXT(const Context *context,
866                                            SemaphoreID semaphore,
867                                            GLenum pname,
868                                            const GLuint64 *params)
869 {
870     if (!context->getExtensions().semaphore)
871     {
872         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
873         return false;
874     }
875 
876     UNIMPLEMENTED();
877     return false;
878 }
879 
ValidateIsSemaphoreEXT(const Context * context,SemaphoreID semaphore)880 bool ValidateIsSemaphoreEXT(const Context *context, SemaphoreID semaphore)
881 {
882     if (!context->getExtensions().semaphore)
883     {
884         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
885         return false;
886     }
887 
888     return true;
889 }
890 
ValidateSemaphoreParameterui64vEXT(const Context * context,SemaphoreID semaphore,GLenum pname,const GLuint64 * params)891 bool ValidateSemaphoreParameterui64vEXT(const Context *context,
892                                         SemaphoreID semaphore,
893                                         GLenum pname,
894                                         const GLuint64 *params)
895 {
896     if (!context->getExtensions().semaphore)
897     {
898         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
899         return false;
900     }
901 
902     UNIMPLEMENTED();
903     return false;
904 }
905 
ValidateSignalSemaphoreEXT(const Context * context,SemaphoreID semaphore,GLuint numBufferBarriers,const BufferID * buffers,GLuint numTextureBarriers,const TextureID * textures,const GLenum * dstLayouts)906 bool ValidateSignalSemaphoreEXT(const Context *context,
907                                 SemaphoreID semaphore,
908                                 GLuint numBufferBarriers,
909                                 const BufferID *buffers,
910                                 GLuint numTextureBarriers,
911                                 const TextureID *textures,
912                                 const GLenum *dstLayouts)
913 {
914     if (!context->getExtensions().semaphore)
915     {
916         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
917         return false;
918     }
919 
920     for (GLuint i = 0; i < numTextureBarriers; ++i)
921     {
922         if (!IsValidImageLayout(FromGLenum<ImageLayout>(dstLayouts[i])))
923         {
924             context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
925             return false;
926         }
927     }
928 
929     return true;
930 }
931 
ValidateWaitSemaphoreEXT(const Context * context,SemaphoreID semaphore,GLuint numBufferBarriers,const BufferID * buffers,GLuint numTextureBarriers,const TextureID * textures,const GLenum * srcLayouts)932 bool ValidateWaitSemaphoreEXT(const Context *context,
933                               SemaphoreID semaphore,
934                               GLuint numBufferBarriers,
935                               const BufferID *buffers,
936                               GLuint numTextureBarriers,
937                               const TextureID *textures,
938                               const GLenum *srcLayouts)
939 {
940     if (!context->getExtensions().semaphore)
941     {
942         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
943         return false;
944     }
945 
946     for (GLuint i = 0; i < numTextureBarriers; ++i)
947     {
948         if (!IsValidImageLayout(FromGLenum<ImageLayout>(srcLayouts[i])))
949         {
950             context->validationError(GL_INVALID_ENUM, kInvalidImageLayout);
951             return false;
952         }
953     }
954 
955     return true;
956 }
957 
ValidateImportSemaphoreFdEXT(const Context * context,SemaphoreID semaphore,HandleType handleType,GLint fd)958 bool ValidateImportSemaphoreFdEXT(const Context *context,
959                                   SemaphoreID semaphore,
960                                   HandleType handleType,
961                                   GLint fd)
962 {
963     if (!context->getExtensions().semaphoreFd)
964     {
965         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
966         return false;
967     }
968 
969     switch (handleType)
970     {
971         case HandleType::OpaqueFd:
972             break;
973         default:
974             context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
975             return false;
976     }
977 
978     return true;
979 }
980 
ValidateImportSemaphoreZirconHandleANGLE(const Context * context,SemaphoreID semaphore,HandleType handleType,GLuint handle)981 bool ValidateImportSemaphoreZirconHandleANGLE(const Context *context,
982                                               SemaphoreID semaphore,
983                                               HandleType handleType,
984                                               GLuint handle)
985 {
986     if (!context->getExtensions().semaphoreFuchsiaANGLE)
987     {
988         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
989         return false;
990     }
991 
992     switch (handleType)
993     {
994         case HandleType::ZirconEvent:
995             break;
996         default:
997             context->validationError(GL_INVALID_ENUM, kInvalidHandleType);
998             return false;
999     }
1000 
1001     return true;
1002 }
1003 
ValidateTexStorageMemFlags2DANGLE(const Context * context,TextureType targetPacked,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,MemoryObjectID memoryPacked,GLuint64 offset,GLbitfield createFlags,GLbitfield usageFlags)1004 bool ValidateTexStorageMemFlags2DANGLE(const Context *context,
1005                                        TextureType targetPacked,
1006                                        GLsizei levels,
1007                                        GLenum internalFormat,
1008                                        GLsizei width,
1009                                        GLsizei height,
1010                                        MemoryObjectID memoryPacked,
1011                                        GLuint64 offset,
1012                                        GLbitfield createFlags,
1013                                        GLbitfield usageFlags)
1014 {
1015     if (!context->getExtensions().memoryObjectFlagsANGLE)
1016     {
1017         context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
1018         return false;
1019     }
1020 
1021     if (!ValidateTexStorageMem2DEXT(context, targetPacked, levels, internalFormat, width, height,
1022                                     memoryPacked, offset))
1023     {
1024         return false;
1025     }
1026 
1027     // |createFlags| and |usageFlags| must only have bits specified by the extension.
1028     constexpr GLbitfield kAllCreateFlags =
1029         GL_CREATE_SPARSE_BINDING_BIT_ANGLE | GL_CREATE_SPARSE_RESIDENCY_BIT_ANGLE |
1030         GL_CREATE_SPARSE_ALIASED_BIT_ANGLE | GL_CREATE_MUTABLE_FORMAT_BIT_ANGLE |
1031         GL_CREATE_CUBE_COMPATIBLE_BIT_ANGLE | GL_CREATE_ALIAS_BIT_ANGLE |
1032         GL_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_ANGLE | GL_CREATE_2D_ARRAY_COMPATIBLE_BIT_ANGLE |
1033         GL_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_ANGLE | GL_CREATE_EXTENDED_USAGE_BIT_ANGLE |
1034         GL_CREATE_PROTECTED_BIT_ANGLE | GL_CREATE_DISJOINT_BIT_ANGLE |
1035         GL_CREATE_CORNER_SAMPLED_BIT_ANGLE | GL_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_ANGLE |
1036         GL_CREATE_SUBSAMPLED_BIT_ANGLE;
1037 
1038     if ((createFlags & ~kAllCreateFlags) != 0)
1039     {
1040         context->validationError(GL_INVALID_VALUE, kInvalidExternalCreateFlags);
1041         return false;
1042     }
1043 
1044     constexpr GLbitfield kAllUsageFlags =
1045         GL_USAGE_TRANSFER_SRC_BIT_ANGLE | GL_USAGE_TRANSFER_DST_BIT_ANGLE |
1046         GL_USAGE_SAMPLED_BIT_ANGLE | GL_USAGE_STORAGE_BIT_ANGLE |
1047         GL_USAGE_COLOR_ATTACHMENT_BIT_ANGLE | GL_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT_ANGLE |
1048         GL_USAGE_TRANSIENT_ATTACHMENT_BIT_ANGLE | GL_USAGE_INPUT_ATTACHMENT_BIT_ANGLE |
1049         GL_USAGE_SHADING_RATE_IMAGE_BIT_ANGLE | GL_USAGE_FRAGMENT_DENSITY_MAP_BIT_ANGLE;
1050 
1051     if ((usageFlags & ~kAllUsageFlags) != 0)
1052     {
1053         context->validationError(GL_INVALID_VALUE, kInvalidExternalUsageFlags);
1054         return false;
1055     }
1056 
1057     return true;
1058 }
1059 
ValidateTexStorageMemFlags2DMultisampleANGLE(const Context * context,TextureType targetPacked,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLboolean fixedSampleLocations,MemoryObjectID memoryPacked,GLuint64 offset,GLbitfield createFlags,GLbitfield usageFlags)1060 bool ValidateTexStorageMemFlags2DMultisampleANGLE(const Context *context,
1061                                                   TextureType targetPacked,
1062                                                   GLsizei samples,
1063                                                   GLenum internalFormat,
1064                                                   GLsizei width,
1065                                                   GLsizei height,
1066                                                   GLboolean fixedSampleLocations,
1067                                                   MemoryObjectID memoryPacked,
1068                                                   GLuint64 offset,
1069                                                   GLbitfield createFlags,
1070                                                   GLbitfield usageFlags)
1071 {
1072     UNIMPLEMENTED();
1073     return false;
1074 }
1075 
ValidateTexStorageMemFlags3DANGLE(const Context * context,TextureType targetPacked,GLsizei levels,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,MemoryObjectID memoryPacked,GLuint64 offset,GLbitfield createFlags,GLbitfield usageFlags)1076 bool ValidateTexStorageMemFlags3DANGLE(const Context *context,
1077                                        TextureType targetPacked,
1078                                        GLsizei levels,
1079                                        GLenum internalFormat,
1080                                        GLsizei width,
1081                                        GLsizei height,
1082                                        GLsizei depth,
1083                                        MemoryObjectID memoryPacked,
1084                                        GLuint64 offset,
1085                                        GLbitfield createFlags,
1086                                        GLbitfield usageFlags)
1087 {
1088     UNIMPLEMENTED();
1089     return false;
1090 }
1091 
ValidateTexStorageMemFlags3DMultisampleANGLE(const Context * context,TextureType targetPacked,GLsizei samples,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLboolean fixedSampleLocations,MemoryObjectID memoryPacked,GLuint64 offset,GLbitfield createFlags,GLbitfield usageFlags)1092 bool ValidateTexStorageMemFlags3DMultisampleANGLE(const Context *context,
1093                                                   TextureType targetPacked,
1094                                                   GLsizei samples,
1095                                                   GLenum internalFormat,
1096                                                   GLsizei width,
1097                                                   GLsizei height,
1098                                                   GLsizei depth,
1099                                                   GLboolean fixedSampleLocations,
1100                                                   MemoryObjectID memoryPacked,
1101                                                   GLuint64 offset,
1102                                                   GLbitfield createFlags,
1103                                                   GLbitfield usageFlags)
1104 {
1105     UNIMPLEMENTED();
1106     return false;
1107 }
1108 
1109 // GL_EXT_buffer_storage
ValidateBufferStorageEXT(const Context * context,BufferBinding targetPacked,GLsizeiptr size,const void * data,GLbitfield flags)1110 bool ValidateBufferStorageEXT(const Context *context,
1111                               BufferBinding targetPacked,
1112                               GLsizeiptr size,
1113                               const void *data,
1114                               GLbitfield flags)
1115 {
1116     if (!context->isValidBufferBinding(targetPacked))
1117     {
1118         context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes);
1119         return false;
1120     }
1121 
1122     if (size < 0)
1123     {
1124         context->validationError(GL_INVALID_VALUE, kNegativeSize);
1125         return false;
1126     }
1127 
1128     constexpr GLbitfield kAllUsageFlags =
1129         (GL_DYNAMIC_STORAGE_BIT_EXT | GL_MAP_READ_BIT | GL_MAP_WRITE_BIT |
1130          GL_MAP_PERSISTENT_BIT_EXT | GL_MAP_PERSISTENT_BIT_EXT | GL_CLIENT_STORAGE_BIT_EXT);
1131     if ((flags & ~kAllUsageFlags) != 0)
1132     {
1133         context->validationError(GL_INVALID_VALUE, kInvalidBufferUsageFlags);
1134         return false;
1135     }
1136 
1137     if (((flags & GL_MAP_PERSISTENT_BIT_EXT) != 0) &&
1138         ((flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0))
1139     {
1140         context->validationError(GL_INVALID_VALUE, kInvalidBufferUsageFlags);
1141         return false;
1142     }
1143 
1144     if (((flags & GL_MAP_COHERENT_BIT_EXT) != 0) && ((flags & GL_MAP_PERSISTENT_BIT_EXT) == 0))
1145     {
1146         context->validationError(GL_INVALID_VALUE, kInvalidBufferUsageFlags);
1147         return false;
1148     }
1149 
1150     Buffer *buffer = context->getState().getTargetBuffer(targetPacked);
1151 
1152     if (buffer == nullptr)
1153     {
1154         context->validationError(GL_INVALID_OPERATION, kBufferNotBound);
1155         return false;
1156     }
1157 
1158     if (buffer->isImmutable())
1159     {
1160         context->validationError(GL_INVALID_OPERATION, kBufferImmutable);
1161         return false;
1162     }
1163 
1164     return true;
1165 }
1166 
1167 // GL_EXT_external_buffer
ValidateBufferStorageExternalEXT(const Context * context,BufferBinding targetPacked,GLintptr offset,GLsizeiptr size,GLeglClientBufferEXT clientBuffer,GLbitfield flags)1168 bool ValidateBufferStorageExternalEXT(const Context *context,
1169                                       BufferBinding targetPacked,
1170                                       GLintptr offset,
1171                                       GLsizeiptr size,
1172                                       GLeglClientBufferEXT clientBuffer,
1173                                       GLbitfield flags)
1174 {
1175     UNIMPLEMENTED();
1176     return false;
1177 }
1178 
ValidateNamedBufferStorageExternalEXT(const Context * context,GLuint buffer,GLintptr offset,GLsizeiptr size,GLeglClientBufferEXT clientBuffer,GLbitfield flags)1179 bool ValidateNamedBufferStorageExternalEXT(const Context *context,
1180                                            GLuint buffer,
1181                                            GLintptr offset,
1182                                            GLsizeiptr size,
1183                                            GLeglClientBufferEXT clientBuffer,
1184                                            GLbitfield flags)
1185 {
1186     UNIMPLEMENTED();
1187     return false;
1188 }
1189 }  // namespace gl
1190