mirrored from https://chromium.googlesource.com/angle/angle
-
Notifications
You must be signed in to change notification settings - Fork 644
/
Copy pathContext.cpp
10552 lines (9240 loc) · 380 KB
/
Context.cpp
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
//
// Copyright 2002 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.
//
// Context.cpp: Implements the gl::Context class, managing all GL state and performing
// rendering operations. It is the GLES2 specific implementation of EGLContext.
#include "libANGLE/Context.inl.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <iterator>
#include <sstream>
#include <vector>
#include "common/PackedEnums.h"
#include "common/angle_version_info.h"
#include "common/hash_utils.h"
#include "common/matrix_utils.h"
#include "common/platform.h"
#include "common/string_utils.h"
#include "common/system_utils.h"
#include "common/tls.h"
#include "common/utilities.h"
#include "image_util/loadimage.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Display.h"
#include "libANGLE/ErrorStrings.h"
#include "libANGLE/Fence.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/MemoryObject.h"
#include "libANGLE/PixelLocalStorage.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramPipeline.h"
#include "libANGLE/Query.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/ResourceManager.h"
#include "libANGLE/Sampler.h"
#include "libANGLE/Semaphore.h"
#include "libANGLE/Surface.h"
#include "libANGLE/Texture.h"
#include "libANGLE/TransformFeedback.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/capture/FrameCapture.h"
#include "libANGLE/capture/serialize.h"
#include "libANGLE/context_private_call.inl.h"
#include "libANGLE/context_private_call_autogen.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/renderer/DisplayImpl.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/trace.h"
#include "libANGLE/validationES.h"
#if defined(ANGLE_PLATFORM_APPLE)
# include <dispatch/dispatch.h>
# include "common/tls.h"
#endif
namespace gl
{
namespace
{
constexpr state::DirtyObjects kDrawDirtyObjectsBase{
state::DIRTY_OBJECT_ACTIVE_TEXTURES,
state::DIRTY_OBJECT_DRAW_FRAMEBUFFER,
state::DIRTY_OBJECT_VERTEX_ARRAY,
state::DIRTY_OBJECT_TEXTURES,
state::DIRTY_OBJECT_PROGRAM_PIPELINE_OBJECT,
state::DIRTY_OBJECT_SAMPLERS,
state::DIRTY_OBJECT_IMAGES,
};
// TexImage uses the unpack state
constexpr state::DirtyBits kTexImageDirtyBits{
state::DIRTY_BIT_UNPACK_STATE,
state::DIRTY_BIT_UNPACK_BUFFER_BINDING,
};
constexpr state::ExtendedDirtyBits kTexImageExtendedDirtyBits{};
constexpr state::DirtyObjects kTexImageDirtyObjects{};
// Readpixels uses the pack state and read FBO
constexpr state::DirtyBits kReadPixelsDirtyBits{
state::DIRTY_BIT_PACK_STATE,
state::DIRTY_BIT_PACK_BUFFER_BINDING,
state::DIRTY_BIT_READ_FRAMEBUFFER_BINDING,
};
constexpr state::ExtendedDirtyBits kReadPixelsExtendedDirtyBits{};
constexpr state::DirtyObjects kReadPixelsDirtyObjectsBase{state::DIRTY_OBJECT_READ_FRAMEBUFFER};
// We sync the draw Framebuffer manually in prepareForClear to allow the clear calls to do
// more custom handling for robust resource init.
constexpr state::DirtyBits kClearDirtyBits{
state::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED,
state::DIRTY_BIT_SCISSOR_TEST_ENABLED,
state::DIRTY_BIT_SCISSOR,
state::DIRTY_BIT_VIEWPORT,
state::DIRTY_BIT_CLEAR_COLOR,
state::DIRTY_BIT_CLEAR_DEPTH,
state::DIRTY_BIT_CLEAR_STENCIL,
state::DIRTY_BIT_COLOR_MASK,
state::DIRTY_BIT_DEPTH_MASK,
state::DIRTY_BIT_STENCIL_WRITEMASK_FRONT,
state::DIRTY_BIT_STENCIL_WRITEMASK_BACK,
state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING,
};
constexpr state::ExtendedDirtyBits kClearExtendedDirtyBits{};
constexpr state::DirtyObjects kClearDirtyObjects{state::DIRTY_OBJECT_DRAW_FRAMEBUFFER};
constexpr state::DirtyBits kBlitDirtyBits{
state::DIRTY_BIT_SCISSOR_TEST_ENABLED,
state::DIRTY_BIT_SCISSOR,
state::DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE,
state::DIRTY_BIT_READ_FRAMEBUFFER_BINDING,
state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING,
};
constexpr state::ExtendedDirtyBits kBlitExtendedDirtyBits{};
constexpr state::DirtyObjects kBlitDirtyObjectsBase{
state::DIRTY_OBJECT_READ_FRAMEBUFFER,
state::DIRTY_OBJECT_DRAW_FRAMEBUFFER,
};
constexpr state::DirtyBits kComputeDirtyBits{
state::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING,
state::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS,
state::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING,
state::DIRTY_BIT_PROGRAM_BINDING,
state::DIRTY_BIT_PROGRAM_EXECUTABLE,
state::DIRTY_BIT_TEXTURE_BINDINGS,
state::DIRTY_BIT_SAMPLER_BINDINGS,
state::DIRTY_BIT_IMAGE_BINDINGS,
state::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING,
};
constexpr state::ExtendedDirtyBits kComputeExtendedDirtyBits{};
constexpr state::DirtyObjects kComputeDirtyObjectsBase{
state::DIRTY_OBJECT_ACTIVE_TEXTURES,
state::DIRTY_OBJECT_TEXTURES,
state::DIRTY_OBJECT_PROGRAM_PIPELINE_OBJECT,
state::DIRTY_OBJECT_IMAGES,
state::DIRTY_OBJECT_SAMPLERS,
};
constexpr state::DirtyBits kCopyImageDirtyBitsBase{state::DIRTY_BIT_READ_FRAMEBUFFER_BINDING};
constexpr state::ExtendedDirtyBits kCopyImageExtendedDirtyBits{};
constexpr state::DirtyObjects kCopyImageDirtyObjectsBase{state::DIRTY_OBJECT_READ_FRAMEBUFFER};
constexpr state::DirtyBits kReadInvalidateDirtyBits{state::DIRTY_BIT_READ_FRAMEBUFFER_BINDING};
constexpr state::ExtendedDirtyBits kReadInvalidateExtendedDirtyBits{};
constexpr state::DirtyBits kDrawInvalidateDirtyBits{state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING};
constexpr state::ExtendedDirtyBits kDrawInvalidateExtendedDirtyBits{};
constexpr state::DirtyBits kTilingDirtyBits{state::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING};
constexpr state::ExtendedDirtyBits kTilingExtendedDirtyBits{};
constexpr state::DirtyObjects kTilingDirtyObjects{state::DIRTY_OBJECT_DRAW_FRAMEBUFFER};
constexpr bool kEnableAEPRequirementLogging = false;
egl::ShareGroup *AllocateOrGetShareGroup(egl::Display *display, const gl::Context *shareContext)
{
if (shareContext)
{
egl::ShareGroup *shareGroup = shareContext->getState().getShareGroup();
shareGroup->addRef();
return shareGroup;
}
else
{
return new egl::ShareGroup(display->getImplementation());
}
}
egl::ContextMutex *AllocateOrUseContextMutex(egl::ContextMutex *sharedContextMutex)
{
if (sharedContextMutex != nullptr)
{
ASSERT(egl::kIsContextMutexEnabled);
ASSERT(sharedContextMutex->isReferenced());
return sharedContextMutex;
}
return new egl::ContextMutex();
}
template <typename T>
angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
{
if (!query)
{
// Some applications call into glGetQueryObjectuiv(...) prior to calling glBeginQuery(...)
// This wouldn't be an issue since the validation layer will handle such a usecases but when
// the app enables EGL_KHR_create_context_no_error extension, we skip the validation layer.
switch (pname)
{
case GL_QUERY_RESULT_EXT:
*params = 0;
break;
case GL_QUERY_RESULT_AVAILABLE_EXT:
*params = GL_FALSE;
break;
default:
UNREACHABLE();
return angle::Result::Stop;
}
return angle::Result::Continue;
}
switch (pname)
{
case GL_QUERY_RESULT_EXT:
return query->getResult(context, params);
case GL_QUERY_RESULT_AVAILABLE_EXT:
{
bool available = false;
if (context->isContextLost())
{
context->contextLostErrorOnBlockingCall(angle::EntryPoint::GLGetQueryObjectuiv);
available = true;
}
else
{
ANGLE_TRY(query->isResultAvailable(context, &available));
}
*params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
return angle::Result::Continue;
}
default:
UNREACHABLE();
return angle::Result::Stop;
}
}
// Attribute map queries.
EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
{
return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
}
EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
{
return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
}
bool GetBackwardCompatibleContext(const egl::AttributeMap &attribs)
{
return attribs.get(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_TRUE) == EGL_TRUE;
}
bool GetWebGLContext(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
}
Version GetClientVersion(egl::Display *display, const egl::AttributeMap &attribs)
{
const Version requestedVersion(static_cast<uint8_t>(GetClientMajorVersion(attribs)),
static_cast<uint8_t>(GetClientMinorVersion(attribs)));
if (GetBackwardCompatibleContext(attribs))
{
if (requestedVersion < ES_2_0)
{
// If the user requests an ES1 context, we cannot return an ES 2+ context.
return Version(1, 1);
}
else
{
// Always up the version to at least the max conformant version this display supports.
// Only return a higher client version if requested.
const Version conformantVersion = std::max(
display->getImplementation()->getMaxConformantESVersion(), requestedVersion);
// Limit the WebGL context to at most version 3.1
const bool isWebGL = GetWebGLContext(attribs);
return isWebGL ? std::min(conformantVersion, Version(3, 1)) : conformantVersion;
}
}
else
{
return requestedVersion;
}
}
GLenum GetResetStrategy(const egl::AttributeMap &attribs)
{
EGLAttrib resetStrategyExt =
attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
EGLAttrib resetStrategyCore =
attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY, resetStrategyExt);
switch (resetStrategyCore)
{
case EGL_NO_RESET_NOTIFICATION:
return GL_NO_RESET_NOTIFICATION_EXT;
case EGL_LOSE_CONTEXT_ON_RESET:
return GL_LOSE_CONTEXT_ON_RESET_EXT;
default:
UNREACHABLE();
return GL_NONE;
}
}
bool GetRobustAccess(const egl::AttributeMap &attribs)
{
EGLAttrib robustAccessExt = attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE);
EGLAttrib robustAccessCore = attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS, robustAccessExt);
bool attribRobustAccess = (robustAccessCore == EGL_TRUE);
bool contextFlagsRobustAccess =
((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0);
return (attribRobustAccess || contextFlagsRobustAccess);
}
bool GetDebug(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
}
bool GetNoError(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
}
bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
{
// If the context is WebGL, extensions are disabled by default
EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
}
bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
}
bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
}
bool GetRobustResourceInit(egl::Display *display, const egl::AttributeMap &attribs)
{
const angle::FrontendFeatures &frontendFeatures = display->getFrontendFeatures();
return (frontendFeatures.forceRobustResourceInit.enabled ||
attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
}
EGLenum GetContextPriority(const egl::AttributeMap &attribs)
{
return static_cast<EGLenum>(
attribs.getAsInt(EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_MEDIUM_IMG));
}
bool GetProtectedContent(const egl::AttributeMap &attribs)
{
return static_cast<bool>(attribs.getAsInt(EGL_PROTECTED_CONTENT_EXT, EGL_FALSE));
}
std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
{
std::string labelName;
if (label != nullptr)
{
size_t labelLength = length < 0 ? strlen(label) : length;
labelName = std::string(label, labelLength);
}
return labelName;
}
void GetObjectLabelBase(const std::string &objectLabel,
GLsizei bufSize,
GLsizei *length,
GLchar *label)
{
size_t writeLength = objectLabel.length();
if (label != nullptr && bufSize > 0)
{
writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
label[writeLength] = '\0';
}
if (length != nullptr)
{
*length = static_cast<GLsizei>(writeLength);
}
}
enum SubjectIndexes : angle::SubjectIndex
{
kTexture0SubjectIndex = 0,
kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
kImage0SubjectIndex = kTextureMaxSubjectIndex,
kImageMaxSubjectIndex = kImage0SubjectIndex + IMPLEMENTATION_MAX_IMAGE_UNITS,
kUniformBuffer0SubjectIndex = kImageMaxSubjectIndex,
kUniformBufferMaxSubjectIndex =
kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
kAtomicCounterBuffer0SubjectIndex = kUniformBufferMaxSubjectIndex,
kAtomicCounterBufferMaxSubjectIndex =
kAtomicCounterBuffer0SubjectIndex + IMPLEMENTATION_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS,
kShaderStorageBuffer0SubjectIndex = kAtomicCounterBufferMaxSubjectIndex,
kShaderStorageBufferMaxSubjectIndex =
kShaderStorageBuffer0SubjectIndex + IMPLEMENTATION_MAX_SHADER_STORAGE_BUFFER_BINDINGS,
kSampler0SubjectIndex = kShaderStorageBufferMaxSubjectIndex,
kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
kReadFramebufferSubjectIndex,
kDrawFramebufferSubjectIndex,
kProgramSubjectIndex,
kProgramPipelineSubjectIndex,
};
bool IsClearBufferEnabled(const FramebufferState &fbState, GLenum buffer, GLint drawbuffer)
{
return buffer != GL_COLOR || fbState.getEnabledDrawBuffers()[drawbuffer];
}
bool IsColorMaskedOut(const BlendStateExt &blendStateExt, const GLint drawbuffer)
{
ASSERT(static_cast<size_t>(drawbuffer) < blendStateExt.getDrawBufferCount());
return blendStateExt.getColorMaskIndexed(static_cast<size_t>(drawbuffer)) == 0;
}
bool GetIsExternal(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_EXTERNAL_CONTEXT_ANGLE, EGL_FALSE) == EGL_TRUE);
}
void GetPerfMonitorString(const std::string &name,
GLsizei bufSize,
GLsizei *length,
GLchar *stringOut)
{
GLsizei numCharsWritten = std::min(bufSize, static_cast<GLsizei>(name.size()));
if (length)
{
if (bufSize == 0)
{
*length = static_cast<GLsizei>(name.size());
}
else
{
// Excludes null terminator.
ASSERT(numCharsWritten > 0);
*length = numCharsWritten - 1;
}
}
if (stringOut)
{
memcpy(stringOut, name.c_str(), numCharsWritten);
}
}
bool CanSupportAEP(const gl::Version &version, const gl::Extensions &extensions)
{
// From the GL_ANDROID_extension_pack_es31a extension spec:
// OpenGL ES 3.1 and GLSL ES 3.10 are required.
// The following extensions are required:
// * KHR_debug
// * KHR_texture_compression_astc_ldr
// * KHR_blend_equation_advanced
// * OES_sample_shading
// * OES_sample_variables
// * OES_shader_image_atomic
// * OES_shader_multisample_interpolation
// * OES_texture_stencil8
// * OES_texture_storage_multisample_2d_array
// * EXT_copy_image
// * EXT_draw_buffers_indexed
// * EXT_geometry_shader
// * EXT_gpu_shader5
// * EXT_primitive_bounding_box
// * EXT_shader_io_blocks
// * EXT_tessellation_shader
// * EXT_texture_border_clamp
// * EXT_texture_buffer
// * EXT_texture_cube_map_array
// * EXT_texture_sRGB_decode
std::pair<const char *, bool> requirements[] = {
{"version >= ES_3_1", version >= ES_3_1},
{"extensions.debugKHR", extensions.debugKHR},
{"extensions.textureCompressionAstcLdrKHR", extensions.textureCompressionAstcLdrKHR},
{"extensions.blendEquationAdvancedKHR", extensions.blendEquationAdvancedKHR},
{"extensions.sampleShadingOES", extensions.sampleShadingOES},
{"extensions.sampleVariablesOES", extensions.sampleVariablesOES},
{"extensions.shaderImageAtomicOES", extensions.shaderImageAtomicOES},
{"extensions.shaderMultisampleInterpolationOES",
extensions.shaderMultisampleInterpolationOES},
{"extensions.textureStencil8OES", extensions.textureStencil8OES},
{"extensions.textureStorageMultisample2dArrayOES",
extensions.textureStorageMultisample2dArrayOES},
{"extensions.copyImageEXT", extensions.copyImageEXT},
{"extensions.drawBuffersIndexedEXT", extensions.drawBuffersIndexedEXT},
{"extensions.geometryShaderEXT", extensions.geometryShaderEXT},
{"extensions.gpuShader5EXT", extensions.gpuShader5EXT},
{"extensions.primitiveBoundingBoxEXT", extensions.primitiveBoundingBoxEXT},
{"extensions.shaderIoBlocksEXT", extensions.shaderIoBlocksEXT},
{"extensions.tessellationShaderEXT", extensions.tessellationShaderEXT},
{"extensions.textureBorderClampEXT", extensions.textureBorderClampEXT},
{"extensions.textureBufferEXT", extensions.textureBufferEXT},
{"extensions.textureCubeMapArrayEXT", extensions.textureCubeMapArrayEXT},
{"extensions.textureSRGBDecodeEXT", extensions.textureSRGBDecodeEXT},
};
bool result = true;
for (const auto &req : requirements)
{
result = result && req.second;
}
if (kEnableAEPRequirementLogging && !result)
{
INFO() << "CanSupportAEP() check failed for missing the following requirements:\n";
for (const auto &req : requirements)
{
if (!req.second)
{
INFO() << "- " << req.first << "\n";
}
}
}
return result;
}
// Temporarily turns off draw buffers being used for pixel local storage, and only if the PLS
// implementation is framebuffer fetch.
//
// NOTE: This is a little nonstandard because the glDrawBuffers entrypoint is supposed to disable
// PLS, but since we only call it when the implementation is
// ShPixelLocalStorageType::FramebufferFetch, it's not a problem.
class ScopedPLSFramebufferFetchDrawBuffersDisable
{
public:
ScopedPLSFramebufferFetchDrawBuffersDisable(Context *context) : mContext(context)
{
GLsizei nonPLSDrawBufferCount;
if (mContext->getImplementation()->getNativePixelLocalStorageOptions().type ==
ShPixelLocalStorageType::FramebufferFetch &&
mContext->getPrivateState().hasActivelyOverriddenPLSDrawBuffers(&nonPLSDrawBufferCount))
{
// Turn off the PLS draw buffers.
mHasPLSDrawBuffersWithFramebufferFetch = true;
Framebuffer *drawFramebuffer = mContext->getState().getDrawFramebuffer();
// PLS isn't supported on the default framebuffer.
ASSERT(!drawFramebuffer->isDefault());
const DrawBuffersVector<GLenum> &drawBuffers = drawFramebuffer->getDrawBufferStates();
ASSERT(drawBuffers.size() <= std::size(mOriginalDrawBufferState));
std::copy(drawBuffers.begin(), drawBuffers.end(), mOriginalDrawBufferState.data());
mOriginalDrawBufferCount = static_cast<GLsizei>(drawBuffers.size());
// Turn off all non-PLS draw buffers.
mContext->drawBuffers(std::min(mOriginalDrawBufferCount, nonPLSDrawBufferCount),
mOriginalDrawBufferState.data());
}
}
~ScopedPLSFramebufferFetchDrawBuffersDisable()
{
if (mHasPLSDrawBuffersWithFramebufferFetch)
{
// Restore the PLS draw buffers.
mContext->drawBuffers(mOriginalDrawBufferCount, mOriginalDrawBufferState.data());
}
}
private:
Context *const mContext;
bool mHasPLSDrawBuffersWithFramebufferFetch = false;
std::array<GLenum, IMPLEMENTATION_MAX_DRAW_BUFFERS> mOriginalDrawBufferState;
GLsizei mOriginalDrawBufferCount;
};
} // anonymous namespace
#if defined(ANGLE_PLATFORM_APPLE)
// TODO(angleproject:6479): Due to a bug in Apple's dyld loader, `thread_local` will cause
// excessive memory use. Temporarily avoid it by using pthread's thread
// local storage instead.
static angle::TLSIndex GetCurrentValidContextTLSIndex()
{
static angle::TLSIndex CurrentValidContextIndex = TLS_INVALID_INDEX;
static dispatch_once_t once;
dispatch_once(&once, ^{
ASSERT(CurrentValidContextIndex == TLS_INVALID_INDEX);
CurrentValidContextIndex = angle::CreateTLSIndex(nullptr);
});
return CurrentValidContextIndex;
}
Context *GetCurrentValidContextTLS()
{
angle::TLSIndex CurrentValidContextIndex = GetCurrentValidContextTLSIndex();
ASSERT(CurrentValidContextIndex != TLS_INVALID_INDEX);
return static_cast<Context *>(angle::GetTLSValue(CurrentValidContextIndex));
}
void SetCurrentValidContextTLS(Context *context)
{
angle::TLSIndex CurrentValidContextIndex = GetCurrentValidContextTLSIndex();
ASSERT(CurrentValidContextIndex != TLS_INVALID_INDEX);
angle::SetTLSValue(CurrentValidContextIndex, context);
}
#elif defined(ANGLE_USE_STATIC_THREAD_LOCAL_VARIABLES)
static thread_local Context *gCurrentValidContext = nullptr;
Context *GetCurrentValidContextTLS()
{
return gCurrentValidContext;
}
void SetCurrentValidContextTLS(Context *context)
{
gCurrentValidContext = context;
}
#else
thread_local Context *gCurrentValidContext = nullptr;
#endif
// Handle setting the current context in TLS on different platforms
extern void SetCurrentValidContext(Context *context)
{
#if defined(ANGLE_USE_ANDROID_TLS_SLOT)
if (angle::gUseAndroidOpenGLTlsSlot)
{
ANGLE_ANDROID_GET_GL_TLS()[angle::kAndroidOpenGLTlsSlot] = static_cast<void *>(context);
return;
}
#endif
#if defined(ANGLE_PLATFORM_APPLE) || defined(ANGLE_USE_STATIC_THREAD_LOCAL_VARIABLES)
SetCurrentValidContextTLS(context);
#else
gCurrentValidContext = context;
#endif
}
Context::Context(egl::Display *display,
const egl::Config *config,
const Context *shareContext,
TextureManager *shareTextures,
SemaphoreManager *shareSemaphores,
egl::ContextMutex *sharedContextMutex,
MemoryProgramCache *memoryProgramCache,
MemoryShaderCache *memoryShaderCache,
const egl::AttributeMap &attribs,
const egl::DisplayExtensions &displayExtensions,
const egl::ClientExtensions &clientExtensions)
: mState(shareContext ? &shareContext->mState : nullptr,
AllocateOrGetShareGroup(display, shareContext),
shareTextures,
shareSemaphores,
AllocateOrUseContextMutex(sharedContextMutex),
&mOverlay,
GetClientVersion(display, attribs),
GetDebug(attribs),
GetBindGeneratesResource(attribs),
GetClientArraysEnabled(attribs),
GetRobustResourceInit(display, attribs),
memoryProgramCache != nullptr,
GetContextPriority(attribs),
GetRobustAccess(attribs),
GetProtectedContent(attribs),
GetIsExternal(attribs)),
mShared(shareContext != nullptr || shareTextures != nullptr || shareSemaphores != nullptr),
mDisplayTextureShareGroup(shareTextures != nullptr),
mDisplaySemaphoreShareGroup(shareSemaphores != nullptr),
mErrors(&mState.getDebug(), display->getFrontendFeatures(), attribs),
mImplementation(display->getImplementation()
->createContext(mState, &mErrors, config, shareContext, attribs)),
mLabel(nullptr),
mCompiler(),
mConfig(config),
mHasBeenCurrent(false),
mSurfacelessSupported(displayExtensions.surfacelessContext),
mCurrentDrawSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mCurrentReadSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mDisplay(display),
mWebGLContext(GetWebGLContext(attribs)),
mBufferAccessValidationEnabled(false),
mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
mMemoryProgramCache(memoryProgramCache),
mMemoryShaderCache(memoryShaderCache),
mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
mProgramObserverBinding(this, kProgramSubjectIndex),
mProgramPipelineObserverBinding(this, kProgramPipelineSubjectIndex),
mFrameCapture(new angle::FrameCapture),
mRefCount(0),
mOverlay(mImplementation.get()),
mIsDestroyed(false)
{
for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
{
mUniformBufferObserverBindings.emplace_back(this, uboIndex);
}
for (angle::SubjectIndex acbIndex = kAtomicCounterBuffer0SubjectIndex;
acbIndex < kAtomicCounterBufferMaxSubjectIndex; ++acbIndex)
{
mAtomicCounterBufferObserverBindings.emplace_back(this, acbIndex);
}
for (angle::SubjectIndex ssboIndex = kShaderStorageBuffer0SubjectIndex;
ssboIndex < kShaderStorageBufferMaxSubjectIndex; ++ssboIndex)
{
mShaderStorageBufferObserverBindings.emplace_back(this, ssboIndex);
}
for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
{
mSamplerObserverBindings.emplace_back(this, samplerIndex);
}
for (angle::SubjectIndex imageIndex = kImage0SubjectIndex; imageIndex < kImageMaxSubjectIndex;
++imageIndex)
{
mImageObserverBindings.emplace_back(this, imageIndex);
}
// Implementations now require the display to be set at context creation.
ASSERT(mDisplay);
}
egl::Error Context::initialize()
{
if (!mImplementation)
{
return egl::Error(EGL_NOT_INITIALIZED, "native context creation failed");
}
// If the final context version created (with backwards compatibility possibly added in),
// generate an error if it's higher than the maximum supported version for the display. This
// validation is always done even with EGL validation disabled because it's not possible to
// detect ahead of time if an ES 3.1 context is supported (no ES_31_BIT) or if
// KHR_no_config_context is used.
if (getClientVersion() > getDisplay()->getMaxSupportedESVersion())
{
return egl::Error(EGL_BAD_ATTRIBUTE, "Requested version is not supported");
}
return egl::NoError();
}
void Context::initializeDefaultResources()
{
mImplementation->setMemoryProgramCache(mMemoryProgramCache);
initCaps();
mState.initialize(this);
mDefaultFramebuffer = std::make_unique<Framebuffer>(this, mImplementation.get());
mFenceNVHandleAllocator.setBaseHandle(0);
// [OpenGL ES 2.0.24] section 3.7 page 83:
// In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
// and cube map texture state vectors respectively associated with them.
// In order that access to these initial textures not be lost, they are treated as texture
// objects all of whose names are 0.
Texture *zeroTexture2D = new Texture(mImplementation.get(), {0}, TextureType::_2D);
mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Texture *zeroTextureCube = new Texture(mImplementation.get(), {0}, TextureType::CubeMap);
mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
if (getClientVersion() >= Version(3, 0) || mSupportedExtensions.texture3DOES)
{
Texture *zeroTexture3D = new Texture(mImplementation.get(), {0}, TextureType::_3D);
mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
}
if (getClientVersion() >= Version(3, 0))
{
Texture *zeroTexture2DArray =
new Texture(mImplementation.get(), {0}, TextureType::_2DArray);
mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
}
if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisampleANGLE)
{
Texture *zeroTexture2DMultisample =
new Texture(mImplementation.get(), {0}, TextureType::_2DMultisample);
mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
}
if (getClientVersion() >= Version(3, 2) ||
mSupportedExtensions.textureStorageMultisample2dArrayOES)
{
Texture *zeroTexture2DMultisampleArray =
new Texture(mImplementation.get(), {0}, TextureType::_2DMultisampleArray);
mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
}
if (getClientVersion() >= Version(3, 1))
{
for (int i = 0; i < mState.getCaps().maxAtomicCounterBufferBindings; i++)
{
bindBufferRange(BufferBinding::AtomicCounter, i, {0}, 0, 0);
}
for (int i = 0; i < mState.getCaps().maxShaderStorageBufferBindings; i++)
{
bindBufferRange(BufferBinding::ShaderStorage, i, {0}, 0, 0);
}
}
if (getClientVersion() >= Version(3, 2) || mSupportedExtensions.textureCubeMapArrayAny())
{
Texture *zeroTextureCubeMapArray =
new Texture(mImplementation.get(), {0}, TextureType::CubeMapArray);
mZeroTextures[TextureType::CubeMapArray].set(this, zeroTextureCubeMapArray);
}
if (getClientVersion() >= Version(3, 2) || mSupportedExtensions.textureBufferAny())
{
Texture *zeroTextureBuffer = new Texture(mImplementation.get(), {0}, TextureType::Buffer);
mZeroTextures[TextureType::Buffer].set(this, zeroTextureBuffer);
}
if (mSupportedExtensions.textureRectangleANGLE)
{
Texture *zeroTextureRectangle =
new Texture(mImplementation.get(), {0}, TextureType::Rectangle);
mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
}
if (mSupportedExtensions.EGLImageExternalOES ||
mSupportedExtensions.EGLStreamConsumerExternalNV)
{
Texture *zeroTextureExternal =
new Texture(mImplementation.get(), {0}, TextureType::External);
mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
}
// This may change native TEXTURE_2D, TEXTURE_EXTERNAL_OES and TEXTURE_RECTANGLE,
// binding states. Ensure state manager is aware of this when binding
// this texture type.
if (mSupportedExtensions.videoTextureWEBGL)
{
Texture *zeroTextureVideoImage =
new Texture(mImplementation.get(), {0}, TextureType::VideoImage);
mZeroTextures[TextureType::VideoImage].set(this, zeroTextureVideoImage);
}
mState.initializeZeroTextures(this, mZeroTextures);
ANGLE_CONTEXT_TRY(mImplementation->initialize(mDisplay->getImageLoadContext()));
// Add context into the share group
mState.getShareGroup()->addSharedContext(this);
bindVertexArray({0});
if (getClientVersion() >= Version(3, 0))
{
// [OpenGL ES 3.0.2] section 2.14.1 pg 85:
// In the initial state, a default transform feedback object is bound and treated as
// a transform feedback object with a name of zero. That object is bound any time
// BindTransformFeedback is called with id of zero
bindTransformFeedback(GL_TRANSFORM_FEEDBACK, {0});
}
for (auto type : angle::AllEnums<BufferBinding>())
{
bindBuffer(type, {0});
}
bindRenderbuffer(GL_RENDERBUFFER, {0});
for (int i = 0; i < mState.getCaps().maxUniformBufferBindings; i++)
{
bindBufferRange(BufferBinding::Uniform, i, {0}, 0, -1);
}
// Initialize GLES1 renderer if appropriate.
if (getClientVersion() < Version(2, 0))
{
mGLES1Renderer.reset(new GLES1Renderer());
}
// Initialize dirty bit masks (in addition to what updateCaps() might have set up).
mDrawDirtyObjects |= kDrawDirtyObjectsBase;
mTexImageDirtyObjects |= kTexImageDirtyObjects;
mReadPixelsDirtyObjects |= kReadPixelsDirtyObjectsBase;
mClearDirtyObjects |= kClearDirtyObjects;
mBlitDirtyObjects |= kBlitDirtyObjectsBase;
mComputeDirtyObjects |= kComputeDirtyObjectsBase;
mCopyImageDirtyBits |= kCopyImageDirtyBitsBase;
mCopyImageDirtyObjects |= kCopyImageDirtyObjectsBase;
mOverlay.init();
}
egl::Error Context::onDestroy(const egl::Display *display)
{
if (!mHasBeenCurrent)
{
// Shared objects and ShareGroup must be released regardless.
releaseSharedObjects();
mState.mShareGroup->release(display);
// The context is never current, so default resources are not allocated.
return egl::NoError();
}
mState.ensureNoPendingLink(this);
// eglDestoryContext() must have been called for this Context and there must not be any Threads
// that still have it current.
ASSERT(mIsDestroyed == true && mRefCount == 0);
ANGLE_TRY(unMakeCurrent(display));
// Dump frame capture if enabled.
getShareGroup()->getFrameCaptureShared()->onDestroyContext(this);
// Remove context from the capture share group
getShareGroup()->removeSharedContext(this);
if (mGLES1Renderer)
{
mGLES1Renderer->onDestroy(this, &mState);
}
mDefaultFramebuffer->onDestroy(this);
mDefaultFramebuffer.reset();
for (auto fence : UnsafeResourceMapIter(mFenceNVMap))
{
if (fence.second)
{
fence.second->onDestroy(this);
}
SafeDelete(fence.second);
}
mFenceNVMap.clear();
for (auto query : UnsafeResourceMapIter(mQueryMap))
{
if (query.second != nullptr)
{
query.second->release(this);
}
}
mQueryMap.clear();
for (auto vertexArray : UnsafeResourceMapIter(mVertexArrayMap))
{
if (vertexArray.second)
{
vertexArray.second->onDestroy(this);
}
}
mVertexArrayMap.clear();
for (auto transformFeedback : UnsafeResourceMapIter(mTransformFeedbackMap))
{
if (transformFeedback.second != nullptr)
{
transformFeedback.second->release(this);
}
}
mTransformFeedbackMap.clear();
for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
{
if (zeroTexture.get() != nullptr)
{
zeroTexture.set(this, nullptr);
}
}
releaseShaderCompiler();
mState.reset(this);
releaseSharedObjects();
mImplementation->onDestroy(this);
// Backend requires implementation to be destroyed first to close down all the objects
mState.mShareGroup->release(display);
mOverlay.destroy(this);
return egl::NoError();
}
void Context::releaseSharedObjects()
{
mState.mBufferManager->release(this);
// mProgramPipelineManager must be before mShaderProgramManager to give each
// PPO the chance to release any references they have to the Programs that
// are bound to them before the Programs are released()'ed.
mState.mProgramPipelineManager->release(this);
mState.mShaderProgramManager->release(this);
mState.mTextureManager->release(this);
mState.mRenderbufferManager->release(this);