Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2016 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 | |
| 7 | // validationES31.cpp: Validation functions for OpenGL ES 3.1 entry point parameters |
| 8 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 9 | #include "libANGLE/validationES31.h" |
| 10 | |
| 11 | #include "libANGLE/Context.h" |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 12 | #include "libANGLE/ErrorStrings.h" |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 13 | #include "libANGLE/Framebuffer.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 14 | #include "libANGLE/VertexArray.h" |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 15 | #include "libANGLE/validationES.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 16 | #include "libANGLE/validationES2.h" |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 17 | #include "libANGLE/validationES3.h" |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 18 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 19 | #include "common/utilities.h" |
| 20 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 21 | using namespace angle; |
| 22 | |
| 23 | namespace gl |
| 24 | { |
| 25 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
| 29 | bool ValidateNamedProgramInterface(GLenum programInterface) |
| 30 | { |
| 31 | switch (programInterface) |
| 32 | { |
| 33 | case GL_UNIFORM: |
| 34 | case GL_UNIFORM_BLOCK: |
| 35 | case GL_PROGRAM_INPUT: |
| 36 | case GL_PROGRAM_OUTPUT: |
| 37 | case GL_TRANSFORM_FEEDBACK_VARYING: |
| 38 | case GL_BUFFER_VARIABLE: |
| 39 | case GL_SHADER_STORAGE_BLOCK: |
| 40 | return true; |
| 41 | default: |
| 42 | return false; |
| 43 | } |
| 44 | } |
| 45 | |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame] | 46 | bool ValidateLocationProgramInterface(GLenum programInterface) |
| 47 | { |
| 48 | switch (programInterface) |
| 49 | { |
| 50 | case GL_UNIFORM: |
| 51 | case GL_PROGRAM_INPUT: |
| 52 | case GL_PROGRAM_OUTPUT: |
| 53 | return true; |
| 54 | default: |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 59 | bool ValidateProgramInterface(GLenum programInterface) |
| 60 | { |
| 61 | return (programInterface == GL_ATOMIC_COUNTER_BUFFER || |
| 62 | ValidateNamedProgramInterface(programInterface)); |
| 63 | } |
| 64 | |
Jiawei Shao | c6f8287 | 2018-04-24 14:14:50 +0800 | [diff] [blame] | 65 | bool ValidateProgramResourceProperty(const Context *context, GLenum prop) |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 66 | { |
Jiawei Shao | c6f8287 | 2018-04-24 14:14:50 +0800 | [diff] [blame] | 67 | ASSERT(context); |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 68 | switch (prop) |
| 69 | { |
| 70 | case GL_ACTIVE_VARIABLES: |
| 71 | case GL_BUFFER_BINDING: |
| 72 | case GL_NUM_ACTIVE_VARIABLES: |
| 73 | |
| 74 | case GL_ARRAY_SIZE: |
| 75 | |
| 76 | case GL_ARRAY_STRIDE: |
| 77 | case GL_BLOCK_INDEX: |
| 78 | case GL_IS_ROW_MAJOR: |
| 79 | case GL_MATRIX_STRIDE: |
| 80 | |
| 81 | case GL_ATOMIC_COUNTER_BUFFER_INDEX: |
| 82 | |
| 83 | case GL_BUFFER_DATA_SIZE: |
| 84 | |
| 85 | case GL_LOCATION: |
| 86 | |
| 87 | case GL_NAME_LENGTH: |
| 88 | |
| 89 | case GL_OFFSET: |
| 90 | |
| 91 | case GL_REFERENCED_BY_VERTEX_SHADER: |
| 92 | case GL_REFERENCED_BY_FRAGMENT_SHADER: |
| 93 | case GL_REFERENCED_BY_COMPUTE_SHADER: |
| 94 | |
| 95 | case GL_TOP_LEVEL_ARRAY_SIZE: |
| 96 | case GL_TOP_LEVEL_ARRAY_STRIDE: |
| 97 | |
| 98 | case GL_TYPE: |
| 99 | return true; |
| 100 | |
Jiawei Shao | c6f8287 | 2018-04-24 14:14:50 +0800 | [diff] [blame] | 101 | case GL_REFERENCED_BY_GEOMETRY_SHADER_EXT: |
| 102 | return context->getExtensions().geometryShader; |
| 103 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 104 | default: |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // GLES 3.10 spec: Page 82 -- Table 7.2 |
| 110 | bool ValidateProgramResourcePropertyByInterface(GLenum prop, GLenum programInterface) |
| 111 | { |
| 112 | switch (prop) |
| 113 | { |
| 114 | case GL_ACTIVE_VARIABLES: |
| 115 | case GL_BUFFER_BINDING: |
| 116 | case GL_NUM_ACTIVE_VARIABLES: |
| 117 | { |
| 118 | switch (programInterface) |
| 119 | { |
| 120 | case GL_ATOMIC_COUNTER_BUFFER: |
| 121 | case GL_SHADER_STORAGE_BLOCK: |
| 122 | case GL_UNIFORM_BLOCK: |
| 123 | return true; |
| 124 | default: |
| 125 | return false; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | case GL_ARRAY_SIZE: |
| 130 | { |
| 131 | switch (programInterface) |
| 132 | { |
| 133 | case GL_BUFFER_VARIABLE: |
| 134 | case GL_PROGRAM_INPUT: |
| 135 | case GL_PROGRAM_OUTPUT: |
| 136 | case GL_TRANSFORM_FEEDBACK_VARYING: |
| 137 | case GL_UNIFORM: |
| 138 | return true; |
| 139 | default: |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | case GL_ARRAY_STRIDE: |
| 145 | case GL_BLOCK_INDEX: |
| 146 | case GL_IS_ROW_MAJOR: |
| 147 | case GL_MATRIX_STRIDE: |
| 148 | { |
| 149 | switch (programInterface) |
| 150 | { |
| 151 | case GL_BUFFER_VARIABLE: |
| 152 | case GL_UNIFORM: |
| 153 | return true; |
| 154 | default: |
| 155 | return false; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | case GL_ATOMIC_COUNTER_BUFFER_INDEX: |
| 160 | { |
| 161 | if (programInterface == GL_UNIFORM) |
| 162 | { |
| 163 | return true; |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | case GL_BUFFER_DATA_SIZE: |
| 169 | { |
| 170 | switch (programInterface) |
| 171 | { |
| 172 | case GL_ATOMIC_COUNTER_BUFFER: |
| 173 | case GL_SHADER_STORAGE_BLOCK: |
| 174 | case GL_UNIFORM_BLOCK: |
| 175 | return true; |
| 176 | default: |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | case GL_LOCATION: |
| 182 | { |
| 183 | return ValidateLocationProgramInterface(programInterface); |
| 184 | } |
| 185 | |
| 186 | case GL_NAME_LENGTH: |
| 187 | { |
| 188 | return ValidateNamedProgramInterface(programInterface); |
| 189 | } |
| 190 | |
| 191 | case GL_OFFSET: |
| 192 | { |
| 193 | switch (programInterface) |
| 194 | { |
| 195 | case GL_BUFFER_VARIABLE: |
| 196 | case GL_UNIFORM: |
| 197 | return true; |
| 198 | default: |
| 199 | return false; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | case GL_REFERENCED_BY_VERTEX_SHADER: |
| 204 | case GL_REFERENCED_BY_FRAGMENT_SHADER: |
| 205 | case GL_REFERENCED_BY_COMPUTE_SHADER: |
Jiawei Shao | c6f8287 | 2018-04-24 14:14:50 +0800 | [diff] [blame] | 206 | case GL_REFERENCED_BY_GEOMETRY_SHADER_EXT: |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 207 | { |
| 208 | switch (programInterface) |
| 209 | { |
| 210 | case GL_ATOMIC_COUNTER_BUFFER: |
| 211 | case GL_BUFFER_VARIABLE: |
| 212 | case GL_PROGRAM_INPUT: |
| 213 | case GL_PROGRAM_OUTPUT: |
| 214 | case GL_SHADER_STORAGE_BLOCK: |
| 215 | case GL_UNIFORM: |
| 216 | case GL_UNIFORM_BLOCK: |
| 217 | return true; |
| 218 | default: |
| 219 | return false; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | case GL_TOP_LEVEL_ARRAY_SIZE: |
| 224 | case GL_TOP_LEVEL_ARRAY_STRIDE: |
| 225 | { |
| 226 | if (programInterface == GL_BUFFER_VARIABLE) |
| 227 | { |
| 228 | return true; |
| 229 | } |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | case GL_TYPE: |
| 234 | { |
| 235 | switch (programInterface) |
| 236 | { |
| 237 | case GL_BUFFER_VARIABLE: |
| 238 | case GL_PROGRAM_INPUT: |
| 239 | case GL_PROGRAM_OUTPUT: |
| 240 | case GL_TRANSFORM_FEEDBACK_VARYING: |
| 241 | case GL_UNIFORM: |
| 242 | return true; |
| 243 | default: |
| 244 | return false; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | default: |
| 249 | return false; |
| 250 | } |
| 251 | } |
| 252 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 253 | bool ValidateProgramResourceIndex(const Program *programObject, |
| 254 | GLenum programInterface, |
| 255 | GLuint index) |
| 256 | { |
| 257 | switch (programInterface) |
| 258 | { |
| 259 | case GL_PROGRAM_INPUT: |
| 260 | return (index < static_cast<GLuint>(programObject->getActiveAttributeCount())); |
| 261 | |
| 262 | case GL_PROGRAM_OUTPUT: |
| 263 | return (index < static_cast<GLuint>(programObject->getOutputResourceCount())); |
| 264 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 265 | case GL_UNIFORM: |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 266 | return (index < static_cast<GLuint>(programObject->getActiveUniformCount())); |
| 267 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 268 | case GL_BUFFER_VARIABLE: |
| 269 | return (index < static_cast<GLuint>(programObject->getActiveBufferVariableCount())); |
| 270 | |
| 271 | case GL_SHADER_STORAGE_BLOCK: |
| 272 | return (index < static_cast<GLuint>(programObject->getActiveShaderStorageBlockCount())); |
| 273 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 274 | case GL_UNIFORM_BLOCK: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 275 | return (index < programObject->getActiveUniformBlockCount()); |
| 276 | |
| 277 | case GL_ATOMIC_COUNTER_BUFFER: |
| 278 | return (index < programObject->getActiveAtomicCounterBufferCount()); |
| 279 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 280 | case GL_TRANSFORM_FEEDBACK_VARYING: |
jchen10 | 910a3da | 2017-11-15 09:40:11 +0800 | [diff] [blame] | 281 | return (index < static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount())); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 282 | |
| 283 | default: |
| 284 | UNREACHABLE(); |
| 285 | return false; |
| 286 | } |
| 287 | } |
| 288 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 289 | bool ValidateProgramUniform(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 290 | GLenum valueType, |
| 291 | GLuint program, |
| 292 | GLint location, |
| 293 | GLsizei count) |
| 294 | { |
| 295 | // Check for ES31 program uniform entry points |
| 296 | if (context->getClientVersion() < Version(3, 1)) |
| 297 | { |
| 298 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 303 | Program *programObject = GetValidProgram(context, program); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 304 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 305 | ValidateUniformValue(context, valueType, uniform->type); |
| 306 | } |
| 307 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 308 | bool ValidateProgramUniformMatrix(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 309 | GLenum valueType, |
| 310 | GLuint program, |
| 311 | GLint location, |
| 312 | GLsizei count, |
| 313 | GLboolean transpose) |
| 314 | { |
| 315 | // Check for ES31 program uniform entry points |
| 316 | if (context->getClientVersion() < Version(3, 1)) |
| 317 | { |
| 318 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 323 | Program *programObject = GetValidProgram(context, program); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 324 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 325 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
| 326 | } |
| 327 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 328 | bool ValidateVertexAttribFormatCommon(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 329 | GLuint attribIndex, |
| 330 | GLint size, |
| 331 | GLenum type, |
| 332 | GLuint relativeOffset, |
| 333 | GLboolean pureInteger) |
| 334 | { |
| 335 | if (context->getClientVersion() < ES_3_1) |
| 336 | { |
| 337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | const Caps &caps = context->getCaps(); |
| 342 | if (relativeOffset > static_cast<GLuint>(caps.maxVertexAttribRelativeOffset)) |
| 343 | { |
| 344 | context->handleError( |
| 345 | InvalidValue() |
| 346 | << "relativeOffset cannot be greater than MAX_VERTEX_ATTRIB_RELATIVE_OFFSET."); |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 351 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 352 | if (context->getGLState().getVertexArrayId() == 0) |
| 353 | { |
| 354 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | return ValidateVertexFormatBase(context, attribIndex, size, type, pureInteger); |
| 359 | } |
| 360 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 361 | } // anonymous namespace |
| 362 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 363 | bool ValidateGetBooleani_v(Context *context, GLenum target, GLuint index, GLboolean *data) |
| 364 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 365 | if (context->getClientVersion() < ES_3_1) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 366 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 367 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 368 | return false; |
| 369 | } |
| 370 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 371 | if (!ValidateIndexedStateQuery(context, target, index, nullptr)) |
| 372 | { |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | bool ValidateGetBooleani_vRobustANGLE(Context *context, |
| 380 | GLenum target, |
| 381 | GLuint index, |
| 382 | GLsizei bufSize, |
| 383 | GLsizei *length, |
| 384 | GLboolean *data) |
| 385 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 386 | if (context->getClientVersion() < ES_3_1) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 387 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 388 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 389 | return false; |
| 390 | } |
| 391 | |
| 392 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 393 | { |
| 394 | return false; |
| 395 | } |
| 396 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 397 | GLsizei numParams = 0; |
| 398 | |
| 399 | if (!ValidateIndexedStateQuery(context, target, index, &numParams)) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 400 | { |
| 401 | return false; |
| 402 | } |
| 403 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 404 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 405 | { |
| 406 | return false; |
| 407 | } |
| 408 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 409 | SetRobustLengthParam(length, numParams); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 410 | return true; |
| 411 | } |
| 412 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 413 | bool ValidateDrawIndirectBase(Context *context, GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 414 | { |
| 415 | if (context->getClientVersion() < ES_3_1) |
| 416 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 417 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | |
| 421 | // Here the third parameter 1 is only to pass the count validation. |
| 422 | if (!ValidateDrawBase(context, mode, 1)) |
| 423 | { |
| 424 | return false; |
| 425 | } |
| 426 | |
| 427 | const State &state = context->getGLState(); |
| 428 | |
| 429 | // An INVALID_OPERATION error is generated if zero is bound to VERTEX_ARRAY_BINDING, |
| 430 | // DRAW_INDIRECT_BUFFER or to any enabled vertex array. |
| 431 | if (!state.getVertexArrayId()) |
| 432 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 433 | context->handleError(InvalidOperation() << "zero is bound to VERTEX_ARRAY_BINDING"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 437 | Buffer *drawIndirectBuffer = state.getTargetBuffer(BufferBinding::DrawIndirect); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 438 | if (!drawIndirectBuffer) |
| 439 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 440 | context->handleError(InvalidOperation() << "zero is bound to DRAW_INDIRECT_BUFFER"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 441 | return false; |
| 442 | } |
| 443 | |
| 444 | // An INVALID_VALUE error is generated if indirect is not a multiple of the size, in basic |
| 445 | // machine units, of uint. |
| 446 | GLint64 offset = reinterpret_cast<GLint64>(indirect); |
| 447 | if ((static_cast<GLuint>(offset) % sizeof(GLuint)) != 0) |
| 448 | { |
| 449 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 450 | InvalidValue() |
| 451 | << "indirect is not a multiple of the size, in basic machine units, of uint"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 455 | // ANGLE_multiview spec, revision 1: |
| 456 | // An INVALID_OPERATION is generated by DrawArraysIndirect and DrawElementsIndirect if the |
| 457 | // number of views in the draw framebuffer is greater than 1. |
| 458 | const Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
| 459 | ASSERT(drawFramebuffer != nullptr); |
| 460 | if (drawFramebuffer->getNumViews() > 1) |
| 461 | { |
| 462 | context->handleError( |
| 463 | InvalidOperation() |
| 464 | << "The number of views in the active draw framebuffer is greater than 1."); |
| 465 | return false; |
| 466 | } |
| 467 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 468 | return true; |
| 469 | } |
| 470 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 471 | bool ValidateDrawArraysIndirect(Context *context, GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 472 | { |
| 473 | const State &state = context->getGLState(); |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 474 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 475 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 476 | !curTransformFeedback->isPaused()) |
| 477 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame^] | 478 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 479 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 480 | if (context->getExtensions().geometryShader) |
| 481 | { |
| 482 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 483 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 484 | { |
| 485 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 486 | return false; |
| 487 | } |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | // An INVALID_OPERATION error is generated if transform feedback is active and not |
| 492 | // paused. |
| 493 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 494 | UnsupportedDrawModeForTransformFeedback); |
| 495 | return false; |
| 496 | } |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (!ValidateDrawIndirectBase(context, mode, indirect)) |
| 500 | return false; |
| 501 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 502 | Buffer *drawIndirectBuffer = state.getTargetBuffer(BufferBinding::DrawIndirect); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 503 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(indirect)); |
| 504 | // In OpenGL ES3.1 spec, session 10.5, it defines the struct of DrawArraysIndirectCommand |
| 505 | // which's size is 4 * sizeof(uint). |
| 506 | auto checkedSum = checkedOffset + 4 * sizeof(GLuint); |
| 507 | if (!checkedSum.IsValid() || |
| 508 | checkedSum.ValueOrDie() > static_cast<size_t>(drawIndirectBuffer->getSize())) |
| 509 | { |
| 510 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 511 | InvalidOperation() |
| 512 | << "the command would source data beyond the end of the buffer object."); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 513 | return false; |
| 514 | } |
| 515 | |
| 516 | return true; |
| 517 | } |
| 518 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 519 | bool ValidateDrawElementsIndirect(Context *context, GLenum mode, GLenum type, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 520 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame^] | 521 | if (!ValidateDrawElementsBase(context, mode, type)) |
| 522 | { |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 523 | return false; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame^] | 524 | } |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 525 | |
| 526 | const State &state = context->getGLState(); |
| 527 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 528 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 529 | if (!elementArrayBuffer) |
| 530 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 531 | context->handleError(InvalidOperation() << "zero is bound to ELEMENT_ARRAY_BUFFER"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 532 | return false; |
| 533 | } |
| 534 | |
| 535 | if (!ValidateDrawIndirectBase(context, mode, indirect)) |
| 536 | return false; |
| 537 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 538 | Buffer *drawIndirectBuffer = state.getTargetBuffer(BufferBinding::DrawIndirect); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 539 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(indirect)); |
| 540 | // In OpenGL ES3.1 spec, session 10.5, it defines the struct of DrawElementsIndirectCommand |
| 541 | // which's size is 5 * sizeof(uint). |
| 542 | auto checkedSum = checkedOffset + 5 * sizeof(GLuint); |
| 543 | if (!checkedSum.IsValid() || |
| 544 | checkedSum.ValueOrDie() > static_cast<size_t>(drawIndirectBuffer->getSize())) |
| 545 | { |
| 546 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 547 | InvalidOperation() |
| 548 | << "the command would source data beyond the end of the buffer object."); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 549 | return false; |
| 550 | } |
| 551 | |
| 552 | return true; |
| 553 | } |
| 554 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 555 | bool ValidateProgramUniform1i(Context *context, GLuint program, GLint location, GLint v0) |
| 556 | { |
| 557 | return ValidateProgramUniform1iv(context, program, location, 1, &v0); |
| 558 | } |
| 559 | |
| 560 | bool ValidateProgramUniform2i(Context *context, GLuint program, GLint location, GLint v0, GLint v1) |
| 561 | { |
| 562 | GLint xy[2] = {v0, v1}; |
| 563 | return ValidateProgramUniform2iv(context, program, location, 1, xy); |
| 564 | } |
| 565 | |
| 566 | bool ValidateProgramUniform3i(Context *context, |
| 567 | GLuint program, |
| 568 | GLint location, |
| 569 | GLint v0, |
| 570 | GLint v1, |
| 571 | GLint v2) |
| 572 | { |
| 573 | GLint xyz[3] = {v0, v1, v2}; |
| 574 | return ValidateProgramUniform3iv(context, program, location, 1, xyz); |
| 575 | } |
| 576 | |
| 577 | bool ValidateProgramUniform4i(Context *context, |
| 578 | GLuint program, |
| 579 | GLint location, |
| 580 | GLint v0, |
| 581 | GLint v1, |
| 582 | GLint v2, |
| 583 | GLint v3) |
| 584 | { |
| 585 | GLint xyzw[4] = {v0, v1, v2, v3}; |
| 586 | return ValidateProgramUniform4iv(context, program, location, 1, xyzw); |
| 587 | } |
| 588 | |
| 589 | bool ValidateProgramUniform1ui(Context *context, GLuint program, GLint location, GLuint v0) |
| 590 | { |
| 591 | return ValidateProgramUniform1uiv(context, program, location, 1, &v0); |
| 592 | } |
| 593 | |
| 594 | bool ValidateProgramUniform2ui(Context *context, |
| 595 | GLuint program, |
| 596 | GLint location, |
| 597 | GLuint v0, |
| 598 | GLuint v1) |
| 599 | { |
| 600 | GLuint xy[2] = {v0, v1}; |
| 601 | return ValidateProgramUniform2uiv(context, program, location, 1, xy); |
| 602 | } |
| 603 | |
| 604 | bool ValidateProgramUniform3ui(Context *context, |
| 605 | GLuint program, |
| 606 | GLint location, |
| 607 | GLuint v0, |
| 608 | GLuint v1, |
| 609 | GLuint v2) |
| 610 | { |
| 611 | GLuint xyz[3] = {v0, v1, v2}; |
| 612 | return ValidateProgramUniform3uiv(context, program, location, 1, xyz); |
| 613 | } |
| 614 | |
| 615 | bool ValidateProgramUniform4ui(Context *context, |
| 616 | GLuint program, |
| 617 | GLint location, |
| 618 | GLuint v0, |
| 619 | GLuint v1, |
| 620 | GLuint v2, |
| 621 | GLuint v3) |
| 622 | { |
| 623 | GLuint xyzw[4] = {v0, v1, v2, v3}; |
| 624 | return ValidateProgramUniform4uiv(context, program, location, 1, xyzw); |
| 625 | } |
| 626 | |
| 627 | bool ValidateProgramUniform1f(Context *context, GLuint program, GLint location, GLfloat v0) |
| 628 | { |
| 629 | return ValidateProgramUniform1fv(context, program, location, 1, &v0); |
| 630 | } |
| 631 | |
| 632 | bool ValidateProgramUniform2f(Context *context, |
| 633 | GLuint program, |
| 634 | GLint location, |
| 635 | GLfloat v0, |
| 636 | GLfloat v1) |
| 637 | { |
| 638 | GLfloat xy[2] = {v0, v1}; |
| 639 | return ValidateProgramUniform2fv(context, program, location, 1, xy); |
| 640 | } |
| 641 | |
| 642 | bool ValidateProgramUniform3f(Context *context, |
| 643 | GLuint program, |
| 644 | GLint location, |
| 645 | GLfloat v0, |
| 646 | GLfloat v1, |
| 647 | GLfloat v2) |
| 648 | { |
| 649 | GLfloat xyz[3] = {v0, v1, v2}; |
| 650 | return ValidateProgramUniform3fv(context, program, location, 1, xyz); |
| 651 | } |
| 652 | |
| 653 | bool ValidateProgramUniform4f(Context *context, |
| 654 | GLuint program, |
| 655 | GLint location, |
| 656 | GLfloat v0, |
| 657 | GLfloat v1, |
| 658 | GLfloat v2, |
| 659 | GLfloat v3) |
| 660 | { |
| 661 | GLfloat xyzw[4] = {v0, v1, v2, v3}; |
| 662 | return ValidateProgramUniform4fv(context, program, location, 1, xyzw); |
| 663 | } |
| 664 | |
| 665 | bool ValidateProgramUniform1iv(Context *context, |
| 666 | GLuint program, |
| 667 | GLint location, |
| 668 | GLsizei count, |
| 669 | const GLint *value) |
| 670 | { |
| 671 | // Check for ES31 program uniform entry points |
| 672 | if (context->getClientVersion() < Version(3, 1)) |
| 673 | { |
| 674 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 679 | Program *programObject = GetValidProgram(context, program); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 680 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 681 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 682 | } |
| 683 | |
| 684 | bool ValidateProgramUniform2iv(Context *context, |
| 685 | GLuint program, |
| 686 | GLint location, |
| 687 | GLsizei count, |
| 688 | const GLint *value) |
| 689 | { |
| 690 | return ValidateProgramUniform(context, GL_INT_VEC2, program, location, count); |
| 691 | } |
| 692 | |
| 693 | bool ValidateProgramUniform3iv(Context *context, |
| 694 | GLuint program, |
| 695 | GLint location, |
| 696 | GLsizei count, |
| 697 | const GLint *value) |
| 698 | { |
| 699 | return ValidateProgramUniform(context, GL_INT_VEC3, program, location, count); |
| 700 | } |
| 701 | |
| 702 | bool ValidateProgramUniform4iv(Context *context, |
| 703 | GLuint program, |
| 704 | GLint location, |
| 705 | GLsizei count, |
| 706 | const GLint *value) |
| 707 | { |
| 708 | return ValidateProgramUniform(context, GL_INT_VEC4, program, location, count); |
| 709 | } |
| 710 | |
| 711 | bool ValidateProgramUniform1uiv(Context *context, |
| 712 | GLuint program, |
| 713 | GLint location, |
| 714 | GLsizei count, |
| 715 | const GLuint *value) |
| 716 | { |
| 717 | return ValidateProgramUniform(context, GL_UNSIGNED_INT, program, location, count); |
| 718 | } |
| 719 | |
| 720 | bool ValidateProgramUniform2uiv(Context *context, |
| 721 | GLuint program, |
| 722 | GLint location, |
| 723 | GLsizei count, |
| 724 | const GLuint *value) |
| 725 | { |
| 726 | return ValidateProgramUniform(context, GL_UNSIGNED_INT_VEC2, program, location, count); |
| 727 | } |
| 728 | |
| 729 | bool ValidateProgramUniform3uiv(Context *context, |
| 730 | GLuint program, |
| 731 | GLint location, |
| 732 | GLsizei count, |
| 733 | const GLuint *value) |
| 734 | { |
| 735 | return ValidateProgramUniform(context, GL_UNSIGNED_INT_VEC3, program, location, count); |
| 736 | } |
| 737 | |
| 738 | bool ValidateProgramUniform4uiv(Context *context, |
| 739 | GLuint program, |
| 740 | GLint location, |
| 741 | GLsizei count, |
| 742 | const GLuint *value) |
| 743 | { |
| 744 | return ValidateProgramUniform(context, GL_UNSIGNED_INT_VEC4, program, location, count); |
| 745 | } |
| 746 | |
| 747 | bool ValidateProgramUniform1fv(Context *context, |
| 748 | GLuint program, |
| 749 | GLint location, |
| 750 | GLsizei count, |
| 751 | const GLfloat *value) |
| 752 | { |
| 753 | return ValidateProgramUniform(context, GL_FLOAT, program, location, count); |
| 754 | } |
| 755 | |
| 756 | bool ValidateProgramUniform2fv(Context *context, |
| 757 | GLuint program, |
| 758 | GLint location, |
| 759 | GLsizei count, |
| 760 | const GLfloat *value) |
| 761 | { |
| 762 | return ValidateProgramUniform(context, GL_FLOAT_VEC2, program, location, count); |
| 763 | } |
| 764 | |
| 765 | bool ValidateProgramUniform3fv(Context *context, |
| 766 | GLuint program, |
| 767 | GLint location, |
| 768 | GLsizei count, |
| 769 | const GLfloat *value) |
| 770 | { |
| 771 | return ValidateProgramUniform(context, GL_FLOAT_VEC3, program, location, count); |
| 772 | } |
| 773 | |
| 774 | bool ValidateProgramUniform4fv(Context *context, |
| 775 | GLuint program, |
| 776 | GLint location, |
| 777 | GLsizei count, |
| 778 | const GLfloat *value) |
| 779 | { |
| 780 | return ValidateProgramUniform(context, GL_FLOAT_VEC4, program, location, count); |
| 781 | } |
| 782 | |
| 783 | bool ValidateProgramUniformMatrix2fv(Context *context, |
| 784 | GLuint program, |
| 785 | GLint location, |
| 786 | GLsizei count, |
| 787 | GLboolean transpose, |
| 788 | const GLfloat *value) |
| 789 | { |
| 790 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT2, program, location, count, |
| 791 | transpose); |
| 792 | } |
| 793 | |
| 794 | bool ValidateProgramUniformMatrix3fv(Context *context, |
| 795 | GLuint program, |
| 796 | GLint location, |
| 797 | GLsizei count, |
| 798 | GLboolean transpose, |
| 799 | const GLfloat *value) |
| 800 | { |
| 801 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT3, program, location, count, |
| 802 | transpose); |
| 803 | } |
| 804 | |
| 805 | bool ValidateProgramUniformMatrix4fv(Context *context, |
| 806 | GLuint program, |
| 807 | GLint location, |
| 808 | GLsizei count, |
| 809 | GLboolean transpose, |
| 810 | const GLfloat *value) |
| 811 | { |
| 812 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT4, program, location, count, |
| 813 | transpose); |
| 814 | } |
| 815 | |
| 816 | bool ValidateProgramUniformMatrix2x3fv(Context *context, |
| 817 | GLuint program, |
| 818 | GLint location, |
| 819 | GLsizei count, |
| 820 | GLboolean transpose, |
| 821 | const GLfloat *value) |
| 822 | { |
| 823 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT2x3, program, location, count, |
| 824 | transpose); |
| 825 | } |
| 826 | |
| 827 | bool ValidateProgramUniformMatrix3x2fv(Context *context, |
| 828 | GLuint program, |
| 829 | GLint location, |
| 830 | GLsizei count, |
| 831 | GLboolean transpose, |
| 832 | const GLfloat *value) |
| 833 | { |
| 834 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT3x2, program, location, count, |
| 835 | transpose); |
| 836 | } |
| 837 | |
| 838 | bool ValidateProgramUniformMatrix2x4fv(Context *context, |
| 839 | GLuint program, |
| 840 | GLint location, |
| 841 | GLsizei count, |
| 842 | GLboolean transpose, |
| 843 | const GLfloat *value) |
| 844 | { |
| 845 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT2x4, program, location, count, |
| 846 | transpose); |
| 847 | } |
| 848 | |
| 849 | bool ValidateProgramUniformMatrix4x2fv(Context *context, |
| 850 | GLuint program, |
| 851 | GLint location, |
| 852 | GLsizei count, |
| 853 | GLboolean transpose, |
| 854 | const GLfloat *value) |
| 855 | { |
| 856 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT4x2, program, location, count, |
| 857 | transpose); |
| 858 | } |
| 859 | |
| 860 | bool ValidateProgramUniformMatrix3x4fv(Context *context, |
| 861 | GLuint program, |
| 862 | GLint location, |
| 863 | GLsizei count, |
| 864 | GLboolean transpose, |
| 865 | const GLfloat *value) |
| 866 | { |
| 867 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT3x4, program, location, count, |
| 868 | transpose); |
| 869 | } |
| 870 | |
| 871 | bool ValidateProgramUniformMatrix4x3fv(Context *context, |
| 872 | GLuint program, |
| 873 | GLint location, |
| 874 | GLsizei count, |
| 875 | GLboolean transpose, |
| 876 | const GLfloat *value) |
| 877 | { |
| 878 | return ValidateProgramUniformMatrix(context, GL_FLOAT_MAT4x3, program, location, count, |
| 879 | transpose); |
| 880 | } |
| 881 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 882 | bool ValidateGetTexLevelParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 883 | TextureTarget target, |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 884 | GLint level, |
| 885 | GLenum pname, |
| 886 | GLsizei *length) |
| 887 | { |
| 888 | if (context->getClientVersion() < ES_3_1) |
| 889 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 890 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 891 | return false; |
| 892 | } |
| 893 | |
| 894 | if (length) |
| 895 | { |
| 896 | *length = 0; |
| 897 | } |
| 898 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 899 | TextureType type = TextureTargetToType(target); |
| 900 | |
| 901 | if (!ValidTexLevelDestinationTarget(context, type)) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 902 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 903 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 904 | return false; |
| 905 | } |
| 906 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 907 | if (context->getTargetTexture(type) == nullptr) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 908 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 909 | context->handleError(InvalidEnum() << "No texture bound."); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 910 | return false; |
| 911 | } |
| 912 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 913 | if (!ValidMipLevel(context, type, level)) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 914 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 915 | context->handleError(InvalidValue()); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 916 | return false; |
| 917 | } |
| 918 | |
| 919 | switch (pname) |
| 920 | { |
| 921 | case GL_TEXTURE_RED_TYPE: |
| 922 | case GL_TEXTURE_GREEN_TYPE: |
| 923 | case GL_TEXTURE_BLUE_TYPE: |
| 924 | case GL_TEXTURE_ALPHA_TYPE: |
| 925 | case GL_TEXTURE_DEPTH_TYPE: |
| 926 | break; |
| 927 | case GL_TEXTURE_RED_SIZE: |
| 928 | case GL_TEXTURE_GREEN_SIZE: |
| 929 | case GL_TEXTURE_BLUE_SIZE: |
| 930 | case GL_TEXTURE_ALPHA_SIZE: |
| 931 | case GL_TEXTURE_DEPTH_SIZE: |
| 932 | case GL_TEXTURE_STENCIL_SIZE: |
| 933 | case GL_TEXTURE_SHARED_SIZE: |
| 934 | break; |
| 935 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 936 | case GL_TEXTURE_WIDTH: |
| 937 | case GL_TEXTURE_HEIGHT: |
| 938 | case GL_TEXTURE_DEPTH: |
| 939 | break; |
| 940 | case GL_TEXTURE_SAMPLES: |
| 941 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 942 | break; |
| 943 | case GL_TEXTURE_COMPRESSED: |
| 944 | break; |
| 945 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 946 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 947 | return false; |
| 948 | } |
| 949 | |
| 950 | if (length) |
| 951 | { |
| 952 | *length = 1; |
| 953 | } |
| 954 | return true; |
| 955 | } |
| 956 | |
| 957 | bool ValidateGetTexLevelParameterfv(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 958 | TextureTarget target, |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 959 | GLint level, |
| 960 | GLenum pname, |
| 961 | GLfloat *params) |
| 962 | { |
| 963 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 964 | } |
| 965 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 966 | bool ValidateGetTexLevelParameterfvRobustANGLE(Context *context, |
| 967 | TextureTarget target, |
| 968 | GLint level, |
| 969 | GLenum pname, |
| 970 | GLsizei bufSize, |
| 971 | GLsizei *length, |
| 972 | GLfloat *params) |
| 973 | { |
| 974 | UNIMPLEMENTED(); |
| 975 | return false; |
| 976 | } |
| 977 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 978 | bool ValidateGetTexLevelParameteriv(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 979 | TextureTarget target, |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 980 | GLint level, |
| 981 | GLenum pname, |
| 982 | GLint *params) |
| 983 | { |
| 984 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 985 | } |
| 986 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 987 | bool ValidateGetTexLevelParameterivRobustANGLE(Context *context, |
| 988 | TextureTarget target, |
| 989 | GLint level, |
| 990 | GLenum pname, |
| 991 | GLsizei bufSize, |
| 992 | GLsizei *length, |
| 993 | GLint *params) |
| 994 | { |
| 995 | UNIMPLEMENTED(); |
| 996 | return false; |
| 997 | } |
| 998 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 999 | bool ValidateTexStorage2DMultisample(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1000 | TextureType target, |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1001 | GLsizei samples, |
| 1002 | GLint internalFormat, |
| 1003 | GLsizei width, |
| 1004 | GLsizei height, |
| 1005 | GLboolean fixedSampleLocations) |
| 1006 | { |
| 1007 | if (context->getClientVersion() < ES_3_1) |
| 1008 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1009 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1010 | return false; |
| 1011 | } |
| 1012 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1013 | if (target != TextureType::_2DMultisample) |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1014 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1015 | context->handleError(InvalidEnum() << "Target must be TEXTURE_2D_MULTISAMPLE."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1016 | return false; |
| 1017 | } |
| 1018 | |
| 1019 | if (width < 1 || height < 1) |
| 1020 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1021 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | const Caps &caps = context->getCaps(); |
| 1026 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1027 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1028 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1029 | context |
| 1030 | ->handleError(InvalidValue() |
| 1031 | << "Width and height must be less than or equal to GL_MAX_TEXTURE_SIZE."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | if (samples == 0) |
| 1036 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1037 | context->handleError(InvalidValue() << "Samples may not be zero."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 1042 | if (!formatCaps.renderable) |
| 1043 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1044 | context->handleError(InvalidEnum() << "SizedInternalformat must be color-renderable, " |
| 1045 | "depth-renderable, or stencil-renderable."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 1050 | // is one of the unsized base internalformats listed in table 8.11. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1051 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 1052 | if (formatInfo.internalFormat == GL_NONE) |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1053 | { |
| 1054 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1055 | InvalidEnum() |
| 1056 | << "Internalformat is one of the unsupported unsized base internalformats."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1057 | return false; |
| 1058 | } |
| 1059 | |
| 1060 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1061 | { |
| 1062 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1063 | InvalidOperation() |
| 1064 | << "Samples must not be greater than maximum supported value for the format."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1065 | return false; |
| 1066 | } |
| 1067 | |
| 1068 | Texture *texture = context->getTargetTexture(target); |
| 1069 | if (!texture || texture->id() == 0) |
| 1070 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1071 | context->handleError(InvalidOperation() << "Zero is bound to target."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1072 | return false; |
| 1073 | } |
| 1074 | |
| 1075 | if (texture->getImmutableFormat()) |
| 1076 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1077 | context->handleError(InvalidOperation() << "The value of TEXTURE_IMMUTABLE_FORMAT for " |
| 1078 | "the texture currently bound to target on " |
| 1079 | "the active texture unit is true."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1080 | return false; |
| 1081 | } |
| 1082 | |
| 1083 | return true; |
| 1084 | } |
| 1085 | |
| 1086 | bool ValidateGetMultisamplefv(Context *context, GLenum pname, GLuint index, GLfloat *val) |
| 1087 | { |
| 1088 | if (context->getClientVersion() < ES_3_1) |
| 1089 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1090 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1091 | return false; |
| 1092 | } |
| 1093 | |
| 1094 | if (pname != GL_SAMPLE_POSITION) |
| 1095 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1096 | context->handleError(InvalidEnum() << "Pname must be SAMPLE_POSITION."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1097 | return false; |
| 1098 | } |
| 1099 | |
JiangYizhou | 5b03f47 | 2017-01-09 10:22:53 +0800 | [diff] [blame] | 1100 | Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1101 | GLint samples = framebuffer->getSamples(context); |
JiangYizhou | 5b03f47 | 2017-01-09 10:22:53 +0800 | [diff] [blame] | 1102 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1103 | if (index >= static_cast<GLuint>(samples)) |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1104 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1105 | context->handleError(InvalidValue() << "Index must be less than the value of SAMPLES."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1106 | return false; |
| 1107 | } |
| 1108 | |
| 1109 | return true; |
| 1110 | } |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1111 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 1112 | bool ValidateGetMultisamplefvRobustANGLE(Context *context, |
| 1113 | GLenum pname, |
| 1114 | GLuint index, |
| 1115 | GLsizei bufSize, |
| 1116 | GLsizei *length, |
| 1117 | GLfloat *val) |
| 1118 | { |
| 1119 | UNIMPLEMENTED(); |
| 1120 | return false; |
| 1121 | } |
| 1122 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1123 | bool ValidateFramebufferParameteri(Context *context, GLenum target, GLenum pname, GLint param) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1124 | { |
| 1125 | if (context->getClientVersion() < ES_3_1) |
| 1126 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1127 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1128 | return false; |
| 1129 | } |
| 1130 | |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1131 | if (!ValidFramebufferTarget(context, target)) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1132 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1133 | context->handleError(InvalidEnum() << "Invalid framebuffer target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1134 | return false; |
| 1135 | } |
| 1136 | |
| 1137 | switch (pname) |
| 1138 | { |
| 1139 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1140 | { |
| 1141 | GLint maxWidth = context->getCaps().maxFramebufferWidth; |
| 1142 | if (param < 0 || param > maxWidth) |
| 1143 | { |
| 1144 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1145 | InvalidValue() |
| 1146 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_WIDTH."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1147 | return false; |
| 1148 | } |
| 1149 | break; |
| 1150 | } |
| 1151 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1152 | { |
| 1153 | GLint maxHeight = context->getCaps().maxFramebufferHeight; |
| 1154 | if (param < 0 || param > maxHeight) |
| 1155 | { |
| 1156 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1157 | InvalidValue() |
| 1158 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_HEIGHT."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1159 | return false; |
| 1160 | } |
| 1161 | break; |
| 1162 | } |
| 1163 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1164 | { |
| 1165 | GLint maxSamples = context->getCaps().maxFramebufferSamples; |
| 1166 | if (param < 0 || param > maxSamples) |
| 1167 | { |
| 1168 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1169 | InvalidValue() |
| 1170 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_SAMPLES."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1171 | return false; |
| 1172 | } |
| 1173 | break; |
| 1174 | } |
| 1175 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1176 | { |
| 1177 | break; |
| 1178 | } |
| 1179 | default: |
| 1180 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1181 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1182 | return false; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 1187 | ASSERT(framebuffer); |
| 1188 | if (framebuffer->id() == 0) |
| 1189 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1190 | context->handleError(InvalidOperation() << "Default framebuffer is bound to target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1191 | return false; |
| 1192 | } |
| 1193 | return true; |
| 1194 | } |
| 1195 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1196 | bool ValidateGetFramebufferParameteriv(Context *context, GLenum target, GLenum pname, GLint *params) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1197 | { |
| 1198 | if (context->getClientVersion() < ES_3_1) |
| 1199 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1200 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1204 | if (!ValidFramebufferTarget(context, target)) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1205 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1206 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1207 | return false; |
| 1208 | } |
| 1209 | |
| 1210 | switch (pname) |
| 1211 | { |
| 1212 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1213 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1214 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1215 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1216 | break; |
| 1217 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1218 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 1223 | ASSERT(framebuffer); |
| 1224 | |
| 1225 | if (framebuffer->id() == 0) |
| 1226 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1227 | context->handleError(InvalidOperation() << "Default framebuffer is bound to target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1228 | return false; |
| 1229 | } |
| 1230 | return true; |
| 1231 | } |
| 1232 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 1233 | bool ValidateGetFramebufferParameterivRobustANGLE(Context *context, |
| 1234 | GLenum target, |
| 1235 | GLenum pname, |
| 1236 | GLsizei bufSize, |
| 1237 | GLsizei *length, |
| 1238 | GLint *params) |
| 1239 | { |
| 1240 | UNIMPLEMENTED(); |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1244 | bool ValidateGetProgramResourceIndex(Context *context, |
| 1245 | GLuint program, |
| 1246 | GLenum programInterface, |
| 1247 | const GLchar *name) |
| 1248 | { |
| 1249 | if (context->getClientVersion() < ES_3_1) |
| 1250 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1251 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | Program *programObject = GetValidProgram(context, program); |
| 1256 | if (programObject == nullptr) |
| 1257 | { |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | if (!ValidateNamedProgramInterface(programInterface)) |
| 1262 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1263 | context->handleError(InvalidEnum() << "Invalid program interface: 0x" << std::hex |
| 1264 | << std::uppercase << programInterface); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1267 | |
| 1268 | return true; |
| 1269 | } |
| 1270 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1271 | bool ValidateBindVertexBuffer(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1272 | GLuint bindingIndex, |
| 1273 | GLuint buffer, |
| 1274 | GLintptr offset, |
| 1275 | GLsizei stride) |
| 1276 | { |
| 1277 | if (context->getClientVersion() < ES_3_1) |
| 1278 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1279 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1280 | return false; |
| 1281 | } |
| 1282 | |
| 1283 | if (!context->isBufferGenerated(buffer)) |
| 1284 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1285 | context->handleError(InvalidOperation() << "Buffer is not generated."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1286 | return false; |
| 1287 | } |
| 1288 | |
| 1289 | const Caps &caps = context->getCaps(); |
| 1290 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 1291 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1292 | context->handleError(InvalidValue() |
| 1293 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1294 | return false; |
| 1295 | } |
| 1296 | |
| 1297 | if (offset < 0) |
| 1298 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1299 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | if (stride < 0 || stride > caps.maxVertexAttribStride) |
| 1304 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1305 | context->handleError(InvalidValue() |
| 1306 | << "stride must be between 0 and MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1307 | return false; |
| 1308 | } |
| 1309 | |
| 1310 | // [OpenGL ES 3.1] Section 10.3.1 page 244: |
| 1311 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 1312 | if (context->getGLState().getVertexArrayId() == 0) |
| 1313 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1314 | context->handleError(InvalidOperation() << "Default vertex array buffer is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | |
| 1318 | return true; |
| 1319 | } |
| 1320 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1321 | bool ValidateVertexBindingDivisor(Context *context, GLuint bindingIndex, GLuint divisor) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1322 | { |
| 1323 | if (context->getClientVersion() < ES_3_1) |
| 1324 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1325 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1326 | return false; |
| 1327 | } |
| 1328 | |
| 1329 | const Caps &caps = context->getCaps(); |
| 1330 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 1331 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1332 | context->handleError(InvalidValue() |
| 1333 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1334 | return false; |
| 1335 | } |
| 1336 | |
| 1337 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 1338 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 1339 | if (context->getGLState().getVertexArrayId() == 0) |
| 1340 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1341 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1342 | return false; |
| 1343 | } |
| 1344 | |
| 1345 | return true; |
| 1346 | } |
| 1347 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1348 | bool ValidateVertexAttribFormat(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1349 | GLuint attribindex, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1350 | GLint size, |
| 1351 | GLenum type, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1352 | GLboolean normalized, |
| 1353 | GLuint relativeoffset) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1354 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1355 | return ValidateVertexAttribFormatCommon(context, attribindex, size, type, relativeoffset, |
| 1356 | false); |
| 1357 | } |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1358 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1359 | bool ValidateVertexAttribIFormat(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1360 | GLuint attribindex, |
| 1361 | GLint size, |
| 1362 | GLenum type, |
| 1363 | GLuint relativeoffset) |
| 1364 | { |
| 1365 | return ValidateVertexAttribFormatCommon(context, attribindex, size, type, relativeoffset, true); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1368 | bool ValidateVertexAttribBinding(Context *context, GLuint attribIndex, GLuint bindingIndex) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1369 | { |
| 1370 | if (context->getClientVersion() < ES_3_1) |
| 1371 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1372 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1373 | return false; |
| 1374 | } |
| 1375 | |
| 1376 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 1377 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 1378 | if (context->getGLState().getVertexArrayId() == 0) |
| 1379 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1380 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1381 | return false; |
| 1382 | } |
| 1383 | |
| 1384 | const Caps &caps = context->getCaps(); |
| 1385 | if (attribIndex >= caps.maxVertexAttributes) |
| 1386 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1387 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
| 1390 | |
| 1391 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 1392 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1393 | context->handleError(InvalidValue() |
| 1394 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS"); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1395 | return false; |
| 1396 | } |
| 1397 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1398 | return true; |
| 1399 | } |
| 1400 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1401 | bool ValidateGetProgramResourceName(Context *context, |
| 1402 | GLuint program, |
| 1403 | GLenum programInterface, |
| 1404 | GLuint index, |
| 1405 | GLsizei bufSize, |
| 1406 | GLsizei *length, |
| 1407 | GLchar *name) |
| 1408 | { |
| 1409 | if (context->getClientVersion() < ES_3_1) |
| 1410 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1411 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1412 | return false; |
| 1413 | } |
| 1414 | |
| 1415 | Program *programObject = GetValidProgram(context, program); |
| 1416 | if (programObject == nullptr) |
| 1417 | { |
| 1418 | return false; |
| 1419 | } |
| 1420 | |
| 1421 | if (!ValidateNamedProgramInterface(programInterface)) |
| 1422 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1423 | context->handleError(InvalidEnum() << "Invalid program interface: 0x" << std::hex |
| 1424 | << std::uppercase << programInterface); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1425 | return false; |
| 1426 | } |
| 1427 | |
| 1428 | if (!ValidateProgramResourceIndex(programObject, programInterface, index)) |
| 1429 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1430 | context->handleError(InvalidValue() << "Invalid index: " << index); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1431 | return false; |
| 1432 | } |
| 1433 | |
| 1434 | if (bufSize < 0) |
| 1435 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1436 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
| 1439 | |
| 1440 | return true; |
| 1441 | } |
| 1442 | |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1443 | bool ValidateDispatchCompute(Context *context, |
| 1444 | GLuint numGroupsX, |
| 1445 | GLuint numGroupsY, |
| 1446 | GLuint numGroupsZ) |
| 1447 | { |
| 1448 | if (context->getClientVersion() < ES_3_1) |
| 1449 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1450 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1451 | return false; |
| 1452 | } |
| 1453 | |
| 1454 | const State &state = context->getGLState(); |
| 1455 | Program *program = state.getProgram(); |
| 1456 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1457 | if (program == nullptr || !program->hasLinkedShaderStage(ShaderType::Compute)) |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1458 | { |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1459 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveProgramWithComputeShader); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1460 | return false; |
| 1461 | } |
| 1462 | |
| 1463 | const Caps &caps = context->getCaps(); |
| 1464 | if (numGroupsX > caps.maxComputeWorkGroupCount[0]) |
| 1465 | { |
| 1466 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1467 | InvalidValue() << "num_groups_x cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[0]=" |
| 1468 | << caps.maxComputeWorkGroupCount[0]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1469 | return false; |
| 1470 | } |
| 1471 | if (numGroupsY > caps.maxComputeWorkGroupCount[1]) |
| 1472 | { |
| 1473 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1474 | InvalidValue() << "num_groups_y cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[1]=" |
| 1475 | << caps.maxComputeWorkGroupCount[1]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1476 | return false; |
| 1477 | } |
| 1478 | if (numGroupsZ > caps.maxComputeWorkGroupCount[2]) |
| 1479 | { |
| 1480 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1481 | InvalidValue() << "num_groups_z cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[2]=" |
| 1482 | << caps.maxComputeWorkGroupCount[2]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1483 | return false; |
| 1484 | } |
| 1485 | |
| 1486 | return true; |
| 1487 | } |
| 1488 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1489 | bool ValidateDispatchComputeIndirect(Context *context, GLintptr indirect) |
| 1490 | { |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1491 | if (context->getClientVersion() < ES_3_1) |
| 1492 | { |
| 1493 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1494 | return false; |
| 1495 | } |
| 1496 | |
| 1497 | const State &state = context->getGLState(); |
| 1498 | Program *program = state.getProgram(); |
| 1499 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1500 | if (program == nullptr || !program->hasLinkedShaderStage(ShaderType::Compute)) |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1501 | { |
| 1502 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveProgramWithComputeShader); |
| 1503 | return false; |
| 1504 | } |
| 1505 | |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1506 | if (indirect < 0) |
| 1507 | { |
| 1508 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 1509 | return false; |
| 1510 | } |
| 1511 | |
| 1512 | if ((indirect & (sizeof(GLuint) - 1)) != 0) |
| 1513 | { |
Qin Jiajia | a4ef843 | 2018-02-22 16:02:24 +0800 | [diff] [blame] | 1514 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OffsetMustBeMultipleOfUint); |
| 1515 | return false; |
| 1516 | } |
| 1517 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1518 | Buffer *dispatchIndirectBuffer = state.getTargetBuffer(BufferBinding::DispatchIndirect); |
Qin Jiajia | a4ef843 | 2018-02-22 16:02:24 +0800 | [diff] [blame] | 1519 | if (!dispatchIndirectBuffer) |
| 1520 | { |
| 1521 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DispatchIndirectBufferNotBound); |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1522 | return false; |
| 1523 | } |
| 1524 | |
| 1525 | CheckedNumeric<GLuint64> checkedOffset(static_cast<GLuint64>(indirect)); |
| 1526 | auto checkedSum = checkedOffset + static_cast<GLuint64>(3 * sizeof(GLuint)); |
| 1527 | if (!checkedSum.IsValid() || |
| 1528 | checkedSum.ValueOrDie() > static_cast<GLuint64>(dispatchIndirectBuffer->getSize())) |
| 1529 | { |
| 1530 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 1531 | return false; |
| 1532 | } |
| 1533 | |
| 1534 | return true; |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1535 | } |
| 1536 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 1537 | bool ValidateBindImageTexture(Context *context, |
| 1538 | GLuint unit, |
| 1539 | GLuint texture, |
| 1540 | GLint level, |
| 1541 | GLboolean layered, |
| 1542 | GLint layer, |
| 1543 | GLenum access, |
| 1544 | GLenum format) |
| 1545 | { |
| 1546 | GLuint maxImageUnits = context->getCaps().maxImageUnits; |
| 1547 | if (unit >= maxImageUnits) |
| 1548 | { |
| 1549 | context->handleError(InvalidValue() |
| 1550 | << "unit cannot be greater than or equal than MAX_IMAGE_UNITS = " |
| 1551 | << maxImageUnits); |
| 1552 | return false; |
| 1553 | } |
| 1554 | |
| 1555 | if (level < 0) |
| 1556 | { |
| 1557 | context->handleError(InvalidValue() << "level is negative."); |
| 1558 | return false; |
| 1559 | } |
| 1560 | |
| 1561 | if (layer < 0) |
| 1562 | { |
| 1563 | context->handleError(InvalidValue() << "layer is negative."); |
| 1564 | return false; |
| 1565 | } |
| 1566 | |
| 1567 | if (access != GL_READ_ONLY && access != GL_WRITE_ONLY && access != GL_READ_WRITE) |
| 1568 | { |
| 1569 | context->handleError(InvalidEnum() << "access is not one of the supported tokens."); |
| 1570 | return false; |
| 1571 | } |
| 1572 | |
| 1573 | switch (format) |
| 1574 | { |
| 1575 | case GL_RGBA32F: |
| 1576 | case GL_RGBA16F: |
| 1577 | case GL_R32F: |
| 1578 | case GL_RGBA32UI: |
| 1579 | case GL_RGBA16UI: |
| 1580 | case GL_RGBA8UI: |
| 1581 | case GL_R32UI: |
| 1582 | case GL_RGBA32I: |
| 1583 | case GL_RGBA16I: |
| 1584 | case GL_RGBA8I: |
| 1585 | case GL_R32I: |
| 1586 | case GL_RGBA8: |
| 1587 | case GL_RGBA8_SNORM: |
| 1588 | break; |
| 1589 | default: |
| 1590 | context->handleError(InvalidValue() |
| 1591 | << "format is not one of supported image unit formats."); |
| 1592 | return false; |
| 1593 | } |
| 1594 | |
| 1595 | if (texture != 0) |
| 1596 | { |
| 1597 | Texture *tex = context->getTexture(texture); |
| 1598 | |
| 1599 | if (tex == nullptr) |
| 1600 | { |
| 1601 | context->handleError(InvalidValue() |
| 1602 | << "texture is not the name of an existing texture object."); |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
| 1606 | if (!tex->getImmutableFormat()) |
| 1607 | { |
| 1608 | context->handleError(InvalidOperation() |
| 1609 | << "texture is not the name of an immutable texture object."); |
| 1610 | return false; |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | return true; |
| 1615 | } |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame] | 1616 | |
| 1617 | bool ValidateGetProgramResourceLocation(Context *context, |
| 1618 | GLuint program, |
| 1619 | GLenum programInterface, |
| 1620 | const GLchar *name) |
| 1621 | { |
| 1622 | if (context->getClientVersion() < ES_3_1) |
| 1623 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1624 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame] | 1625 | return false; |
| 1626 | } |
| 1627 | |
| 1628 | Program *programObject = GetValidProgram(context, program); |
| 1629 | if (programObject == nullptr) |
| 1630 | { |
| 1631 | return false; |
| 1632 | } |
| 1633 | |
| 1634 | if (!programObject->isLinked()) |
| 1635 | { |
| 1636 | context->handleError(InvalidOperation() << "Program is not successfully linked."); |
| 1637 | return false; |
| 1638 | } |
| 1639 | |
| 1640 | if (!ValidateLocationProgramInterface(programInterface)) |
| 1641 | { |
| 1642 | context->handleError(InvalidEnum() << "Invalid program interface."); |
| 1643 | return false; |
| 1644 | } |
| 1645 | return true; |
| 1646 | } |
| 1647 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1648 | bool ValidateGetProgramResourceiv(Context *context, |
| 1649 | GLuint program, |
| 1650 | GLenum programInterface, |
| 1651 | GLuint index, |
| 1652 | GLsizei propCount, |
| 1653 | const GLenum *props, |
| 1654 | GLsizei bufSize, |
| 1655 | GLsizei *length, |
| 1656 | GLint *params) |
| 1657 | { |
| 1658 | if (context->getClientVersion() < ES_3_1) |
| 1659 | { |
jchen10 | d9cd7b7 | 2017-08-30 15:04:25 +0800 | [diff] [blame] | 1660 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1661 | return false; |
| 1662 | } |
| 1663 | |
| 1664 | Program *programObject = GetValidProgram(context, program); |
| 1665 | if (programObject == nullptr) |
| 1666 | { |
| 1667 | return false; |
| 1668 | } |
| 1669 | if (!ValidateProgramInterface(programInterface)) |
| 1670 | { |
| 1671 | context->handleError(InvalidEnum() << "Invalid program interface."); |
| 1672 | return false; |
| 1673 | } |
| 1674 | if (propCount <= 0) |
| 1675 | { |
| 1676 | context->handleError(InvalidValue() << "Invalid propCount."); |
| 1677 | return false; |
| 1678 | } |
| 1679 | if (bufSize < 0) |
| 1680 | { |
| 1681 | context->handleError(InvalidValue() << "Invalid bufSize."); |
| 1682 | return false; |
| 1683 | } |
| 1684 | if (!ValidateProgramResourceIndex(programObject, programInterface, index)) |
| 1685 | { |
| 1686 | context->handleError(InvalidValue() << "Invalid index: " << index); |
| 1687 | return false; |
| 1688 | } |
| 1689 | for (GLsizei i = 0; i < propCount; i++) |
| 1690 | { |
Jiawei Shao | c6f8287 | 2018-04-24 14:14:50 +0800 | [diff] [blame] | 1691 | if (!ValidateProgramResourceProperty(context, props[i])) |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 1692 | { |
| 1693 | context->handleError(InvalidEnum() << "Invalid prop."); |
| 1694 | return false; |
| 1695 | } |
| 1696 | if (!ValidateProgramResourcePropertyByInterface(props[i], programInterface)) |
| 1697 | { |
| 1698 | context->handleError(InvalidOperation() << "Not an allowed prop for interface"); |
| 1699 | return false; |
| 1700 | } |
| 1701 | } |
| 1702 | return true; |
| 1703 | } |
| 1704 | |
jchen10 | d9cd7b7 | 2017-08-30 15:04:25 +0800 | [diff] [blame] | 1705 | bool ValidateGetProgramInterfaceiv(Context *context, |
| 1706 | GLuint program, |
| 1707 | GLenum programInterface, |
| 1708 | GLenum pname, |
| 1709 | GLint *params) |
| 1710 | { |
| 1711 | if (context->getClientVersion() < ES_3_1) |
| 1712 | { |
| 1713 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1714 | return false; |
| 1715 | } |
| 1716 | |
| 1717 | Program *programObject = GetValidProgram(context, program); |
| 1718 | if (programObject == nullptr) |
| 1719 | { |
| 1720 | return false; |
| 1721 | } |
| 1722 | |
| 1723 | if (!ValidateProgramInterface(programInterface)) |
| 1724 | { |
| 1725 | context->handleError(InvalidEnum() << "Invalid program interface."); |
| 1726 | return false; |
| 1727 | } |
| 1728 | |
| 1729 | switch (pname) |
| 1730 | { |
| 1731 | case GL_ACTIVE_RESOURCES: |
| 1732 | case GL_MAX_NAME_LENGTH: |
| 1733 | case GL_MAX_NUM_ACTIVE_VARIABLES: |
| 1734 | break; |
| 1735 | |
| 1736 | default: |
| 1737 | context->handleError(InvalidEnum() << "Unknown property of program interface."); |
| 1738 | return false; |
| 1739 | } |
| 1740 | |
| 1741 | if (pname == GL_MAX_NAME_LENGTH && programInterface == GL_ATOMIC_COUNTER_BUFFER) |
| 1742 | { |
| 1743 | context->handleError(InvalidOperation() |
| 1744 | << "Active atomic counter resources are not assigned name strings."); |
| 1745 | return false; |
| 1746 | } |
| 1747 | |
| 1748 | if (pname == GL_MAX_NUM_ACTIVE_VARIABLES) |
| 1749 | { |
| 1750 | switch (programInterface) |
| 1751 | { |
| 1752 | case GL_ATOMIC_COUNTER_BUFFER: |
| 1753 | case GL_SHADER_STORAGE_BLOCK: |
| 1754 | case GL_UNIFORM_BLOCK: |
| 1755 | break; |
| 1756 | |
| 1757 | default: |
| 1758 | context->handleError( |
| 1759 | InvalidOperation() |
| 1760 | << "MAX_NUM_ACTIVE_VARIABLES requires a buffer or block interface."); |
| 1761 | return false; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | return true; |
| 1766 | } |
| 1767 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 1768 | bool ValidateGetProgramInterfaceivRobustANGLE(Context *context, |
| 1769 | GLuint program, |
| 1770 | GLenum programInterface, |
| 1771 | GLenum pname, |
| 1772 | GLsizei bufSize, |
| 1773 | GLsizei *length, |
| 1774 | GLint *params) |
| 1775 | { |
| 1776 | UNIMPLEMENTED(); |
| 1777 | return false; |
| 1778 | } |
| 1779 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1780 | static bool ValidateGenOrDeleteES31(Context *context, GLint n) |
| 1781 | { |
| 1782 | if (context->getClientVersion() < ES_3_1) |
| 1783 | { |
| 1784 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1785 | return false; |
| 1786 | } |
| 1787 | |
| 1788 | return ValidateGenOrDelete(context, n); |
| 1789 | } |
| 1790 | |
| 1791 | bool ValidateGenProgramPipelines(Context *context, GLint n, GLuint *) |
| 1792 | { |
| 1793 | return ValidateGenOrDeleteES31(context, n); |
| 1794 | } |
| 1795 | |
| 1796 | bool ValidateDeleteProgramPipelines(Context *context, GLint n, const GLuint *) |
| 1797 | { |
| 1798 | return ValidateGenOrDeleteES31(context, n); |
| 1799 | } |
| 1800 | |
| 1801 | bool ValidateBindProgramPipeline(Context *context, GLuint pipeline) |
| 1802 | { |
| 1803 | if (context->getClientVersion() < ES_3_1) |
| 1804 | { |
| 1805 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
| 1809 | if (!context->isProgramPipelineGenerated(pipeline)) |
| 1810 | { |
| 1811 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ObjectNotGenerated); |
| 1812 | return false; |
| 1813 | } |
| 1814 | |
| 1815 | return true; |
| 1816 | } |
| 1817 | |
| 1818 | bool ValidateIsProgramPipeline(Context *context, GLuint pipeline) |
| 1819 | { |
| 1820 | if (context->getClientVersion() < ES_3_1) |
| 1821 | { |
| 1822 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1823 | return false; |
| 1824 | } |
| 1825 | |
| 1826 | return true; |
| 1827 | } |
| 1828 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1829 | bool ValidateUseProgramStages(Context *context, GLuint pipeline, GLbitfield stages, GLuint program) |
| 1830 | { |
| 1831 | UNIMPLEMENTED(); |
| 1832 | return false; |
| 1833 | } |
| 1834 | |
| 1835 | bool ValidateActiveShaderProgram(Context *context, GLuint pipeline, GLuint program) |
| 1836 | { |
| 1837 | UNIMPLEMENTED(); |
| 1838 | return false; |
| 1839 | } |
| 1840 | |
| 1841 | bool ValidateCreateShaderProgramv(Context *context, |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 1842 | ShaderType type, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1843 | GLsizei count, |
| 1844 | const GLchar *const *strings) |
| 1845 | { |
| 1846 | UNIMPLEMENTED(); |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | bool ValidateGetProgramPipelineiv(Context *context, GLuint pipeline, GLenum pname, GLint *params) |
| 1851 | { |
| 1852 | UNIMPLEMENTED(); |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | bool ValidateValidateProgramPipeline(Context *context, GLuint pipeline) |
| 1857 | { |
| 1858 | UNIMPLEMENTED(); |
| 1859 | return false; |
| 1860 | } |
| 1861 | |
| 1862 | bool ValidateGetProgramPipelineInfoLog(Context *context, |
| 1863 | GLuint pipeline, |
| 1864 | GLsizei bufSize, |
| 1865 | GLsizei *length, |
| 1866 | GLchar *infoLog) |
| 1867 | { |
| 1868 | UNIMPLEMENTED(); |
| 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | bool ValidateMemoryBarrier(Context *context, GLbitfield barriers) |
| 1873 | { |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1874 | if (context->getClientVersion() < ES_3_1) |
| 1875 | { |
| 1876 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1877 | return false; |
| 1878 | } |
| 1879 | |
| 1880 | if (barriers == GL_ALL_BARRIER_BITS) |
| 1881 | { |
| 1882 | return true; |
| 1883 | } |
| 1884 | |
| 1885 | GLbitfield supported_barrier_bits = |
| 1886 | GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT | GL_ELEMENT_ARRAY_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT | |
| 1887 | GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_COMMAND_BARRIER_BIT | |
| 1888 | GL_PIXEL_BUFFER_BARRIER_BIT | GL_TEXTURE_UPDATE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT | |
| 1889 | GL_FRAMEBUFFER_BARRIER_BIT | GL_TRANSFORM_FEEDBACK_BARRIER_BIT | |
| 1890 | GL_ATOMIC_COUNTER_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT; |
| 1891 | if ((barriers & ~supported_barrier_bits) != 0) |
| 1892 | { |
| 1893 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMemoryBarrierBit); |
| 1894 | return false; |
| 1895 | } |
| 1896 | |
| 1897 | return true; |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | bool ValidateMemoryBarrierByRegion(Context *context, GLbitfield barriers) |
| 1901 | { |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1902 | if (context->getClientVersion() < ES_3_1) |
| 1903 | { |
| 1904 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1905 | return false; |
| 1906 | } |
| 1907 | |
| 1908 | if (barriers == GL_ALL_BARRIER_BITS) |
| 1909 | { |
| 1910 | return true; |
| 1911 | } |
| 1912 | |
| 1913 | GLbitfield supported_barrier_bits = GL_ATOMIC_COUNTER_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT | |
| 1914 | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | |
| 1915 | GL_SHADER_STORAGE_BARRIER_BIT | |
| 1916 | GL_TEXTURE_FETCH_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT; |
| 1917 | if ((barriers & ~supported_barrier_bits) != 0) |
| 1918 | { |
| 1919 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMemoryBarrierBit); |
| 1920 | return false; |
| 1921 | } |
| 1922 | |
| 1923 | return true; |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | bool ValidateSampleMaski(Context *context, GLuint maskNumber, GLbitfield mask) |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 1927 | { |
| 1928 | if (context->getClientVersion() < ES_3_1) |
| 1929 | { |
| 1930 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES31Required); |
| 1931 | return false; |
| 1932 | } |
| 1933 | |
| 1934 | if (maskNumber >= context->getCaps().maxSampleMaskWords) |
| 1935 | { |
| 1936 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSampleMaskNumber); |
| 1937 | return false; |
| 1938 | } |
| 1939 | |
| 1940 | return true; |
| 1941 | } |
| 1942 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1943 | } // namespace gl |