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