Hash :
bb3f79dc
Author :
Date :
2025-06-26T16:59:48
Reorder shader resource dirty bits Process storage and atomic buffer dirty bits before uniform dirty bits. This helps the vulkan backend avoid duplicate work when multiple shader resources are dirty Bug: angleproject:426412564 Change-Id: Ibab3da44ee32d22078df851bfed4967d1c2a605e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6680035 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: mohan maiya <m.maiya@samsung.com> Reviewed-by: Charlie Lao <cclao@google.com>
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 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
//
// Copyright 2014 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.
//
// State.h: Defines the State class, encapsulating raw GL state
#ifndef LIBANGLE_STATE_H_
#define LIBANGLE_STATE_H_
#include <bitset>
#include <memory>
#include "common/Color.h"
#include "common/angleutils.h"
#include "common/bitset_utils.h"
#include "libANGLE/ContextMutex.h"
#include "libANGLE/Debug.h"
#include "libANGLE/GLES1State.h"
#include "libANGLE/Overlay.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramExecutable.h"
#include "libANGLE/ProgramPipeline.h"
#include "libANGLE/RefCountObject.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/Sampler.h"
#include "libANGLE/Texture.h"
#include "libANGLE/TransformFeedback.h"
#include "libANGLE/Version.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/angletypes.h"
namespace egl
{
class ShareGroup;
} // namespace egl
namespace gl
{
class BufferManager;
struct Caps;
class Context;
class FramebufferManager;
class MemoryObjectManager;
class ProgramPipelineManager;
class Query;
class RenderbufferManager;
class SamplerManager;
class SemaphoreManager;
class ShaderProgramManager;
class SyncManager;
class TextureManager;
class VertexArray;
template <typename T>
using BufferBindingMap = angle::PackedEnumMap<BufferBinding, T>;
using BoundBufferMap = BufferBindingMap<BindingPointer<Buffer>>;
using TextureBindingVector = std::vector<BindingPointer<Texture>>;
using TextureBindingMap = angle::PackedEnumMap<TextureType, TextureBindingVector>;
using ActiveQueryMap = angle::PackedEnumMap<QueryType, BindingPointer<Query>>;
class ActiveTexturesCache final : angle::NonCopyable
{
public:
ActiveTexturesCache();
~ActiveTexturesCache();
Texture *operator[](size_t textureIndex) const { return mTextures[textureIndex]; }
void clear();
void set(size_t textureIndex, Texture *texture);
void reset(size_t textureIndex);
bool empty() const;
size_t size() const { return mTextures.size(); }
private:
ActiveTextureArray<Texture *> mTextures;
};
namespace state
{
enum DirtyBitType
{
// Note: process draw framebuffer binding first, so that other dirty bits whose effect
// depend on the current draw framebuffer are not processed while the old framebuffer is
// still bound.
DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING,
DIRTY_BIT_READ_FRAMEBUFFER_BINDING,
DIRTY_BIT_SCISSOR_TEST_ENABLED,
DIRTY_BIT_SCISSOR,
DIRTY_BIT_VIEWPORT,
DIRTY_BIT_DEPTH_RANGE,
DIRTY_BIT_BLEND_ENABLED,
DIRTY_BIT_BLEND_COLOR,
DIRTY_BIT_BLEND_FUNCS,
DIRTY_BIT_BLEND_EQUATIONS,
DIRTY_BIT_COLOR_MASK,
DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED,
DIRTY_BIT_SAMPLE_COVERAGE_ENABLED,
DIRTY_BIT_SAMPLE_COVERAGE,
DIRTY_BIT_SAMPLE_MASK_ENABLED,
DIRTY_BIT_SAMPLE_MASK,
DIRTY_BIT_DEPTH_TEST_ENABLED,
DIRTY_BIT_DEPTH_FUNC,
DIRTY_BIT_DEPTH_MASK,
DIRTY_BIT_STENCIL_TEST_ENABLED,
DIRTY_BIT_STENCIL_FUNCS_FRONT,
DIRTY_BIT_STENCIL_FUNCS_BACK,
DIRTY_BIT_STENCIL_OPS_FRONT,
DIRTY_BIT_STENCIL_OPS_BACK,
DIRTY_BIT_STENCIL_WRITEMASK_FRONT,
DIRTY_BIT_STENCIL_WRITEMASK_BACK,
DIRTY_BIT_CULL_FACE_ENABLED,
DIRTY_BIT_CULL_FACE,
DIRTY_BIT_FRONT_FACE,
DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED,
DIRTY_BIT_POLYGON_OFFSET,
DIRTY_BIT_RASTERIZER_DISCARD_ENABLED,
DIRTY_BIT_LINE_WIDTH,
DIRTY_BIT_PRIMITIVE_RESTART_ENABLED,
DIRTY_BIT_CLEAR_COLOR,
DIRTY_BIT_CLEAR_DEPTH,
DIRTY_BIT_CLEAR_STENCIL,
DIRTY_BIT_UNPACK_STATE,
DIRTY_BIT_UNPACK_BUFFER_BINDING,
DIRTY_BIT_PACK_STATE,
DIRTY_BIT_PACK_BUFFER_BINDING,
DIRTY_BIT_DITHER_ENABLED,
DIRTY_BIT_RENDERBUFFER_BINDING,
DIRTY_BIT_VERTEX_ARRAY_BINDING,
DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING,
DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING,
// Note: Fine-grained dirty bits for each index could be an optimization.
DIRTY_BIT_PROGRAM_BINDING, // Must be before DIRTY_BIT_PROGRAM_EXECUTABLE
DIRTY_BIT_PROGRAM_EXECUTABLE,
// Note: Fine-grained dirty bits for each texture/sampler could be an optimization.
DIRTY_BIT_SAMPLER_BINDINGS,
DIRTY_BIT_TEXTURE_BINDINGS,
DIRTY_BIT_IMAGE_BINDINGS,
DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING,
DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING,
DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING,
// Top-level dirty bit. Also see mUniformBufferBlocksDirtyTypeMask.
DIRTY_BIT_UNIFORM_BUFFER_BINDINGS,
DIRTY_BIT_MULTISAMPLING,
DIRTY_BIT_SAMPLE_ALPHA_TO_ONE,
DIRTY_BIT_COVERAGE_MODULATION, // CHROMIUM_framebuffer_mixed_samples
DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE, // GL_EXT_sRGB_write_control
DIRTY_BIT_CURRENT_VALUES,
DIRTY_BIT_PROVOKING_VERTEX,
DIRTY_BIT_SAMPLE_SHADING,
DIRTY_BIT_PATCH_VERTICES,
DIRTY_BIT_EXTENDED, // clip distances, mipmap generation hint, derivative hint,
// EXT_clip_control, EXT_depth_clamp
DIRTY_BIT_INVALID,
DIRTY_BIT_MAX = DIRTY_BIT_INVALID,
};
static_assert(DIRTY_BIT_MAX <= 64, "State dirty bits must be capped at 64");
using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
enum ExtendedDirtyBitType
{
EXTENDED_DIRTY_BIT_CLIP_CONTROL, // EXT_clip_control
EXTENDED_DIRTY_BIT_CLIP_DISTANCES, // clip distances
EXTENDED_DIRTY_BIT_DEPTH_CLAMP_ENABLED, // EXT_depth_clamp
EXTENDED_DIRTY_BIT_MIPMAP_GENERATION_HINT, // mipmap generation hint
EXTENDED_DIRTY_BIT_POLYGON_MODE, // NV_polygon_mode
EXTENDED_DIRTY_BIT_POLYGON_OFFSET_POINT_ENABLED, // NV_polygon_mode
EXTENDED_DIRTY_BIT_POLYGON_OFFSET_LINE_ENABLED, // NV_polygon_mode
EXTENDED_DIRTY_BIT_SHADER_DERIVATIVE_HINT, // shader derivative hint
EXTENDED_DIRTY_BIT_SHADING_RATE, // QCOM_shading_rate
EXTENDED_DIRTY_BIT_LOGIC_OP_ENABLED, // ANGLE_logic_op
EXTENDED_DIRTY_BIT_LOGIC_OP, // ANGLE_logic_op
EXTENDED_DIRTY_BIT_BLEND_ADVANCED_COHERENT, // KHR_blend_operation_advanced_coherent
EXTENDED_DIRTY_BIT_INVALID,
EXTENDED_DIRTY_BIT_MAX = EXTENDED_DIRTY_BIT_INVALID,
};
static_assert(EXTENDED_DIRTY_BIT_MAX <= 32, "State extended dirty bits must be capped at 32");
using ExtendedDirtyBits = angle::BitSet32<EXTENDED_DIRTY_BIT_MAX>;
// TODO(jmadill): Consider storing dirty objects in a list instead of by binding.
enum DirtyObjectType
{
DIRTY_OBJECT_ACTIVE_TEXTURES, // Top-level dirty bit. Also see mDirtyActiveTextures.
DIRTY_OBJECT_TEXTURES_INIT,
DIRTY_OBJECT_IMAGES_INIT,
DIRTY_OBJECT_READ_ATTACHMENTS, // Only used if robust resource init is enabled
DIRTY_OBJECT_DRAW_ATTACHMENTS, // Only used if robust resource init is enabled
DIRTY_OBJECT_READ_FRAMEBUFFER,
DIRTY_OBJECT_DRAW_FRAMEBUFFER,
DIRTY_OBJECT_VERTEX_ARRAY,
DIRTY_OBJECT_TEXTURES, // Top-level dirty bit. Also see mDirtyTextures.
DIRTY_OBJECT_IMAGES, // Top-level dirty bit. Also see mDirtyImages.
DIRTY_OBJECT_SAMPLERS, // Top-level dirty bit. Also see mDirtySamplers.
DIRTY_OBJECT_PROGRAM_PIPELINE_OBJECT,
DIRTY_OBJECT_INVALID,
DIRTY_OBJECT_MAX = DIRTY_OBJECT_INVALID,
};
using DirtyObjects = angle::BitSet<DIRTY_OBJECT_MAX>;
} // namespace state
// This class represents the portion of the GL context's state that is purely private to the
// context. Manipulating this state does not affect the other contexts in any way, nor do operations
// in other contexts affect this.
//
// Note that "currently bound X" states do not belong here because unbinding most objects could lead
// to object destruction which in turn may trigger a notification to an observer that may affect
// another context.
class PrivateState : angle::NonCopyable
{
public:
PrivateState(const Version &clientVersion,
bool debug,
bool bindGeneratesResourceCHROMIUM,
bool clientArraysEnabled,
bool robustResourceInit,
bool programBinaryCacheEnabled,
bool isExternal);
~PrivateState();
void initialize(Context *context);
void initializeForCapture(const Context *context);
void reset();
const Version &getClientVersion() const { return mClientVersion; }
bool isWebGL() const { return getExtensions().webglCompatibilityANGLE; }
bool isWebGL1() const { return isWebGL() && getClientVersion() == ES_2_0; }
bool isGLES1() const { return getClientVersion() < ES_2_0; }
const Caps &getCaps() const { return mCaps; }
const TextureCapsMap &getTextureCaps() const { return mTextureCaps; }
const Extensions &getExtensions() const { return mExtensions; }
const Limitations &getLimitations() const { return mLimitations; }
bool isExternal() const { return mIsExternal; }
Caps *getMutableCaps() { return &mCaps; }
TextureCapsMap *getMutableTextureCaps() { return &mTextureCaps; }
Extensions *getMutableExtensions() { return &mExtensions; }
Limitations *getMutableLimitations() { return &mLimitations; }
// State chunk getters
const RasterizerState &getRasterizerState() const { return mRasterizer; }
const BlendState &getBlendState() const { return mBlendState; }
const BlendStateExt &getBlendStateExt() const { return mBlendStateExt; }
const DepthStencilState &getDepthStencilState() const { return mDepthStencil; }
// Clear values
void setColorClearValue(float red, float green, float blue, float alpha);
void setDepthClearValue(float depth);
void setStencilClearValue(int stencil);
const ColorF &getColorClearValue() const { return mColorClearValue; }
float getDepthClearValue() const { return mDepthClearValue; }
int getStencilClearValue() const { return mStencilClearValue; }
// Write mask manipulation
void setColorMask(bool red, bool green, bool blue, bool alpha);
void setColorMaskIndexed(bool red, bool green, bool blue, bool alpha, GLuint index);
void setDepthMask(bool mask);
// Discard toggle & query
bool isRasterizerDiscardEnabled() const { return mRasterizer.rasterizerDiscard; }
void setRasterizerDiscard(bool enabled);
// Primitive restart
bool isPrimitiveRestartEnabled() const { return mPrimitiveRestart; }
void setPrimitiveRestart(bool enabled);
// Face culling state manipulation
bool isCullFaceEnabled() const { return mRasterizer.cullFace; }
void setCullFace(bool enabled);
void setCullMode(CullFaceMode mode);
void setFrontFace(GLenum front);
// EXT_depth_clamp
bool isDepthClampEnabled() const { return mRasterizer.depthClamp; }
void setDepthClamp(bool enabled);
// Depth test state manipulation
bool isDepthTestEnabled() const { return mDepthStencil.depthTest; }
bool isDepthWriteEnabled() const { return mDepthStencil.depthTest && mDepthStencil.depthMask; }
void setDepthTest(bool enabled);
void setDepthFunc(GLenum depthFunc);
void setDepthRange(float zNear, float zFar);
float getNearPlane() const { return mNearZ; }
float getFarPlane() const { return mFarZ; }
// EXT_clip_control
void setClipControl(ClipOrigin origin, ClipDepthMode depth);
ClipOrigin getClipOrigin() const { return mClipOrigin; }
ClipDepthMode getClipDepthMode() const { return mClipDepthMode; }
bool isClipDepthModeZeroToOne() const { return mClipDepthMode == ClipDepthMode::ZeroToOne; }
// Blend state manipulation
bool isBlendEnabled() const { return isBlendEnabledIndexed(0); }
bool isBlendEnabledIndexed(GLuint index) const
{
ASSERT(static_cast<size_t>(index) < mBlendStateExt.getDrawBufferCount());
return isActivelyOverriddenPLSDrawBuffer(index)
? mPLSDeferredBlendEnables.test(index)
: mBlendStateExt.getEnabledMask().test(index);
}
DrawBufferMask getBlendEnabledDrawBufferMask() const { return mBlendStateExt.getEnabledMask(); }
void setBlend(bool enabled);
void setBlendIndexed(bool enabled, GLuint index);
void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
void setBlendFactorsIndexed(GLenum sourceRGB,
GLenum destRGB,
GLenum sourceAlpha,
GLenum destAlpha,
GLuint index);
void setBlendColor(float red, float green, float blue, float alpha);
void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
void setBlendEquationIndexed(GLenum rgbEquation, GLenum alphaEquation, GLuint index);
const ColorF &getBlendColor() const { return mBlendColor; }
// Stencil state maniupulation
bool isStencilTestEnabled() const { return mDepthStencil.stencilTest; }
bool isStencilWriteEnabled(GLuint framebufferStencilSize) const
{
return mDepthStencil.stencilTest &&
!(mDepthStencil.isStencilNoOp(framebufferStencilSize) &&
mDepthStencil.isStencilBackNoOp(framebufferStencilSize));
}
void setStencilTest(bool enabled);
void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
void setStencilWritemask(GLuint stencilWritemask);
void setStencilBackWritemask(GLuint stencilBackWritemask);
void setStencilOperations(GLenum stencilFail,
GLenum stencilPassDepthFail,
GLenum stencilPassDepthPass);
void setStencilBackOperations(GLenum stencilBackFail,
GLenum stencilBackPassDepthFail,
GLenum stencilBackPassDepthPass);
GLint getStencilRef() const { return mStencilRef; }
GLint getStencilBackRef() const { return mStencilBackRef; }
PolygonMode getPolygonMode() const { return mRasterizer.polygonMode; }
void setPolygonMode(PolygonMode mode);
// Depth bias/polygon offset state manipulation
bool isPolygonOffsetPointEnabled() const { return mRasterizer.polygonOffsetPoint; }
bool isPolygonOffsetLineEnabled() const { return mRasterizer.polygonOffsetLine; }
bool isPolygonOffsetFillEnabled() const { return mRasterizer.polygonOffsetFill; }
bool isPolygonOffsetEnabled() const { return mRasterizer.isPolygonOffsetEnabled(); }
void setPolygonOffsetPoint(bool enabled);
void setPolygonOffsetLine(bool enabled);
void setPolygonOffsetFill(bool enabled);
void setPolygonOffsetParams(GLfloat factor, GLfloat units, GLfloat clamp);
// Multisample coverage state manipulation
bool isSampleAlphaToCoverageEnabled() const { return mSampleAlphaToCoverage; }
void setSampleAlphaToCoverage(bool enabled);
bool isSampleCoverageEnabled() const { return mSampleCoverage; }
void setSampleCoverage(bool enabled);
void setSampleCoverageParams(GLclampf value, bool invert);
GLclampf getSampleCoverageValue() const { return mSampleCoverageValue; }
bool getSampleCoverageInvert() const { return mSampleCoverageInvert; }
// Multisample mask state manipulation.
bool isSampleMaskEnabled() const { return mSampleMask; }
void setSampleMaskEnabled(bool enabled);
void setSampleMaskParams(GLuint maskNumber, GLbitfield mask);
GLbitfield getSampleMaskWord(GLuint maskNumber) const
{
ASSERT(maskNumber < mMaxSampleMaskWords);
return mSampleMaskValues[maskNumber];
}
SampleMaskArray<GLbitfield> getSampleMaskValues() const { return mSampleMaskValues; }
GLuint getMaxSampleMaskWords() const { return mMaxSampleMaskWords; }
// Multisampling/alpha to one manipulation.
void setSampleAlphaToOne(bool enabled);
bool isSampleAlphaToOneEnabled() const { return mSampleAlphaToOne; }
void setMultisampling(bool enabled);
bool isMultisamplingEnabled() const { return mMultiSampling; }
void setSampleShading(bool enabled);
bool isSampleShadingEnabled() const { return mIsSampleShadingEnabled; }
void setMinSampleShading(float value);
float getMinSampleShading() const { return mMinSampleShading; }
// Scissor test state toggle & query
bool isScissorTestEnabled() const { return mScissorTest; }
void setScissorTest(bool enabled);
void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
const Rectangle &getScissor() const { return mScissor; }
// Dither state toggle & query
bool isDitherEnabled() const { return mRasterizer.dither; }
void setDither(bool enabled);
// GL_KHR_blend_equation_advanced_coherent
void setBlendAdvancedCoherent(bool enabled);
bool isBlendAdvancedCoherentEnabled() const { return mBlendAdvancedCoherent; }
// GL_CHROMIUM_bind_generates_resource
bool isBindGeneratesResourceEnabled() const { return mBindGeneratesResource; }
// GL_ANGLE_client_arrays
bool areClientArraysEnabled() const { return mClientArraysEnabled; }
// GL_ANGLE_robust_resource_initialization
bool isRobustResourceInitEnabled() const { return mRobustResourceInit; }
// GL_ANGLE_program_cache_control
bool isProgramBinaryCacheEnabled() const { return mProgramBinaryCacheEnabled; }
// Viewport state setter/getter
void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
const Rectangle &getViewport() const { return mViewport; }
// QCOM_shading_rate helpers
void setShadingRate(GLenum rate);
ShadingRate getShadingRate() const { return mShadingRate; }
// GL_EXT_fragment_shading_rate helpers
void setShadingRateCombinerOps(GLenum combinerOp0, GLenum combinerOp1);
CombinerOp *getShadingRateCombinerOps() { return mCombinerOps; }
// Pixel pack state manipulation
void setPackAlignment(GLint alignment);
GLint getPackAlignment() const { return mPack.alignment; }
void setPackReverseRowOrder(bool reverseRowOrder);
bool getPackReverseRowOrder() const { return mPack.reverseRowOrder; }
void setPackRowLength(GLint rowLength);
GLint getPackRowLength() const { return mPack.rowLength; }
void setPackSkipRows(GLint skipRows);
GLint getPackSkipRows() const { return mPack.skipRows; }
void setPackSkipPixels(GLint skipPixels);
GLint getPackSkipPixels() const { return mPack.skipPixels; }
const PixelPackState &getPackState() const { return mPack; }
PixelPackState &getPackState() { return mPack; }
// Pixel unpack state manipulation
void setUnpackAlignment(GLint alignment);
GLint getUnpackAlignment() const { return mUnpack.alignment; }
void setUnpackRowLength(GLint rowLength);
GLint getUnpackRowLength() const { return mUnpack.rowLength; }
void setUnpackImageHeight(GLint imageHeight);
GLint getUnpackImageHeight() const { return mUnpack.imageHeight; }
void setUnpackSkipImages(GLint skipImages);
GLint getUnpackSkipImages() const { return mUnpack.skipImages; }
void setUnpackSkipRows(GLint skipRows);
GLint getUnpackSkipRows() const { return mUnpack.skipRows; }
void setUnpackSkipPixels(GLint skipPixels);
GLint getUnpackSkipPixels() const { return mUnpack.skipPixels; }
const PixelUnpackState &getUnpackState() const { return mUnpack; }
PixelUnpackState &getUnpackState() { return mUnpack; }
// CHROMIUM_framebuffer_mixed_samples coverage modulation
void setCoverageModulation(GLenum components);
GLenum getCoverageModulation() const { return mCoverageModulation; }
// GL_EXT_sRGB_write_control
void setFramebufferSRGB(bool sRGB);
bool getFramebufferSRGB() const { return mFramebufferSRGB; }
// GL_EXT_tessellation_shader
void setPatchVertices(GLuint value);
GLuint getPatchVertices() const { return mPatchVertices; }
// GL_ANGLE_shader_pixel_local_storage
void setPixelLocalStorageActivePlanes(GLsizei n);
GLsizei getPixelLocalStorageActivePlanes() const { return mPixelLocalStorageActivePlanes; }
// While pixel local storage is active, some draw buffers may be reserved for internal use by
// PLS and blocked from the client. All draw buffers at or beyond 'firstActivePLSDrawBuffer' are
// overridden.
bool hasActivelyOverriddenPLSDrawBuffers(GLint *firstActivePLSDrawBuffer) const;
bool isActivelyOverriddenPLSDrawBuffer(GLint drawbuffer) const;
// Line width state setter
void setLineWidth(GLfloat width);
float getLineWidth() const { return mLineWidth; }
void setActiveSampler(unsigned int active);
unsigned int getActiveSampler() const { return static_cast<unsigned int>(mActiveSampler); }
// Hint setters
void setGenerateMipmapHint(GLenum hint);
GLenum getGenerateMipmapHint() const { return mGenerateMipmapHint; }
GLenum getFragmentShaderDerivativeHint() const { return mFragmentShaderDerivativeHint; }
void setFragmentShaderDerivativeHint(GLenum hint);
ProvokingVertexConvention getProvokingVertex() const { return mProvokingVertex; }
void setProvokingVertex(ProvokingVertexConvention val)
{
mDirtyBits.set(state::DIRTY_BIT_PROVOKING_VERTEX);
mProvokingVertex = val;
}
const VertexAttribCurrentValueData &getVertexAttribCurrentValue(size_t attribNum) const
{
ASSERT(attribNum < mVertexAttribCurrentValues.size());
return mVertexAttribCurrentValues[attribNum];
}
const std::vector<VertexAttribCurrentValueData> &getVertexAttribCurrentValues() const
{
return mVertexAttribCurrentValues;
}
// This actually clears the current value dirty bits.
// TODO(jmadill): Pass mutable dirty bits into Impl.
AttributesMask getAndResetDirtyCurrentValues() const;
ComponentTypeMask getCurrentValuesTypeMask() const { return mCurrentValuesTypeMask; }
const ClipDistanceEnableBits &getEnabledClipDistances() const { return mClipDistancesEnabled; }
void setClipDistanceEnable(int idx, bool enable);
bool noSimultaneousConstantColorAndAlphaBlendFunc() const
{
return mNoSimultaneousConstantColorAndAlphaBlendFunc;
}
GLfloat getBoundingBoxMinX() const { return mBoundingBoxMinX; }
GLfloat getBoundingBoxMinY() const { return mBoundingBoxMinY; }
GLfloat getBoundingBoxMinZ() const { return mBoundingBoxMinZ; }
GLfloat getBoundingBoxMinW() const { return mBoundingBoxMinW; }
GLfloat getBoundingBoxMaxX() const { return mBoundingBoxMaxX; }
GLfloat getBoundingBoxMaxY() const { return mBoundingBoxMaxY; }
GLfloat getBoundingBoxMaxZ() const { return mBoundingBoxMaxZ; }
GLfloat getBoundingBoxMaxW() const { return mBoundingBoxMaxW; }
void setBoundingBox(GLfloat minX,
GLfloat minY,
GLfloat minZ,
GLfloat minW,
GLfloat maxX,
GLfloat maxY,
GLfloat maxZ,
GLfloat maxW);
bool isTextureRectangleEnabled() const { return mTextureRectangleEnabled; }
DrawBufferMask getBlendFuncConstantAlphaDrawBuffers() const
{
return mBlendFuncConstantAlphaDrawBuffers;
}
DrawBufferMask getBlendFuncConstantColorDrawBuffers() const
{
return mBlendFuncConstantColorDrawBuffers;
}
void setLogicOpEnabled(bool enabled);
bool isLogicOpEnabled() const { return mLogicOpEnabled; }
void setLogicOp(LogicalOperation opcode);
LogicalOperation getLogicOp() const { return mLogicOp; }
// Vertex attrib manipulation
void setVertexAttribf(GLuint index, const GLfloat values[4]);
void setVertexAttribu(GLuint index, const GLuint values[4]);
void setVertexAttribi(GLuint index, const GLint values[4]);
// QCOM_tiled_rendering
void setTiledRendering(bool tiledRendering) { mTiledRendering = tiledRendering; }
bool isTiledRendering() const { return mTiledRendering; }
// Debug state
const Debug &getDebug() const { return mDebug; }
Debug &getDebug() { return mDebug; }
// GL_ANGLE_blob_cache
const BlobCacheCallbacks &getBlobCacheCallbacks() const { return mBlobCacheCallbacks; }
BlobCacheCallbacks &getBlobCacheCallbacks() { return mBlobCacheCallbacks; }
// Generic state toggle & query
void setEnableFeature(GLenum feature, bool enabled);
void setEnableFeatureIndexed(GLenum feature, bool enabled, GLuint index);
bool getEnableFeature(GLenum feature) const;
bool getEnableFeatureIndexed(GLenum feature, GLuint index) const;
// State query functions
void getBooleanv(GLenum pname, GLboolean *params) const;
void getFloatv(GLenum pname, GLfloat *params) const;
void getIntegerv(GLenum pname, GLint *params) const;
void getIntegeri_v(GLenum target, GLuint index, GLint *data) const;
void getBooleani_v(GLenum target, GLuint index, GLboolean *data) const;
GLES1State *getMutableGLES1State() { return &mGLES1State; }
const GLES1State &gles1() const { return mGLES1State; }
const state::DirtyBits &getDirtyBits() const { return mDirtyBits; }
void clearDirtyBits(const state::DirtyBits &bitset) { mDirtyBits &= ~bitset; }
void setAllDirtyBits()
{
mDirtyBits.set();
mExtendedDirtyBits.set();
mDirtyCurrentValues = mAllAttribsMask;
}
const state::ExtendedDirtyBits &getExtendedDirtyBits() const { return mExtendedDirtyBits; }
void clearExtendedDirtyBits(const state::ExtendedDirtyBits &bitset)
{
mExtendedDirtyBits &= ~bitset;
}
const state::DirtyObjects &getDirtyObjects() const { return mDirtyObjects; }
void clearDirtyObjects() { mDirtyObjects.reset(); }
void setPerfMonitorActive(bool active) { mIsPerfMonitorActive = active; }
bool isPerfMonitorActive() const { return mIsPerfMonitorActive; }
private:
bool hasConstantColor(GLenum sourceRGB, GLenum destRGB) const;
bool hasConstantAlpha(GLenum sourceRGB, GLenum destRGB) const;
const Version mClientVersion;
// Caps to use for validation
Caps mCaps;
TextureCapsMap mTextureCaps;
Extensions mExtensions;
Limitations mLimitations;
const bool mIsExternal;
ColorF mColorClearValue;
GLfloat mDepthClearValue;
int mStencilClearValue;
RasterizerState mRasterizer;
bool mScissorTest;
Rectangle mScissor;
bool mNoUnclampedBlendColor;
BlendState mBlendState; // Buffer zero blend state legacy struct
BlendStateExt mBlendStateExt;
ColorF mBlendColor;
bool mSampleAlphaToCoverage;
bool mSampleCoverage;
GLfloat mSampleCoverageValue;
bool mSampleCoverageInvert;
bool mSampleMask;
GLuint mMaxSampleMaskWords;
SampleMaskArray<GLbitfield> mSampleMaskValues;
bool mIsSampleShadingEnabled;
float mMinSampleShading;
DepthStencilState mDepthStencil;
GLint mStencilRef;
GLint mStencilBackRef;
GLfloat mLineWidth;
GLenum mGenerateMipmapHint;
GLenum mFragmentShaderDerivativeHint;
Rectangle mViewport;
float mNearZ;
float mFarZ;
ClipOrigin mClipOrigin;
ClipDepthMode mClipDepthMode;
// GL_ANGLE_provoking_vertex
ProvokingVertexConvention mProvokingVertex;
using VertexAttribVector = std::vector<VertexAttribCurrentValueData>;
VertexAttribVector mVertexAttribCurrentValues; // From glVertexAttrib
ComponentTypeMask mCurrentValuesTypeMask;
// Mask of all attributes that are available to this context: [0, maxVertexAttributes)
AttributesMask mAllAttribsMask;
// Texture and sampler bindings
GLint mActiveSampler; // Active texture unit selector - GL_TEXTURE0
PixelUnpackState mUnpack;
PixelPackState mPack;
bool mPrimitiveRestart;
bool mMultiSampling;
bool mSampleAlphaToOne;
// GL_KHR_blend_equation_advanced_coherent
bool mBlendAdvancedCoherent;
GLenum mCoverageModulation;
// GL_EXT_sRGB_write_control
bool mFramebufferSRGB;
// GL_ANGLE_webgl_compatibility
bool mTextureRectangleEnabled;
// GL_ANGLE_logic_op
bool mLogicOpEnabled;
LogicalOperation mLogicOp;
// GL_APPLE_clip_distance / GL_EXT_clip_cull_distance / GL_ANGLE_clip_cull_distance
ClipDistanceEnableBits mClipDistancesEnabled;
// GL_EXT_tessellation_shader
GLuint mPatchVertices;
// GL_ANGLE_shader_pixel_local_storage
GLsizei mPixelLocalStorageActivePlanes;
// Overridden PLS draw buffers require no blend and a full color mask. While PLS is active,
// defer any updates to these states until it ends.
DrawBufferMask mPLSDeferredBlendEnables;
BlendStateExt::ColorMaskStorage::Type mPLSDeferredColorMasks;
// GLES1 emulation: state specific to GLES1
GLES1State mGLES1State;
// OES_draw_buffers_indexed
DrawBufferMask mBlendFuncConstantAlphaDrawBuffers;
DrawBufferMask mBlendFuncConstantColorDrawBuffers;
bool mNoSimultaneousConstantColorAndAlphaBlendFunc;
// Whether the indexed variants of setBlend* have been called. If so, the call to the
// non-indexed variants are not no-oped.
bool mSetBlendIndexedInvoked;
bool mSetBlendFactorsIndexedInvoked;
bool mSetBlendEquationsIndexedInvoked;
// GL_EXT_primitive_bounding_box
GLfloat mBoundingBoxMinX;
GLfloat mBoundingBoxMinY;
GLfloat mBoundingBoxMinZ;
GLfloat mBoundingBoxMinW;
GLfloat mBoundingBoxMaxX;
GLfloat mBoundingBoxMaxY;
GLfloat mBoundingBoxMaxZ;
GLfloat mBoundingBoxMaxW;
// QCOM_shading_rate
bool mShadingRatePreserveAspectRatio;
ShadingRate mShadingRate;
// GL_EXT_fragment_shading_rate
CombinerOp mCombinerOps[2];
// GL_ARM_shader_framebuffer_fetch
bool mFetchPerSample;
// Whether perf monitoring is enabled through GL_AMD_performance_monitor.
bool mIsPerfMonitorActive;
// QCOM_tiled_rendering
bool mTiledRendering;
const bool mBindGeneratesResource;
const bool mClientArraysEnabled;
const bool mRobustResourceInit;
const bool mProgramBinaryCacheEnabled;
Debug mDebug;
// ANGLE_blob_cache
BlobCacheCallbacks mBlobCacheCallbacks;
state::DirtyBits mDirtyBits;
state::ExtendedDirtyBits mExtendedDirtyBits;
state::DirtyObjects mDirtyObjects;
mutable AttributesMask mDirtyCurrentValues;
};
// This class represents all of the GL context's state.
class State : angle::NonCopyable
{
public:
State(const State *shareContextState,
egl::ShareGroup *shareGroup,
TextureManager *shareTextures,
SemaphoreManager *shareSemaphores,
egl::ContextMutex *contextMutex,
const OverlayType *overlay,
const Version &clientVersion,
bool debug,
bool bindGeneratesResourceCHROMIUM,
bool clientArraysEnabled,
bool robustResourceInit,
bool programBinaryCacheEnabled,
EGLenum contextPriority,
bool hasRobustAccess,
bool hasProtectedContent,
bool isExternal);
~State();
void initialize(Context *context);
void reset(const Context *context);
// Getters
ContextID getContextID() const { return mID; }
EGLenum getContextPriority() const { return mContextPriority; }
bool hasRobustAccess() const { return mHasRobustAccess; }
bool hasProtectedContent() const { return mHasProtectedContent; }
bool isDebugContext() const { return mIsDebugContext; }
const Version &getClientVersion() const { return mPrivateState.getClientVersion(); }
egl::ShareGroup *getShareGroup() const { return mShareGroup; }
bool isWebGL() const { return mPrivateState.isWebGL(); }
bool isWebGL1() const { return mPrivateState.isWebGL1(); }
bool isGLES1() const { return mPrivateState.isGLES1(); }
const Caps &getCaps() const { return mPrivateState.getCaps(); }
const TextureCapsMap &getTextureCaps() const { return mPrivateState.getTextureCaps(); }
const Extensions &getExtensions() const { return mPrivateState.getExtensions(); }
const Limitations &getLimitations() const { return mPrivateState.getLimitations(); }
bool isExternal() const { return mPrivateState.isExternal(); }
Caps *getMutableCaps() { return mPrivateState.getMutableCaps(); }
TextureCapsMap *getMutableTextureCaps() { return mPrivateState.getMutableTextureCaps(); }
Extensions *getMutableExtensions() { return mPrivateState.getMutableExtensions(); }
Limitations *getMutableLimitations() { return mPrivateState.getMutableLimitations(); }
const TextureCaps &getTextureCap(GLenum internalFormat) const
{
return getTextureCaps().get(internalFormat);
}
bool allActiveDrawBufferChannelsMasked() const;
bool anyActiveDrawBufferChannelMasked() const;
// Texture binding & active texture unit manipulation
void setSamplerTexture(const Context *context, TextureType type, Texture *texture);
Texture *getTargetTexture(TextureType type) const
{
return getSamplerTexture(getActiveSampler(), type);
}
Texture *getSamplerTexture(unsigned int sampler, TextureType type) const
{
ASSERT(sampler < mSamplerTextures[type].size());
return mSamplerTextures[type][sampler].get();
}
TextureID getSamplerTextureId(unsigned int sampler, TextureType type) const;
void detachTexture(Context *context, const TextureMap &zeroTextures, TextureID texture);
void initializeZeroTextures(const Context *context, const TextureMap &zeroTextures);
void invalidateTextureBindings(TextureType type);
bool isTextureBoundToActivePLS(TextureID) const;
// Sampler object binding manipulation
void setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler);
SamplerID getSamplerId(GLuint textureUnit) const
{
ASSERT(textureUnit < mSamplers.size());
return mSamplers[textureUnit].id();
}
Sampler *getSampler(GLuint textureUnit) const { return mSamplers[textureUnit].get(); }
const SamplerBindingVector &getSamplers() const { return mSamplers; }
void detachSampler(const Context *context, SamplerID sampler);
// Renderbuffer binding manipulation
void setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer);
RenderbufferID getRenderbufferId() const { return mRenderbuffer.id(); }
Renderbuffer *getCurrentRenderbuffer() const { return mRenderbuffer.get(); }
void detachRenderbuffer(Context *context, RenderbufferID renderbuffer);
// Framebuffer binding manipulation
void setReadFramebufferBinding(Framebuffer *framebuffer);
void setDrawFramebufferBinding(Framebuffer *framebuffer);
Framebuffer *getTargetFramebuffer(GLenum target) const;
Framebuffer *getReadFramebuffer() const { return mReadFramebuffer; }
Framebuffer *getDrawFramebuffer() const { return mDrawFramebuffer; }
Framebuffer *getDefaultFramebuffer() const;
bool removeReadFramebufferBinding(FramebufferID framebuffer);
bool removeDrawFramebufferBinding(FramebufferID framebuffer);
// Vertex array object binding manipulation
void setVertexArrayBinding(const Context *context, VertexArray *vertexArray);
bool removeVertexArrayBinding(const Context *context, VertexArrayID vertexArray);
VertexArrayID getVertexArrayId() const;
VertexArray *getVertexArray() const
{
ASSERT(mVertexArray != nullptr);
return mVertexArray;
}
// If both a Program and a ProgramPipeline are bound, the Program will
// always override the ProgramPipeline.
ProgramExecutable *getProgramExecutable() const { return mExecutable.get(); }
void ensureNoPendingLink(const Context *context) const
{
if (mProgram)
{
mProgram->resolveLink(context);
}
else if (mProgramPipeline.get())
{
mProgramPipeline->resolveLink(context);
}
}
ProgramExecutable *getLinkedProgramExecutable(const Context *context) const
{
ensureNoPendingLink(context);
return mExecutable.get();
}
// Program binding manipulation
angle::Result setProgram(const Context *context, Program *newProgram);
Program *getProgram() const
{
ASSERT(!mProgram || !mProgram->isLinking());
return mProgram;
}
ANGLE_INLINE Program *getLinkedProgram(const Context *context) const
{
if (ANGLE_LIKELY(mProgram))
{
mProgram->resolveLink(context);
}
return mProgram;
}
ProgramPipeline *getProgramPipeline() const { return mProgramPipeline.get(); }
ProgramPipeline *getLinkedProgramPipeline(const Context *context) const
{
if (mProgramPipeline.get())
{
mProgramPipeline->resolveLink(context);
}
return mProgramPipeline.get();
}
// Transform feedback object (not buffer) binding manipulation
void setTransformFeedbackBinding(const Context *context, TransformFeedback *transformFeedback);
TransformFeedback *getCurrentTransformFeedback() const { return mTransformFeedback.get(); }
ANGLE_INLINE bool isTransformFeedbackActive() const
{
TransformFeedback *curTransformFeedback = mTransformFeedback.get();
return curTransformFeedback && curTransformFeedback->isActive();
}
ANGLE_INLINE bool isTransformFeedbackActiveUnpaused() const
{
TransformFeedback *curTransformFeedback = mTransformFeedback.get();
return curTransformFeedback && curTransformFeedback->isActive() &&
!curTransformFeedback->isPaused();
}
bool removeTransformFeedbackBinding(const Context *context,
TransformFeedbackID transformFeedback);
// Query binding manipulation
bool isQueryActive(QueryType type) const;
bool isQueryActive(Query *query) const;
void setActiveQuery(const Context *context, QueryType type, Query *query);
QueryID getActiveQueryId(QueryType type) const;
Query *getActiveQuery(QueryType type) const;
// Program Pipeline binding manipulation
angle::Result setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline);
void detachProgramPipeline(const Context *context, ProgramPipelineID pipeline);
//// Typed buffer binding point manipulation ////
ANGLE_INLINE void setBufferBinding(const Context *context, BufferBinding target, Buffer *buffer)
{
(this->*(kBufferSetters[target]))(context, buffer);
}
ANGLE_INLINE Buffer *getTargetBuffer(BufferBinding target) const
{
switch (target)
{
case BufferBinding::ElementArray:
return getVertexArray()->getElementArrayBuffer();
default:
return mBoundBuffers[target].get();
}
}
ANGLE_INLINE Buffer *getArrayBuffer() const { return getTargetBuffer(BufferBinding::Array); }
angle::Result setIndexedBufferBinding(const Context *context,
BufferBinding target,
GLuint index,
Buffer *buffer,
GLintptr offset,
GLsizeiptr size);
size_t getAtomicCounterBufferCount() const { return mAtomicCounterBuffers.size(); }
ANGLE_INLINE bool hasValidAtomicCounterBuffer() const
{
return mBoundAtomicCounterBuffersMask.any();
}
const OffsetBindingPointer<Buffer> &getIndexedUniformBuffer(size_t index) const;
const OffsetBindingPointer<Buffer> &getIndexedAtomicCounterBuffer(size_t index) const;
const OffsetBindingPointer<Buffer> &getIndexedShaderStorageBuffer(size_t index) const;
const angle::BitSet<gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS> &getUniformBuffersMask()
const
{
return mBoundUniformBuffersMask;
}
const angle::BitSet<gl::IMPLEMENTATION_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS> &
getAtomicCounterBuffersMask() const
{
return mBoundAtomicCounterBuffersMask;
}
const angle::BitSet<gl::IMPLEMENTATION_MAX_SHADER_STORAGE_BUFFER_BINDINGS> &
getShaderStorageBuffersMask() const
{
return mBoundShaderStorageBuffersMask;
}
// Detach a buffer from all bindings
angle::Result detachBuffer(Context *context, const Buffer *buffer);
// Vertex attrib manipulation
void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
ANGLE_INLINE void setVertexAttribPointer(const Context *context,
unsigned int attribNum,
Buffer *boundBuffer,
GLint size,
VertexAttribType type,
bool normalized,
GLsizei stride,
const void *pointer,
bool *isVertexAttribDirtyOut)
{
ASSERT(isVertexAttribDirtyOut);
mVertexArray->setVertexAttribPointer(context, attribNum, boundBuffer, size, type,
normalized, stride, pointer, isVertexAttribDirtyOut);
if (*isVertexAttribDirtyOut)
{
mDirtyObjects.set(state::DIRTY_OBJECT_VERTEX_ARRAY);
}
}
ANGLE_INLINE void setVertexAttribIPointer(const Context *context,
unsigned int attribNum,
Buffer *boundBuffer,
GLint size,
VertexAttribType type,
GLsizei stride,
const void *pointer,
bool *isVertexAttribDirtyOut)
{
ASSERT(isVertexAttribDirtyOut);
mVertexArray->setVertexAttribIPointer(context, attribNum, boundBuffer, size, type, stride,
pointer, isVertexAttribDirtyOut);
if (*isVertexAttribDirtyOut)
{
mDirtyObjects.set(state::DIRTY_OBJECT_VERTEX_ARRAY);
}
}
void setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor);
const void *getVertexAttribPointer(unsigned int attribNum) const;
void bindVertexBuffer(const Context *context,
GLuint bindingIndex,
Buffer *boundBuffer,
GLintptr offset,
GLsizei stride);
void setVertexAttribFormat(GLuint attribIndex,
GLint size,
VertexAttribType type,
bool normalized,
bool pureInteger,
GLuint relativeOffset);
void setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex)
{
mVertexArray->setVertexAttribBinding(context, attribIndex, bindingIndex);
mDirtyObjects.set(state::DIRTY_OBJECT_VERTEX_ARRAY);
}
void setVertexBindingDivisor(const Context *context, GLuint bindingIndex, GLuint divisor);
// State query functions
void getBooleanv(GLenum pname, GLboolean *params) const;
void getFloatv(GLenum pname, GLfloat *params) const { mPrivateState.getFloatv(pname, params); }
angle::Result getIntegerv(const Context *context, GLenum pname, GLint *params) const;
void getPointerv(const Context *context, GLenum pname, void **params) const;
void getIntegeri_v(const Context *context, GLenum target, GLuint index, GLint *data) const;
void getInteger64i_v(GLenum target, GLuint index, GLint64 *data) const;
void getBooleani_v(GLenum target, GLuint index, GLboolean *data) const;
bool isDrawFramebufferBindingDirty() const
{
return mDirtyBits.test(state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
}
// Sets the dirty bit for the program executable.
angle::Result installProgramExecutable(const Context *context);
// Sets the dirty bit for the program pipeline executable.
angle::Result installProgramPipelineExecutable(const Context *context);
const state::DirtyBits getDirtyBits() const
{
return mDirtyBits | mPrivateState.getDirtyBits();
}
void clearDirtyBits(const state::DirtyBits &bitset)
{
mDirtyBits &= ~bitset;
mPrivateState.clearDirtyBits(bitset);
}
void setAllDirtyBits()
{
mDirtyBits.set();
mExtendedDirtyBits.set();
mPrivateState.setAllDirtyBits();
}
const state::ExtendedDirtyBits getExtendedDirtyBits() const
{
return mExtendedDirtyBits | mPrivateState.getExtendedDirtyBits();
}
void clearExtendedDirtyBits(const state::ExtendedDirtyBits &bitset)
{
mExtendedDirtyBits &= ~bitset;
mPrivateState.clearExtendedDirtyBits(bitset);
}
void clearDirtyObjects()
{
mDirtyObjects.reset();
mPrivateState.clearDirtyObjects();
}
void setAllDirtyObjects()
{
mDirtyObjects.set();
if (!isRobustResourceInitEnabled())
{
mDirtyObjects.reset(state::DIRTY_OBJECT_READ_ATTACHMENTS);
mDirtyObjects.reset(state::DIRTY_OBJECT_DRAW_ATTACHMENTS);
}
}
angle::Result syncDirtyObjects(const Context *context,
const state::DirtyObjects &bitset,
Command command);
angle::Result syncDirtyObject(const Context *context, GLenum target, Command command);
void setObjectDirty(GLenum target);
void setTextureDirty(size_t textureUnitIndex);
void setSamplerDirty(size_t samplerIndex);
ANGLE_INLINE void setReadFramebufferDirty()
{
mDirtyObjects.set(state::DIRTY_OBJECT_READ_FRAMEBUFFER);
if (isRobustResourceInitEnabled())
{
mDirtyObjects.set(state::DIRTY_OBJECT_READ_ATTACHMENTS);
}
}
ANGLE_INLINE void setDrawFramebufferDirty()
{
mDirtyObjects.set(state::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
if (isRobustResourceInitEnabled())
{
mDirtyObjects.set(state::DIRTY_OBJECT_DRAW_ATTACHMENTS);
}
}
void setImageUnit(const Context *context,
size_t unit,
Texture *texture,
GLint level,
GLboolean layered,
GLint layer,
GLenum access,
GLenum format);
const ImageUnit &getImageUnit(size_t unit) const { return mImageUnits[unit]; }
const ActiveTexturesCache &getActiveTexturesCache() const { return mActiveTexturesCache; }
// "onActiveTextureChange" is called when a texture binding changes.
void onActiveTextureChange(const Context *context, size_t textureUnit);
// "onActiveTextureStateChange" is called when the Texture changed but the binding did not.
void onActiveTextureStateChange(const Context *context, size_t textureUnit);
void onImageStateChange(const Context *context, size_t unit);
void onUniformBufferStateChange(size_t uniformBufferIndex, angle::SubjectMessage message);
void onAtomicCounterBufferStateChange(size_t atomicCounterBufferIndex);
void onShaderStorageBufferStateChange(size_t shaderStorageBufferIndex);
bool isCurrentTransformFeedback(const TransformFeedback *tf) const
{
return tf == mTransformFeedback.get();
}
bool isCurrentVertexArray(const VertexArray *va) const { return va == mVertexArray; }
// Helpers for setting bound buffers. They should all have the same signature.
// Not meant to be called externally. Used for local helpers in State.cpp.
template <BufferBinding Target>
void setGenericBufferBindingWithBit(const Context *context, Buffer *buffer);
template <BufferBinding Target>
void setGenericBufferBinding(const Context *context, Buffer *buffer);
using BufferBindingSetter = void (State::*)(const Context *, Buffer *);
ANGLE_INLINE bool validateSamplerFormats() const
{
return (!mExecutable || !(mTexturesIncompatibleWithSamplers.intersects(
mExecutable->getActiveSamplersMask())));
}
ANGLE_INLINE void setReadFramebufferBindingDirty()
{
mDirtyBits.set(state::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
}
ANGLE_INLINE void setDrawFramebufferBindingDirty()
{
mDirtyBits.set(state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
}
const OverlayType *getOverlay() const { return mOverlay; }
// Not for general use.
const BufferManager &getBufferManagerForCapture() const { return *mBufferManager; }
const BoundBufferMap &getBoundBuffersForCapture() const { return mBoundBuffers; }
const TextureManager &getTextureManagerForCapture() const { return *mTextureManager; }
const TextureBindingMap &getBoundTexturesForCapture() const { return mSamplerTextures; }
const RenderbufferManager &getRenderbufferManagerForCapture() const
{
return *mRenderbufferManager;
}
const FramebufferManager &getFramebufferManagerForCapture() const
{
return *mFramebufferManager;
}
const ShaderProgramManager &getShaderProgramManagerForCapture() const
{
return *mShaderProgramManager;
}
const SyncManager &getSyncManagerForCapture() const { return *mSyncManager; }
const SamplerManager &getSamplerManagerForCapture() const { return *mSamplerManager; }
const ProgramPipelineManager *getProgramPipelineManagerForCapture() const
{
return mProgramPipelineManager;
}
const SamplerBindingVector &getSamplerBindingsForCapture() const { return mSamplers; }
const ActiveQueryMap &getActiveQueriesForCapture() const { return mActiveQueries; }
void initializeForCapture(const Context *context);
bool hasConstantAlphaBlendFunc() const
{
return (getBlendFuncConstantAlphaDrawBuffers() & getBlendStateExt().getEnabledMask()).any();
}
bool hasSimultaneousConstantColorAndAlphaBlendFunc() const
{
return (getBlendFuncConstantColorDrawBuffers() & getBlendStateExt().getEnabledMask())
.any() &&
hasConstantAlphaBlendFunc();
}
const BufferVector &getOffsetBindingPointerUniformBuffers() const { return mUniformBuffers; }
const BufferVector &getOffsetBindingPointerAtomicCounterBuffers() const
{
return mAtomicCounterBuffers;
}
const BufferVector &getOffsetBindingPointerShaderStorageBuffers() const
{
return mShaderStorageBuffers;
}
ActiveTextureMask getTexturesIncompatibleWithSamplers() const
{
return mTexturesIncompatibleWithSamplers;
}
const std::vector<ImageUnit> &getImageUnits() const { return mImageUnits; }
bool hasDisplayTextureShareGroup() const { return mDisplayTextureShareGroup; }
// GL_KHR_parallel_shader_compile
void setMaxShaderCompilerThreads(GLuint count);
GLuint getMaxShaderCompilerThreads() const { return mMaxShaderCompilerThreads; }
// Convenience functions that forward to context-private state.
const RasterizerState &getRasterizerState() const { return mPrivateState.getRasterizerState(); }
const BlendState &getBlendState() const { return mPrivateState.getBlendState(); }
const BlendStateExt &getBlendStateExt() const { return mPrivateState.getBlendStateExt(); }
const DepthStencilState &getDepthStencilState() const
{
return mPrivateState.getDepthStencilState();
}
const ColorF &getColorClearValue() const { return mPrivateState.getColorClearValue(); }
float getDepthClearValue() const { return mPrivateState.getDepthClearValue(); }
int getStencilClearValue() const { return mPrivateState.getStencilClearValue(); }
bool isRasterizerDiscardEnabled() const { return mPrivateState.isRasterizerDiscardEnabled(); }
bool isPrimitiveRestartEnabled() const { return mPrivateState.isPrimitiveRestartEnabled(); }
bool isCullFaceEnabled() const { return mPrivateState.isCullFaceEnabled(); }
bool isDepthClampEnabled() const { return mPrivateState.isDepthClampEnabled(); }
bool isDepthTestEnabled() const { return mPrivateState.isDepthTestEnabled(); }
bool isDepthWriteEnabled() const { return mPrivateState.isDepthWriteEnabled(); }
float getNearPlane() const { return mPrivateState.getNearPlane(); }
float getFarPlane() const { return mPrivateState.getFarPlane(); }
ClipOrigin getClipOrigin() const { return mPrivateState.getClipOrigin(); }
ClipDepthMode getClipDepthMode() const { return mPrivateState.getClipDepthMode(); }
bool isClipDepthModeZeroToOne() const { return mPrivateState.isClipDepthModeZeroToOne(); }
bool isBlendEnabled() const { return mPrivateState.isBlendEnabled(); }
bool isBlendEnabledIndexed(GLuint index) const
{
return mPrivateState.isBlendEnabledIndexed(index);
}
DrawBufferMask getBlendEnabledDrawBufferMask() const
{
return mPrivateState.getBlendEnabledDrawBufferMask();
}
const ColorF &getBlendColor() const { return mPrivateState.getBlendColor(); }
bool isStencilTestEnabled() const { return mPrivateState.isStencilTestEnabled(); }
bool isBlendAdvancedCoherentEnabled() const
{
return mPrivateState.isBlendAdvancedCoherentEnabled();
}
bool isStencilWriteEnabled(GLuint framebufferStencilSize) const
{
return mPrivateState.isStencilWriteEnabled(framebufferStencilSize);
}
GLint getStencilRef() const { return mPrivateState.getStencilRef(); }
GLint getStencilBackRef() const { return mPrivateState.getStencilBackRef(); }
PolygonMode getPolygonMode() const { return mPrivateState.getPolygonMode(); }
bool isPolygonOffsetPointEnabled() const { return mPrivateState.isPolygonOffsetPointEnabled(); }
bool isPolygonOffsetLineEnabled() const { return mPrivateState.isPolygonOffsetLineEnabled(); }
bool isPolygonOffsetFillEnabled() const { return mPrivateState.isPolygonOffsetFillEnabled(); }
bool isPolygonOffsetEnabled() const { return mPrivateState.isPolygonOffsetEnabled(); }
bool isSampleAlphaToCoverageEnabled() const
{
return mPrivateState.isSampleAlphaToCoverageEnabled();
}
bool isSampleCoverageEnabled() const { return mPrivateState.isSampleCoverageEnabled(); }
GLclampf getSampleCoverageValue() const { return mPrivateState.getSampleCoverageValue(); }
bool getSampleCoverageInvert() const { return mPrivateState.getSampleCoverageInvert(); }
bool isSampleMaskEnabled() const { return mPrivateState.isSampleMaskEnabled(); }
GLbitfield getSampleMaskWord(GLuint maskNumber) const
{
return mPrivateState.getSampleMaskWord(maskNumber);
}
SampleMaskArray<GLbitfield> getSampleMaskValues() const
{
return mPrivateState.getSampleMaskValues();
}
GLuint getMaxSampleMaskWords() const { return mPrivateState.getMaxSampleMaskWords(); }
bool isSampleAlphaToOneEnabled() const { return mPrivateState.isSampleAlphaToOneEnabled(); }
bool isMultisamplingEnabled() const { return mPrivateState.isMultisamplingEnabled(); }
bool isSampleShadingEnabled() const { return mPrivateState.isSampleShadingEnabled(); }
float getMinSampleShading() const { return mPrivateState.getMinSampleShading(); }
bool isScissorTestEnabled() const { return mPrivateState.isScissorTestEnabled(); }
const Rectangle &getScissor() const { return mPrivateState.getScissor(); }
bool isDitherEnabled() const { return mPrivateState.isDitherEnabled(); }
bool isBindGeneratesResourceEnabled() const
{
return mPrivateState.isBindGeneratesResourceEnabled();
}
bool areClientArraysEnabled() const { return mPrivateState.areClientArraysEnabled(); }
bool isRobustResourceInitEnabled() const { return mPrivateState.isRobustResourceInitEnabled(); }
bool isProgramBinaryCacheEnabled() const { return mPrivateState.isProgramBinaryCacheEnabled(); }
const Rectangle &getViewport() const { return mPrivateState.getViewport(); }
ShadingRate getShadingRate() const { return mPrivateState.getShadingRate(); }
CombinerOp *getShadingRateCombinerOps() { return mPrivateState.getShadingRateCombinerOps(); }
GLint getPackAlignment() const { return mPrivateState.getPackAlignment(); }
bool getPackReverseRowOrder() const { return mPrivateState.getPackReverseRowOrder(); }
GLint getPackRowLength() const { return mPrivateState.getPackRowLength(); }
GLint getPackSkipRows() const { return mPrivateState.getPackSkipRows(); }
GLint getPackSkipPixels() const { return mPrivateState.getPackSkipPixels(); }
const PixelPackState &getPackState() const { return mPrivateState.getPackState(); }
PixelPackState &getPackState() { return mPrivateState.getPackState(); }
GLint getUnpackAlignment() const { return mPrivateState.getUnpackAlignment(); }
GLint getUnpackRowLength() const { return mPrivateState.getUnpackRowLength(); }
GLint getUnpackImageHeight() const { return mPrivateState.getUnpackImageHeight(); }
GLint getUnpackSkipImages() const { return mPrivateState.getUnpackSkipImages(); }
GLint getUnpackSkipRows() const { return mPrivateState.getUnpackSkipRows(); }
GLint getUnpackSkipPixels() const { return mPrivateState.getUnpackSkipPixels(); }
const PixelUnpackState &getUnpackState() const { return mPrivateState.getUnpackState(); }
PixelUnpackState &getUnpackState() { return mPrivateState.getUnpackState(); }
GLenum getCoverageModulation() const { return mPrivateState.getCoverageModulation(); }
bool getFramebufferSRGB() const { return mPrivateState.getFramebufferSRGB(); }
GLuint getPatchVertices() const { return mPrivateState.getPatchVertices(); }
GLsizei getPixelLocalStorageActivePlanes() const
{
return mPrivateState.getPixelLocalStorageActivePlanes();
}
float getLineWidth() const { return mPrivateState.getLineWidth(); }
unsigned int getActiveSampler() const { return mPrivateState.getActiveSampler(); }
GLenum getGenerateMipmapHint() const { return mPrivateState.getGenerateMipmapHint(); }
GLenum getFragmentShaderDerivativeHint() const
{
return mPrivateState.getFragmentShaderDerivativeHint();
}
ProvokingVertexConvention getProvokingVertex() const
{
return mPrivateState.getProvokingVertex();
}
const VertexAttribCurrentValueData &getVertexAttribCurrentValue(size_t attribNum) const
{
return mPrivateState.getVertexAttribCurrentValue(attribNum);
}
const std::vector<VertexAttribCurrentValueData> &getVertexAttribCurrentValues() const
{
return mPrivateState.getVertexAttribCurrentValues();
}
AttributesMask getAndResetDirtyCurrentValues() const
{
return mPrivateState.getAndResetDirtyCurrentValues();
}
ComponentTypeMask getCurrentValuesTypeMask() const
{
return mPrivateState.getCurrentValuesTypeMask();
}
const ClipDistanceEnableBits &getEnabledClipDistances() const
{
return mPrivateState.getEnabledClipDistances();
}
bool noSimultaneousConstantColorAndAlphaBlendFunc() const
{
return mPrivateState.noSimultaneousConstantColorAndAlphaBlendFunc();
}
GLfloat getBoundingBoxMinX() const { return mPrivateState.getBoundingBoxMinX(); }
GLfloat getBoundingBoxMinY() const { return mPrivateState.getBoundingBoxMinY(); }
GLfloat getBoundingBoxMinZ() const { return mPrivateState.getBoundingBoxMinZ(); }
GLfloat getBoundingBoxMinW() const { return mPrivateState.getBoundingBoxMinW(); }
GLfloat getBoundingBoxMaxX() const { return mPrivateState.getBoundingBoxMaxX(); }
GLfloat getBoundingBoxMaxY() const { return mPrivateState.getBoundingBoxMaxY(); }
GLfloat getBoundingBoxMaxZ() const { return mPrivateState.getBoundingBoxMaxZ(); }
GLfloat getBoundingBoxMaxW() const { return mPrivateState.getBoundingBoxMaxW(); }
bool isTextureRectangleEnabled() const { return mPrivateState.isTextureRectangleEnabled(); }
DrawBufferMask getBlendFuncConstantAlphaDrawBuffers() const
{
return mPrivateState.getBlendFuncConstantAlphaDrawBuffers();
}
DrawBufferMask getBlendFuncConstantColorDrawBuffers() const
{
return mPrivateState.getBlendFuncConstantColorDrawBuffers();
}
bool isLogicOpEnabled() const { return mPrivateState.isLogicOpEnabled(); }
LogicalOperation getLogicOp() const { return mPrivateState.getLogicOp(); }
bool isPerfMonitorActive() const { return mPrivateState.isPerfMonitorActive(); }
const Debug &getDebug() const { return mPrivateState.getDebug(); }
Debug &getDebug() { return mPrivateState.getDebug(); }
const BlobCacheCallbacks &getBlobCacheCallbacks() const
{
return mPrivateState.getBlobCacheCallbacks();
}
BlobCacheCallbacks &getBlobCacheCallbacks() { return mPrivateState.getBlobCacheCallbacks(); }
bool getEnableFeature(GLenum feature) const { return mPrivateState.getEnableFeature(feature); }
bool getEnableFeatureIndexed(GLenum feature, GLuint index) const
{
return mPrivateState.getEnableFeatureIndexed(feature, index);
}
ProgramUniformBlockMask getAndResetDirtyUniformBlocks() const
{
ProgramUniformBlockMask dirtyBits = mDirtyUniformBlocks;
mDirtyUniformBlocks.reset();
return dirtyBits;
}
BufferDirtyTypeBitMask getAndResetUniformBufferBlocksDirtyTypeMask() const
{
BufferDirtyTypeBitMask dirtyTypeMask = mUniformBufferBlocksDirtyTypeMask;
mUniformBufferBlocksDirtyTypeMask.reset();
return dirtyTypeMask;
}
const PrivateState &privateState() const { return mPrivateState; }
const GLES1State &gles1() const { return mPrivateState.gles1(); }
// Used by the capture/replay tool to create state.
PrivateState *getMutablePrivateStateForCapture() { return &mPrivateState; }
private:
friend class Context;
// Used only by the entry points to set private state without holding the share group lock.
PrivateState *getMutablePrivateState() { return &mPrivateState; }
GLES1State *getMutableGLES1State() { return mPrivateState.getMutableGLES1State(); }
angle::Result installProgramPipelineExecutableIfNotAlready(const Context *context);
angle::Result onExecutableChange(const Context *context);
void unsetActiveTextures(const ActiveTextureMask &textureMask);
void setActiveTextureDirty(size_t textureIndex, Texture *texture);
void updateTextureBinding(const Context *context, size_t textureIndex, Texture *texture);
void updateActiveTextureStateOnSync(const Context *context,
size_t textureIndex,
const Sampler *sampler,
Texture *texture);
Texture *getTextureForActiveSampler(TextureType type, size_t index);
// Functions to synchronize dirty states
angle::Result syncActiveTextures(const Context *context, Command command);
angle::Result syncTexturesInit(const Context *context, Command command);
angle::Result syncImagesInit(const Context *context, Command command);
angle::Result syncReadAttachments(const Context *context, Command command);
angle::Result syncDrawAttachments(const Context *context, Command command);
angle::Result syncReadFramebuffer(const Context *context, Command command);
angle::Result syncDrawFramebuffer(const Context *context, Command command);
angle::Result syncVertexArray(const Context *context, Command command);
angle::Result syncTextures(const Context *context, Command command);
angle::Result syncImages(const Context *context, Command command);
angle::Result syncSamplers(const Context *context, Command command);
angle::Result syncProgramPipelineObject(const Context *context, Command command);
using DirtyObjectHandler = angle::Result (State::*)(const Context *context, Command command);
using DirtyObjectHandlerArray = std::array<DirtyObjectHandler, state::DIRTY_OBJECT_MAX>;
static constexpr DirtyObjectHandlerArray MakeDirtyObjectHandlers()
{
// Work around C++'s lack of array element support in designated initializers
// This function cannot be a lambda due to MSVC C++17 limitations b/330910097#comment5
DirtyObjectHandlerArray handlers{};
handlers[state::DIRTY_OBJECT_ACTIVE_TEXTURES] = &State::syncActiveTextures;
handlers[state::DIRTY_OBJECT_TEXTURES_INIT] = &State::syncTexturesInit;
handlers[state::DIRTY_OBJECT_IMAGES_INIT] = &State::syncImagesInit;
handlers[state::DIRTY_OBJECT_READ_ATTACHMENTS] = &State::syncReadAttachments;
handlers[state::DIRTY_OBJECT_DRAW_ATTACHMENTS] = &State::syncDrawAttachments;
handlers[state::DIRTY_OBJECT_READ_FRAMEBUFFER] = &State::syncReadFramebuffer;
handlers[state::DIRTY_OBJECT_DRAW_FRAMEBUFFER] = &State::syncDrawFramebuffer;
handlers[state::DIRTY_OBJECT_VERTEX_ARRAY] = &State::syncVertexArray;
handlers[state::DIRTY_OBJECT_TEXTURES] = &State::syncTextures;
handlers[state::DIRTY_OBJECT_IMAGES] = &State::syncImages;
handlers[state::DIRTY_OBJECT_SAMPLERS] = &State::syncSamplers;
handlers[state::DIRTY_OBJECT_PROGRAM_PIPELINE_OBJECT] = &State::syncProgramPipelineObject;
// If a handler is missing, reset everything for ease of static_assert
for (auto handler : handlers)
{
if (handler == nullptr)
{
return DirtyObjectHandlerArray();
}
}
return handlers;
}
angle::Result dirtyObjectHandler(size_t dirtyObject, const Context *context, Command command)
{
static constexpr DirtyObjectHandlerArray handlers = MakeDirtyObjectHandlers();
static_assert(handlers[0] != nullptr, "MakeDirtyObjectHandlers missing a handler");
return (this->*handlers[dirtyObject])(context, command);
}
// Robust init must happen before Framebuffer init for the Vulkan back-end.
static_assert(state::DIRTY_OBJECT_ACTIVE_TEXTURES < state::DIRTY_OBJECT_TEXTURES_INIT,
"init order");
static_assert(state::DIRTY_OBJECT_TEXTURES_INIT < state::DIRTY_OBJECT_DRAW_FRAMEBUFFER,
"init order");
static_assert(state::DIRTY_OBJECT_IMAGES_INIT < state::DIRTY_OBJECT_DRAW_FRAMEBUFFER,
"init order");
static_assert(state::DIRTY_OBJECT_DRAW_ATTACHMENTS < state::DIRTY_OBJECT_DRAW_FRAMEBUFFER,
"init order");
static_assert(state::DIRTY_OBJECT_READ_ATTACHMENTS < state::DIRTY_OBJECT_READ_FRAMEBUFFER,
"init order");
// Dispatch table for buffer update functions.
static const angle::PackedEnumMap<BufferBinding, BufferBindingSetter> kBufferSetters;
ContextID mID;
EGLenum mContextPriority;
bool mHasRobustAccess;
bool mHasProtectedContent;
bool mIsDebugContext;
egl::ShareGroup *mShareGroup;
mutable egl::ContextMutex mContextMutex;
// Resource managers.
BufferManager *mBufferManager;
ShaderProgramManager *mShaderProgramManager;
TextureManager *mTextureManager;
RenderbufferManager *mRenderbufferManager;
SamplerManager *mSamplerManager;
SyncManager *mSyncManager;
FramebufferManager *mFramebufferManager;
ProgramPipelineManager *mProgramPipelineManager;
MemoryObjectManager *mMemoryObjectManager;
SemaphoreManager *mSemaphoreManager;
Framebuffer *mReadFramebuffer;
Framebuffer *mDrawFramebuffer;
BindingPointer<Renderbuffer> mRenderbuffer;
Program *mProgram;
BindingPointer<ProgramPipeline> mProgramPipeline;
// The _installed_ executable. Note that this may be different from the program's (or the
// program pipeline's) executable, as they may have been unsuccessfully relinked.
SharedProgramExecutable mExecutable;
VertexArray *mVertexArray;
TextureBindingMap mSamplerTextures;
// Active Textures Cache
// ---------------------
// The active textures cache gives ANGLE components access to a complete array of textures
// on a draw call. gl::State implements angle::Observer and watches gl::Texture for state
// changes via the onSubjectStateChange method above. We update the cache before draws.
// See Observer.h and the design doc linked there for more info on Subject/Observer events.
//
// On state change events (re-binding textures, samplers, programs etc) we clear the cache
// and flag dirty bits. nullptr indicates unbound or incomplete.
ActiveTexturesCache mActiveTexturesCache;
std::vector<angle::ObserverBinding> mCompleteTextureBindings;
ActiveTextureMask mTexturesIncompatibleWithSamplers;
SamplerBindingVector mSamplers;
// It would be nice to merge the image and observer binding. Same for textures.
std::vector<ImageUnit> mImageUnits;
ActiveQueryMap mActiveQueries;
// Stores the currently bound buffer for each binding point. It has an entry for the element
// array buffer but it should not be used. Instead this bind point is owned by the current
// vertex array object.
BoundBufferMap mBoundBuffers;
BufferVector mUniformBuffers;
BufferVector mAtomicCounterBuffers;
BufferVector mShaderStorageBuffers;
angle::BitSet<gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS> mBoundUniformBuffersMask;
angle::BitSet<gl::IMPLEMENTATION_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS>
mBoundAtomicCounterBuffersMask;
angle::BitSet<gl::IMPLEMENTATION_MAX_SHADER_STORAGE_BUFFER_BINDINGS>
mBoundShaderStorageBuffersMask;
BindingPointer<TransformFeedback> mTransformFeedback;
bool mDisplayTextureShareGroup;
// GL_KHR_parallel_shader_compile
GLuint mMaxShaderCompilerThreads;
// The Overlay object, used by the backend to render the overlay.
const OverlayType *mOverlay;
state::DirtyBits mDirtyBits;
state::ExtendedDirtyBits mExtendedDirtyBits;
state::DirtyObjects mDirtyObjects;
ActiveTextureMask mDirtyActiveTextures;
ActiveTextureMask mDirtyTextures;
ActiveTextureMask mDirtySamplers;
ImageUnitMask mDirtyImages;
// Tracks uniform blocks that need reprocessing, for example because their mapped bindings have
// changed, or buffers in their mapped bindings have changed. This is in State because every
// context needs to react to such changes.
mutable ProgramUniformBlockMask mDirtyUniformBlocks;
// Fine grained dirty type for uniform buffers.
mutable BufferDirtyTypeBitMask mUniformBufferBlocksDirtyTypeMask;
PrivateState mPrivateState;
};
ANGLE_INLINE angle::Result State::syncDirtyObjects(const Context *context,
const state::DirtyObjects &bitset,
Command command)
{
// Accumulate any dirty objects that might have been set due to context-private state changes.
mDirtyObjects |= mPrivateState.getDirtyObjects();
mPrivateState.clearDirtyObjects();
ASSERT(isRobustResourceInitEnabled() ||
(!mDirtyObjects.test(state::DIRTY_OBJECT_DRAW_ATTACHMENTS) &&
!mDirtyObjects.test(state::DIRTY_OBJECT_READ_ATTACHMENTS)));
const state::DirtyObjects &dirtyObjects = mDirtyObjects & bitset;
for (size_t dirtyObject : dirtyObjects)
{
ANGLE_TRY(dirtyObjectHandler(dirtyObject, context, command));
}
mDirtyObjects &= ~dirtyObjects;
return angle::Result::Continue;
}
} // namespace gl
#endif // LIBANGLE_STATE_H_