Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions filament/backend/include/backend/platforms/PlatformEGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <utils/Invocable.h>

#include <initializer_list>
#include <optional>
#include <utility>
#include <vector>

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

// supported extensions detected at runtime
struct {
Expand Down
33 changes: 30 additions & 3 deletions filament/backend/src/opengl/platforms/PlatformEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#endif
#include <utils/compiler.h>

#include <utils/algorithm.h>
#include <utils/Invocable.h>
#include <utils/Logger.h>
#include <utils/debug.h>
Expand Down Expand Up @@ -491,14 +492,35 @@ bool PlatformEGL::isMSAASwapChainSupported(uint32_t samples) const noexcept {
return true;
}

// The number of samples must be a power-of-two > 1.
if ((samples & (samples - 1)) != 0) {
LOG(INFO) << "The number of samples for MSAA is not a power of two: " << samples;
return false;
}

// `samples` is a power-of-two that is greater than 1 (e.g., 2, 4, 8, ...).
// We use this to compute an index into our cache.
const uint32_t power = utils::ctz(samples); // `power` is 3 if the number of samples is 8x.
const uint32_t index = power - 1; // The index 0 originally means 1x, which we don't count.
// So make the index 0 to indicate 2x.
if (mMSAASupport.size() <= index) {
mMSAASupport.resize(index + 1);
}

// Return the cached value if we have one.
if (mMSAASupport[index]) {
return *mMSAASupport[index];
}

// Retrieve the config to see if the given number of samples is supported. The result is cached.
Config configAttribs = {
{ EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT },
{ EGL_RED_SIZE, 8 },
{ EGL_GREEN_SIZE, 8 },
{ EGL_BLUE_SIZE, 8 },
{ EGL_DEPTH_SIZE, 24 },
{ EGL_SAMPLE_BUFFERS, 1 },
{ EGL_SAMPLES, samples },
{ EGL_SAMPLES, (EGLint)samples },
};

if (!ext.egl.KHR_no_config_context) {
Expand All @@ -514,11 +536,16 @@ bool PlatformEGL::isMSAASwapChainSupported(uint32_t samples) const noexcept {

EGLConfig config = EGL_NO_CONFIG_KHR;
EGLint configsCount;
bool supported = false;
if (!eglChooseConfig(mEGLDisplay, configAttribs.data(), &config, 1, &configsCount)) {
return false;
supported = false;
} else {
supported = configsCount > 0;
}

return configsCount > 0;
mMSAASupport[index] = supported;

return supported;
}

Platform::SwapChain* PlatformEGL::createSwapChain(
Expand Down
Loading