From df54a5d087d7e3a5cf20bb34fefd8d643a7b2f58 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 4 Apr 2021 15:59:54 +0200 Subject: [PATCH] Add QRhiTexture::RG16 format Those are needed to handle 16bit YUV formats in Qt Multimedia. Change-Id: I39c67bf4fcf558487b7819ea38e578f99c12a3ed Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhi.cpp | 5 +++++ src/gui/rhi/qrhi_p.h | 1 + src/gui/rhi/qrhid3d11.cpp | 4 ++++ src/gui/rhi/qrhigles2.cpp | 13 +++++++++++++ src/gui/rhi/qrhimetal.mm | 2 ++ src/gui/rhi/qrhivulkan.cpp | 4 ++++ 6 files changed, 29 insertions(+) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index fea688e9cd..8c24f11079 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2378,6 +2378,8 @@ QRhiResource::Type QRhiRenderBuffer::resourceType() const \value R16 One component, unsigned normalized 16 bit. + \value RG16 Two component, unsigned normalized 16 bit. + \value RED_OR_ALPHA8 Either same as R8, or is a similar format with the component swizzled to alpha, depending on \l{QRhi::RedOrAlpha8IsRed}{RedOrAlpha8IsRed}. @@ -4533,6 +4535,9 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi case QRhiTexture::R16: bpc = 2; break; + case QRhiTexture::RG16: + bpc = 4; + break; case QRhiTexture::RED_OR_ALPHA8: bpc = 1; break; diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index a4d65a661a..b43d490ea9 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -765,6 +765,7 @@ public: R8, RG8, R16, + RG16, RED_OR_ALPHA8, RGBA16F, diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index addb058d4d..46851ad612 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1214,6 +1214,8 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex return DXGI_FORMAT_R8G8_UNORM; case QRhiTexture::R16: return DXGI_FORMAT_R16_UNORM; + case QRhiTexture::RG16: + return DXGI_FORMAT_R16G16_UNORM; case QRhiTexture::RED_OR_ALPHA8: return DXGI_FORMAT_R8_UNORM; @@ -1300,6 +1302,8 @@ static inline QRhiTexture::Format colorTextureFormatFromDxgiFormat(DXGI_FORMAT f return QRhiTexture::RG8; case DXGI_FORMAT_R16_UNORM: return QRhiTexture::R16; + case DXGI_FORMAT_R16G16_UNORM: + return QRhiTexture::RG16; default: // this cannot assert, must warn and return unknown qWarning("DXGI_FORMAT %d is not a recognized uncompressed color format", format); break; diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index c2035869c3..8eaf02f817 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -160,6 +160,10 @@ QT_BEGIN_NAMESPACE #define GL_R16 0x822A #endif +#ifndef GL_RG16 +#define GL_RG16 0x822C +#endif + #ifndef GL_RED #define GL_RED 0x1903 #endif @@ -822,6 +826,12 @@ static inline void toGlTextureFormat(QRhiTexture::Format format, const QRhiGles2 *glformat = GL_RED; *gltype = GL_UNSIGNED_SHORT; break; + case QRhiTexture::RG16: + *glintformat = GL_RG16; + *glsizedintformat = *glintformat; + *glformat = GL_RG; + *gltype = GL_UNSIGNED_SHORT; + break; case QRhiTexture::R8: *glintformat = GL_R8; *glsizedintformat = *glintformat; @@ -926,6 +936,9 @@ bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture case QRhiTexture::R16: return caps.r16Format; + case QRhiTexture::RG16: + return caps.r16Format; + case QRhiTexture::RGBA16F: case QRhiTexture::RGBA32F: return caps.floatFormats; diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index ab255f74df..850b3a91aa 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -2348,6 +2348,8 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR #endif case QRhiTexture::R16: return MTLPixelFormatR16Unorm; + case QRhiTexture::RG16: + return MTLPixelFormatRG16Unorm; case QRhiTexture::RED_OR_ALPHA8: return MTLPixelFormatR8Unorm; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 26d6de498b..e7e31b1b2d 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -886,6 +886,8 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture return srgb ? VK_FORMAT_R8G8_SRGB : VK_FORMAT_R8G8_UNORM; case QRhiTexture::R16: return VK_FORMAT_R16_UNORM; + case QRhiTexture::RG16: + return VK_FORMAT_R16G16_UNORM; case QRhiTexture::RED_OR_ALPHA8: return VK_FORMAT_R8_UNORM; @@ -993,6 +995,8 @@ static inline QRhiTexture::Format colorTextureFormatFromVkFormat(VkFormat format return QRhiTexture::RG8; case VK_FORMAT_R16_UNORM: return QRhiTexture::R16; + case VK_FORMAT_R16G16_UNORM: + return QRhiTexture::RG16; default: // this cannot assert, must warn and return unknown qWarning("VkFormat %d is not a recognized uncompressed color format", format); break;