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" |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 12 | #include "libANGLE/Framebuffer.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 13 | #include "libANGLE/VertexArray.h" |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 14 | #include "libANGLE/validationES.h" |
| 15 | #include "libANGLE/validationES3.h" |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 16 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 17 | #include "common/utilities.h" |
| 18 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 19 | using namespace angle; |
| 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 24 | namespace |
| 25 | { |
| 26 | |
| 27 | bool ValidateNamedProgramInterface(GLenum programInterface) |
| 28 | { |
| 29 | switch (programInterface) |
| 30 | { |
| 31 | case GL_UNIFORM: |
| 32 | case GL_UNIFORM_BLOCK: |
| 33 | case GL_PROGRAM_INPUT: |
| 34 | case GL_PROGRAM_OUTPUT: |
| 35 | case GL_TRANSFORM_FEEDBACK_VARYING: |
| 36 | case GL_BUFFER_VARIABLE: |
| 37 | case GL_SHADER_STORAGE_BLOCK: |
| 38 | return true; |
| 39 | default: |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame^] | 44 | bool ValidateLocationProgramInterface(GLenum programInterface) |
| 45 | { |
| 46 | switch (programInterface) |
| 47 | { |
| 48 | case GL_UNIFORM: |
| 49 | case GL_PROGRAM_INPUT: |
| 50 | case GL_PROGRAM_OUTPUT: |
| 51 | return true; |
| 52 | default: |
| 53 | return false; |
| 54 | } |
| 55 | } |
| 56 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 57 | bool ValidateProgramResourceIndex(const Program *programObject, |
| 58 | GLenum programInterface, |
| 59 | GLuint index) |
| 60 | { |
| 61 | switch (programInterface) |
| 62 | { |
| 63 | case GL_PROGRAM_INPUT: |
| 64 | return (index < static_cast<GLuint>(programObject->getActiveAttributeCount())); |
| 65 | |
| 66 | case GL_PROGRAM_OUTPUT: |
| 67 | return (index < static_cast<GLuint>(programObject->getOutputResourceCount())); |
| 68 | |
| 69 | // TODO(Jie): more interfaces. |
| 70 | case GL_UNIFORM: |
| 71 | case GL_UNIFORM_BLOCK: |
| 72 | case GL_TRANSFORM_FEEDBACK_VARYING: |
| 73 | case GL_BUFFER_VARIABLE: |
| 74 | case GL_SHADER_STORAGE_BLOCK: |
| 75 | UNIMPLEMENTED(); |
| 76 | return false; |
| 77 | |
| 78 | default: |
| 79 | UNREACHABLE(); |
| 80 | return false; |
| 81 | } |
| 82 | } |
| 83 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 84 | } // anonymous namespace |
| 85 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 86 | bool ValidateGetBooleani_v(Context *context, GLenum target, GLuint index, GLboolean *data) |
| 87 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 88 | if (context->getClientVersion() < ES_3_1) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 89 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 90 | context->handleError(InvalidOperation() << "Context does not support GLES3.1"); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 91 | return false; |
| 92 | } |
| 93 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 94 | if (!ValidateIndexedStateQuery(context, target, index, nullptr)) |
| 95 | { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | bool ValidateGetBooleani_vRobustANGLE(Context *context, |
| 103 | GLenum target, |
| 104 | GLuint index, |
| 105 | GLsizei bufSize, |
| 106 | GLsizei *length, |
| 107 | GLboolean *data) |
| 108 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 109 | if (context->getClientVersion() < ES_3_1) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 110 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 111 | context->handleError(InvalidOperation() << "Context does not support GLES3.1"); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
| 115 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 116 | { |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 121 | { |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 126 | { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | return true; |
| 131 | } |
| 132 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 133 | bool ValidateDrawIndirectBase(Context *context, GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 134 | { |
| 135 | if (context->getClientVersion() < ES_3_1) |
| 136 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 137 | context->handleError(InvalidOperation() << "Context does not support GLES3.1"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | |
| 141 | // Here the third parameter 1 is only to pass the count validation. |
| 142 | if (!ValidateDrawBase(context, mode, 1)) |
| 143 | { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | const State &state = context->getGLState(); |
| 148 | |
| 149 | // An INVALID_OPERATION error is generated if zero is bound to VERTEX_ARRAY_BINDING, |
| 150 | // DRAW_INDIRECT_BUFFER or to any enabled vertex array. |
| 151 | if (!state.getVertexArrayId()) |
| 152 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 153 | context->handleError(InvalidOperation() << "zero is bound to VERTEX_ARRAY_BINDING"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 154 | return false; |
| 155 | } |
| 156 | |
| 157 | gl::Buffer *drawIndirectBuffer = state.getDrawIndirectBuffer(); |
| 158 | if (!drawIndirectBuffer) |
| 159 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 160 | context->handleError(InvalidOperation() << "zero is bound to DRAW_INDIRECT_BUFFER"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 161 | return false; |
| 162 | } |
| 163 | |
| 164 | // An INVALID_VALUE error is generated if indirect is not a multiple of the size, in basic |
| 165 | // machine units, of uint. |
| 166 | GLint64 offset = reinterpret_cast<GLint64>(indirect); |
| 167 | if ((static_cast<GLuint>(offset) % sizeof(GLuint)) != 0) |
| 168 | { |
| 169 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 170 | InvalidValue() |
| 171 | << "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] | 172 | return false; |
| 173 | } |
| 174 | |
| 175 | return true; |
| 176 | } |
| 177 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 178 | bool ValidateDrawArraysIndirect(Context *context, GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 179 | { |
| 180 | const State &state = context->getGLState(); |
| 181 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
| 182 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 183 | !curTransformFeedback->isPaused()) |
| 184 | { |
| 185 | // 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] | 186 | context->handleError(InvalidOperation() << "transform feedback is active and not paused."); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 187 | return false; |
| 188 | } |
| 189 | |
| 190 | if (!ValidateDrawIndirectBase(context, mode, indirect)) |
| 191 | return false; |
| 192 | |
| 193 | gl::Buffer *drawIndirectBuffer = state.getDrawIndirectBuffer(); |
| 194 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(indirect)); |
| 195 | // In OpenGL ES3.1 spec, session 10.5, it defines the struct of DrawArraysIndirectCommand |
| 196 | // which's size is 4 * sizeof(uint). |
| 197 | auto checkedSum = checkedOffset + 4 * sizeof(GLuint); |
| 198 | if (!checkedSum.IsValid() || |
| 199 | checkedSum.ValueOrDie() > static_cast<size_t>(drawIndirectBuffer->getSize())) |
| 200 | { |
| 201 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 202 | InvalidOperation() |
| 203 | << "the command would source data beyond the end of the buffer object."); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 210 | bool ValidateDrawElementsIndirect(Context *context, GLenum mode, GLenum type, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 211 | { |
| 212 | if (!ValidateDrawElementsBase(context, type)) |
| 213 | return false; |
| 214 | |
| 215 | const State &state = context->getGLState(); |
| 216 | const VertexArray *vao = state.getVertexArray(); |
| 217 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
| 218 | if (!elementArrayBuffer) |
| 219 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 220 | context->handleError(InvalidOperation() << "zero is bound to ELEMENT_ARRAY_BUFFER"); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 221 | return false; |
| 222 | } |
| 223 | |
| 224 | if (!ValidateDrawIndirectBase(context, mode, indirect)) |
| 225 | return false; |
| 226 | |
| 227 | gl::Buffer *drawIndirectBuffer = state.getDrawIndirectBuffer(); |
| 228 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(indirect)); |
| 229 | // In OpenGL ES3.1 spec, session 10.5, it defines the struct of DrawElementsIndirectCommand |
| 230 | // which's size is 5 * sizeof(uint). |
| 231 | auto checkedSum = checkedOffset + 5 * sizeof(GLuint); |
| 232 | if (!checkedSum.IsValid() || |
| 233 | checkedSum.ValueOrDie() > static_cast<size_t>(drawIndirectBuffer->getSize())) |
| 234 | { |
| 235 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 236 | InvalidOperation() |
| 237 | << "the command would source data beyond the end of the buffer object."); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | |
| 241 | return true; |
| 242 | } |
| 243 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 244 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 245 | GLenum target, |
| 246 | GLint level, |
| 247 | GLenum pname, |
| 248 | GLsizei *length) |
| 249 | { |
| 250 | if (context->getClientVersion() < ES_3_1) |
| 251 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 252 | context->handleError(InvalidOperation() << "Context does not support GLES3.1"); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 253 | return false; |
| 254 | } |
| 255 | |
| 256 | if (length) |
| 257 | { |
| 258 | *length = 0; |
| 259 | } |
| 260 | |
| 261 | if (!ValidTexLevelDestinationTarget(context, target)) |
| 262 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 263 | context->handleError(InvalidEnum() << "Invalid texture target"); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | |
| 267 | if (context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target) == |
| 268 | nullptr) |
| 269 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 270 | context->handleError(InvalidEnum() << "No texture bound."); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 271 | return false; |
| 272 | } |
| 273 | |
| 274 | if (!ValidMipLevel(context, target, level)) |
| 275 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 276 | context->handleError(InvalidValue()); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | |
| 280 | switch (pname) |
| 281 | { |
| 282 | case GL_TEXTURE_RED_TYPE: |
| 283 | case GL_TEXTURE_GREEN_TYPE: |
| 284 | case GL_TEXTURE_BLUE_TYPE: |
| 285 | case GL_TEXTURE_ALPHA_TYPE: |
| 286 | case GL_TEXTURE_DEPTH_TYPE: |
| 287 | break; |
| 288 | case GL_TEXTURE_RED_SIZE: |
| 289 | case GL_TEXTURE_GREEN_SIZE: |
| 290 | case GL_TEXTURE_BLUE_SIZE: |
| 291 | case GL_TEXTURE_ALPHA_SIZE: |
| 292 | case GL_TEXTURE_DEPTH_SIZE: |
| 293 | case GL_TEXTURE_STENCIL_SIZE: |
| 294 | case GL_TEXTURE_SHARED_SIZE: |
| 295 | break; |
| 296 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 297 | case GL_TEXTURE_WIDTH: |
| 298 | case GL_TEXTURE_HEIGHT: |
| 299 | case GL_TEXTURE_DEPTH: |
| 300 | break; |
| 301 | case GL_TEXTURE_SAMPLES: |
| 302 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 303 | break; |
| 304 | case GL_TEXTURE_COMPRESSED: |
| 305 | break; |
| 306 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 307 | context->handleError(InvalidEnum() << "Unknown pname."); |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | |
| 311 | if (length) |
| 312 | { |
| 313 | *length = 1; |
| 314 | } |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | bool ValidateGetTexLevelParameterfv(Context *context, |
| 319 | GLenum target, |
| 320 | GLint level, |
| 321 | GLenum pname, |
| 322 | GLfloat *params) |
| 323 | { |
| 324 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 325 | } |
| 326 | |
| 327 | bool ValidateGetTexLevelParameteriv(Context *context, |
| 328 | GLenum target, |
| 329 | GLint level, |
| 330 | GLenum pname, |
| 331 | GLint *params) |
| 332 | { |
| 333 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 334 | } |
| 335 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 336 | bool ValidateTexStorage2DMultiSample(Context *context, |
| 337 | GLenum target, |
| 338 | GLsizei samples, |
| 339 | GLint internalFormat, |
| 340 | GLsizei width, |
| 341 | GLsizei height, |
| 342 | GLboolean fixedSampleLocations) |
| 343 | { |
| 344 | if (context->getClientVersion() < ES_3_1) |
| 345 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 346 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 347 | return false; |
| 348 | } |
| 349 | |
| 350 | if (target != GL_TEXTURE_2D_MULTISAMPLE) |
| 351 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 352 | context->handleError(InvalidEnum() << "Target must be TEXTURE_2D_MULTISAMPLE."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 353 | return false; |
| 354 | } |
| 355 | |
| 356 | if (width < 1 || height < 1) |
| 357 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 358 | context->handleError(InvalidValue() << "Width and height must be positive."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
| 362 | const Caps &caps = context->getCaps(); |
| 363 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 364 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 365 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 366 | context |
| 367 | ->handleError(InvalidValue() |
| 368 | << "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] | 369 | return false; |
| 370 | } |
| 371 | |
| 372 | if (samples == 0) |
| 373 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 374 | context->handleError(InvalidValue() << "Samples may not be zero."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
| 378 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 379 | if (!formatCaps.renderable) |
| 380 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 381 | context->handleError(InvalidEnum() << "SizedInternalformat must be color-renderable, " |
| 382 | "depth-renderable, or stencil-renderable."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 383 | return false; |
| 384 | } |
| 385 | |
| 386 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 387 | // is one of the unsized base internalformats listed in table 8.11. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 388 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 389 | if (formatInfo.internalFormat == GL_NONE) |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 390 | { |
| 391 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 392 | InvalidEnum() |
| 393 | << "Internalformat is one of the unsupported unsized base internalformats."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 394 | return false; |
| 395 | } |
| 396 | |
| 397 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 398 | { |
| 399 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 400 | InvalidOperation() |
| 401 | << "Samples must not be greater than maximum supported value for the format."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 402 | return false; |
| 403 | } |
| 404 | |
| 405 | Texture *texture = context->getTargetTexture(target); |
| 406 | if (!texture || texture->id() == 0) |
| 407 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 408 | context->handleError(InvalidOperation() << "Zero is bound to target."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
| 412 | if (texture->getImmutableFormat()) |
| 413 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 414 | context->handleError(InvalidOperation() << "The value of TEXTURE_IMMUTABLE_FORMAT for " |
| 415 | "the texture currently bound to target on " |
| 416 | "the active texture unit is true."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 417 | return false; |
| 418 | } |
| 419 | |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | bool ValidateGetMultisamplefv(Context *context, GLenum pname, GLuint index, GLfloat *val) |
| 424 | { |
| 425 | if (context->getClientVersion() < ES_3_1) |
| 426 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 427 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 428 | return false; |
| 429 | } |
| 430 | |
| 431 | if (pname != GL_SAMPLE_POSITION) |
| 432 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 433 | context->handleError(InvalidEnum() << "Pname must be SAMPLE_POSITION."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | |
| 437 | GLint maxSamples = context->getCaps().maxSamples; |
| 438 | if (index >= static_cast<GLuint>(maxSamples)) |
| 439 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 440 | context->handleError(InvalidValue() << "Index must be less than the value of SAMPLES."); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 441 | return false; |
| 442 | } |
| 443 | |
| 444 | return true; |
| 445 | } |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 446 | |
| 447 | bool ValidationFramebufferParameteri(Context *context, GLenum target, GLenum pname, GLint param) |
| 448 | { |
| 449 | if (context->getClientVersion() < ES_3_1) |
| 450 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 451 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
| 455 | if (!ValidFramebufferTarget(target)) |
| 456 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 457 | context->handleError(InvalidEnum() << "Invalid framebuffer target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 458 | return false; |
| 459 | } |
| 460 | |
| 461 | switch (pname) |
| 462 | { |
| 463 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 464 | { |
| 465 | GLint maxWidth = context->getCaps().maxFramebufferWidth; |
| 466 | if (param < 0 || param > maxWidth) |
| 467 | { |
| 468 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 469 | InvalidValue() |
| 470 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_WIDTH."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 471 | return false; |
| 472 | } |
| 473 | break; |
| 474 | } |
| 475 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 476 | { |
| 477 | GLint maxHeight = context->getCaps().maxFramebufferHeight; |
| 478 | if (param < 0 || param > maxHeight) |
| 479 | { |
| 480 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 481 | InvalidValue() |
| 482 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_HEIGHT."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 483 | return false; |
| 484 | } |
| 485 | break; |
| 486 | } |
| 487 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 488 | { |
| 489 | GLint maxSamples = context->getCaps().maxFramebufferSamples; |
| 490 | if (param < 0 || param > maxSamples) |
| 491 | { |
| 492 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 493 | InvalidValue() |
| 494 | << "Params less than 0 or greater than GL_MAX_FRAMEBUFFER_SAMPLES."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 495 | return false; |
| 496 | } |
| 497 | break; |
| 498 | } |
| 499 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 500 | { |
| 501 | break; |
| 502 | } |
| 503 | default: |
| 504 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 505 | context->handleError(InvalidEnum() |
| 506 | << "Invalid pname: 0x" << std::hex << std::uppercase << pname); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 507 | return false; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 512 | ASSERT(framebuffer); |
| 513 | if (framebuffer->id() == 0) |
| 514 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 515 | context->handleError(InvalidOperation() << "Default framebuffer is bound to target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 516 | return false; |
| 517 | } |
| 518 | return true; |
| 519 | } |
| 520 | |
| 521 | bool ValidationGetFramebufferParameteri(Context *context, |
| 522 | GLenum target, |
| 523 | GLenum pname, |
| 524 | GLint *params) |
| 525 | { |
| 526 | if (context->getClientVersion() < ES_3_1) |
| 527 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 528 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 529 | return false; |
| 530 | } |
| 531 | |
| 532 | if (!ValidFramebufferTarget(target)) |
| 533 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 534 | context->handleError(InvalidEnum() << "Invalid framebuffer target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 535 | return false; |
| 536 | } |
| 537 | |
| 538 | switch (pname) |
| 539 | { |
| 540 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 541 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 542 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 543 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 544 | break; |
| 545 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 546 | context->handleError(InvalidEnum() |
| 547 | << "Invalid pname: 0x" << std::hex << std::uppercase << pname); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 548 | return false; |
| 549 | } |
| 550 | |
| 551 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 552 | ASSERT(framebuffer); |
| 553 | |
| 554 | if (framebuffer->id() == 0) |
| 555 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 556 | context->handleError(InvalidOperation() << "Default framebuffer is bound to target."); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 557 | return false; |
| 558 | } |
| 559 | return true; |
| 560 | } |
| 561 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 562 | bool ValidateGetProgramResourceIndex(Context *context, |
| 563 | GLuint program, |
| 564 | GLenum programInterface, |
| 565 | const GLchar *name) |
| 566 | { |
| 567 | if (context->getClientVersion() < ES_3_1) |
| 568 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 569 | context->handleError(InvalidOperation() << "Context does not support GLES 3.1."); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | |
| 573 | Program *programObject = GetValidProgram(context, program); |
| 574 | if (programObject == nullptr) |
| 575 | { |
| 576 | return false; |
| 577 | } |
| 578 | |
| 579 | if (!ValidateNamedProgramInterface(programInterface)) |
| 580 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 581 | context->handleError(InvalidEnum() << "Invalid program interface: 0x" << std::hex |
| 582 | << std::uppercase << programInterface); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 583 | return false; |
| 584 | } |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 585 | |
| 586 | return true; |
| 587 | } |
| 588 | |
| 589 | bool ValidateBindVertexBuffer(ValidationContext *context, |
| 590 | GLuint bindingIndex, |
| 591 | GLuint buffer, |
| 592 | GLintptr offset, |
| 593 | GLsizei stride) |
| 594 | { |
| 595 | if (context->getClientVersion() < ES_3_1) |
| 596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 597 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | |
| 601 | if (!context->isBufferGenerated(buffer)) |
| 602 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 603 | context->handleError(InvalidOperation() << "Buffer is not generated."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 604 | return false; |
| 605 | } |
| 606 | |
| 607 | const Caps &caps = context->getCaps(); |
| 608 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 609 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 610 | context->handleError(InvalidValue() |
| 611 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 612 | return false; |
| 613 | } |
| 614 | |
| 615 | if (offset < 0) |
| 616 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 617 | context->handleError(InvalidValue() << "offset cannot be negative."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 618 | return false; |
| 619 | } |
| 620 | |
| 621 | if (stride < 0 || stride > caps.maxVertexAttribStride) |
| 622 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 623 | context->handleError(InvalidValue() |
| 624 | << "stride must be between 0 and MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 625 | return false; |
| 626 | } |
| 627 | |
| 628 | // [OpenGL ES 3.1] Section 10.3.1 page 244: |
| 629 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 630 | if (context->getGLState().getVertexArrayId() == 0) |
| 631 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 632 | context->handleError(InvalidOperation() << "Default vertex array buffer is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 633 | return false; |
| 634 | } |
| 635 | |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | bool ValidateVertexBindingDivisor(ValidationContext *context, GLuint bindingIndex, GLuint divisor) |
| 640 | { |
| 641 | if (context->getClientVersion() < ES_3_1) |
| 642 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 643 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 644 | return false; |
| 645 | } |
| 646 | |
| 647 | const Caps &caps = context->getCaps(); |
| 648 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 649 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 650 | context->handleError(InvalidValue() |
| 651 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | |
| 655 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 656 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 657 | if (context->getGLState().getVertexArrayId() == 0) |
| 658 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 659 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 660 | return false; |
| 661 | } |
| 662 | |
| 663 | return true; |
| 664 | } |
| 665 | |
| 666 | bool ValidateVertexAttribFormat(ValidationContext *context, |
| 667 | GLuint attribIndex, |
| 668 | GLint size, |
| 669 | GLenum type, |
| 670 | GLuint relativeOffset, |
| 671 | GLboolean pureInteger) |
| 672 | { |
| 673 | if (context->getClientVersion() < ES_3_1) |
| 674 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 675 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 676 | return false; |
| 677 | } |
| 678 | |
| 679 | const Caps &caps = context->getCaps(); |
| 680 | if (relativeOffset > static_cast<GLuint>(caps.maxVertexAttribRelativeOffset)) |
| 681 | { |
| 682 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 683 | InvalidValue() |
| 684 | << "relativeOffset cannot be greater than MAX_VERTEX_ATTRIB_RELATIVE_OFFSET."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 685 | return false; |
| 686 | } |
| 687 | |
| 688 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 689 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 690 | if (context->getGLState().getVertexArrayId() == 0) |
| 691 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 692 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 693 | return false; |
| 694 | } |
| 695 | |
| 696 | return ValidateVertexFormatBase(context, attribIndex, size, type, pureInteger); |
| 697 | } |
| 698 | |
| 699 | bool ValidateVertexAttribBinding(ValidationContext *context, |
| 700 | GLuint attribIndex, |
| 701 | GLuint bindingIndex) |
| 702 | { |
| 703 | if (context->getClientVersion() < ES_3_1) |
| 704 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 705 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | |
| 709 | // [OpenGL ES 3.1] Section 10.3.1 page 243: |
| 710 | // An INVALID_OPERATION error is generated if the default vertex array object is bound. |
| 711 | if (context->getGLState().getVertexArrayId() == 0) |
| 712 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 713 | context->handleError(InvalidOperation() << "Default vertex array object is bound."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 714 | return false; |
| 715 | } |
| 716 | |
| 717 | const Caps &caps = context->getCaps(); |
| 718 | if (attribIndex >= caps.maxVertexAttributes) |
| 719 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 720 | context->handleError(InvalidValue() |
| 721 | << "attribindex must be smaller than MAX_VERTEX_ATTRIBS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 722 | return false; |
| 723 | } |
| 724 | |
| 725 | if (bindingIndex >= caps.maxVertexAttribBindings) |
| 726 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 727 | context->handleError(InvalidValue() |
| 728 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS"); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 729 | return false; |
| 730 | } |
| 731 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 732 | return true; |
| 733 | } |
| 734 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 735 | bool ValidateGetProgramResourceName(Context *context, |
| 736 | GLuint program, |
| 737 | GLenum programInterface, |
| 738 | GLuint index, |
| 739 | GLsizei bufSize, |
| 740 | GLsizei *length, |
| 741 | GLchar *name) |
| 742 | { |
| 743 | if (context->getClientVersion() < ES_3_1) |
| 744 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 745 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 746 | return false; |
| 747 | } |
| 748 | |
| 749 | Program *programObject = GetValidProgram(context, program); |
| 750 | if (programObject == nullptr) |
| 751 | { |
| 752 | return false; |
| 753 | } |
| 754 | |
| 755 | if (!ValidateNamedProgramInterface(programInterface)) |
| 756 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 757 | context->handleError(InvalidEnum() << "Invalid program interface: 0x" << std::hex |
| 758 | << std::uppercase << programInterface); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 759 | return false; |
| 760 | } |
| 761 | |
| 762 | if (!ValidateProgramResourceIndex(programObject, programInterface, index)) |
| 763 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 764 | context->handleError(InvalidValue() << "Invalid index: " << index); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 765 | return false; |
| 766 | } |
| 767 | |
| 768 | if (bufSize < 0) |
| 769 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 770 | context->handleError(InvalidValue() << "Invalid bufSize: " << bufSize); |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | |
| 774 | return true; |
| 775 | } |
| 776 | |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 777 | bool ValidateDispatchCompute(Context *context, |
| 778 | GLuint numGroupsX, |
| 779 | GLuint numGroupsY, |
| 780 | GLuint numGroupsZ) |
| 781 | { |
| 782 | if (context->getClientVersion() < ES_3_1) |
| 783 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 784 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | |
| 788 | const State &state = context->getGLState(); |
| 789 | Program *program = state.getProgram(); |
| 790 | |
| 791 | if (program == nullptr) |
| 792 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 793 | context->handleError(InvalidOperation() |
| 794 | << "No active program object for the compute shader stage."); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 795 | return false; |
| 796 | } |
| 797 | |
| 798 | if (program->isLinked() == false || program->getAttachedComputeShader() == nullptr) |
| 799 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 800 | context->handleError( |
| 801 | InvalidOperation() |
| 802 | << "Program has not been successfully linked, or program contains no compute shaders."); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 803 | return false; |
| 804 | } |
| 805 | |
| 806 | const Caps &caps = context->getCaps(); |
| 807 | if (numGroupsX > caps.maxComputeWorkGroupCount[0]) |
| 808 | { |
| 809 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 810 | InvalidValue() << "num_groups_x cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[0]=" |
| 811 | << caps.maxComputeWorkGroupCount[0]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 812 | return false; |
| 813 | } |
| 814 | if (numGroupsY > caps.maxComputeWorkGroupCount[1]) |
| 815 | { |
| 816 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 817 | InvalidValue() << "num_groups_y cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[1]=" |
| 818 | << caps.maxComputeWorkGroupCount[1]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 819 | return false; |
| 820 | } |
| 821 | if (numGroupsZ > caps.maxComputeWorkGroupCount[2]) |
| 822 | { |
| 823 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 824 | InvalidValue() << "num_groups_z cannot be greater than MAX_COMPUTE_WORK_GROUP_COUNT[2]=" |
| 825 | << caps.maxComputeWorkGroupCount[2]); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 826 | return false; |
| 827 | } |
| 828 | |
| 829 | return true; |
| 830 | } |
| 831 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 832 | bool ValidateBindImageTexture(Context *context, |
| 833 | GLuint unit, |
| 834 | GLuint texture, |
| 835 | GLint level, |
| 836 | GLboolean layered, |
| 837 | GLint layer, |
| 838 | GLenum access, |
| 839 | GLenum format) |
| 840 | { |
| 841 | GLuint maxImageUnits = context->getCaps().maxImageUnits; |
| 842 | if (unit >= maxImageUnits) |
| 843 | { |
| 844 | context->handleError(InvalidValue() |
| 845 | << "unit cannot be greater than or equal than MAX_IMAGE_UNITS = " |
| 846 | << maxImageUnits); |
| 847 | return false; |
| 848 | } |
| 849 | |
| 850 | if (level < 0) |
| 851 | { |
| 852 | context->handleError(InvalidValue() << "level is negative."); |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | if (layer < 0) |
| 857 | { |
| 858 | context->handleError(InvalidValue() << "layer is negative."); |
| 859 | return false; |
| 860 | } |
| 861 | |
| 862 | if (access != GL_READ_ONLY && access != GL_WRITE_ONLY && access != GL_READ_WRITE) |
| 863 | { |
| 864 | context->handleError(InvalidEnum() << "access is not one of the supported tokens."); |
| 865 | return false; |
| 866 | } |
| 867 | |
| 868 | switch (format) |
| 869 | { |
| 870 | case GL_RGBA32F: |
| 871 | case GL_RGBA16F: |
| 872 | case GL_R32F: |
| 873 | case GL_RGBA32UI: |
| 874 | case GL_RGBA16UI: |
| 875 | case GL_RGBA8UI: |
| 876 | case GL_R32UI: |
| 877 | case GL_RGBA32I: |
| 878 | case GL_RGBA16I: |
| 879 | case GL_RGBA8I: |
| 880 | case GL_R32I: |
| 881 | case GL_RGBA8: |
| 882 | case GL_RGBA8_SNORM: |
| 883 | break; |
| 884 | default: |
| 885 | context->handleError(InvalidValue() |
| 886 | << "format is not one of supported image unit formats."); |
| 887 | return false; |
| 888 | } |
| 889 | |
| 890 | if (texture != 0) |
| 891 | { |
| 892 | Texture *tex = context->getTexture(texture); |
| 893 | |
| 894 | if (tex == nullptr) |
| 895 | { |
| 896 | context->handleError(InvalidValue() |
| 897 | << "texture is not the name of an existing texture object."); |
| 898 | return false; |
| 899 | } |
| 900 | |
| 901 | if (!tex->getImmutableFormat()) |
| 902 | { |
| 903 | context->handleError(InvalidOperation() |
| 904 | << "texture is not the name of an immutable texture object."); |
| 905 | return false; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | return true; |
| 910 | } |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame^] | 911 | |
| 912 | bool ValidateGetProgramResourceLocation(Context *context, |
| 913 | GLuint program, |
| 914 | GLenum programInterface, |
| 915 | const GLchar *name) |
| 916 | { |
| 917 | if (context->getClientVersion() < ES_3_1) |
| 918 | { |
| 919 | context->handleError(InvalidOperation() << "Context does not support GLES3.1."); |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | Program *programObject = GetValidProgram(context, program); |
| 924 | if (programObject == nullptr) |
| 925 | { |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | if (!programObject->isLinked()) |
| 930 | { |
| 931 | context->handleError(InvalidOperation() << "Program is not successfully linked."); |
| 932 | return false; |
| 933 | } |
| 934 | |
| 935 | if (!ValidateLocationProgramInterface(programInterface)) |
| 936 | { |
| 937 | context->handleError(InvalidEnum() << "Invalid program interface."); |
| 938 | return false; |
| 939 | } |
| 940 | return true; |
| 941 | } |
| 942 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 943 | } // namespace gl |