summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-06-12 18:00:45 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-06-15 15:33:39 +0200
commit6a8eb26bbafa32ef6561792c52ec72f80007377a (patch)
tree7623d8511a1ecd9654c8ae2dd41672bc11e8f2e9 /src/gui/rhi
parenta0bfa4e1f8e223927cbb285bb17d1a00a5c2d4b6 (diff)
rhi: Add a feature flag for readback format support
Indicate that doing a QRhiResourceUpdateBatch::readBackTexture() for texture formats other than RGBA/BGRA is not necessarily supported at run time. Change-Id: Ie9ca9546a3af9bff142b875f1ecf26bf26bcc442 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/rhi')
-rw-r--r--src/gui/rhi/qrhi.cpp12
-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/qrhimetal.mm2
-rw-r--r--src/gui/rhi/qrhivulkan.cpp2
6 files changed, 23 insertions, 1 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index f7ecacf456..6e7c975753 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -596,6 +596,18 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
type attributes will be broken. In practice this feature will be unsupported
with OpenGL ES 2.0 and OpenGL 2.x, while it will likely be supported
everywhere else.
+
+ \value ScreenSpaceDerivatives Indicates that functions such as dFdx(),
+ dFdy(), and fwidth() are supported in shaders.
+
+ \value ReadBackAnyTextureFormat Indicates that reading back texture
+ contents can be expected to work for any QRhiTexture::Format. When reported
+ as false, which will typically happen with OpenGL, only the formats
+ QRhiTexture::RGBA8 and QRhiTexture::BGRA8 are guaranteed to be supported
+ for readbacks. In addition, with OpenGL, but not OpenGL ES, reading back
+ the 1 byte per component formats QRhiTexture::R8 and
+ QRhiTexture::RED_OR_ALPHA8 are supported as well. Backends other than
+ OpenGL can be expected to return true for this feature.
*/
/*!
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index 9f94fea1dc..12fd3c46c2 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1457,7 +1457,8 @@ public:
TexelFetch,
RenderToNonBaseMipLevel,
UIntAttributes,
- ScreenSpaceDerivatives
+ ScreenSpaceDerivatives,
+ ReadBackAnyTextureFormat
};
enum BeginFrameFlag {
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index 710ebd62cc..38f2993049 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -481,6 +481,8 @@ bool QRhiD3D11::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::ScreenSpaceDerivatives:
return true;
+ case QRhi::ReadBackAnyTextureFormat:
+ return true;
default:
Q_UNREACHABLE();
return false;
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 383b65cda7..139375fbec 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -875,6 +875,8 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
return caps.uintAttributes;
case QRhi::ScreenSpaceDerivatives:
return caps.screenSpaceDerivatives;
+ case QRhi::ReadBackAnyTextureFormat:
+ return false;
default:
Q_UNREACHABLE();
return false;
@@ -2400,6 +2402,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
const int h = result->pixelSize.height();
if (mipLevel == 0 || caps.nonBaseLevelFramebufferTexture) {
// With GLES, GL_RGBA is the only mandated readback format, so stick with it.
+ // (and that's why we return false for the ReadBackAnyTextureFormat feature)
if (result->format == QRhiTexture::R8 || result->format == QRhiTexture::RED_OR_ALPHA8) {
result->data.resize(w * h);
QByteArray tmpBuf;
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index 0c42eaa3e9..46a121c812 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -570,6 +570,8 @@ bool QRhiMetal::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::ScreenSpaceDerivatives:
return true;
+ case QRhi::ReadBackAnyTextureFormat:
+ return true;
default:
Q_UNREACHABLE();
return false;
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index fdc80e1e80..ad6f5ebd8b 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -4052,6 +4052,8 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
return true;
case QRhi::ScreenSpaceDerivatives:
return true;
+ case QRhi::ReadBackAnyTextureFormat:
+ return true;
default:
Q_UNREACHABLE();
return false;