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