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>
bb10
Laszlo Agocs 2020-06-12 18:00:45 +02:00
parent a0bfa4e1f8
commit 6a8eb26bba
6 changed files with 23 additions and 1 deletions

View File

@ -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.
*/
/*!

View File

@ -1457,7 +1457,8 @@ public:
TexelFetch,
RenderToNonBaseMipLevel,
UIntAttributes,
ScreenSpaceDerivatives
ScreenSpaceDerivatives,
ReadBackAnyTextureFormat
};
enum BeginFrameFlag {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;