Skip to content

Commit aca135a

Browse files
committed
feedback
1 parent 82ba9ec commit aca135a

File tree

2 files changed

+44
-53
lines changed

2 files changed

+44
-53
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: 41 additions & 49 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;
@@ -494,58 +495,17 @@ bool PlatformEGL::isMSAASwapChainSupported(uint32_t samples) const noexcept {
494495

495496
// The number of samples must be a power-of-two > 1.
496497
if ((samples & (samples - 1)) != 0) {
497-
LOG(INFO) << "The number of samples for MSAA is not a power of two: " << samples;
498+
LOG(WARNING) << "The number of samples for MSAA is not a power of two: " << samples;
498499
return false;
499500
}
500501

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;
502+
if (samples == 4) {
503+
return mMSAA4XSupport;
544504
}
545505

546-
mMSAASupport[index] = supported;
547-
548-
return supported;
506+
// Other sample counts are not cached, retrieve it.
507+
LOG(INFO) << "MSAA sample count " << samples << " is queried, consider caching it.";
508+
return checkIfMSAASwapChainSupported(samples);
549509
}
550510

551511
Platform::SwapChain* PlatformEGL::createSwapChain(
@@ -865,6 +825,38 @@ EGLContext PlatformEGL::getContextForType(ContextType type) const noexcept {
865825
}
866826
}
867827

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

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

0 commit comments

Comments
 (0)