Skip to content

Commit 653f786

Browse files
committed
feedback
1 parent 82ba9ec commit 653f786

File tree

2 files changed

+43
-58
lines changed

2 files changed

+43
-58
lines changed

filament/backend/include/backend/platforms/PlatformEGL.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <utils/Invocable.h>
2929

3030
#include <initializer_list>
31-
#include <optional>
3231
#include <utility>
3332
#include <vector>
3433

@@ -169,9 +168,7 @@ class PlatformEGL : public OpenGLPlatform {
169168
EGLConfig mEGLConfig = EGL_NO_CONFIG_KHR;
170169
Config mContextAttribs;
171170
std::vector<EGLContext> mAdditionalContexts;
172-
// A cache for MSAA support queries. The index of the vector corresponds to the power of 2 of
173-
// the sample count. For example, index 0 is for 2 samples, 1 is for 4 samples, etc.
174-
mutable std::vector<std::optional<bool>> mMSAASupport{4}; // caches for 2x, 4x, 8x, 16x
171+
bool mMSAA4XSupport;
175172

176173
// supported extensions detected at runtime
177174
struct {
@@ -222,6 +219,8 @@ class PlatformEGL : public OpenGLPlatform {
222219
return makeCurrent(mCurrentContext, drawSurface, readSurface);
223220
}
224221
} egl{ mEGLDisplay };
222+
223+
bool checkIfMSAASwapChainSupported(uint32_t samples) const noexcept;
225224
};
226225

227226
} // namespace filament::backend

filament/backend/src/opengl/platforms/PlatformEGL.cpp

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#endif
3333
#include <utils/compiler.h>
3434

35-
#include <utils/algorithm.h>
3635
#include <utils/Invocable.h>
3736
#include <utils/Logger.h>
3837
#include <utils/debug.h>
@@ -108,7 +107,9 @@ void PlatformEGL::clearGlError() noexcept {
108107

109108
// ---------------------------------------------------------------------------------------------
110109

111-
PlatformEGL::PlatformEGL() noexcept = default;
110+
PlatformEGL::PlatformEGL() noexcept : OpenGLPlatform() {
111+
mMSAA4XSupport = checkIfMSAASwapChainSupported(4);
112+
}
112113

113114
int PlatformEGL::getOSVersion() const noexcept {
114115
return 0;
@@ -492,60 +493,13 @@ bool PlatformEGL::isMSAASwapChainSupported(uint32_t samples) const noexcept {
492493
return true;
493494
}
494495

495-
// The number of samples must be a power-of-two > 1.
496-
if ((samples & (samples - 1)) != 0) {
497-
LOG(INFO) << "The number of samples for MSAA is not a power of two: " << samples;
498-
return false;
496+
if (samples == 4) {
497+
return mMSAA4XSupport;
499498
}
500499

501-
// `samples` is a power-of-two that is greater than 1 (e.g., 2, 4, 8, ...).
502-
// We use this to compute an index into our cache.
503-
const uint32_t power = utils::ctz(samples); // `power` is 3 if the number of samples is 8x.
504-
const uint32_t index = power - 1; // The index 0 originally means 1x, which we don't count.
505-
// So make the index 0 to indicate 2x.
506-
if (mMSAASupport.size() <= index) {
507-
mMSAASupport.resize(index + 1);
508-
}
509-
510-
// Return the cached value if we have one.
511-
if (mMSAASupport[index]) {
512-
return *mMSAASupport[index];
513-
}
514-
515-
// Retrieve the config to see if the given number of samples is supported. The result is cached.
516-
Config configAttribs = {
517-
{ EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT },
518-
{ EGL_RED_SIZE, 8 },
519-
{ EGL_GREEN_SIZE, 8 },
520-
{ EGL_BLUE_SIZE, 8 },
521-
{ EGL_DEPTH_SIZE, 24 },
522-
{ EGL_SAMPLE_BUFFERS, 1 },
523-
{ EGL_SAMPLES, (EGLint)samples },
524-
};
525-
526-
if (!ext.egl.KHR_no_config_context) {
527-
if (isOpenGL()) {
528-
configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_BIT;
529-
} else {
530-
configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_ES2_BIT;
531-
if (ext.egl.KHR_create_context) {
532-
configAttribs[EGL_RENDERABLE_TYPE] |= EGL_OPENGL_ES3_BIT_KHR;
533-
}
534-
}
535-
}
536-
537-
EGLConfig config = EGL_NO_CONFIG_KHR;
538-
EGLint configsCount;
539-
bool supported = false;
540-
if (!eglChooseConfig(mEGLDisplay, configAttribs.data(), &config, 1, &configsCount)) {
541-
supported = false;
542-
} else {
543-
supported = configsCount > 0;
544-
}
545-
546-
mMSAASupport[index] = supported;
547-
548-
return supported;
500+
// Other sample counts are not cached, retrieve it.
501+
LOG(INFO) << "MSAA sample count " << samples << " is queried, consider caching it.";
502+
return checkIfMSAASwapChainSupported(samples);
549503
}
550504

551505
Platform::SwapChain* PlatformEGL::createSwapChain(
@@ -865,6 +819,38 @@ EGLContext PlatformEGL::getContextForType(ContextType type) const noexcept {
865819
}
866820
}
867821

822+
bool PlatformEGL::checkIfMSAASwapChainSupported(uint32_t samples) const noexcept {
823+
// Retrieve the config to see if the given number of samples is supported. The result is cached.
824+
Config configAttribs = {
825+
{ EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT },
826+
{ EGL_RED_SIZE, 8 },
827+
{ EGL_GREEN_SIZE, 8 },
828+
{ EGL_BLUE_SIZE, 8 },
829+
{ EGL_DEPTH_SIZE, 24 },
830+
{ EGL_SAMPLE_BUFFERS, 1 },
831+
{ EGL_SAMPLES, (EGLint)samples },
832+
};
833+
834+
if (!ext.egl.KHR_no_config_context) {
835+
if (isOpenGL()) {
836+
configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_BIT;
837+
} else {
838+
configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_ES2_BIT;
839+
if (ext.egl.KHR_create_context) {
840+
configAttribs[EGL_RENDERABLE_TYPE] |= EGL_OPENGL_ES3_BIT_KHR;
841+
}
842+
}
843+
}
844+
845+
EGLConfig config = EGL_NO_CONFIG_KHR;
846+
EGLint configsCount;
847+
if (!eglChooseConfig(mEGLDisplay, configAttribs.data(), &config, 1, &configsCount)) {
848+
return false;
849+
}
850+
851+
return configsCount > 0;
852+
}
853+
868854
// ---------------------------------------------------------------------------------------------
869855

870856
PlatformEGL::Config::Config() = default;

0 commit comments

Comments
 (0)