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