Add support for sRGB swapchains
This change adds a 'SRGB' config flag when creating a SwapChain that enables linear to sRGB conversion on write. When using this flag, the linear->srgb conversion in the color grading post processing should be disabled (or, the whole post-processing stage should be disabled). There is also a new query to determine if this flag is supported by the underlaying platform. On Metal, this happens automatically when the underlaying layer is sRGB.
This commit is contained in:
committed by
Mathias Agopian
parent
84e999fe57
commit
eab14da30e
@@ -11,6 +11,7 @@ A new header is inserted each time a *tag* is created.
|
||||
|
||||
- vulkan: fix memory leak in readPixels
|
||||
- engine: added support for draw-commands channels (stronger ordering of commands/renderables)
|
||||
- engine: added support for sRGB swapchains. See `SwapChain.h`
|
||||
|
||||
## v1.31.2
|
||||
|
||||
|
||||
@@ -60,6 +60,11 @@ static constexpr uint64_t SWAP_CHAIN_CONFIG_READABLE = 0x2;
|
||||
*/
|
||||
static constexpr uint64_t SWAP_CHAIN_CONFIG_ENABLE_XCB = 0x4;
|
||||
|
||||
/**
|
||||
* Indicates that the SwapChain must automatically perform linear to srgb encoding.
|
||||
*/
|
||||
static constexpr uint64_t SWAP_CHAIN_CONFIG_SRGB_COLORSPACE = 0x8;
|
||||
|
||||
/**
|
||||
* Indicates that the native window is a CVPixelBufferRef.
|
||||
*
|
||||
|
||||
@@ -68,6 +68,14 @@ public:
|
||||
*/
|
||||
virtual SwapChain* createSwapChain(void* nativeWindow, uint64_t flags) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Return whether createSwapChain supports the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag.
|
||||
* The default implementation returns false.
|
||||
*
|
||||
* @return true is SWAP_CHAIN_CONFIG_SRGB_COLORSPACE is supported, false otherwise.
|
||||
*/
|
||||
virtual bool isSRGBSwapChainSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* Called by the driver create a headless SwapChain.
|
||||
*
|
||||
|
||||
@@ -58,6 +58,7 @@ protected:
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
bool isSRGBSwapChainSupported() const noexcept override;
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
@@ -105,6 +106,7 @@ protected:
|
||||
} gl;
|
||||
struct {
|
||||
bool KHR_no_config_context = false;
|
||||
bool KHR_gl_colorspace = false;
|
||||
} egl;
|
||||
} ext;
|
||||
|
||||
|
||||
@@ -299,6 +299,7 @@ DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameBufferFetchSupported)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameBufferFetchMultiSampleSupported)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameTimeSupported)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isAutoDepthResolveSupported)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isSRGBSwapChainSupported)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(uint8_t, getMaxDrawBuffers)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(math::float2, getClipSpaceParams)
|
||||
DECL_DRIVER_API_SYNCHRONOUS_0(bool, canGenerateMipmaps)
|
||||
|
||||
@@ -706,6 +706,11 @@ bool MetalDriver::isAutoDepthResolveSupported() {
|
||||
return mContext->supportsAutoDepthResolve;
|
||||
}
|
||||
|
||||
bool MetalDriver::isSRGBSwapChainSupported() {
|
||||
// the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag is not supported
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MetalDriver::isWorkaroundNeeded(Workaround workaround) {
|
||||
switch (workaround) {
|
||||
case Workaround::SPLIT_EASU:
|
||||
|
||||
@@ -173,7 +173,11 @@ bool NoopDriver::isAutoDepthResolveSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NoopDriver::isWorkaroundNeeded(Workaround workaround) {
|
||||
bool NoopDriver::isSRGBSwapChainSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NoopDriver::isWorkaroundNeeded(Workaround) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -328,6 +328,12 @@ void OpenGLContext::setDefaultState() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
#if BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GL
|
||||
// we enable GL_FRAMEBUFFER_SRGB to match GLES. This enables sRGB conversion when the
|
||||
// framebuffer has an sRGB attachment. GLES doesn't have an enable for this by default.
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
#endif
|
||||
|
||||
// Point sprite size and seamless cubemap filtering are disabled by default in desktop GL.
|
||||
// In OpenGL ES, these flags do not exist because they are always on.
|
||||
#if BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GL
|
||||
|
||||
@@ -1691,6 +1691,10 @@ bool OpenGLDriver::isAutoDepthResolveSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenGLDriver::isSRGBSwapChainSupported() {
|
||||
return mPlatform.isSRGBSwapChainSupported();
|
||||
}
|
||||
|
||||
bool OpenGLDriver::isWorkaroundNeeded(Workaround workaround) {
|
||||
switch (workaround) {
|
||||
case Workaround::SPLIT_EASU:
|
||||
|
||||
@@ -27,6 +27,10 @@ Driver* OpenGLPlatform::createDefaultDriver(OpenGLPlatform* platform,
|
||||
|
||||
OpenGLPlatform::~OpenGLPlatform() noexcept = default;
|
||||
|
||||
bool OpenGLPlatform::isSRGBSwapChainSupported() const noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t OpenGLPlatform::createDefaultRenderTarget() noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ Driver* PlatformEGL::createDriver(void* sharedContext, const Platform::DriverCon
|
||||
auto extensions = GLUtils::split(eglQueryString(mEGLDisplay, EGL_EXTENSIONS));
|
||||
|
||||
ext.egl.KHR_no_config_context = extensions.has("EGL_KHR_no_config_context");
|
||||
ext.egl.KHR_gl_colorspace = extensions.has("EGL_KHR_gl_colorspace");
|
||||
|
||||
eglCreateSyncKHR = (PFNEGLCREATESYNCKHRPROC) eglGetProcAddress("eglCreateSyncKHR");
|
||||
eglDestroySyncKHR = (PFNEGLDESTROYSYNCKHRPROC) eglGetProcAddress("eglDestroySyncKHR");
|
||||
@@ -281,6 +282,10 @@ EGLConfig PlatformEGL::findSwapChainConfig(uint64_t flags) const {
|
||||
return config;
|
||||
}
|
||||
|
||||
bool PlatformEGL::isSRGBSwapChainSupported() const noexcept {
|
||||
return ext.egl.KHR_gl_colorspace;
|
||||
}
|
||||
|
||||
Platform::SwapChain* PlatformEGL::createSwapChain(
|
||||
void* nativeWindow, uint64_t flags) noexcept {
|
||||
|
||||
@@ -295,8 +300,20 @@ Platform::SwapChain* PlatformEGL::createSwapChain(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EGLint attribs[] = {
|
||||
EGL_NONE, EGL_NONE,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
if (ext.egl.KHR_gl_colorspace) {
|
||||
if (flags & SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) {
|
||||
attribs[0] = EGL_GL_COLORSPACE_KHR;
|
||||
attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR;
|
||||
}
|
||||
}
|
||||
|
||||
EGLSurface sur = eglCreateWindowSurface(mEGLDisplay, config,
|
||||
(EGLNativeWindowType)nativeWindow, nullptr);
|
||||
(EGLNativeWindowType)nativeWindow, attribs);
|
||||
|
||||
if (UTILS_UNLIKELY(sur == EGL_NO_SURFACE)) {
|
||||
logEglError("eglCreateWindowSurface");
|
||||
@@ -323,12 +340,20 @@ Platform::SwapChain* PlatformEGL::createSwapChain(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const EGLint attribs[] = {
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, EGLint(width),
|
||||
EGL_HEIGHT, EGLint(height),
|
||||
EGL_NONE, EGL_NONE,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
if (ext.egl.KHR_gl_colorspace) {
|
||||
if (flags & SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) {
|
||||
attribs[4] = EGL_GL_COLORSPACE_KHR;
|
||||
attribs[5] = EGL_GL_COLORSPACE_SRGB_KHR;
|
||||
}
|
||||
}
|
||||
|
||||
EGLSurface sur = eglCreatePbufferSurface(mEGLDisplay, config, attribs);
|
||||
|
||||
if (UTILS_UNLIKELY(sur == EGL_NO_SURFACE)) {
|
||||
|
||||
@@ -635,6 +635,11 @@ bool VulkanDriver::isAutoDepthResolveSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VulkanDriver::isSRGBSwapChainSupported() {
|
||||
// TODO: implement SWAP_CHAIN_CONFIG_SRGB_COLORSPACE
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VulkanDriver::isWorkaroundNeeded(Workaround workaround) {
|
||||
VkPhysicalDeviceProperties const& deviceProperties = mContext.physicalDeviceProperties;
|
||||
switch (workaround) {
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
namespace filament {
|
||||
|
||||
class Engine;
|
||||
|
||||
/**
|
||||
* A swap chain represents an Operating System's *native* renderable surface.
|
||||
*
|
||||
@@ -182,6 +184,29 @@ public:
|
||||
static const uint64_t CONFIG_APPLE_CVPIXELBUFFER =
|
||||
backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER;
|
||||
|
||||
/**
|
||||
* Indicates that the SwapChain must automatically perform linear to sRGB encoding.
|
||||
*
|
||||
* This flag is ignored if isSRGBSwapChainSupported() is false.
|
||||
*
|
||||
* When using this flag, the output colorspace in ColorGrading should be set to
|
||||
* Rec709-Linear-D65, or post-processing should be disabled.
|
||||
*
|
||||
* @see isSRGBSwapChainSupported()
|
||||
* @see ColorGrading.outputColorSpace()
|
||||
* @see View.setPostProcessingEnabled()
|
||||
*/
|
||||
static constexpr uint64_t CONFIG_SRGB_COLORSPACE = backend::SWAP_CHAIN_CONFIG_SRGB_COLORSPACE;
|
||||
|
||||
/**
|
||||
* Return whether createSwapChain supports the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag.
|
||||
* The default implementation returns false.
|
||||
*
|
||||
* @param engine A pointer to the filament Engine
|
||||
* @return true is SWAP_CHAIN_CONFIG_SRGB_COLORSPACE is supported, false otherwise.
|
||||
*/
|
||||
static bool isSRGBSwapChainSupported(Engine& engine) noexcept;
|
||||
|
||||
void* getNativeWindow() const noexcept;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "details/SwapChain.h"
|
||||
|
||||
#include "details/Engine.h"
|
||||
|
||||
namespace filament {
|
||||
|
||||
void* SwapChain::getNativeWindow() const noexcept {
|
||||
@@ -30,4 +32,8 @@ void SwapChain::setFrameCompletedCallback(FrameCompletedCallback callback, void*
|
||||
return downcast(this)->setFrameCompletedCallback(callback, user);
|
||||
}
|
||||
|
||||
bool SwapChain::isSRGBSwapChainSupported(Engine& engine) noexcept {
|
||||
return FSwapChain::isSRGBSwapChainSupported(downcast(engine));
|
||||
}
|
||||
|
||||
} // namespace filament
|
||||
|
||||
@@ -42,4 +42,8 @@ void FSwapChain::setFrameCompletedCallback(FrameCompletedCallback callback, void
|
||||
mEngine.getDriverApi().setFrameCompletedCallback(mSwapChain, callback, user);
|
||||
}
|
||||
|
||||
bool FSwapChain::isSRGBSwapChainSupported(FEngine& engine) noexcept {
|
||||
return engine.getDriverApi().isSRGBSwapChainSupported();
|
||||
}
|
||||
|
||||
} // namespace filament
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
|
||||
void setFrameCompletedCallback(FrameCompletedCallback callback, void* user);
|
||||
|
||||
static bool isSRGBSwapChainSupported(FEngine& engine) noexcept;
|
||||
|
||||
private:
|
||||
FEngine& mEngine;
|
||||
backend::Handle<backend::HwSwapChain> mSwapChain;
|
||||
|
||||
Reference in New Issue
Block a user