summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-06-08 12:16:14 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-06-12 09:26:15 +0200
commiteb72d788fe9d6301e6254fd86d388783c4484873 (patch)
tree68deb45173af3bc9c1c19bccdd87f5cd2ab3d95e /src/gui
parent3f6142f5a1a01f201593f6711930ec77640dea46 (diff)
Add RHI feature check for screen space derivatives
Fragment shader functions like fwidth() are useful for antialiasing distance field text in the case of perspective projections. In order to enable this as an alternative code path, we need to detect support. - OpenGL: Supported with GL_OES_standard_derivatives or GLES3 and up - Direct 3D: Supported for ps_2_x, so always supported on Direct3D 11 - Vulkan/Metal: Always supported Task-number: QTBUG-84695 Change-Id: I5e3fa8014c808a9a2d639305c5e90ec25d44655c Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/opengl/qopenglextensions_p.h1
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp8
-rw-r--r--src/gui/rhi/qrhi_p.h3
-rw-r--r--src/gui/rhi/qrhid3d11.cpp2
-rw-r--r--src/gui/rhi/qrhigles2.cpp3
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h4
-rw-r--r--src/gui/rhi/qrhimetal.mm2
-rw-r--r--src/gui/rhi/qrhivulkan.cpp2
8 files changed, 22 insertions, 3 deletions
diff --git a/src/gui/opengl/qopenglextensions_p.h b/src/gui/opengl/qopenglextensions_p.h
index 137f1e831f..0d58b5f301 100644
--- a/src/gui/opengl/qopenglextensions_p.h
+++ b/src/gui/opengl/qopenglextensions_p.h
@@ -92,6 +92,7 @@ public:
DiscardFramebuffer = 0x00400000,
Sized16Formats = 0x00800000,
TextureSwizzle = 0x01000000,
+ StandardDerivatives = 0x02000000,
};
Q_DECLARE_FLAGS(OpenGLExtensions, OpenGLExtension)
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index a95f064ac5..7c17d3798b 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -376,6 +376,8 @@ static int qt_gl_resolve_extensions()
extensions |= QOpenGLExtensions::PixelBufferObject;
if (extensionMatcher.match("GL_ARB_texture_swizzle") || extensionMatcher.match("GL_EXT_texture_swizzle"))
extensions |= QOpenGLExtensions::TextureSwizzle;
+ if (extensionMatcher.match("GL_OES_standard_derivatives"))
+ extensions |= QOpenGLExtensions::StandardDerivatives;
if (ctx->isOpenGLES()) {
if (format.majorVersion() >= 2)
@@ -388,7 +390,8 @@ static int qt_gl_resolve_extensions()
| QOpenGLExtensions::MapBufferRange
| QOpenGLExtensions::FramebufferBlit
| QOpenGLExtensions::FramebufferMultisample
- | QOpenGLExtensions::Sized8Formats;
+ | QOpenGLExtensions::Sized8Formats
+ | QOpenGLExtensions::StandardDerivatives;
#ifndef Q_OS_WASM
// WebGL 2.0 specification explicitly does not support texture swizzles
// https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.19
@@ -445,6 +448,9 @@ static int qt_gl_resolve_extensions()
if (format.version() >= qMakePair(1, 4) || extensionMatcher.match("GL_SGIS_generate_mipmap"))
extensions |= QOpenGLExtensions::GenerateMipmap;
+ if (format.majorVersion() >= 2)
+ extensions |= QOpenGLExtensions::StandardDerivatives;
+
if (format.majorVersion() >= 3 || extensionMatcher.match("GL_ARB_framebuffer_object")) {
extensions |= QOpenGLExtensions::FramebufferMultisample
| QOpenGLExtensions::FramebufferBlit
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index bd476c3927..9f94fea1dc 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1456,7 +1456,8 @@ public:
ReadBackNonBaseMipLevel,
TexelFetch,
RenderToNonBaseMipLevel,
- UIntAttributes
+ UIntAttributes,
+ ScreenSpaceDerivatives
};
enum BeginFrameFlag {
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index c284e17f46..710ebd62cc 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -479,6 +479,8 @@ bool QRhiD3D11::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::UIntAttributes:
return true;
+ case QRhi::ScreenSpaceDerivatives:
+ return true;
default:
Q_UNREACHABLE();
return false;
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index ebe66f302b..632a5154e7 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -522,6 +522,7 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.texelFetch = caps.ctxMajor >= 3; // 3.0 or ES 3.0
caps.uintAttributes = caps.ctxMajor >= 3; // 3.0 or ES 3.0
+ caps.screenSpaceDerivatives = f->hasOpenGLExtension(QOpenGLExtensions::StandardDerivatives);
if (!caps.gles) {
f->glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
@@ -872,6 +873,8 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
return caps.nonBaseLevelFramebufferTexture;
case QRhi::UIntAttributes:
return caps.uintAttributes;
+ case QRhi::ScreenSpaceDerivatives:
+ return caps.screenSpaceDerivatives;
default:
Q_UNREACHABLE();
return false;
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index 2c393da3b4..03ed81dfb2 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -869,7 +869,8 @@ public:
properMapBuffer(false),
nonBaseLevelFramebufferTexture(false),
texelFetch(false),
- uintAttributes(true)
+ uintAttributes(true),
+ screenSpaceDerivatives(false)
{ }
int ctxMajor;
int ctxMinor;
@@ -904,6 +905,7 @@ public:
uint nonBaseLevelFramebufferTexture : 1;
uint texelFetch : 1;
uint uintAttributes : 1;
+ uint screenSpaceDerivatives : 1;
} caps;
QGles2SwapChain *currentSwapChain = nullptr;
QVector<GLint> supportedCompressedFormats;
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index b249dc55cc..0c42eaa3e9 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -568,6 +568,8 @@ bool QRhiMetal::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::UIntAttributes:
return true;
+ case QRhi::ScreenSpaceDerivatives:
+ return true;
default:
Q_UNREACHABLE();
return false;
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index 59898d3839..fdc80e1e80 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -4050,6 +4050,8 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::UIntAttributes:
return true;
+ case QRhi::ScreenSpaceDerivatives:
+ return true;
default:
Q_UNREACHABLE();
return false;